/* * @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 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 http from '@utils/http.js'; import apiService from './api/index'; import store from './store/store.js'; import '@utils/utils.js'; import 'babel-polyfill'; Vue.prototype.$moment = moment; Vue.config.productionTip = false; Vue.use(Vuex); Vue.use(commonComponents); Vue.use(directiveInit); Vue.use(ElementUI, { size: 'small' }); window.onresize = () => { let size = document.body.clientWidth / 1920; store.commit("setScale", size); }; 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(arr, indexPath) { let status = false; arr.map(v => { if (v.children) { this.findMen(v.children) } else { if (('/' + v.linkPath) === indexPath) { status = true } } }) return status }, 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; } }); }, // 获取菜单 loadMenus() { http.get('/sc-user-center/user/findUserMenu', { appId: '1003' }).then(({ status, data, msg }) => { if (0 === status) { store.commit('setMenuList', data[0].children) } }); } }; router.beforeEach((to, from, next) => { if (to.path !== '/404') { // console.log() let PermissionsRouter = Vue.prototype.routerLoad.findMen(store.getters.getMenuList, to.fullPath) if (PermissionsRouter) { next(); } else { next({ path: 404 }) } // 跳转时存储路由 localStorage.setItem('path', to.fullPath) } else { next(); } }); new Vue({ router, store, render: h => h(App), created() { if (localStorage.getItem('SC_token')) { this.routerLoad.loadMenus(); } } }).$mount('#app'); Vue.prototype.$http = http; Vue.prototype.$api = apiService(http);