Selaa lähdekoodia

权限验证登录

lipengtao 6 vuotta sitten
vanhempi
commit
fc7e002a70

+ 1 - 2
src/api/login.js

@ -6,8 +6,7 @@ export function login(account, pw, vc) {
6 6
    method: 'post',
7 7
    data: {
8 8
      account,
9
      pw,
10
      vc
9
      pw
11 10
    }
12 11
  })
13 12
}

+ 3 - 0
src/api/loginnew.js

@ -0,0 +1,3 @@
1
export const loginUrl = '/ajax/sys/login'
2
export const getInfoUrl = '/ajax/sys/manager'
3
export const logoutUrl = '/ajax/sys/logout'

+ 2 - 0
src/api/modifyAccountInformation.js

@ -0,0 +1,2 @@
1
export const url = '/ajax/sys/manager'
2
export const modifyUrl = '/ajax/sys/manager'

+ 1 - 0
src/api/modifyPassword.js

@ -0,0 +1 @@
1
export default '/ajax/sys/manager/changepasswd' //  重置密码

src/views/contentPub/editorUE.vue → src/components/editorUE/index.vue


src/views/contentPub/searchTemplate.vue → src/components/searchBar/index.vue


src/views/contentPub/uploadFile.vue → src/components/uploadFile/index.vue


+ 47 - 54
src/permission.js

@ -1,58 +1,51 @@
1
// import router from './router'
2
// import store from './store'
3
// import NProgress from 'nprogress' // Progress 进度条
4
// import 'nprogress/nprogress.css'// Progress 进度条样式
5
// import { Message } from 'element-ui'
6
// import { getCookiesName } from '@/utils/auth' // 验权
7
// import queryInfo from '@/utils/queryInfo'
1
import router from './router'
2
import store from './store'
3
import NProgress from 'nprogress' // Progress 进度条
4
import 'nprogress/nprogress.css'// Progress 进度条样式
5
import { Message } from 'element-ui'
6
import Cookies from 'js-cookie'
7
//  import queryInfo from '@/utils/queryInfo'
8 8
9
// NProgress.configure({ showSpinner: false })// NProgress Configuration
9
NProgress.configure({ showSpinner: false })// NProgress Configuration
10 10
11
// function hasPermission(roles, permissionRoles) {
12
//   if (roles.indexOf('1') >= 0) return true
13
//   if (!permissionRoles) return true
14
//   return roles.some(role => permissionRoles.indexOf(role) >= 0)
15
// }
11
const whiteList = ['/login', '/findPwd'] // 不重定向白名单
16 12
17
// const whiteList = ['/login', '/findPwd'] // 不重定向白名单
13
router.beforeEach((to, from, next) => {
14
  NProgress.start()
15
  if (Cookies.get('userid')) {
16
    if (to.path === '/login') {
17
      next({ path: '/' })
18
      NProgress.done()
19
    } else {
20
      if (!store.getters.account) { // 判断当前用户是否已拉取完user_info信息
21
        store.dispatch('GetUserInfo').then(res => { // 拉取user_info
22
          if (res.success && res.data) {
23
            store.dispatch('GenerateRoutes', res.data.rightCode).then(() => { // 根据roles权限生成可访问的路由表
24
              router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
25
              next({ ...to, replace: true })
26
            })
27
          }
28
        }).catch((err) => {
29
          store.dispatch('LogOut').then(() => {
30
            Message.error(err || '登录状态失效,请重新登录')
31
            next({ path: '/' })
32
          })
33
        })
34
      } else {
35
        next()
36
      }
37
      //  queryInfo.queryAllInfo()
38
    }
39
  } else {
40
    if (whiteList.indexOf(to.path) !== -1) {
41
      next()
42
    } else {
43
      next('/login')
44
      NProgress.done()
45
    }
46
  }
47
})
18 48
19
// router.beforeEach((to, from, next) => {
20
//   NProgress.start()
21
//   if (getCookiesName()) {
22
//     if (to.path === '/login') {
23
//       next({ path: '/' })
24
//       NProgress.done()
25
//     } else {
26
//       if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
27
//         store.dispatch('GetUserInfo').then(res => { // 拉取user_info
28
//           const roles = [res.data.type.toString()]
29
//           store.dispatch('GenerateRoutes', { roles }).then(() => { // 根据roles权限生成可访问的路由表
30
//             router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
31
//             next({ ...to, replace: true })
32
//           })
33
//         }).catch((err) => {
34
//           store.dispatch('FedLogOut').then(() => {
35
//             Message.error(err || '登录状态失效,请重新登录')
36
//             next({ path: '/' })
37
//           })
38
//         })
39
//       } else {
40
//         if (hasPermission(store.getters.roles, to.meta.roles)) {
41
//           next()
42
//         }
43
//       }
44
//       queryInfo.queryAllInfo()
45
//     }
46
//   } else {
47
//     if (whiteList.indexOf(to.path) !== -1) {
48
//       next()
49
//     } else {
50
//       next('/login')
51
//       NProgress.done()
52
//     }
53
//   }
54
// })
55
56
// router.afterEach(() => {
57
//   NProgress.done() // 结束Progress
58
// })
49
router.afterEach(() => {
50
  NProgress.done() // 结束Progress
51
})

+ 256 - 256
src/router/index.js

@ -39,288 +39,288 @@ export const constantRouterMap = [
39 39
      name: 'dashboard',
40 40
      meta: { title: '主页' }
41 41
    }]
42
  },
43
  {
44
    path: '',
45
    component: Layout,
46
    name: 'contentModule',
47
    redirect: 'noredirect',
48
    meta: { title: '内容发布' },
49
    children: [
50
      {
51
        path: 'content',
52
        component: () => import('@/views/contentPub/index'),
53
        name: 'content',
54
        redirect: '/content/pubList',
55
        meta: { title: '内容发布列表' },
56
        children: [
57
          {
58
            path: 'pubList',
59
            component: () => import('@/views/contentPub/pubList'),
60
            name: 'pubList',
61
            meta: { title: '内容发布列表' }
62
          },
63
          {
64
            path: 'publish',
65
            hidden: true,
66
            component: () => import('@/views/contentPub/publish'),
67
            name: 'publish',
68
            meta: { title: ' 新内容发布' }
69
          }
70
        ]
71
      },
72
      {
73
        path: 'recycle',
74
        component: () => import('@/views/contentPub/index'),
75
        name: 'recycle',
76
        redirect: '/recycle/recycleBinList',
77
        meta: { title: '内容回收站列表' },
78
        children: [
79
          {
80
            path: 'recycleBinList',
81
            component: () => import('@/views/contentPub/recycleBin'),
82
            name: 'recycleBinList',
83
            meta: { title: '内容回收站列表' }
84
          },
85
          {
86
            path: 'viewRecycling',
87
            hidden: true,
88
            component: () => import('@/views/contentPub/viewRecyclingBins'),
89
            name: 'viewRecycling',
90
            meta: { title: ' 查看回收内容' }
91
          }
92
        ]
93
      },
94
      {
95
        path: 'draftList',
96
        component: () => import('@/views/contentPub/draftList'),
97
        name: 'draftList',
98
        meta: { title: '内容草稿箱列表' }
99
      }
100
    ]
101
  },
102
  {
103
    path: '',
104
    component: Layout,
105
    name: 'demand',
106
    redirect: 'noredirect',
107
    meta: { title: '需求中心' },
108
    children: [
109
      {
110
        path: 'publishedList',
111
        component: () => import('@/views/demandCen/publishedList'),
112
        name: 'publishedList',
113
        meta: { title: '发布中需求' }
114
      },
115
      {
116
        path: 'expiredList',
117
        component: () => import('@/views/demandCen/expiredList'),
118
        name: 'expiredList',
119
        meta: { title: '已过期需求' }
120
      },
121
      {
122
        path: 'completedList',
123
        component: () => import('@/views/demandCen/completedList'),
124
        name: 'completedList',
125
        meta: { title: '已完成需求' }
126
      },
127
      {
128
        path: 'closedList',
129
        component: () => import('@/views/demandCen/closedList'),
130
        name: 'closedList',
131
        meta: { title: '已关闭需求' }
132
      }
133
    ]
134
  },
135
  {
136
    path: '',
137
    component: Layout,
138
    name: 'specialExperts',
139
    redirect: 'noredirect',
140
    alwaysShow: true,
141
    meta: { title: '特约专家' },
142
    children: [
143
      {
144
        path: 'expertslist',
145
        component: () => import('@/views/specialExperts/index'),
146
        name: 'publishedList',
147
        meta: { title: '特约专家列表' }
148
      }
149
    ]
150
  },
151
  {
152
    path: '',
153
    component: Layout,
154
    name: 'cooperationAgency',
155
    redirect: 'noredirect',
156
    alwaysShow: true,
157
    meta: { title: '合作机构' },
158
    children: [
159
      {
160
        path: 'agencylist',
161
        component: () => import('@/views/cooperationAgency/index'),
162
        name: 'publishedList',
163
        meta: { title: '合作机构管理列表' }
164
      }
165
    ]
166
  },
167
  {
168
    path: '',
169
    component: Layout,
170
    name: 'company',
171
    redirect: 'noredirect',
172
    meta: { title: '企业中心' },
173
    children: [
174
      {
175
        path: 'noactive',
176
        component: () => import('@/views/companyCen/noactive/index'),
177
        name: 'noactive',
178
        parentPath: true,
179
        redirect: { name: 'noactiveList' },
180
        meta: { title: '未激活企业' },
181
        children: [
182
          {
183
            path: 'noactiveList',
184
            name: 'noactiveList',
185
            hidden: true,
186
            component: () => import('@/views/companyCen/noactive/noactiveList')
187
          },
188
          {
189
            path: 'compHome',
190
            component: () => import('@/views/companyCen/noactive/compHome'),
191
            name: 'compHome',
192
            parentPath: true,
193
            redirect: { name: 'compInfo' },
194
            meta: { title: '企业信息' },
195
            children: [
196
              {
197
                path: 'compInfo',
198
                name: 'compInfo',
199
                hidden: true,
200
                component: () => import('@/views/companyCen/noactive/compInfo')
201
              },
202
              {
203
                path: 'productHome',
204
                component: () => import('@/views/companyCen/noactive/productHome'),
205
                name: 'productHome',
206
                parentPath: true,
207
                redirect: { name: 'compProduct' },
208
                children: [
209
                  {
210
                    path: 'compProduct',
211
                    component: () => import('@/views/companyCen/noactive/compProduct'),
212
                    name: 'compProduct',
213
                    meta: { title: '企业产品' }
214
                  },
215
                  {
216
                    path: 'productInfo',
217
                    component: () => import('@/views/companyCen/noactive/productInfo'),
218
                    name: 'productInfo',
219
                    hidden: true,
220
                    meta: { title: '产品详情' }
221
                  }
222
                ]
223
              }
224
            ]
225
          }
226
        ]
227
      },
228
      {
229
        path: 'activeList',
230
        component: () => import('@/views/companyCen/activeList'),
231
        name: 'activeList',
232
        meta: { title: '已激活企业' }
233
      }
234
    ]
235
  },
236
  {
237
    path: '',
238
    component: Layout,
239
    name: 'platinfo',
240
    redirect: 'noredirect',
241
    alwaysShow: true,
242
    meta: { title: '平台信息' },
243
    children: [
244
      {
245
        path: 'platUpdate',
246
        component: () => import('@/views/platInfo/platUpdate'),
247
        name: 'platUpdate',
248
        meta: { title: '修改平台信息' }
249
      }
250
    ]
251
  },
252
  {
253
    path: '',
254
    component: Layout,
255
    name: 'userinfo',
256
    redirect: 'noredirect',
257
    alwaysShow: true,
258
    meta: { title: '用户信息' },
259
    children: [
260
      {
261
        path: 'usingList',
262
        component: () => import('@/views/userInfo/usingList'),
263
        name: 'usingList',
264
        meta: { title: '正常用户' }
265
      },
266
      {
267
        path: 'blackList',
268
        component: () => import('@/views/userInfo/blackList'),
269
        name: 'blackList',
270
        meta: { title: '黑名单用户' }
271
      }
272
    ]
273
  },
274
  {
275
    path: '',
276
    component: Layout,
277
    name: 'sysSetting',
278
    redirect: 'noredirect',
279
    alwaysShow: true,
280
    meta: { title: '系统设置' },
281
    children: [
282
      {
283
        path: 'adminUser',
284
        component: () => import('@/views/sysSetting/adminUser'),
285
        name: 'adminUser',
286
        meta: { title: '平台后台用户管理列表' }
287
      }
288
    ]
289
  },
42
  }
43
]
44
45
export const asynsingle = [
290 46
  {
291 47
    path: '',
292 48
    component: Layout,
293
    name: 'accountSettings',
294 49
    redirect: 'noredirect',
295 50
    meta: { title: '账户设置' },
296 51
    children: [
297 52
      {
298 53
        path: 'modifyInformation',
299 54
        component: () => import('@/views/accountSettings/modifyAccountInformation'),
300
        name: 'modifyInformation',
301 55
        meta: { title: '修改账户资料' }
302 56
      },
303 57
      {
304 58
        path: 'modifyPassword',
305 59
        component: () => import('@/views/accountSettings/modifyPassword'),
306
        name: 'modifyPassword',
307 60
        meta: { title: '修改密码' }
308 61
      }
309 62
    ]
310
  },
63
  }
311 64
]
312
313 65
// 实例化vue的时候只挂载constantRouter
314 66
315 67
export default new Router({
316 68
  // mode: 'history', //后端支持可开
317 69
  scrollBehavior: () => ({ y: 0 }),
318
  routes: constantRouterMap
70
  routes: [...constantRouterMap, ...asynsingle]
319 71
})
320 72
321 73
// 异步挂载的路由
322 74
// 动态需要根据权限加载的路由表
323
75
//  { path: '*', redirect: '/404', hidden: true }
324 76
export const asyncRouterMap = [
325
  { path: '*', redirect: '/404', hidden: true }
77
  {
78
    '0': {
79
      path: '',
80
      component: Layout,
81
      name: 'sysSetting',
82
      redirect: 'noredirect',
83
      alwaysShow: true,
84
      meta: { title: '系统设置' },
85
      children: [
86
        {
87
          path: 'adminUser',
88
          component: () => import('@/views/sysSetting/adminUser'),
89
          name: 'adminUser',
90
          meta: { title: '平台后台用户管理列表' }
91
        }
92
      ]
93
    },
94
    '1': {
95
      path: '',
96
      component: Layout,
97
      name: 'contentModule',
98
      redirect: 'noredirect',
99
      meta: { title: '内容发布' },
100
      children: [
101
        {
102
          path: 'content',
103
          component: () => import('@/views/contentPub/index'),
104
          name: 'content',
105
          redirect: '/content/pubList',
106
          meta: { title: '内容发布列表' },
107
          children: [
108
            {
109
              path: 'pubList',
110
              component: () => import('@/views/contentPub/pubList'),
111
              name: 'pubList',
112
              meta: { title: '内容发布列表' }
113
            },
114
            {
115
              path: 'publish',
116
              hidden: true,
117
              component: () => import('@/views/contentPub/publish'),
118
              name: 'publish',
119
              meta: { title: ' 新内容发布' }
120
            }
121
          ]
122
        },
123
        {
124
          path: 'recycle',
125
          component: () => import('@/views/contentPub/index'),
126
          name: 'recycle',
127
          redirect: '/recycle/recycleBinList',
128
          meta: { title: '内容回收站列表' },
129
          children: [
130
            {
131
              path: 'recycleBinList',
132
              component: () => import('@/views/contentPub/recycleBin'),
133
              name: 'recycleBinList',
134
              meta: { title: '内容回收站列表'            meta: { title: '内容回收站列表' }
135
            },
136
            {
137
              path: 'viewRecycling',
138
              hidden: true,
139
              component: () => import('@/views/contentPub/viewRecyclingBins'),
140
              name: 'viewRecycling',
141
              meta: { title: ' 查看回收内容' }
142
            }
143
          ]
144
        },
145
        {
146
          path: 'draftList',
147
          component: () => import('@/views/contentPub/draftList'),
148
          name: 'draftList',
149
          meta: { title: '内容草稿箱列表' }
150
        }
151
      ]
152
    },
153
    '2': {
154
      path: '',
155
      component: Layout,
156
      name: 'specialExperts',
157
      redirect: 'noredirect',
158
      alwaysShow: true,
159
      meta: { title: '特约专家' },
160
      children: [
161
        {
162
          path: 'expertslist',
163
          component: () => import('@/views/specialExperts/index'),
164
          name: 'publishedList',
165
          meta: { title: '特约专家列表' }
166
        }
167
      ]
168
    },
169
    '3': {
170
      path: '',
171
      component: Layout,
172
      name: 'cooperationAgency',
173
      redirect: 'noredirect',
174
      alwaysShow: true,
175
      meta: { title: '合作机构' },
176
      children: [
177
        {
178
          path: 'agencylist',
179
          component: () => import('@/views/cooperationAgency/index'),
180
          name: 'publishedList',
181
          meta: { title: '合作机构管理列表' }
182
        }
183
      ]
184
    },
185
    '4': {
186
      path: '',
187
      component: Layout,
188
      name: 'company',
189
      redirect: 'noredirect',
190
      meta: { title: '企业中心' },
191
      children: [
192
        {
193
          path: 'noactive',
194
          component: () => import('@/views/companyCen/noactive/index'),
195
          name: 'noactive',
196
          parentPath: true,
197
          redirect: { name: 'noactiveList' },
198
          meta: { title: '未激活企业' },
199
          children: [
200
            {
201
              path: 'noactiveList',
202
              name: 'noactiveList',
203
              hidden: true,
204
              component: () => import('@/views/companyCen/noactive/noactiveList')
205
            },
206
            {
207
              path: 'compHome',
208
              component: () => import('@/views/companyCen/noactive/compHome'),
209
              name: 'compHome',
210
              parentPath: true,
211
              redirect: { name: 'compInfo' },
212
              meta: { title: '企业信息' },
213
              children: [
214
                {
215
                  path: 'compInfo',
216
                  name: 'compInfo',
217
                  hidden: true,
218
                  component: () => import('@/views/companyCen/noactive/compInfo')
219
                },
220
                {
221
                  path: 'productHome',
222
                  component: () => import('@/views/companyCen/noactive/productHome'),
223
                  name: 'productHome',
224
                  parentPath: true,
225
                  redirect: { name: 'compProduct' },
226
                  children: [
227
                    {
228
                      path: 'compProduct',
229
                      component: () => import('@/views/companyCen/noactive/compProduct'),
230
                      name: 'compProduct',
231
                      meta: { title: '企业产品' }
232
                    },
233
                    {
234
                      path: 'productInfo',
235
                      component: () => import('@/views/companyCen/noactive/productInfo'),
236
                      name: 'productInfo',
237
                      hidden: true,
238
                      meta: { title: '产品详情' }
239
                    }
240
                  ]
241
                }
242
              ]
243
            }
244
          ]
245
        },
246
        {
247
          path: 'activeList',
248
          component: () => import('@/views/companyCen/activeList'),
249
          name: 'activeList',
250
          meta: { title: '已激活企业' }
251
        }
252
      ]
253
    },
254
    '5': {
255
      path: '',
256
      component: Layout,
257
      name: 'platinfo',
258
      redirect: 'noredirect',
259
      alwaysShow: true,
260
      meta: { title: '平台信息' },
261
      children: [
262
        {
263
          path: 'platUpdate',
264
          component: () => import('@/views/platInfo/platUpdate'),
265
          name: 'platUpdate',
266
          meta: { title: '修改平台信息' }
267
        }
268
      ]
269
    },
270
    '6': {
271
      path: '',
272
      component: Layout,
273
      name: 'userinfo',
274
      redirect: 'noredirect',
275
      alwaysShow: true,
276
      meta: { title: '用户信息' },
277
      children: [
278
        {
279
          path: 'usingList',
280
          component: () => import('@/views/userInfo/usingList'),
281
          name: 'usingList',
282
          meta: { title: '正常用户' }
283
        },
284
        {
285
          path: 'blackList',
286
          component: () => import('@/views/userInfo/blackList'),
287
          name: 'blackList',
288
          meta: { title: '黑名单用户' }
289
        }
290
      ]
291
    },
292
    '7': {
293
      path: '',
294
      component: Layout,
295
      name: 'demand',
296
      redirect: 'noredirect',
297
      meta: { title: '需求中心' },
298
      children: [
299
        {
300
          path: 'publishedList',
301
          component: () => import('@/views/demandCen/publishedList'),
302
          name: 'publishedList',
303
          meta: { title: '发布中需求' }
304
        },
305
        {
306
          path: 'expiredList',
307
          component: () => import('@/views/demandCen/expiredList'),
308
          name: 'expiredList',
309
          meta: { title: '已过期需求' }
310
        },
311
        {
312
          path: 'completedList',
313
          component: () => import('@/views/demandCen/completedList'),
314
          name: 'completedList',
315
          meta: { title: '已完成需求' }
316
        },
317
        {
318
          path: 'closedList',
319
          component: () => import('@/views/demandCen/closedList'),
320
          name: 'closedList',
321
          meta: { title: '已关闭需求' }
322
        }
323
      ]
324
    }
325
  }
326 326
]

+ 1 - 4
src/store/getters.js

@ -1,12 +1,9 @@
1 1
const getters = {
2 2
  sidebar: state => state.app.sidebar,
3 3
  device: state => state.app.device,
4
  account: state => state.user.account,
5 4
  userid: state => state.user.userid,
5
  account: state => state.user.account,
6 6
  name: state => state.user.name,
7
  roles: state => state.user.roles,
8
  logins: state => state.user.logins,
9
  session: state => state.user.session,
10 7
  permission_routers: state => state.permission.routers,
11 8
  addRouters: state => state.permission.addRouters
12 9
}

+ 33 - 33
src/store/modules/permission.js

@ -1,36 +1,37 @@
1
import { asyncRouterMap, constantRouterMap } from '@/router'
1
import { asyncRouterMap, constantRouterMap, asynsingle } from '@/router'
2 2
3
/**
4
 * 通过meta.role判断是否与当前用户权限匹配
5
 * @param roles
6
 * @param route
7
 */
8
function hasPermission(roles, route) {
9
  if (route.meta.roles) {
10
    return roles.some(role => route.meta.roles.indexOf(role) >= 0)
11
  } else {
12
    return true
13
  }
14
}
15
16
/**
17
 * 递归过滤异步路由表,返回符合用户角色权限的路由表
18
 * @param asyncRouterMap
19
 * @param roles
20
 */
21
function filterAsyncRouter(asyncRouterMap, roles) {
22
  const accessedRouters = asyncRouterMap.filter(route => {
23
    if (hasPermission(roles, route)) {
24
      if (route.children && route.children.length) {
25
        route.children = filterAsyncRouter(route.children, roles)
3
const ret = {
4
  arr: [],
5
  pos(value) {
6
    return this.arr.indexOf(value)
7
  },
8
  setArr() {
9
    if (this.arr.length < 2) {
10
      return this.route()
11
    }
12
    if (this.pos('0') !== -1) {
13
      this.arr.splice(this.pos('0'), 1)
14
      this.arr.push('0')
15
    }
16
    if (this.pos('7') !== -1) {
17
      this.arr.splice(this.pos('7'), 1)
18
      if (this.pos('1') !== -1) {
19
        this.arr.splice(0, 1, '1', '7')
20
      } else {
21
        this.arr.unshift('7')
26 22
      }
27
      return true
28 23
    }
29
    return false
30
  })
31
  return accessedRouters
24
    return this.route()
25
  },
26
  route() {
27
    for (let i = 0; i < this.arr.length; i++) {
28
      if (asyncRouterMap[0][this.arr[i]]) {
29
        this.arr[i] = asyncRouterMap[0][this.arr[i]]
30
      }
31
    }
32
    return [...this.arr, ...asynsingle]
33
  }
32 34
}
33
34 35
const permission = {
35 36
  state: {
36 37
    routers: constantRouterMap,
@ -39,15 +40,14 @@ const permission = {
39 40
  mutations: {
40 41
    SET_ROUTERS: (state, routers) => {
41 42
      state.addRouters = routers
42
      state.routers = constantRouterMap.concat(routers)
43
      state.routers = [...constantRouterMap, ...routers]
43 44
    }
44 45
  },
45 46
  actions: {
46 47
    GenerateRoutes({ commit }, data) {
47 48
      return new Promise(resolve => {
48
        const { roles } = data
49
        // const roles = ['2']
50
        const accessedRouters = filterAsyncRouter(asyncRouterMap, roles)
49
        ret.arr = data.sort((par1, par2) => par1 - par2)
50
        const accessedRouters = ret.setArr()
51 51
        commit('SET_ROUTERS', accessedRouters)
52 52
        resolve()
53 53
      })

+ 19 - 47
src/store/modules/user.js

@ -1,57 +1,42 @@
1
import { login, logout, getInfo } from '@/api/login'
2
import { getCookiesName, setCookiesName, removeCookiesName } from '@/utils/auth'
1
import { loginUrl, logoutUrl, getInfoUrl } from '@/api/loginnew'
2
import http from '@/utils/request'
3
import Cookies from 'js-cookie'
3 4
4 5
const user = {
5 6
  state: {
6
    account: '',
7 7
    userid: '',
8 8
    name: '',
9
    roles: [],
10
    logins: '',
11
    session: getCookiesName()
9
    account: ''
12 10
  },
13 11
  mutations: {
14
    SET_ACCOUNT: (state, account) => {
15
      state.account = account
16
    },
17 12
    SET_USERID: (state, userid) => {
18 13
      state.userid = userid
19 14
    },
20 15
    SET_NAME: (state, name) => {
21 16
      state.name = name
22 17
    },
23
    SET_ROLES: (state, roles) => {
24
      state.roles = roles
25
    },
26
    SET_LOGIN: (state, logins) => {
27
      state.logins = logins
28
    },
29
    SET_SESSION: (state, session) => {
30
      state.session = session
18
    SET_COUNT: (state, account) => {
19
      state.account = account
31 20
    }
32 21
  },
33 22
34 23
  actions: {
35 24
    // 用户名登录
36 25
    LoginByUsername({ commit }, userInfo) {
37
      const account = userInfo.username.trim()
38
      const pw = userInfo.password
39
      const vc = userInfo.imgVerifyCode.toLocaleUpperCase()
40 26
      return new Promise((resolve, reject) => {
41
        login(account, pw, vc).then((response) => {
27
        http.post(loginUrl, userInfo, (response) => {
42 28
          if (response.success) {
43 29
            if (response.data) {
44 30
              const dataS = response.data
45
              if (dataS.active) {
46
                commit('SET_ACCOUNT', dataS.account)
31
              if (dataS.actived) {
47 32
                commit('SET_USERID', dataS.id)
48 33
                commit('SET_NAME', dataS.name)
49
                setCookiesName(dataS.name)
34
                Cookies.set('userid', dataS.id)
50 35
              }
51 36
            }
52 37
          }
53 38
          resolve(response)
54
        }).catch(error => {
39
        }, (error) => {
55 40
          reject(error)
56 41
        })
57 42
      })
@ -60,21 +45,20 @@ const user = {
60 45
    // 获取用户信息
61 46
    GetUserInfo({ commit, state }) {
62 47
      return new Promise((resolve, reject) => {
63
        getInfo().then(response => {
48
        http.get(getInfoUrl, '', response => {
64 49
          if (response.success) {
65 50
            if (response.data) {
66 51
              const dataS = response.data
67
              if (dataS.active) {
68
                commit('SET_ACCOUNT', dataS.account)
52
              if (dataS.actived) {
69 53
                commit('SET_USERID', dataS.id)
70
                // commit('SET_ROLES', ['2'])
71
                commit('SET_ROLES', [dataS.type.toString()])
72 54
                commit('SET_NAME', dataS.name)
55
                commit('SET_COUNT', dataS.account)
56
                Cookies.set('userid', dataS.id)
73 57
              }
74 58
            }
75 59
          }
76 60
          resolve(response)
77
        }).catch(error => {
61
        }, error => {
78 62
          reject(error)
79 63
        })
80 64
      })
@ -83,27 +67,15 @@ const user = {
83 67
    // 登出
84 68
    LogOut({ commit, state }) {
85 69
      return new Promise((resolve, reject) => {
86
        logout().then(() => {
87
          commit('SET_ACCOUNT', '')
70
        http.get(logoutUrl, '', (response) => {
88 71
          commit('SET_USERID', '')
89
          commit('SET_ROLES', [])
90 72
          commit('SET_NAME', '')
91
          commit('SET_SESSION', '')
92
          removeCookiesName()
93
          resolve()
94
        }).catch(error => {
73
          Cookies.remove('userid')
74
          resolve(response)
75
        }, error => {
95 76
          reject(error)
96 77
        })
97 78
      })
98
    },
99
100
    // 前端 登出
101
    FedLogOut({ commit }) {
102
      return new Promise(resolve => {
103
        commit('SET_SESSION', '')
104
        removeCookiesName()
105
        resolve()
106
      })
107 79
    }
108 80
  }
109 81
}

+ 102 - 103
src/views/accountSettings/modifyAccountInformation.vue

@ -4,151 +4,150 @@
4 4
      <div class="contain-title">修改账户资料</div>
5 5
    </div>
6 6
    <div class="content-container">
7
      <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" label-width="100px" class="demo-ruleForm">
8
        <el-row>
9
          <el-col :span="12">
10
            <el-form-item label="账号" prop="pass">
11
              13526242569
12
               </el-form-item>
13
          </el-col>
14
          <el-col :span="12">
15
            <el-form-item label="用户名" prop="checkPass">
16
              <el-input type="password" v-model="ruleForm2.checkPass" autocomplete="off" placeholder="请填写您的用户名"></el-input>
17
               </el-form-item>
18
          </el-col>
19
        </el-row>
20
        <el-row>
21
          <el-col :span="12">
22
            <el-form-item label="联系电话" prop="age">
23
              <el-input v-model.number="ruleForm2.age" placeholder="请填写您的联系电话"></el-input>
24
               </el-form-item>
25
          </el-col>
26
          <el-col :span="12">
27
            <el-form-item label="联系邮箱" prop="mail">
28
              <el-input v-model.number="ruleForm2.mail" placeholder="请填写您的联系邮箱"></el-input>
29
               </el-form-item>
30
          </el-col>
31
        </el-row>
32
        <el-row>
33
          <el-col :span="12">
34
            <el-form-item label="职位" prop="position">
35
              <el-input v-model.number="ruleForm2.position" placeholder="请填写您的职位"></el-input>
36
               </el-form-item>
37
          </el-col>
38
          <el-col :span="12">
39
            <el-form-item label="所在部门" prop="department">
40
              <el-input v-model.number="ruleForm2.department" placeholder="请填写您的所在部门"></el-input>
41
               </el-form-item>
42
          </el-col>
43
        </el-row>
44
        <el-row>
45
          <el-form-item label="所在机构" prop="agency">
46
            <el-input v-model.number="ruleForm2.agency" placeholder="请填写您的所在机构"></el-input>
47
             </el-form-item>
48
        </el-row>
7
      <el-row>
8
        <el-col :span="18">
9
          <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" label-width="100px" class="demo-ruleForm">
10
            <el-row>
11
              <el-col :span="12">
12
                   <el-form-item label="账号" prop="account">
13
                  <el-input v-model="ruleForm2.account" placeholder="请填写您的账号" maxlength="20"></el-input>
14
                </el-form-item>
15
              </el-col>
16
              <el-col :span="12">
17
                   <el-form-item label="用户名" prop="name">
18
                  <el-input v-model="ruleForm2.name" placeholder="请填写您的用户名" maxlength="20"></el-input>
19
                </el-form-item>
20
              </el-col>
21
            </el-row>
22
            <el-row>
23
              <el-col :span="12">
24
                   <el-form-item label="联系电话" prop="phone">
25
                  <el-input v-model.number="ruleForm2.phone" placeholder="请填写您的联系电话" maxlength="20"></el-input>
26
                </el-form-item>
27
              </el-col>
28
              <el-col :span="12">
29
                   <el-form-item label="联系邮箱" prop="email">
30
                  <el-input v-model="ruleForm2.email" placeholder="请填写您的联系邮箱" maxlength="50"></el-input>
31
                </el-form-item>
32
              </el-col>
33
            </el-row>
34
            <el-row>
35
              <el-col :span="12">
36
                   <el-form-item label="职位" prop="job">
37
                  <el-input v-model="ruleForm2.job" placeholder="请填写您的职位" maxlength="20"></el-input>
38
                </el-form-item>
39
              </el-col>
40
              <el-col :span="12">
41
                   <el-form-item label="所在部门" prop="dep">
42
                  <el-input v-model="ruleForm2.dep" placeholder="请填写您的所在部门" maxlength="20"></el-input>
43
                </el-form-item>
44
              </el-col>
45
            </el-row>
46
            <el-row>
47
                 <el-form-item label="所在机构" prop="comp">
48
                <el-input v-model="ruleForm2.comp" placeholder="请填写您的所在机构" maxlength="50"></el-input>
49
              </el-form-item>
50
            </el-row>
49 51
50
        <el-form-item class="modiaB">
51
          <el-button type="primary" @click="submitForm('ruleForm2')">保存修改</el-button>
52
        </el-form-item>
53
      </el-form>
52
            <el-form-item class="modiaB">
53
              <el-button type="primary" @click="submitForm('ruleForm2')">保存修改</el-button>
54
            </el-form-item>
55
          </el-form>
56
        </el-col>
57
      </el-row>
54 58
    </div>
55 59
  </div>
56 60
</template>
57 61
58 62
<script>
63
  import { url, modifyUrl } from '@/api/modifyAccountInformation'
59 64
  export default {
60 65
    data() {
61
      var checkAge = (rule, value, callback) => {
66
      var checkPhone = (rule, value, callback) => {
67
        const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
62 68
        if (!value) {
63
          return callback(new Error('年龄不能为空'))
64
        }
65
        setTimeout(() => {
66
          if (!Number.isInteger(value)) {
67
            callback(new Error('请输入数字值'))
68
          } else {
69
            if (value < 18) {
70
              callback(new Error('必须年满18岁'))
71
            } else {
72
              callback()
73
            }
74
          }
75
        }, 1000)
76
      }
77
      var validatePass = (rule, value, callback) => {
78
        if (value === '') {
79
          callback(new Error('请输入密码'))
80
        } else {
81
          if (this.ruleForm2.checkPass !== '') {
82
            this.$refs.ruleForm2.validateField('checkPass')
83
          }
84
          callback()
85
        }
86
      }
87
      var validatePass2 = (rule, value, callback) => {
88
        if (value === '') {
89
          callback(new Error('请再次输入密码'))
90
        } else if (value !== this.ruleForm2.pass) {
91
          callback(new Error('两次输入密码不一致!'))
69
          return callback(new Error('请填写联系电话'))
70
        } else if (!reg.test(value)) {
71
          callback(new Error('联系电话格式有误,请检查后重新填写'))
92 72
        } else {
93 73
          callback()
94 74
        }
95 75
      }
96 76
      return {
97 77
        ruleForm2: {
98
          pass: '',
99
          checkPass: '',
100
          age: '',
101
          mail: '',
102
          position: '',
103
          department: '',
104
          agency: ''
78
          account: '',
79
          name: '',
80
          phone: '',
81
          email: '',
82
          job: '',
83
          dep: '',
84
          comp: ''
105 85
        },
106 86
        rules2: {
107
          pass: [
108
            { validator: validatePass, trigger: 'blur' }
87
          account: [
88
            { message: '请填写账号', required: true }
109 89
          ],
110
          checkPass: [
111
            { validator: validatePass2, trigger: 'blur', required: true }
90
          name: [
91
            { message: '请填写用户名', required: true }
112 92
          ],
113
          age: [
114
            { validator: checkAge, trigger: 'blur', required: true }
93
          phone: [
94
            { validator: checkPhone, trigger: 'blur', required: true }
115 95
          ],
116
          position: [
117
            { required: true }
96
          email: [
97
            { type: 'email', message: '联系邮箱格式有误,请检查后重新填写', trigger: 'blur' }
118 98
          ],
119
          department: [
120
            { required: true }
99
          job: [
100
            { message: '请填写职位', required: true }
121 101
          ],
122
          agency: [
123
            { required: true }
102
          dep: [
103
            { message: '请填写所在部门', required: true }
104
          ],
105
          comp: [
106
            { message: '请填写所在机构', required: true }
124 107
          ]
125 108
        }
126 109
      }
127 110
    },
111
    created() {
112
      this.$http.get(url, '', (response) => {
113
        if (response.success && response.data) {
114
          this.ruleForm2 = {
115
            account: response.data.account,
116
            name: response.data.name,
117
            phone: response.data.phone,
118
            email: response.data.email || '',
119
            job: response.data.job,
120
            dep: response.data.dep,
121
            comp: response.data.comp
122
          }
123
        }
124
      })
125
    },
128 126
    methods: {
129 127
      submitForm(formName) {
130 128
        this.$refs[formName].validate((valid) => {
131 129
          if (valid) {
132
            alert('submit!')
130
            this.$http.put(modifyUrl, this.ruleForm2, (response) => {
131
              if (response.success) {
132
                this.$message({
133
                  message: '资料修改成功',
134
                  type: 'success'
135
                })
136
              }
137
            })
133 138
          } else {
134 139
            console.log('error submit!!')
135 140
            return false
136 141
          }
137 142
        })
138
      },
139
      resetForm(formName) {
140
        this.$refs[formName].resetFields()
141 143
      }
142 144
    }
143 145
  }
144 146
</script>
145 147
146 148
<style scoped>
147
  .demo-ruleForm {
148
    width: 900px;
149
  }
150 149
  .modiaB {
151 150
    text-align: center;
152
    margin: 170px 0;
151
    margin: 100px 0;
153 152
  }
154 153
</style>

+ 48 - 49
src/views/accountSettings/modifyPassword.vue

@ -4,55 +4,47 @@
4 4
      <div class="contain-title">重置密码</div>
5 5
    </div>
6 6
    <div class="content-container">
7
      <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" label-width="100px" class="demo-ruleForm">
8
        <el-form-item label="新的密码" prop="pass">
9
          <el-input type="password" v-model="ruleForm2.pass" autocomplete="off" placeholder="请填写新的密码"></el-input>
10
           </el-form-item>
11
        <el-form-item label="确认密码" prop="checkPass">
12
          <el-input type="password" v-model="ruleForm2.checkPass" autocomplete="off" placeholder="再次输入新的密码"></el-input>
13
           </el-form-item>
14
        <el-form-item class="modiaB">
15
          <el-button type="primary" @click="submitForm('ruleForm2')">确定</el-button>
16
           </el-form-item>
17
      </el-form>
7
      <el-row>
8
        <el-col :span="14">
9
          <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" label-width="100px" class="demo-ruleForm">
10
               <el-form-item label="新的密码" prop="pass">
11
              <el-input type="password" v-model="ruleForm2.pass" placeholder="请填写新的密码"></el-input>
12
            </el-form-item>
13
               <el-form-item label="确认密码" prop="checkPass">
14
              <el-input type="password" v-model="ruleForm2.checkPass" placeholder="再次输入新的密码"></el-input>
15
            </el-form-item>
16
               <el-form-item class="modiaB">
17
              <el-button type="primary" @click="submitForm('ruleForm2')">确定</el-button>
18
            </el-form-item>
19
          </el-form>
20
        </el-col>
21
      </el-row>
18 22
    </div>
19 23
  </div>
20 24
</template>
21 25
22 26
<script>
27
  import url from '@/api/modifyPassword'
23 28
  export default {
24 29
    data() {
25
      var checkAge = (rule, value, callback) => {
26
        if (!value) {
27
          return callback(new Error('年龄不能为空'))
28
        }
29
        setTimeout(() => {
30
          if (!Number.isInteger(value)) {
31
            callback(new Error('请输入数字值'))
32
          } else {
33
            if (value < 18) {
34
              callback(new Error('必须年满18岁'))
35
            } else {
36
              callback()
37
            }
38
          }
39
        }, 1000)
40
      }
41 30
      var validatePass = (rule, value, callback) => {
31
        const reg = /^[a-zA-Z0-9]{6,24}$/
42 32
        if (value === '') {
43
          callback(new Error('请输入密码'))
33
          callback(new Error('请设置您的新密码'))
34
        } else if (!reg.test(value)) {
35
          callback(new Error('密码由6-24位数字和字母组成,区分大小写'))
44 36
        } else {
45
          if (this.ruleForm2.checkPass !== '') {
46
            this.$refs.ruleForm2.validateField('checkPass')
47
          }
48 37
          callback()
49 38
        }
50 39
      }
51 40
      var validatePass2 = (rule, value, callback) => {
41
        const reg = /^[a-zA-Z0-9]{6,24}$/
52 42
        if (value === '') {
53
          callback(new Error('请再次输入密码'))
54
        } else if (value !== this.ruleForm2.pass) {
55
          callback(new Error('两次输入密码不一致!'))
43
          callback(new Error('请再次输入密码确认'))
44
        } else if (!reg.test(value)) {
45
          callback(new Error('密码由6-24位数字和字母组成,区分大小写'))
46
        } else if (value !== this.ruleForm2.pass && value) {
47
          callback(new Error('两次输入不一致,请重新输入'))
56 48
        } else {
57 49
          callback()
58 50
        }
@ -60,18 +52,14 @@
60 52
      return {
61 53
        ruleForm2: {
62 54
          pass: '',
63
          checkPass: '',
64
          age: ''
55
          checkPass: ''
65 56
        },
66 57
        rules2: {
67 58
          pass: [
68
            { validator: validatePass, trigger: 'blur' }
59
            { validator: validatePass, trigger: 'blur', required: true }
69 60
          ],
70 61
          checkPass: [
71
            { validator: validatePass2, trigger: 'blur' }
72
          ],
73
          age: [
74
            { validator: checkAge, trigger: 'blur' }
62
            { validator: validatePass2, trigger: 'blur', required: true }
75 63
          ]
76 64
        }
77 65
      }
@ -80,25 +68,36 @@
80 68
      submitForm(formName) {
81 69
        this.$refs[formName].validate((valid) => {
82 70
          if (valid) {
83
            alert('submit!')
71
            this.$http.post(url, { npw: this.ruleForm2.pass }, (response) => {
72
              if (response.success) {
73
                this.$confirm('密码已修改,快去登录吧!', '修改密码', {
74
                  confirmButtonText: '确定',
75
                  cancelButtonText: '取消',
76
                  center: true,
77
                  showCancelButton: false,
78
                  showClose: false,
79
                  closeOnClickModal: false,
80
                  type: 'success'
81
                }).then(() => {
82
                  this.$store.dispatch('LogOut').then((response) => {
83
                    if (response.success) {
84
                      this.$router.push('/login')
85
                    }
86
                  })
87
                })
88
              }
89
            })
84 90
          } else {
85 91
            console.log('error submit!!')
86 92
            return false
87 93
          }
88 94
        })
89
      },
90
      resetForm(formName) {
91
        this.$refs[formName].resetFields()
92 95
      }
93 96
    }
94 97
  }
95 98
</script>
96 99
97 100
<style scoped>
98
  .demo-ruleForm {
99
    width: 900px;
100
  }
101
102 101
  .modiaB {
103 102
    text-align: center;
104 103
    margin: 100px 0;

+ 3 - 3
src/views/contentPub/publish.vue

@ -42,9 +42,9 @@
42 42
</template>
43 43
44 44
<script>
45
  import searchTemplate from './searchTemplate'
46
  import uploadFile from './uploadFile'
47
  import UE from './editorUE'
45
  import searchTemplate from '@/components/searchBar'
46
  import uploadFile from '@/components/uploadFile'
47
  import UE from '@/components/editorUE'
48 48
  export default {
49 49
    data() {
50 50
      var checkTitle = (rule, value, callback) => {

+ 2 - 6
src/views/layout/components/Sidebar/index.vue

@ -8,7 +8,7 @@
8 8
      text-color="#bfcbd9"
9 9
      active-text-color="#409EFF"
10 10
    >
11
      <sidebar-item v-for="route in routes" :key="route.name" :item="route" :base-path="route.path"></sidebar-item>
11
      <sidebar-item v-for="route in permission_routers" :key="permission_routers.name" :item="route" :base-path="route.path"></sidebar-item>
12 12
    </el-menu>
13 13
  </el-scrollbar>
14 14
</template>
@ -19,10 +19,6 @@ import SidebarItem from './SidebarItem'
19 19
20 20
export default {
21 21
  components: { SidebarItem },
22
  computed: {
23
    routes() {
24
      return this.$router.options.routes
25
    }
26
  }
22
  computed: mapGetters(['permission_routers'])
27 23
}
28 24
</script>

+ 1 - 44
src/views/layout/components/TopNavbar.vue

@ -15,50 +15,18 @@
15 15
<script>
16 16
import { mapGetters } from 'vuex'
17 17
import { MessageBox } from 'element-ui'
18
import Cookies from 'js-cookie'
19 18
import '@/styles/variables.scss'
20 19
21 20
export default {
22
  data() {
23
    return {
24
      bridgeId: '',
25
      showName: '',
26
      dataList: ''
27
    }
28
  },
29 21
  computed: {
30 22
    ...mapGetters([
31
      'name',
32
      'roles'
23
      'name'
33 24
    ])
34 25
  },
35
  watch: {
36
    '$route'(to, from) {
37
      if (to.path === '/dashboard') {
38
        var dataList = this.dataList
39
        for (let i = 0; i < dataList.length; i++) {
40
          dataList[i].disab = false
41
        }
42
        Cookies.remove('bridgeId')
43
        Cookies.remove('bridgeName')
44
        this.showName = ''
45
      } else {
46
        this.bridgeId = Cookies.get('bridgeId')
47
        this.showName = Cookies.get('bridgeName')
48
      }
49
    }
50
  },
51
  created() {
52
    this.bridgeId = Cookies.get('bridgeId')
53
    this.showName = Cookies.get('bridgeName')
54
  },
55 26
  methods: {
56 27
    toHome() {
57 28
      this.$router.replace({ path: '/' })
58 29
    },
59
    toggleSideBar() {
60
      this.$store.dispatch('ToggleSideBar')
61
    },
62 30
    logout() {
63 31
      MessageBox.confirm('您确认要退出登录吗?', '提示', {
64 32
        confirmButtonText: '确定',
@ -67,22 +35,11 @@ export default {
67 35
        center: true
68 36
      }).then(() => {
69 37
        this.$store.dispatch('LogOut').then(() => {
70
          Cookies.remove('bridgeId')
71
          Cookies.remove('bridgeName')
72 38
          location.reload() // 为了重新实例化vue-router对象 避免bug
73 39
        })
74 40
      }).catch(() => {
75 41
        console.log('已取消退出')
76 42
      })
77
    },
78
    goToDashboardC(id, name) {
79
      this.showName = name
80
      Cookies.set('bridgeId', id)
81
      Cookies.set('bridgeName', name)
82
      this.$router.replace({
83
        name: 'bridgeDetail',
84
        query: { id: id, name: name }
85
      })
86 43
    }
87 44
  }
88 45
}

+ 75 - 117
src/views/login/index.vue

@ -5,141 +5,99 @@
5 5
    </div>
6 6
    <el-form class="login-form" autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left">
7 7
      <h3 class="title">登录</h3>
8
      <el-form-item prop="username">
8
      <el-form-item prop="account">
9 9
        <span class="svg-container svg-container_login">
10 10
          <svg-icon icon-class="user" />
11 11
        </span>
12
        <el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" placeholder="请输入您的手机号码" maxlength="11" />
12
        <el-input name="username" type="text" v-model="loginForm.account" autoComplete="on" placeholder="请输入用户账号"
13
          maxlength="11" />
13 14
      </el-form-item>
14
      <el-form-item prop="password">
15
      <el-form-item prop="pw">
15 16
        <span class="svg-container">
16
          <svg-icon icon-class="password"/>
17
          <svg-icon icon-class="password" />
17 18
        </span>
18
        <el-input name="password" :type="pwdType" v-model="loginForm.password" autoComplete="on"
19
          placeholder="请输入您的登录密码" maxlength="24"></el-input>
20
          <span class="show-pwd" @click="showPwd"><svg-icon icon-class="eye" v-show="!falg"/><svg-icon icon-class="password-view" v-show="falg"/></span>
21
      </el-form-item>
22
      <el-form-item prop="imgVerifyCode">
23
        <span class="svg-container">
24
          <svg-icon icon-class="msgvc"></svg-icon>
25
        </span>
26
        <el-input v-model="loginForm.imgVerifyCode" placeholder="请输入图形验证码" @keyup.enter.native="handleLogin" class="code-btn" maxlength="4">
27
        <img slot="append" :src="imgVcUrl" @click="changeImgVc" /></el-input>
19
        <el-input name="password" :type="pwdType" v-model="loginForm.pw" autoComplete="on" placeholder="请输入登录密码"
20
          maxlength="24"></el-input>
21
        <span class="show-pwd" @click="showPwd">
22
          <svg-icon icon-class="eye" v-show="!falg" />
23
          <svg-icon icon-class="password-view" v-show="falg" /></span>
28 24
      </el-form-item>
29 25
      <el-form-item>
30 26
        <el-button class="log-btn" type="primary" :loading="loading" @click.native.prevent="handleLogin">登录</el-button>
31 27
      </el-form-item>
32
      <el-form-item class="el-form-find">
33
        <el-button type="text" @click.native.prevent="goBackPwd">忘记密码?</el-button>
34
      </el-form-item>
35 28
    </el-form>
36 29
  </div>
37 30
</template>
38 31
39 32
<script>
40
import { Message } from 'element-ui'
41
import { getPictureVC } from '@/api/pictureVc'
42
import '@/styles/loginform.scss'
43
44
export default {
45
  name: 'login',
46
  data() {
47
    var validPhone = (rule, value, callback) => {
48
      const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
49
      if (!value) {
50
        callback(new Error('请输入您的手机号码'))
51
      } else if (!reg.test(value)) {
52
        callback(new Error('请输入正确的手机号码'))
53
      } else {
33
  import { Message } from 'element-ui'
34
  import '@/styles/loginform.scss'
35
  export default {
36
    name: 'login',
37
    data() {
38
      var validPassword = (rule, value, callback) => {
39
        const reg = /^[a-zA-Z0-9]{6,24}$/
40
        if (!value) {
41
          callback(new Error('请输入您的登录密码'))
42
        }
43
        if (!reg.test(value)) {
44
          callback(new Error('密码由6-24个数字和字母组成,区分大小写'))
45
        }
54 46
        callback()
55 47
      }
56
    }
57
    return {
58
      falg: false,
59
      imgVcUrl: '',
60
      loginForm: {
61
        username: 'admin',
62
        password: 'admin',
63
        imgVerifyCode: ''
64
      },
65
      loginRules: {
66
        // username: [{ required: true, trigger: 'blur', validator: validPhone }],
67
        // password: [
68
        //   { required: true, message: '请输入您的登录密码', trigger: 'blur' },
69
        //   { min: 6, max: 24, message: '密码由6-24个字符组成,区分大小写', trigger: 'blur' }
70
        // ],
71
        // imgVerifyCode: [{ required: true, message: '请输入图形验证码', trigger: 'blur' }]
72
      },
73
      loading: false,
74
      pwdType: 'password'
75
    }
76
  },
77
  created() {
78
    this.changeImgVc()
79
  },
80
  methods: {
81
    showPwd() {
82
      this.falg = !this.falg
83
      if (this.pwdType === 'password') {
84
        this.pwdType = ''
85
      } else {
86
        this.pwdType = 'password'
48
      return {
49
        falg: false,
50
        loginForm: {
51
          account: '',
52
          pw: ''
53
        },
54
        loginRules: {
55
          account: [{ required: true, message: '请输入您的用户账号' }],
56
          pw: [
57
            { required: true, validator: validPassword, trigger: 'blur' }
58
          ]
59
        },
60
        loading: false,
61
        pwdType: 'password'
87 62
      }
88 63
    },
89
    handleLogin() {
90
      this.$router.push({ path: '/dashboard' })
91
      // this.$refs.loginForm.validate(valid => {
92
      //   if (valid) {
93
      //     this.loading = true
94
      //     this.$store.dispatch('LoginByUsername', this.loginForm).then((response) => {
95
      //       this.loading = false
96
      //       if (response.success) {
97
      //         if (response.data) {
98
      //           this.$store.dispatch('GetUserInfo').then(res => {
99
      //           })
100
      //           this.$router.push({ path: '/dashboard' })
101
      //         } else {
102
      //           Message.error('登录账号与密码不匹配,请检查后重试')
103
      //           this.changeImgVc()
104
      //           return
105
      //         }
106
      //       } else {
107
      //         const errorCode = [{
108
      //           code: -60001,
109
      //           msg: '图形验证码不存在'
110
      //         }, {
111
      //           code: -60002,
112
      //           msg: '图形验证码超时'
113
      //         }, {
114
      //           code: -60003,
115
      //           msg: '图形验证码不正确'
116
      //         }, {
117
      //           code: -60005,
118
      //           msg: '该账号已停用,请联系管理员'
119
      //         }]
120
      //         for (let i = 0; i < errorCode.length; i++) {
121
      //           if (response.code === errorCode[i].code) {
122
      //             Message.error(errorCode[i].msg)
123
      //             this.changeImgVc()
124
      //             return
125
      //           }
126
      //         }
127
      //       }
128
      //     }).catch(() => {
129
      //       this.loading = false
130
      //     })
131
      //   } else {
132
      //     console.log('error submit!!')
133
      //     return false
134
      //   }
135
      // })
136
    },
137
    goBackPwd() {
138
      this.$router.push({ path: '/findPwd' })
139
    },
140
    changeImgVc() {
141
      this.imgVcUrl = getPictureVC('PIC_LOGIN')
64
    methods: {
65
      showPwd() {
66
        this.falg = !this.falg
67
        if (this.pwdType === 'password') {
68
          this.pwdType = ''
69
        } else {
70
          this.pwdType = 'password'
71
        }
72
      },
73
      handleLogin() {
74
        this.$refs.loginForm.validate(valid => {
75
          if (valid) {
76
            this.loading = true
77
            this.$store.dispatch('LoginByUsername', this.loginForm).then((response) => {
78
              this.loading = false
79
              if (response.success) {
80
                if (response.data) {
81
                  this.$store.dispatch('GetUserInfo').then(res => {
82
                  })
83
                  this.$router.push({ path: '/dashboard' })
84
                } else {
85
                  Message.error('该账号已停用,请联系管理员')
86
                }
87
              } else {
88
                if (response.code === -200001) {
89
                  Message.error('账号或密码错误,请重新输入')
90
                }
91
              }
92
            }).catch(() => {
93
              this.loading = false
94
            })
95
          } else {
96
            console.log('error submit!!')
97
            return false
98
          }
99
        })
100
      }
142 101
    }
143 102
  }
144
}
145
</script>
103
</script>