Skip to content

Commit 48043c1

Browse files
authored
Merge pull request PanJiaChen#23 from PanJiaChen/refactor/remove_permission-control
refactor: remove_permission-control
2 parents 05ed30b + 9abd44f commit 48043c1

File tree

7 files changed

+37
-107
lines changed

7 files changed

+37
-107
lines changed

src/permission.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@ import NProgress from 'nprogress' // Progress 进度条
44
import 'nprogress/nprogress.css'// Progress 进度条样式
55
import { getToken } from '@/utils/auth' // 验权
66

7-
const whiteList = ['/login']
7+
const whiteList = ['/login'] // 不重定向白名单
88
router.beforeEach((to, from, next) => {
99
NProgress.start()
1010
if (getToken()) {
1111
if (to.path === '/login') {
1212
next({ path: '/' })
1313
} else {
1414
if (store.getters.roles.length === 0) {
15-
store.dispatch('GetInfo').then(res => {
16-
const roles = res.data.role
17-
store.dispatch('GenerateRoutes', { roles }).then(() => {
18-
router.addRoutes(store.getters.addRouters)
19-
next({ ...to })
20-
})
15+
store.dispatch('GetInfo').then(res => { // 拉取用户信息
16+
next()
2117
})
2218
} else {
2319
next()

src/router/index.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import Layout from '../views/layout/Layout'
88

99
Vue.use(Router)
1010

11-
/**
12-
* icon : the icon show in the sidebar
13-
* hidden : if `hidden:true` will not show in the sidebar
14-
* redirect : if `redirect:noredirect` will not redirct in the levelbar
15-
* noDropdown : if `noDropdown:true` will not has submenu in the sidebar
16-
* meta : `{ role: ['admin'] }` will control the page role
17-
**/
11+
/**
12+
* icon : the icon show in the sidebar
13+
* hidden : if `hidden:true` will not show in the sidebar
14+
* redirect : if `redirect:noredirect` will not redirct in the levelbar
15+
* noDropdown : if `noDropdown:true` will not has submenu in the sidebar
16+
* meta : `{ role: ['admin'] }` will control the page role
17+
**/
1818
export const constantRouterMap = [
1919
{ path: '/login', component: _import('login/index'), hidden: true },
2020
{ path: '/404', component: _import('404'), hidden: true },
@@ -25,16 +25,8 @@ export const constantRouterMap = [
2525
name: 'Dashboard',
2626
hidden: true,
2727
children: [{ path: 'dashboard', component: _import('dashboard/index') }]
28-
}
29-
]
30-
31-
export default new Router({
32-
// mode: 'history', //后端支持可开
33-
scrollBehavior: () => ({ y: 0 }),
34-
routes: constantRouterMap
35-
})
28+
},
3629

37-
export const asyncRouterMap = [
3830
{
3931
path: '/example',
4032
component: Layout,
@@ -57,3 +49,10 @@ export const asyncRouterMap = [
5749

5850
{ path: '*', redirect: '/404', hidden: true }
5951
]
52+
53+
export default new Router({
54+
// mode: 'history', //后端支持可开
55+
scrollBehavior: () => ({ y: 0 }),
56+
routes: constantRouterMap
57+
})
58+

src/store/getters.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const getters = {
33
token: state => state.user.token,
44
avatar: state => state.user.avatar,
55
name: state => state.user.name,
6-
roles: state => state.user.roles,
7-
permission_routers: state => state.permission.routers,
8-
addRouters: state => state.permission.addRouters
6+
roles: state => state.user.roles
97
}
108
export default getters

src/store/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ import Vue from 'vue'
22
import Vuex from 'vuex'
33
import app from './modules/app'
44
import user from './modules/user'
5-
import permission from './modules/permission'
65
import getters from './getters'
76

87
Vue.use(Vuex)
98

109
const store = new Vuex.Store({
1110
modules: {
1211
app,
13-
user,
14-
permission
12+
user
1513
},
1614
getters
1715
})

src/store/modules/permission.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/views/layout/Sidebar.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<template>
22
<el-menu mode="vertical" theme="dark" :default-active="$route.path">
3-
<sidebar-item :routes='permission_routers'></sidebar-item>
3+
<sidebar-item :routes="routes"></sidebar-item>
44
</el-menu>
55
</template>
66

77
<script>
8-
import { mapGetters } from 'vuex'
98
import SidebarItem from './SidebarItem'
109
export default {
1110
components: { SidebarItem },
1211
computed: {
13-
...mapGetters([
14-
'permission_routers'
15-
])
12+
routes() {
13+
return this.$router.options.routes
14+
}
1615
}
1716
}
1817
</script>

src/views/login/index.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,29 @@
22
<div class="login-container">
33
<el-form autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left" label-width="0px"
44
class="card-box login-form">
5-
<h3 class="title">系统登录</h3>
6-
<el-form-item prop="username">
5+
<h3 class="title">vue-element-admin</h3>
6+
<el-form-item prop="username">
77
<span class="svg-container svg-container_login">
88
<icon-svg icon-class="yonghuming" />
99
</span>
10-
<el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" placeholder="邮箱" />
10+
<el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" placeholder="username" />
1111
</el-form-item>
1212
<el-form-item prop="password">
1313
<span class="svg-container">
14-
<icon-svg icon-class="mima" ></icon-svg>
14+
<icon-svg icon-class="mima"></icon-svg>
1515
</span>
1616
<el-input name="password" type="password" @keyup.enter.native="handleLogin" v-model="loginForm.password" autoComplete="on"
17-
placeholder="密码"></el-input>
17+
placeholder="password"></el-input>
1818
</el-form-item>
1919
<el-form-item>
2020
<el-button type="primary" style="width:100%;" :loading="loading" @click.native.prevent="handleLogin">
21-
登录
21+
Sign in
2222
</el-button>
2323
</el-form-item>
24-
<div class='tips'>账号:admin 密码随便填</div>
25-
<div class='tips'>账号:editor 密码随便填</div>
24+
<div class='tips'>
25+
<span style="margin-right:20px;">username: admin</span>
26+
</span> password: admin</span>
27+
</div>
2628
</el-form>
2729
</div>
2830
</template>
@@ -41,16 +43,16 @@ export default {
4143
}
4244
}
4345
const validatePass = (rule, value, callback) => {
44-
if (value.length < 6) {
45-
callback(new Error('密码不能小于6位'))
46+
if (value.length < 5) {
47+
callback(new Error('密码不能小于5位'))
4648
} else {
4749
callback()
4850
}
4951
}
5052
return {
5153
loginForm: {
5254
username: 'admin',
53-
password: '111111'
55+
password: 'admin'
5456
},
5557
loginRules: {
5658
username: [{ required: true, trigger: 'blur', validator: validateUsername }],

0 commit comments

Comments
 (0)