main.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue'
  4. import ElementUI from 'element-ui';
  5. // import 'element-ui/lib/theme-chalk/index.css';
  6. import App from './App'
  7. import router from './router'
  8. import axios from 'axios'
  9. Vue.prototype.$axios = axios //全局注册,使用方法为:this.$axios
  10. Vue.prototype.$EventBus = new Vue()
  11. import './util/http.js'
  12. import {
  13. VueJsonp
  14. } from 'vue-jsonp' //解决百度地图跨域
  15. Vue.use(VueJsonp)
  16. import qs from 'qs'
  17. Vue.prototype.qs = qs //全局注册,使用方法为:this.qs
  18. Vue.prototype.$EventBus = new Vue() //中央时间总线
  19. Vue.use(ElementUI);
  20. import { Message } from 'element-ui';
  21. //定义一个新的Message方法,多传入一个offset参数
  22. const $message = options => {
  23. return Message({
  24. ...options,
  25. offset: 160,
  26. type: options.type
  27. });
  28. };
  29. //重写一遍success的方法,将offset写入options
  30. ['success', 'warning', 'info', 'error'].forEach(type => {
  31. $message[type] = options => {
  32. if (typeof options === 'string') {
  33. options = {
  34. message: options,
  35. offset: 160
  36. };
  37. }
  38. options.type = type;
  39. return Message(options);
  40. };
  41. });
  42. //将$message挂载到this上
  43. Vue.prototype.$message = $message;
  44. //节流
  45. function throttle(){
  46. let prev=0
  47. Vue.prototype.$throttle = function(func,wait){
  48. let now=Date.now()
  49. if(now-prev>wait){
  50. func.apply(this)
  51. prev=now
  52. }
  53. }
  54. }
  55. throttle()
  56. import VueLazyLoad from 'vue-lazyload'
  57. Vue.use(VueLazyLoad, {
  58. preLoad: 1,
  59. // error: require('./assets/images/noimage.png'),
  60. error: require('./assets/images/newImg/noimage.png'),
  61. // loading: require('./assets/images/shot-1.gif'),
  62. loading: require('./assets/images/newImg/shot-1.gif'),
  63. attempt: 2,
  64. })
  65. Vue.prototype.jsonUrl = 'http://182.92.193.64'; //地图三级下钻页面使用-韩有波
  66. Vue.prototype.$imghost = 'http://static.yfpyx.com/projectimg' // 线上图片服务器路径常量
  67. Vue.prototype.$insectHost = 'https://images.weserv.nl/?url=' // 线上图片服务器路径常量
  68. Vue.prototype.$deriveData = 'http://114.115.147.140:8002' // 导出
  69. Vue.prototype.$faultvideo = 'http://192.168.1.3:8000' //售后视频地址前缀
  70. Vue.config.productionTip = false
  71. import 'babel-polyfill' //兼容IE11
  72. require("babel-polyfill")
  73. import promise from 'es6-promise'
  74. promise.polyfill();
  75. //导入全局样式
  76. import './assets/css/global.css'
  77. // 样式
  78. import './assets/icon/iconfont.css'
  79. // import './assets/css/theme/ffffff/index.css' //皮肤一
  80. import '../theme/index.css' //皮肤一
  81. import VueHighcharts from 'vue-highcharts';
  82. Vue.use(VueHighcharts);
  83. import Viewer from 'v-viewer'
  84. Vue.use(Viewer, {
  85. defaultOptions: {
  86. "zIndex": 9999,
  87. }
  88. })
  89. import 'viewerjs/dist/viewer.css'
  90. // 高德
  91. // import VueAMap from 'vue-amap';
  92. // Vue.use(VueAMap);
  93. // VueAMap.initAMapApiLoader({
  94. // key: '3939967b919a8003377dd113fc445a3d',
  95. // plugin: ['AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType','AMap.Geocoder','AMap.Geolocation','AMap.MouseTool'],
  96. // v: '1.4.4'
  97. // });
  98. // // 引入百度地图
  99. // import BaiduMap from 'vue-baidu-map'
  100. // import {
  101. // BmPolygon,
  102. // BmControl,
  103. // BmMarker
  104. // } from 'vue-baidu-map'
  105. // Vue.use(BaiduMap, BmPolygon, BmControl, BmMarker, {
  106. // ak: 'nroAiX0Lf6ppNEGt2dBLtDkOldGCPFwF'
  107. // })
  108. //导入全局样式
  109. import './assets/css/global.css'
  110. // 图片放大
  111. import preview from 'vue-photo-preview'
  112. import 'vue-photo-preview/dist/skin.css'
  113. Vue.use(preview)
  114. // 图片裁剪
  115. import VueCropper from 'vue-cropper'
  116. Vue.use(VueCropper)
  117. import animated from 'animate.css' // npm install animate.css --save-dev安装,再引入
  118. Vue.use(animated)
  119. //格式化时间戳
  120. import './util/formatTime'
  121. //设备类型
  122. Vue.filter('equipType', function (i) {
  123. switch (i) {
  124. case '2':
  125. return '杀虫灯';
  126. break;
  127. case '3':
  128. return '虫情测报灯';
  129. break;
  130. case '4':
  131. return '性诱测报';
  132. break;
  133. case '5':
  134. return '环境监测';
  135. break;
  136. case '6':
  137. return '监控';
  138. break;
  139. case '7':
  140. return '孢子仪';
  141. break;
  142. case '9':
  143. return '糖醋测报';
  144. break;
  145. case 2:
  146. return '杀虫灯';
  147. break;
  148. case 3:
  149. return '虫情测报灯';
  150. break;
  151. case 4:
  152. return '性诱测报';
  153. break;
  154. case 5:
  155. return '环境监测';
  156. break;
  157. case 6:
  158. return '监控';
  159. break;
  160. case 7:
  161. return '孢子仪';
  162. break;
  163. case 9:
  164. return '糖醋测报';
  165. break;
  166. }
  167. })
  168. // 弹框拖拽
  169. import './util/directives.js'
  170. // 弹框样式
  171. import '@/assets/css/form.css'
  172. router.beforeEach((to, from, next) => {
  173. let isLogin = JSON.parse(localStorage.getItem('isLogin'));
  174. if (to.path === '/login') {
  175. if (isLogin) {
  176. next('/plantGuard') //登录后默认跳转到首页
  177. } else {
  178. next()
  179. }
  180. } else if (to.name == 'PlantGuard') {
  181. next()
  182. } else {
  183. // let type = to.meta.login_require; //是否需要登录,为了解决扫码在手机上看
  184. axios({
  185. method: 'POST',
  186. url: '/api/api_gateway?method=user.login.users_check'
  187. }).then(res => {
  188. if (res.data.data == 1) { //登录状态
  189. // console.log('check_success');
  190. localStorage.setItem("isLogin", true)
  191. next()
  192. // checkLoginRequire(type, isLogin, next)
  193. } else { //session过期
  194. // console.log('check_false');
  195. localStorage.setItem("isLogin", false)
  196. next('/login');
  197. }
  198. }, err => {
  199. // console.log('check_error');
  200. localStorage.setItem("isLogin", false);
  201. next('/login');
  202. })
  203. }
  204. })
  205. // 引入vuex-store
  206. import store from './store/store';
  207. /* eslint-disable no-new */
  208. new Vue({
  209. el: '#app',
  210. router,
  211. store,
  212. components: { App },
  213. template: '<App/>'
  214. })