123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- /*
- * @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);
- // import VueAMap from 'vue-amap';
- 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'
- });
- // 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'
- // });
- 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.linkPath !== indexPath) {
- // if (!!v.children) {
- // this.findMen(arrList, item.children, indexPath);
- // } else {
- // arrList.push(true)
- // }
- // } else {
- // }
- 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;
- }
- });
- },
- // 获取菜单
- loadMenus() {
- http.get('/sc-user-center/user/findUserMenu', { appId: '1002' }).then(({ status, data, msg }) => {
- if (0 === status) {
- store.commit('setMenuList', data[0].children);
- if (data[0].children[0].children == null) {
- router.push({
- path: '/' + data[0].children[0].linkPath
- });
- } else {
- router.push({
- path: '/' + data[0].children[0].children[0].linkPath
- });
- }
- store.commit('setThisDetai', data[0]);
- }
- });
- }
- };
- //使用钩子函数对路由进行权限跳转
- // router.beforeEach((to, from, next) => {
- // debugger;
- // 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();
- // }
- // });
- router.beforeEach((to, from, next) => {
- if (to.path !== '/404') {
- // console.log()
- let newa = [];
- console.log()
- Vue.prototype.routerLoad.findMen(newa, store.getters.getMenuList, to.fullPath);
- if (newa.length) {
- next();
- } else {
- next({ path: '404' });
- }
- next();
- // 跳转时存储路由
- 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);
|