Преглед на файлове

Merge branch 'v4' of http://git.ycjcjy.com/welcome/pc-welcome3 into v4

魏熙美 преди 6 години
родител
ревизия
52d655d7a5
променени са 7 файла, в които са добавени 149 реда и са изтрити 36 реда
  1. 1
    1
      public/index.html
  2. 13
    2
      src/layout/default/index.vue
  3. 43
    16
      src/router.js
  4. 19
    7
      src/store/system.js
  5. 31
    0
      src/views/NoRights.vue
  6. 31
    0
      src/views/NotFound.vue
  7. 11
    10
      src/views/index.js

+ 1
- 1
public/index.html Целия файл

@@ -5,7 +5,7 @@
5 5
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
6 6
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
7 7
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
8
-    <link rel="stylesheet" href="//at.alicdn.com/t/font_1070150_8lyiyriedbr.css">
8
+    <link rel="stylesheet" href="//at.alicdn.com/t/font_644855_tkpiimqvin.css">
9 9
     <title>迎宾系统</title>
10 10
   </head>
11 11
   <body>

+ 13
- 2
src/layout/default/index.vue Целия файл

@@ -37,8 +37,9 @@ export default {
37 37
   },
38 38
   data () {
39 39
     return {
40
-      menus: pages,
41
-      menuArray: pageArray,
40
+      menus: [],
41
+      menuArray: [],
42
+      userAuthority: [],
42 43
     }
43 44
   },
44 45
   computed: {
@@ -59,6 +60,16 @@ export default {
59 60
       return p.concat(route)
60 61
     }
61 62
   },
63
+  created () {
64
+    // if (this.$route.path.indexOf('exception') === -1) {
65
+    //   this.$store.dispatch('getUser').then(() => {
66
+    //     this.menuArray = pageArray
67
+    //     this.menus = pages
68
+    //   })
69
+    // }
70
+    this.menuArray = pageArray
71
+    this.menus = pages
72
+  },
62 73
   methods: {
63 74
     isInMenuList(menu) {
64 75
       return !!this.menuArray.filter(x => x.name === menu.name)[0]

+ 43
- 16
src/router.js Целия файл

@@ -21,7 +21,24 @@ const routes = [
21 21
     path: '/login',
22 22
     name: 'login',
23 23
     component: () => import('@/views/Login.vue')
24
-  }
24
+  },
25
+  {
26
+    path: '/exception',
27
+    name: 'exception',
28
+    component: () => import('@/layout/index.vue'),
29
+    children: [
30
+      {
31
+        path: '404',
32
+        name: 'notfound',
33
+        component: () => import('@/views/NotFound.vue'),
34
+      },
35
+      {
36
+        path: 'norights',
37
+        name: 'norights',
38
+        component: () => import('@/views/NoRights.vue'),
39
+      },
40
+    ]
41
+  },
25 42
 ]
26 43
 
27 44
 const router = new VueRouter({ routes })
@@ -29,24 +46,29 @@ const router = new VueRouter({ routes })
29 46
 // 校验用户权限
30 47
 router.beforeEach((to, from, next) => {
31 48
   NProgress.start()
32
-  if (to.name === 'login') {
49
+
50
+  const toLogin = { name: 'login', query: { from: to.name } }
51
+  const toIndex = { name: 'index' }
52
+  const to403 = { name: 'norights' }
53
+  
54
+  // 白名单, 异常页不处理
55
+  if (to.fullPath.indexOf('/exception') > -1) {
33 56
     next()
34 57
     return
35 58
   }
36
-  store.dispatch('checkLogin').then((isLogin) => {
37
-    if (isLogin) {
38
-      if (to.name === 'login') {
39
-        next({ name: 'index' })
40
-      } else {
41
-        next()
42
-      }
43
-    } else {
44
-      if (to.name === 'login') {
45
-        next()
46
-      } else {
47
-        next({ name: 'login', query: { from: to.name } })
48
-      }
49
-    }
59
+
60
+  store.dispatch('checkLogin').then(() => {
61
+  
62
+    // 校验权限
63
+    checkRigths(to).then(() => {
64
+      return to.name === 'login' ? next(toIndex) : next()
65
+    }).catch(() => {
66
+      next(to403)
67
+    })
68
+
69
+  }).catch((err) => {
70
+    window.console.error(err.message || err)
71
+    return to.name === 'login' ? next() : next(toLogin)
50 72
   })
51 73
 })
52 74
 
@@ -54,4 +76,9 @@ router.afterEach(() => {
54 76
   NProgress.done()
55 77
 })
56 78
 
79
+
80
+function checkRigths(route) {
81
+  return store.dispatch('checkMenuAuthority', route.name)
82
+}
83
+
57 84
 export default router

+ 19
- 7
src/store/system.js Целия файл

@@ -11,6 +11,7 @@ export default {
11 11
     },
12 12
     menus: [],
13 13
     user: {},
14
+    userLoged: false,
14 15
   },
15 16
   mutations: {
16 17
     updateUser(state, user) {
@@ -18,32 +19,42 @@ export default {
18 19
         ...state.user,
19 20
         ...user,
20 21
       }
22
+    },
23
+    syncState(state, payload = {}) {
24
+      Object.keys(payload).forEach(k => state[k] = payload[k])
21 25
     }
22 26
   },
23 27
   actions: {
24 28
     checkLogin({ state, commit }) {
25 29
       return new Promise((resolve, reject) => {
26
-        if (state.user.username) {
30
+        if (state.userLoged) {
27 31
           resolve(state.user)
28 32
           return
29 33
         }
34
+
30 35
         const api = lodash.get(apis, 'user.getuser')
31 36
         interact(api).then((data) => {
32
-          commit('updateUser', data)
33
-          resolve(data)
37
+          commit('syncState', { ...data, userLoged: true })
38
+          resolve(data.user)
34 39
         }).catch(() => {
35 40
           reject('获取人员信息失败')
36 41
         })
37 42
       })
38 43
     },
44
+    checkMenuAuthority({ state }, menuId) {
45
+      const menuAuthority = ((state.menus || []).filter(m => m.menuId === menuId).authority || '').split(',').filter(x => x)
46
+      const userAuthority = (state.user.authority || '').split(',').filter(x => x)
47
+      return menuAuthority.some(x => userAuthority.indexOf(x) > -1) ? Promise.resolve() : Promise.reject()
48
+    },
39 49
     login({ commit }, user) {
40 50
       return new Promise((resolve, reject) => {
41 51
         const api = lodash.get(apis, 'user.login')
42
-        interact(api, {...user}).then((data) => {
43
-          commit('updateUser', data)
52
+        interact(api, {...user}).then(() => {
53
+          // commit('updateUser', data)
54
+          commit('syncState', { userLoged: true })
44 55
           resolve()
45
-        }).catch(() => {
46
-          reject('账户密码不正确')
56
+        }).catch((err) => {
57
+          reject(err.message || err)
47 58
         })
48 59
       })
49 60
     },
@@ -51,6 +62,7 @@ export default {
51 62
       const api = lodash.get(apis, 'user.logout')
52 63
       interact(api).then(() => {
53 64
         commit('updateUser', {})
65
+        commit('syncState', { userLoged: false })
54 66
       })
55 67
     }
56 68
   }

+ 31
- 0
src/views/NoRights.vue Целия файл

@@ -0,0 +1,31 @@
1
+<template>
2
+  <div class="no-rights">
3
+    <i class="iconfont icon-menjin"></i>
4
+    <span>没有权限访问本页面 (403)</span>
5
+  </div>
6
+</template>
7
+
8
+<style lang="scss" scoped>
9
+.no-rights {
10
+  width: 600px;
11
+  margin-top: 100px !important;
12
+  background: transparent !important;
13
+  margin: auto;
14
+  text-align: center;
15
+  line-height: 128px;
16
+
17
+  span {
18
+    display: inline-block;
19
+    vertical-align: top;
20
+    height: 128px;
21
+    font-size: 18px;
22
+    margin-left: 48px;
23
+  }
24
+
25
+  .iconfont {
26
+    font-size: 128px;
27
+    color: #666;
28
+  }
29
+}
30
+</style>
31
+

+ 31
- 0
src/views/NotFound.vue Целия файл

@@ -0,0 +1,31 @@
1
+<template>
2
+  <div class="no-rights">
3
+    <i class="iconfont icon-duankailianjie"></i>
4
+    <span>页面不存在 (404)</span>
5
+  </div>
6
+</template>
7
+
8
+<style lang="scss" scoped>
9
+.no-rights {
10
+  width: 600px;
11
+  margin-top: 100px !important;
12
+  background: transparent !important;
13
+  margin: auto;
14
+  text-align: center;
15
+  line-height: 128px;
16
+
17
+  span {
18
+    display: inline-block;
19
+    vertical-align: top;
20
+    height: 128px;
21
+    font-size: 18px;
22
+    margin-left: 48px;
23
+  }
24
+
25
+  .iconfont {
26
+    font-size: 128px;
27
+    color: #666;
28
+  }
29
+}
30
+</style>
31
+

+ 11
- 10
src/views/index.js Целия файл

@@ -7,6 +7,7 @@ const pages = [
7 7
     meta: {
8 8
       menuShow: true,
9 9
       title: 'Dashboard',
10
+      authority: [],  // 该字段会由服务端返回
10 11
     }
11 12
   },
12 13
   {
@@ -27,6 +28,15 @@ const pages = [
27 28
           title: '系统人员',
28 29
         },
29 30
       },
31
+      {
32
+        path: 'sysuser/edit',
33
+        name: 'sysuseredit',
34
+        component: () => import('./sysuser/edit.vue'),
35
+        meta: {
36
+          menuShow: false,
37
+          title: '人员维护',
38
+        },
39
+      },
30 40
       {
31 41
         path: 'sysuser/userRole',
32 42
         name: 'userRole',
@@ -96,7 +106,7 @@ const pages = [
96 106
         component: () => import('./sysparam/edit.vue'),
97 107
         meta: {
98 108
           menuShow: false,
99
-          title: '系统参数配置',
109
+          title: '系统参数维护',
100 110
         },
101 111
       },
102 112
       {
@@ -108,15 +118,6 @@ const pages = [
108 118
           title: '人员类型',
109 119
         },
110 120
       },
111
-      {
112
-        path: 'sysuser/edit',
113
-        name: 'sysuseredit',
114
-        component: () => import('./sysuser/edit.vue'),
115
-        meta: {
116
-          menuShow: false,
117
-          title: '销售管理',
118
-        },
119
-      },
120 121
      {
121 122
         path: 'typeedit',
122 123
         name: 'typeedit',