123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /*
- * @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 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'
- });
- 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: '1001' }).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();
- });
- new Vue({
- router,
- store,
- render: h => h(App),
- created() {
- if (localStorage.getItem('SC_token')) {
- this.routerLoad.loadMenus();
- }
- }
- }).$mount('#app');
|