main.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import Vue from 'vue'
  2. import App from './App'
  3. //引入uview组件库
  4. import uView from 'uview-ui';
  5. Vue.use(uView);
  6. import MescrollBody from "@/components/mescroll-body/mescroll-body.vue"
  7. Vue.component('mescroll-body', MescrollBody)
  8. //引入路由拦截
  9. import {router,RouterMount} from './router.js' //路径换成自己的
  10. Vue.use(router)
  11. //封装api
  12. import { api } from 'assets/http/api.js'
  13. Vue.prototype.$api = api
  14. //引入util.js
  15. import Util from 'utils/util.js'
  16. Vue.prototype.$util = Util
  17. //封装缓存
  18. import simpleCache from "@/utils/cache.js"
  19. Vue.prototype.$cache = simpleCache
  20. //登陆类型
  21. Vue.prototype.$loginType={
  22. STAFF:'staff',
  23. ENTERPRISE:'enterprise',
  24. AGENCY:'agency'
  25. }
  26. //设备类型【通过前缀查找】
  27. Vue.prototype.$device_prefix={
  28. SMOKE:'ctwing/smoke3',//烟感
  29. GAS:'ctwing/gasmonitoring',//气感,燃气监控
  30. }
  31. //设备类型【通过设备类型查找】
  32. Vue.prototype.$device_type={
  33. FIRE_HYDRANT:'960417', //消防栓
  34. ELECTRIC_METER:'100030'//电表
  35. }
  36. //订阅消息模板
  37. Vue.prototype.$tmplIds=['QeE-CxbJGd05fo0lGkVa39wj3L5rKeXZclFsyC4am00']
  38. //小程序版本
  39. Vue.prototype.$miniprogramState={
  40. DEVELOPER:'developer', //开发版
  41. TRIAL:'trial', //体验版
  42. FORMAL:'formal',//正式版
  43. }
  44. //封装提示框
  45. Vue.prototype.$showModel = (content,isShowCancel=true,title='提示',)=>{
  46. return new Promise((resolve,reject)=>{
  47. uni.showModal({
  48. title: title,
  49. content: content,
  50. showCancel:isShowCancel,
  51. success: (res)=>{
  52. if (res.confirm) {
  53. resolve(res)
  54. }
  55. }
  56. });
  57. })
  58. }
  59. //封装提示框
  60. Vue.prototype.$showToast=function(title,type,position){
  61. this.$refs.uToast.show({
  62. title: title,
  63. position:position||'top',
  64. type: type ||'success'
  65. })
  66. }
  67. //是否认证登陆
  68. Vue.prototype.$isAuth=()=>{
  69. return simpleCache.get('loginType')
  70. }
  71. //创建时间
  72. Vue.prototype.$createDateTime=()=>{
  73. var mydate = new Date();
  74. var str = "" + mydate.getFullYear() + "-";
  75. //判断小于是是直接小于10月就可以了
  76. if(mydate.getMonth()<10){
  77. str +="0"+ (mydate.getMonth() + 1) + "-";
  78. }else{
  79. str += (mydate.getMonth() + 1) + "-";
  80. }
  81. //判断小于是是直接小于10日就可以了
  82. if(mydate.getDate()<10){
  83. str += "0"+mydate.getDate() + " ";
  84. }else{
  85. str += mydate.getDate() + " ";
  86. }
  87. if(mydate.getHours()<10){
  88. str += "0"+mydate.getHours() + ":";
  89. }else{
  90. str += mydate.getHours() + ":";
  91. }
  92. if(mydate.getMinutes()<10){
  93. str += "0"+mydate.getMinutes() + ":";
  94. }else{
  95. str += mydate.getMinutes() + ":";
  96. }
  97. if(mydate.getSeconds()<10){
  98. str += "0"+mydate.getSeconds();
  99. }else{
  100. str += mydate.getSeconds();
  101. }
  102. return str;
  103. }
  104. //封装判空函数
  105. Vue.prototype.$isEmpty=function(value){
  106. switch (typeof value) {
  107. case 'undefined':
  108. return true;
  109. case 'string':
  110. if(value=='undefined') return true
  111. if (value.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0) return true;
  112. break;
  113. case 'boolean':
  114. if (!value) return true;
  115. break;
  116. case 'number':
  117. if (0 === value || isNaN(value)) return true;
  118. break;
  119. case 'object':
  120. if (null === value || value.length === 0) return true;
  121. for (var i in value) {
  122. return false;
  123. }
  124. return true;
  125. }
  126. return false;
  127. }
  128. Vue.config.productionTip = false
  129. App.mpType = 'app'
  130. const app = new Vue({
  131. ...App
  132. })
  133. //v1.3.5起 H5端 你应该去除原有的app.$mount();使用路由自带的渲染方式
  134. // #ifdef H5
  135. RouterMount(app,router,'#app')
  136. // #endif
  137. // #ifndef H5
  138. app.$mount(); //为了兼容小程序及app端必须这样写才有效果
  139. // #endif