main.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. }
  35. //订阅消息模板
  36. Vue.prototype.$tmplIds=['QeE-CxbJGd05fo0lGkVa39wj3L5rKeXZclFsyC4am00']
  37. //小程序版本
  38. Vue.prototype.$miniprogramState={
  39. DEVELOPER:'developer', //开发版
  40. TRIAL:'trial', //体验版
  41. FORMAL:'formal',//正式版
  42. }
  43. //封装提示框
  44. Vue.prototype.$showModel = (content,isShowCancel=true,title='提示',)=>{
  45. return new Promise((resolve,reject)=>{
  46. uni.showModal({
  47. title: title,
  48. content: content,
  49. showCancel:isShowCancel,
  50. success: (res)=>{
  51. if (res.confirm) {
  52. resolve(res)
  53. }
  54. }
  55. });
  56. })
  57. }
  58. //封装提示框
  59. Vue.prototype.$showToast=function(title,type,position){
  60. this.$refs.uToast.show({
  61. title: title,
  62. position:position||'top',
  63. type: type ||'success'
  64. })
  65. }
  66. //是否认证登陆
  67. Vue.prototype.$isAuth=()=>{
  68. return simpleCache.get('loginType')
  69. }
  70. //创建时间
  71. Vue.prototype.$createDateTime=()=>{
  72. var mydate = new Date();
  73. var str = "" + mydate.getFullYear() + "-";
  74. //判断小于是是直接小于10月就可以了
  75. if(mydate.getMonth()<10){
  76. str +="0"+ (mydate.getMonth() + 1) + "-";
  77. }else{
  78. str += (mydate.getMonth() + 1) + "-";
  79. }
  80. //判断小于是是直接小于10日就可以了
  81. if(mydate.getDate()<10){
  82. str += "0"+mydate.getDate() + " ";
  83. }else{
  84. str += mydate.getDate() + " ";
  85. }
  86. if(mydate.getHours()<10){
  87. str += "0"+mydate.getHours() + ":";
  88. }else{
  89. str += mydate.getHours() + ":";
  90. }
  91. if(mydate.getMinutes()<10){
  92. str += "0"+mydate.getMinutes() + ":";
  93. }else{
  94. str += mydate.getMinutes() + ":";
  95. }
  96. if(mydate.getSeconds()<10){
  97. str += "0"+mydate.getSeconds();
  98. }else{
  99. str += mydate.getSeconds();
  100. }
  101. return str;
  102. }
  103. //封装判空函数
  104. Vue.prototype.$isEmpty=function(value){
  105. switch (typeof value) {
  106. case 'undefined':
  107. return true;
  108. case 'string':
  109. if(value=='undefined') return true
  110. if (value.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0) return true;
  111. break;
  112. case 'boolean':
  113. if (!value) return true;
  114. break;
  115. case 'number':
  116. if (0 === value || isNaN(value)) return true;
  117. break;
  118. case 'object':
  119. if (null === value || value.length === 0) return true;
  120. for (var i in value) {
  121. return false;
  122. }
  123. return true;
  124. }
  125. return false;
  126. }
  127. Vue.config.productionTip = false
  128. App.mpType = 'app'
  129. const app = new Vue({
  130. ...App
  131. })
  132. //v1.3.5起 H5端 你应该去除原有的app.$mount();使用路由自带的渲染方式
  133. // #ifdef H5
  134. RouterMount(app,router,'#app')
  135. // #endif
  136. // #ifndef H5
  137. app.$mount(); //为了兼容小程序及app端必须这样写才有效果
  138. // #endif