/* * @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/element-variables.scss"; import './assets/css/main.scss'; import './assets/css/element-variables.scss'; import '@utils/rem.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'; import "./assets/common.styl"; import "./assets/v2.styl"; import "./assets/zz.styl"; import "./assets/ucd.styl"; // import VueAMap from 'vue-amap'; import { funcRouter } from "./router/dynamicMuen"; Vue.prototype.$moment = moment; Vue.config.productionTip = false; Vue.use(Vuex); Vue.use(commonComponents); Vue.use(directiveInit); Vue.use(ElementUI, { size: 'small' }); // Vue.use(VueAMap); // // // 初始化vue-amap // VueAMap.initAMapApiLoader({ // // 高德的key // key: 'def65c683e32ae89dd7f8982b433b7f8', // // 插件集合 // plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'], // // 高德 sdk 版本,默认为 1.4.4 // v: '1.4.4' // }); Vue.prototype.$http = http; Vue.prototype.$api = apiService(http); 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 } } }) }, // 获取菜单 loadMenus() { http.get('/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => { if (0 === status) { let routerArr = this.findOne(data[0].children); if (routerArr[0].length) { defaultPath = routerArr[0][0].path; } else { defaultPath = routerArr[0].path; } if (localStorage.getItem('path') == '/') { localStorage.setItem('path', defaultPath) } router.push({ path: localStorage.getItem('path') }) } }); } }; //使用钩子函数对路由进行权限跳转 router.beforeEach((to, from, next) => { // if (to.path != '/404') { // // 跳转时存储路由 // localStorage.setItem('path', to.fullPath) // } // next(); if (localStorage.getItem("SC_token")) { let menuList = window.sessionStorage.getItem("operationMuen") let newAr = []; if (menuList === null || menuList === undefined) { http.get('/sc-user-center/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => { if (0 == status) { let datas = data[0].children window.sessionStorage.setItem('operationMuen', JSON.stringify(datas)) 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 { next() } } } else { next(); } }); new Vue({ router, store, render: h => h(App), created() { // if (localStorage.getItem('SC_token')) { // this.routerLoad.loadMenus(); // } } }).$mount('#app');