Browse Source

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

魏熙美 6 years ago
parent
commit
52d655d7a5
7 changed files with 149 additions and 36 deletions
  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 View File

5
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
5
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
6
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
7
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
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
     <title>迎宾系统</title>
9
     <title>迎宾系统</title>
10
   </head>
10
   </head>
11
   <body>
11
   <body>

+ 13
- 2
src/layout/default/index.vue View File

37
   },
37
   },
38
   data () {
38
   data () {
39
     return {
39
     return {
40
-      menus: pages,
41
-      menuArray: pageArray,
40
+      menus: [],
41
+      menuArray: [],
42
+      userAuthority: [],
42
     }
43
     }
43
   },
44
   },
44
   computed: {
45
   computed: {
59
       return p.concat(route)
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
   methods: {
73
   methods: {
63
     isInMenuList(menu) {
74
     isInMenuList(menu) {
64
       return !!this.menuArray.filter(x => x.name === menu.name)[0]
75
       return !!this.menuArray.filter(x => x.name === menu.name)[0]

+ 43
- 16
src/router.js View File

21
     path: '/login',
21
     path: '/login',
22
     name: 'login',
22
     name: 'login',
23
     component: () => import('@/views/Login.vue')
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
 const router = new VueRouter({ routes })
44
 const router = new VueRouter({ routes })
29
 // 校验用户权限
46
 // 校验用户权限
30
 router.beforeEach((to, from, next) => {
47
 router.beforeEach((to, from, next) => {
31
   NProgress.start()
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
     next()
56
     next()
34
     return
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
   NProgress.done()
76
   NProgress.done()
55
 })
77
 })
56
 
78
 
79
+
80
+function checkRigths(route) {
81
+  return store.dispatch('checkMenuAuthority', route.name)
82
+}
83
+
57
 export default router
84
 export default router

+ 19
- 7
src/store/system.js View File

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

+ 31
- 0
src/views/NoRights.vue View File

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 View File

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 View File

7
     meta: {
7
     meta: {
8
       menuShow: true,
8
       menuShow: true,
9
       title: 'Dashboard',
9
       title: 'Dashboard',
10
+      authority: [],  // 该字段会由服务端返回
10
     }
11
     }
11
   },
12
   },
12
   {
13
   {
27
           title: '系统人员',
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
         path: 'sysuser/userRole',
41
         path: 'sysuser/userRole',
32
         name: 'userRole',
42
         name: 'userRole',
96
         component: () => import('./sysparam/edit.vue'),
106
         component: () => import('./sysparam/edit.vue'),
97
         meta: {
107
         meta: {
98
           menuShow: false,
108
           menuShow: false,
99
-          title: '系统参数配置',
109
+          title: '系统参数维护',
100
         },
110
         },
101
       },
111
       },
102
       {
112
       {
108
           title: '人员类型',
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
         path: 'typeedit',
122
         path: 'typeedit',
122
         name: 'typeedit',
123
         name: 'typeedit',