main.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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 'element-ui/lib/theme-chalk/index.css';
  5. import App from './App';
  6. import router from './router';
  7. import { message } from './util/resetMessage';
  8. import CryptoJS from 'crypto-js';
  9. import NProgress from 'nprogress';
  10. import 'nprogress/nprogress.css';
  11. import './util/http.js';
  12. import { VueJsonp } from 'vue-jsonp';
  13. import JSONView from 'vue-json-viewer';
  14. import store from '@/store/store.js';
  15. // 打印
  16. import Print from 'vue-print-nb';
  17. // 滚动
  18. import scroll from 'vue-seamless-scroll';
  19. // 三级权限查询
  20. import { QueryPermission } from './util/QueryPermission';
  21. import './plugin/index';
  22. import VueLazyLoad from 'vue-lazyload';
  23. import VueClipBoard from 'vue-clipboard2'
  24. // 使用VueClipBoard插件,主要功能:类似于剪切板
  25. // import 'babel-polyfill'; // 兼容IE11
  26. // import promise from 'es6-promise'
  27. // promise.polyfill();
  28. // 导入全局样式
  29. // import './assets/css/global.css'
  30. // 样式
  31. import './assets/icon/iconfont.css';
  32. import './assets/css/theme/ffffff/index.css'; // 皮肤一
  33. import './assets/css/theme/hhhh/index.css'; // 皮肤一
  34. // import '../theme/index.css' //皮肤一
  35. import VueHighcharts from 'vue-highcharts';
  36. import Viewer from 'v-viewer';
  37. import 'viewerjs/dist/viewer.css';
  38. import './assets/svg'; // icon
  39. // 引入百度地图
  40. import BaiduMap from 'vue-baidu-map';
  41. import { BmPolygon, BmControl, BmMarker } from 'vue-baidu-map';
  42. // 动态网站标题
  43. import VueWechatTitle from 'vue-wechat-title';
  44. // 导入全局样式
  45. import './assets/css/global.css';
  46. import './assets/css/listCard.less';
  47. // 图片放大
  48. import preview from 'vue-photo-preview';
  49. import 'vue-photo-preview/dist/skin.css';
  50. // 图片裁剪
  51. import VueCropper from 'vue-cropper';
  52. import { loginPath, isFJ } from '@/util/constants';
  53. // 格式化时间戳
  54. import './util/formatTime';
  55. // 引入全局组件
  56. import Dialog from '@/components/Dialog';
  57. import Drawer from '@/components/Drawer';
  58. Vue.use(VueClipBoard)// 使用剪切板
  59. Vue.use(VueHighcharts);
  60. // let Vue = require('vue')
  61. // Vue=Vue.default
  62. Vue.config.productionTip = false;
  63. Vue.config.devtools = true;
  64. // import ElementUI from 'element-ui';
  65. const ElementUI = require('element-ui');
  66. // import axios from 'axios'
  67. // import VueAMap from 'vue-amap';
  68. // const ElementUI = require('element-ui')
  69. const axios = require('axios');
  70. const Qs = require('qs');
  71. Vue.prototype.$axios = axios; // 全局注册,使用方法为:this.$axios
  72. Vue.prototype.$EventBus = new Vue(); // 解决百度地图跨域
  73. Vue.use(VueJsonp); // JSON格式化高亮
  74. Vue.use(JSONView); // JSON格式化高亮
  75. // import qs from 'qs'
  76. Vue.prototype.qs = Qs; // 全局注册,使用方法为:this.qs
  77. Vue.prototype.$EventBus = new Vue(); // 中央时间总线
  78. Vue.use(ElementUI);
  79. Vue.prototype.$resetMessage = message;
  80. Vue.prototype.$store = store;
  81. // 注册
  82. Vue.use(Print);
  83. Vue.use(scroll);
  84. // Vue.use(QueryPermission)
  85. Vue.prototype.$QueryPermission = QueryPermission;
  86. Vue.component('CommonDialog', Dialog);
  87. Vue.component('CommonDrawer', Drawer);
  88. // 节流
  89. function throttle() {
  90. let prev = 0;
  91. Vue.prototype.$throttle = function(func, wait) {
  92. let now = Date.now();
  93. if (now - prev > wait) {
  94. func.apply(this);
  95. prev = now;
  96. }
  97. };
  98. }
  99. throttle();
  100. // 全局过滤 - 文本超出显示省略号 - -目前只在杀虫灯列表中使用
  101. Vue.filter('csdname', function(value) {
  102. if (!value) return '';
  103. if (value.length > 6) {
  104. return value.slice(0, 6) + '...';
  105. }
  106. return value;
  107. });
  108. // 实时监听本地存储
  109. Vue.prototype.resetSetItem = function(key, newVal) {
  110. if (key === 'btnName') {
  111. // 创建一个StorageEvent事件
  112. var newStorageEvent = document.createEvent('StorageEvent');
  113. const storage = {
  114. setItem: function(k, val) {
  115. sessionStorage.setItem(k, val);
  116. // 初始化创建的事件
  117. newStorageEvent.initStorageEvent(
  118. 'setItem',
  119. false,
  120. false,
  121. k,
  122. null,
  123. val,
  124. null,
  125. null
  126. );
  127. // 派发对象
  128. window.dispatchEvent(newStorageEvent);
  129. }
  130. };
  131. return storage.setItem(key, newVal);
  132. }
  133. };
  134. Vue.use(VueLazyLoad, {
  135. preLoad: 1,
  136. error: require('./assets/images/newImg/noimage.png'),
  137. loading: require('./assets/images/newImg/shot-1.gif'),
  138. attempt: 2
  139. });
  140. // Vue.prototype.jsonUrl = 'http://8.136.98.49'; //地图三级下钻页面使用-韩有波
  141. Vue.prototype.$amapKey = 'b96a1c32b0bb828f1d153b219fa59ecc'; // 高德地图 web服务 key
  142. Vue.prototype.$imageURL = 'https://s3.hnyfwlw.com/webstaticimg'; // 线上图片服务器路径常量1
  143. Vue.prototype.$imghost = 'https://s3.hnyfwlw.com/webstaticimg/projectimg'; // 线上图片服务器路径常量2
  144. Vue.prototype.$insectHost = 'https://images.weserv.nl/?url='; // 线上图片服务器路径常量
  145. Vue.prototype.$deriveData = Vue.prototype.DOMIN; // 导出
  146. // Vue.prototype.$deriveData = 'http://192.168.1.112:8002' // 导出
  147. Vue.prototype.$faultvideo = 'http://192.168.1.3:8000'; // 售后视频地址前缀
  148. Vue.config.productionTip = false;
  149. Vue.use(Viewer, {
  150. defaultOptions: {
  151. zIndex: 9999
  152. }
  153. });
  154. Vue.use(BaiduMap, BmPolygon, BmControl, BmMarker, {
  155. ak: 'pAT8YhkMx1HVQIWOLZcYoQAty1myB4Sn'
  156. });
  157. Vue.use(VueWechatTitle);
  158. Vue.use(preview);
  159. Vue.use(VueCropper);
  160. // 设备类型
  161. Vue.filter('equipType', function(i) {
  162. switch (i) {
  163. case '2':
  164. return '杀虫灯';
  165. case '3':
  166. return '虫情测报灯';
  167. case '4':
  168. return '性诱测报';
  169. case '5':
  170. return '环境监测';
  171. case '6':
  172. return '监控';
  173. case '7':
  174. return '孢子仪';
  175. case '8':
  176. return '性诱3.0';
  177. case '9':
  178. return '糖醋测报';
  179. case '10':
  180. return '性诱2.0';
  181. case '11':
  182. return '小麦赤霉病';
  183. case '12':
  184. return '吸虫塔';
  185. case '13':
  186. return '水肥一体化';
  187. case '14':
  188. return '虫害可视监测';
  189. case '15':
  190. return '管式墒情';
  191. case '16':
  192. return '温室大棚';
  193. case '17':
  194. return '水电双计';
  195. case '18':
  196. return '水肥一体化';
  197. case '19':
  198. return '玉米大斑病';
  199. case '20':
  200. return '小麦条锈病';
  201. }
  202. });
  203. Vue.directive('btnRight', {
  204. inserted: function(el, binding, vnode) {
  205. const optName = binding.arg;
  206. const routeName = binding.value.slice(7); // 路由地址
  207. const authName = `${routeName}_${optName}`; // 这里根据路由名和操作类型拼出按钮名 overview-edit
  208. const btnRightList = store.getters.btnRight;
  209. if (btnRightList[authName] == 0) {
  210. el.parentNode.removeChild(el);
  211. } else if (btnRightList[authName] == 1) {
  212. }
  213. }
  214. });
  215. let webTitle = '大数据平台';
  216. var getPath = arr => {
  217. const firstMenu = 'systemManagement';
  218. const secondMenu = 'userManger';
  219. const thirdMenu = 'add_user_purview';
  220. const firstData = arr.children.find(v => v.menu === firstMenu);
  221. if (firstData) {
  222. const secondData = firstData.children.find(v => v.menu === secondMenu);
  223. if (secondData) {
  224. const thirdData = secondData.children.find(v => v.menu === thirdMenu);
  225. if (thirdData) {
  226. return true;
  227. } else {
  228. return false;
  229. }
  230. } else {
  231. return false;
  232. }
  233. } else {
  234. return false;
  235. }
  236. };
  237. router.beforeEach(async (to, from, next) => {
  238. // console.log(to.path, to.name, from);
  239. let isSy =
  240. to.path.indexOf('syIndex') != -1 ||
  241. to.path.indexOf('syLogin') != -1 ||
  242. to.path.indexOf('bsy_park') != -1 ||
  243. to.path.indexOf('sySys_v2_1') != -1 ||
  244. to.path.indexOf('syIndex_v2_1') != -1 ||
  245. to.path.indexOf('syLogin_v2_1') != -1 ||
  246. to.path.indexOf('/syM/') != -1 ||
  247. to.path.indexOf('/syM_v2_1/') != -1 ||
  248. to.path.indexOf('/syLoading') != -1 ||
  249. to.name == 'downApk' ||
  250. to.name == 'downApk_v2_1' ||
  251. to.name == 'bSy_v2';
  252. NProgress.start();
  253. if (to.meta.title) {
  254. // document.title = to.meta.title + ' - ' + webTitle;
  255. if (to.meta.isAbsoluteTitle) {
  256. document.title = to.meta.title;
  257. } else {
  258. document.title = webTitle + ' - ' + to.meta.title;
  259. }
  260. } else {
  261. document.title = webTitle;
  262. }
  263. if (to.meta.title == '数联设备预警页' || to.meta.title == '农产品溯源系统') {
  264. document.title = to.meta.title;
  265. }
  266. const isLogin = store.state.isLogin; // 大数据平台登录状态
  267. if (to.path == '/login' || to.path == '/fjlogin') {
  268. if (isLogin) {
  269. if (isFJ) {
  270. next({
  271. path: '/fengjiang/index'
  272. });
  273. } else {
  274. next({
  275. path: '/index/' + store.state.firstPage
  276. });
  277. }
  278. } else {
  279. next();
  280. }
  281. } else if (
  282. to.path == '/recognition' ||
  283. to.path == '/externalindex' ||
  284. to.path == '/warning' ||
  285. to.path == '/qualitytesting' ||
  286. to.path == '/qualitytestinginfo' ||
  287. to.path == '/pestanalysis' ||
  288. to.path == '/retrospect' ||
  289. to.path == '/recognitionpaddyfield' ||
  290. to.path == '/external-env-setting' ||
  291. to.path == '/external-env-setting/list' ||
  292. to.path == '/external-env-setting/factor' ||
  293. to.path == '/external-env-setting/sensor' ||
  294. to.name == 'TracebackDetailApp' ||
  295. to.name == 'TracebackDetail' ||
  296. to.name == 'FaultUp' ||
  297. to.name == 'expertDatabase' ||
  298. to.name == 'cbdFile' ||
  299. to.name == 'scdFile' ||
  300. to.name == 'bzyFile' ||
  301. to.name == 'xycbFile' ||
  302. to.name == 'qxzFile' ||
  303. to.name == 'nlxyFile' ||
  304. to.name == 'sqtxFile' ||
  305. to.name == 'xctFile'
  306. ) {
  307. next();
  308. } else {
  309. // 白名单
  310. // //console.log(to.query.token)
  311. if (to.query.type == 'xctx') {
  312. var key = 'hnyfkj_yfb_zhang';
  313. var iv = 11;
  314. let secreIv = CryptoJS.enc.Utf8.parse(iv);
  315. let secreKey = CryptoJS.enc.Utf8.parse(key);
  316. let decrypt = CryptoJS.AES.decrypt(to.query.username, secreKey, {
  317. iv: secreIv,
  318. mode: CryptoJS.mode.ECB,
  319. padding: CryptoJS.pad.Pkcs7
  320. });
  321. let decrypt2 = CryptoJS.AES.decrypt(to.query.passwold, secreKey, {
  322. iv: secreIv,
  323. mode: CryptoJS.mode.ECB,
  324. padding: CryptoJS.pad.Pkcs7
  325. });
  326. var username = CryptoJS.enc.Utf8.stringify(decrypt);
  327. var password = CryptoJS.enc.Utf8.stringify(decrypt2);
  328. axios({
  329. method: 'POST',
  330. url: '/api/api_gateway?method=user.login.login_user',
  331. data: Qs.stringify({
  332. username: username,
  333. password: password
  334. })
  335. }).then(res => {
  336. if (res.data.message == '') {
  337. // 菜单第一项
  338. let first = res.data.data.data.children[0];
  339. // console.log(first);
  340. let firstPage = '';
  341. // console.log(res.data.data.data);
  342. const isNotToIndex = res.data.data.data.children.find(
  343. v => v.menu === 'bHome'
  344. );
  345. localStorage.setItem('isQuanXian', getPath(res.data.data.data)); // 当前用户权限
  346. if (first.children) {
  347. firstPage = first.children[0].menu; // 有二级菜单
  348. } else {
  349. firstPage = first.menu; // 首页
  350. }
  351. localStorage.setItem('firstPage', firstPage);
  352. localStorage.setItem('cUsername', res.data.params.username);
  353. if (to.path == '/index/pestsStats') {
  354. next({
  355. path: to.path + '?identify_model=A'
  356. });
  357. } else {
  358. next({
  359. path: to.path
  360. });
  361. }
  362. } else {
  363. next({
  364. path: loginPath
  365. });
  366. }
  367. });
  368. } else if (to.query.type == 'dhkj') {
  369. // 针对大华 登录
  370. // 校验token
  371. axios({
  372. method: 'POST',
  373. url: '/api/api_gateway?method=user.login.dh_login_user',
  374. data: Qs.stringify({
  375. dh_token: to.query.token,
  376. addr: to.query.addr,
  377. uid: to.query.uid,
  378. type: to.query.type
  379. })
  380. }).then(res => {
  381. if (res.data.message == '') {
  382. // console.log(res.data.data.data);
  383. // 菜单第一项
  384. let first = res.data.data.data.children[0];
  385. let firstPage = '';
  386. // console.log(res.data.data.data);
  387. // const isNotToIndex = res.data.data.data.children.find(
  388. // v => v.menu === 'bHome'
  389. // );
  390. // 去除中间页跳转
  391. const isNotToIndex = false
  392. localStorage.setItem('isQuanXian', getPath(res.data.data.data)); // 当前用户权限
  393. if (isNotToIndex) {
  394. // this.$router.push("/SwitchPages");
  395. next({
  396. path: '/SwitchPages'
  397. });
  398. } else {
  399. if (first.children) {
  400. firstPage = first.children[0].menu; // 有二级菜单
  401. } else {
  402. firstPage = first.menu; // 首页
  403. }
  404. let selHome = sessionStorage.getItem('selHome');
  405. if (selHome) {
  406. next({
  407. path: selHome
  408. });
  409. } else {
  410. next({
  411. path: '/index/' + firstPage
  412. });
  413. localStorage.setItem('firstPage', firstPage);
  414. }
  415. }
  416. // console.log(res);
  417. localStorage.setItem('cUsername', res.data.params.username);
  418. next();
  419. } else {
  420. next({
  421. path: loginPath
  422. });
  423. }
  424. });
  425. // next({
  426. // path: '/login'
  427. // });
  428. } else if (isLogin) {
  429. next();
  430. } else {
  431. try {
  432. if (!isSy) {
  433. // 进入大数据平台
  434. var box = document.getElementById('app-loading');
  435. box.style.zIndex = '1000';
  436. var boxText = document.getElementById('app-loading-text');
  437. boxText.innerText = '玩命加载中...';
  438. // 获取用户信息和权限信息及网站信息
  439. await store.dispatch('loginUsersCheck');
  440. await store.dispatch('getUserInfo');
  441. const userName = await store.dispatch('getNavList');
  442. boxText.innerText = '欢迎您,' + userName;
  443. if (to.path == '/') {
  444. if (isFJ) {
  445. next({
  446. path: '/fengjiang/index'
  447. });
  448. } else {
  449. next({
  450. path: '/index/' + store.state.firstPage
  451. });
  452. }
  453. } else {
  454. next({
  455. ...to,
  456. replace: true
  457. });
  458. }
  459. } else {
  460. // //console.log(to, from, 'to, from')
  461. // 进入溯源系统
  462. document.title = '溯源平台';
  463. let sy_isLogin = sessionStorage.getItem('sy_isLogin'); // 溯源2.0登录状态
  464. if (to.path === '/syLogin') {
  465. // 溯源2.0登录
  466. if (sy_isLogin) {
  467. next('/syLoading');
  468. } else {
  469. next();
  470. }
  471. } else if (to.path === '/syLogin_v2_1') {
  472. // 溯源2.1
  473. if (sy_isLogin == true) {
  474. next('/syLoading_v2_1');
  475. } else {
  476. next();
  477. }
  478. } else if (to.path === '/syLoading') {
  479. // 进入的是2.0
  480. next('/syIndex');
  481. } else if (to.path === '/syLoading_v2_1') {
  482. // 进入的是2.1
  483. next('/syIndex_v2_1');
  484. } else if (
  485. to.name === 'sanCode' ||
  486. to.name === 'downApk' ||
  487. to.name === 'sanCode_v2_1' ||
  488. to.name === 'downApk_v2_1'
  489. ) {
  490. // 扫溯源码页面,扫码下载app页面
  491. next();
  492. } else if (to.path.indexOf('/syM/') != -1) {
  493. // 操作员手机端
  494. next();
  495. } else {
  496. if (sy_isLogin) {
  497. next();
  498. } else {
  499. next('/syLogin');
  500. }
  501. }
  502. }
  503. } catch (error) {
  504. await store.dispatch('loginOut');
  505. next({
  506. path: loginPath
  507. });
  508. }
  509. }
  510. }
  511. });
  512. router.afterEach(() => {
  513. NProgress.done();
  514. var box = document.getElementById('app-loading');
  515. box.style.zIndex = '-1';
  516. });
  517. /* eslint-disable no-new */
  518. new Vue({
  519. el: '#app',
  520. router,
  521. store,
  522. components: {
  523. App
  524. },
  525. template: '<App/>'
  526. });