Skip to content

Commit 3bfa6cb

Browse files
committed
feat(*): permissions
change auth to permission
1 parent 398313c commit 3bfa6cb

File tree

19 files changed

+135
-161
lines changed

19 files changed

+135
-161
lines changed

src/components/base/table/lin-table.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
plain
4242
:key="index"
4343
size="mini"
44-
v-auth="{ auth: item.auth ? item.auth : '', type: 'disabled' }"
44+
v-permission="{ permission: item.permission ? item.permission : '', type: 'disabled' }"
4545
@click.native.prevent.stop="buttonMethods(item.func, scope.$index, scope.row)"
4646
>{{ item.name }}</el-button
4747
>

src/components/layout/NavBar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<breadcrumb />
55
<!-- 暂时放这里 -->
66
<div class="right-info">
7-
<notify v-auth="'消息推送'" v-show="false" />
7+
<notify v-permission="'消息推送'" v-show="false" />
88
<clear-tab></clear-tab>
99
<screenfull /> <user></user>
1010
</div>

src/components/layout/User.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export default {
317317
},
318318
})
319319
.then(res => {
320-
if (res.error_code === 0) {
320+
if (res.error_code < 100) {
321321
this.$message({
322322
type: 'success',
323323
message: '更新昵称成功',

src/config/stage/center.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const centerRouter = {
66
icon: 'iconfont icon-tushuguanli',
77
filePath: 'views/center/', // 文件路径
88
order: null,
9-
inNav: true,
9+
inNav: false,
1010
}
1111

1212
export default centerRouter

src/lin/directives/authorize.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Vue from 'vue'
22
import store from '@/store'
33

44
function isAllowed(permission, user, permissions) {
5-
if (user.isSuper) {
5+
if (user.admin) {
66
return true
77
}
88
if (typeof permission === 'string') {
@@ -14,21 +14,21 @@ function isAllowed(permission, user, permissions) {
1414
return false
1515
}
1616

17-
Vue.directive('auth', {
17+
Vue.directive('permission', {
1818
bind(el, binding) {
19-
let auth
19+
let permission
2020
let type
2121
if (Object.prototype.toString.call(binding.value) === '[object Object]') {
2222
// eslint-disable-next-line prefer-destructuring
23-
auth = binding.value.auth
23+
permission = binding.value.permission
2424
// eslint-disable-next-line prefer-destructuring
2525
type = binding.value.type
2626
} else {
27-
auth = binding.value
27+
permission = binding.value
2828
}
29-
const isAllow = isAllowed(auth, store.state.user || {}, store.state.permissions)
29+
const isAllow = isAllowed(permission, store.state.user || {}, store.state.permissions)
3030
const element = el
31-
if (!isAllow && auth) {
31+
if (!isAllow && permission) {
3232
if (type) {
3333
element.disabled = true
3434
element.style.opacity = 0.4
@@ -40,4 +40,4 @@ Vue.directive('auth', {
4040
},
4141
})
4242

43-
export default Vue.directive('auth')
43+
export default Vue.directive('permission')

src/lin/mixin/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ const globalMixin = {
1010
/* eslint-disable no-unused-expressions */
1111
window.history.length > 1 ? this.$router.go(-1) : this.$router.push('/')
1212
},
13-
isAllowed(_auth) {
13+
isAllowed(_permission) {
1414
/* eslint-disable no-restricted-syntax */
1515
/* eslint-disable guard-for-in */
1616
const { permissions } = this.user
1717
for (const mod of permissions) {
1818
for (const item in mod) {
1919
for (const a of mod[item]) {
20-
// console.log(a.auth)
21-
if (a.permission === _auth) {
20+
// console.log(a.permission)
21+
if (a.permission === _permission) {
2222
return true
2323
}
2424
// console.log(a.module)

src/lin/models/admin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class Admin {
3131
}
3232
}
3333

34-
static getAllAuths() {
34+
static getAllPermissions() {
3535
return get('cms/admin/permission')
3636
}
3737

@@ -62,7 +62,7 @@ export default class Admin {
6262
return this.getAdminUsers({})
6363
}
6464

65-
async getGroupsWithAuths({ count = this.uCount, page = this.uPag }) {
65+
async getGroupsWithPermissions({ count = this.uCount, page = this.uPag }) {
6666
const res = await get('cms/admin/groups', {
6767
count,
6868
page,
@@ -72,12 +72,12 @@ export default class Admin {
7272

7373
async nextGroupsPage() {
7474
await this.increseGpage()
75-
return this.getGroupsWithAuths({})
75+
return this.getGroupsWithPermissions({})
7676
}
7777

7878
async preGroupsPage() {
7979
await this.decreseGpage()
80-
return this.getGroupsWithAuths({})
80+
return this.getGroupsWithPermissions({})
8181
}
8282

8383
static async getAllGroups() {
@@ -125,7 +125,7 @@ export default class Admin {
125125
return res
126126
}
127127

128-
static async dispatchAuths(group_id, permission_ids) {
128+
static async dispatchPermissions(group_id, permission_ids) {
129129
const res = await post('cms/admin/permission/dispatch/batch', {
130130
group_id,
131131
permission_ids,
@@ -141,7 +141,7 @@ export default class Admin {
141141
return res
142142
}
143143

144-
static async removeAuths(group_id, permission_ids) {
144+
static async removePermissions(group_id, permission_ids) {
145145
const res = await post('cms/admin/permission/remove', {
146146
group_id,
147147
permission_ids,

src/lin/models/user.js

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,8 @@
11
import { post, get, put } from '@/lin/plugins/axios'
22
import { saveTokens } from '../utils/token'
3+
import store from '@/store'
34

45
export default class User {
5-
// 昵称
6-
nickname = null
7-
8-
// 邮箱
9-
email = null
10-
11-
avatar = null // 头像
12-
13-
// 所属分组信息
14-
groups = []
15-
16-
// 用户名
17-
username = null
18-
19-
// 是否为超级管理员
20-
isSuper = null
21-
22-
// 拥有的权限
23-
permissions = []
24-
25-
constructor(nickname, username, admin, groups, permissions, email, avatar) {
26-
this.email = email
27-
this.groups = groups
28-
this.username = username
29-
this.avatar = avatar
30-
this.isSuper = admin
31-
this.permissions = permissions || []
32-
this.nickname = nickname
33-
}
34-
356
/**
367
* 分配用户
378
* @param {object} data 注册信息
@@ -59,15 +30,17 @@ export default class User {
5930
*/
6031
static async getInformation() {
6132
const info = await get('cms/user/information')
62-
return new User(info.nickname, info.username, info.admin, info.groups, info.permissions, info.email, info.avatar)
33+
const storeUser = store.getters.user === null ? {} : store.getters.user
34+
return Object.assign({ ...storeUser }, info)
6335
}
6436

6537
/**
6638
* 获取当前用户信息和所拥有的权限
6739
*/
6840
static async getPermissions() {
6941
const info = await get('cms/user/permissions')
70-
return new User(info.nickname, info.username, info.admin, info.groups, info.permissions, info.email, info.avatar)
42+
const storeUser = store.getters.user === null ? {} : store.getters.user
43+
return Object.assign({ ...storeUser }, info)
7144
}
7245

7346
/**

src/lin/plugins/axios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ _axios.interceptors.request.use(
8484
/* eslint-disable-next-line */
8585
console.warn(`其他请求类型: ${reqConfig.method}, 暂无自动处理`)
8686
}
87-
// step2: auth 处理
87+
// step2: permission 处理
8888
if (reqConfig.url === 'cms/user/refresh') {
8989
const refreshToken = getToken('refresh_token')
9090
if (refreshToken) {

src/lin/utils/util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ Utils.deepClone = data => cloneDeep(data)
189189
/**
190190
* 判断权限
191191
*/
192-
Utils.hasPermission = (auths, route, user) => {
192+
Utils.hasPermission = (permissions, route, user) => {
193193
// eslint-disable-line
194-
if (user && user.isSuper) {
194+
if (user && user.admin) {
195195
return true
196196
}
197197
if (route.permission) {
198-
return auths.some(auth => route.permission.indexOf(auth) > -1)
198+
return permissions.some(permission => route.permission.indexOf(permission) > -1)
199199
}
200200
return true
201201
}

0 commit comments

Comments
 (0)