/* * @Author: zouwenying * @Date: 2020-10-21 18:14:35 * @LastEditTime: 2020-11-18 16:28:23 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \vue-manage-system-master\src\main.js */ import Vue from 'vue'; import App from './App.vue'; import router from './router'; import { funcRouter } from './router/dynamicMuen'; import Vuex from 'vuex'; import ElementUI from 'element-ui'; import commonComponents from './components/common'; import 'element-ui/lib/theme-chalk/index.css'; // 默认主题 import moment from 'moment'; moment.locale('zh-cn'); import './assets/css/icon.css'; import './assets/css/main.scss'; import './assets/css/element-variables.scss'; import '@utils/rem.js'; import '@utils/AmapSearch.js'; import directiveInit from '@utils/directives'; import directived from '@utils/directived'; import http from '@utils/http.js'; import apiService from './api/index'; import store from './store/store.js'; import '@utils/utils.js'; import 'babel-polyfill'; // 过滤 import filter from './utils/filters'; Object.keys(filter).forEach((key) => Vue.filter(key, filter[key])); // 滚动条 import GeminiScrollbar from 'vue-gemini-scrollbar'; Vue.use(GeminiScrollbar); Vue.prototype.$moment = moment; Vue.config.productionTip = false; Vue.use(Vuex); Vue.use(commonComponents); Vue.use(directiveInit); Vue.use(directived); Vue.use(ElementUI, { size: 'small' }); window.onresize = () => { let size = document.body.clientWidth / 1920; store.commit('setScale', size); }; let defaultPath = ''; Vue.prototype.routerLoad = { findOne(arr) { return arr.map((v) => { if (v.children) { return this.findOne(v.children); } else { return { path: '/' + v.linkPath, name: v.name }; } }); }, findMen(arrList, arr, indexPath) { arr.map((v) => { if (v.children) { this.findMen(arrList, v.children, indexPath); } else { if ('/' + v.linkPath == indexPath) { arrList.push(true); } } }); }, close() { let activeRout = localStorage.getItem('path'); let tagsList = store.getters['getTagsList']; tagsList.forEach((item, index) => { if (item.path == activeRout) { tagsList.splice(index, 1); return true; } }); } }; //使用钩子函数对路由进行权限跳转 router.beforeEach((to, from, next) => { document.title = store.getters['getThisDetai'].name || !!window.sessionStorage.getItem('setThisDetai') ? JSON.parse(window.sessionStorage.getItem('setThisDetai')).name : ''; if (localStorage.getItem('CZC_token')) { let menuList = window.sessionStorage.getItem('SC_listMuen'); let newAr = []; if (menuList == null || menuList == undefined) { http.get('/czc-user-center/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => { if (0 == status) { let datas = data[0].children; window.sessionStorage.setItem('SC_listMuen', JSON.stringify(datas)); window.sessionStorage.setItem('setThisDetai', JSON.stringify(data[0])); store.commit('setThisDetai', data[0]); funcRouter(newAr, datas, router); next({ ...to, replace: true }); } else { this.$message.error(msg); } }); } else { if (router.options.routes[0].children.length == 0) { funcRouter(newAr, JSON.parse(menuList), router); next({ ...to, replace: true }); } else { let thisAll = JSON.parse(menuList)[0]; if (to.path == '/') { if (!!thisAll.children) { next({ path: `/${thisAll.children[0].linkPath}` }); } else { next({ path: `/${thisAll.linkPath}` }); } } else { next(); } } } } else { next(); } }); new Vue({ router, store, render: (h) => h(App) }).$mount('#app'); Vue.prototype.$http = http; Vue.prototype.$api = apiService(http);