2 |
3 |
4 |
5 |
6 |
7 | {{ item.menuName}}
8 |
9 |
10 |
11 |
20 |
21 | {{item.menuName}}
22 |
23 |
24 |
25 |
26 |
36 |
58 |
--------------------------------------------------------------------------------
/xinguan-vue-main/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import App from './App.vue'
3 | import router from './router/index'
4 | import store from './store'
5 | import ElementUI from 'element-ui'
6 | import 'element-ui/lib/theme-chalk/index.css'
7 | import NProgress from 'nprogress'
8 | import 'nprogress/nprogress.css'
9 | import axios from 'axios'
10 | import echarts from 'echarts'
11 | import ZkTable from 'vue-table-with-tree-grid'
12 | import { hasPermission } from './utils/permissionDirect'
13 | const Plugins = [hasPermission]
14 |
15 | Plugins.map((plugin) => {
16 | Vue.use(plugin)
17 | })
18 | Vue.use(ZkTable)
19 | Vue.use(echarts)
20 | NProgress.configure({ ease: 'ease', speed: 500 })
21 | NProgress.configure({ minimum: 0.3 })
22 |
23 | let BASE_API_URL = 'http://localhost:8989/'
24 | //const BASE_API_URL="https://www.zykhome.club/api/";
25 |
26 | Vue.prototype.$http = axios
27 | Vue.prototype.BASE_API_URL = BASE_API_URL
28 | axios.defaults.baseURL = BASE_API_URL
29 |
30 | //请求拦截器
31 | axios.interceptors.request.use(
32 | (config) => {
33 | NProgress.start()
34 | config.headers.Authorization = LocalStorage.get(
35 | LOCAL_KEY_XINGUAN_ACCESS_TOKEN
36 | )
37 | return config
38 | },
39 | (error) => {
40 | return Promise.reject(error)
41 | }
42 | )
43 |
44 | //响应拦截器
45 | axios.interceptors.response.use(
46 | function(response) {
47 | NProgress.done()
48 | const res = response.data
49 | if (res.success) {
50 | return response
51 | }
52 |
53 | if (res.data != null && res.data.errorCode === 50001) {
54 | LocalStorage.clearAll()
55 | return router.push('/login')
56 | }
57 | return response
58 | },
59 | function(error) {
60 | return Promise.reject(error)
61 | }
62 | )
63 |
64 | /**
65 | * 自定义权限指令
66 | */
67 | Vue.config.productionTip = false
68 | Vue.use(ElementUI)
69 | new Vue({
70 | router,
71 | store,
72 | render: (h) => h(App),
73 | }).$mount('#app')
74 |
--------------------------------------------------------------------------------
/xinguan-vue-main/src/store/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Vuex from 'vuex'
3 |
4 | Vue.use(Vuex)
5 |
6 | const store= new Vuex.Store({
7 | state: {
8 | userInfo:JSON.parse(localStorage.getItem("userInfo")) || {},
9 | },
10 | mutations:{
11 | setUserInfo(state,userInfo){
12 | localStorage.setItem('userInfo', JSON.stringify(userInfo));//将传递的数据先保存到localStorage中
13 | state.userInfo = userInfo;// 之后才是修改state中的状态
14 | }
15 | },
16 | actions:{},
17 | modules:{},
18 | })
19 | export default store
20 |
--------------------------------------------------------------------------------
/xinguan-vue-main/src/utils/permissionDirect.js:
--------------------------------------------------------------------------------
1 | export const hasPermission = {
2 | install (Vue) {
3 | Vue.directive('hasPermission', {
4 | bind (el, binding, vnode) {
5 | var flag=false;//默认不显示
6 | let userInfo = vnode.context.$store.state.userInfo;
7 |
8 |
9 | var value=binding.value;
10 |
11 | if(userInfo.isAdmin){
12 | //如果是超级管理员
13 | flag=true;
14 | }else if(userInfo.perms.indexOf(value)!=-1){
15 | //如果有该权限按钮显示
16 | flag=true;
17 | }
18 | if (!flag) {
19 | // if (!el.parentNode) {
20 | // el.style.display = 'none'
21 | // } else {
22 | // el.parentNode.removeChild(el);
23 | // }
24 | el.setAttribute("disabled",true);
25 | el.classList.add("is-disabled");
26 | }
27 | }
28 | })
29 | }
30 | }
31 |
--------------------------------------------------------------------------------