Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wjkang committed Dec 31, 2018
1 parent 7d3675c commit f074a58
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"jsonlint": "^1.6.3",
"lodash": "^4.17.11",
"lowdb": "^1.0.0",
"matchit": "^1.0.7",
"mockjs": "^1.0.1-beta3",
"nprogress": "^0.2.0",
"particles.js": "^2.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/api/sys/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function getMenu(id) {
return request({
url: '/menu/' + id,
method: 'get',
interfaceCheck: false,
loading: {
type: 'nprogress',
interval: 500
Expand Down
22 changes: 18 additions & 4 deletions src/libs/permission.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import { exec, match, parse } from 'matchit';
export default {
access: function (config, store) {
let functionAccess = true
let interfaceAccess = true
let isAdmin = store.state.d2admin.permission.isAdmin;
if (config.permission && config.permission.length > 0) {
let needPermissions = config.permission;
let permissions = store.state.d2admin.permission.functions.concat(store.state.d2admin.permission.roles);
let isAdmin = store.state.d2admin.permission.isAdmin;
let hasPermission = permissions.some(s => {
return needPermissions.indexOf(s) > -1;
})
if (!hasPermission && !isAdmin) {
return false
if (!hasPermission) {
functionAccess = false
}
}
return true
if (config.interfaceCheck) {
let path = config.url.replace(config.baseURL, "");
let method = config.method;
let interfaces = store.state.d2admin.permission.interfaces
let matched = interfaces.filter(s => {
return s.path == path && s.method == method
})
if (matched.length == 0) {
interfaceAccess = false
}
}
return functionAccess && interfaceAccess
}
}
5 changes: 0 additions & 5 deletions src/pages/sys/interface/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
{{scope.row.method}}
</template>
</el-table-column>
<el-table-column label="状态" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{scope.row.isLocked}}
</template>
</el-table-column>
<el-table-column label="描述" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{scope.row.description}}
Expand Down
10 changes: 7 additions & 3 deletions src/plugin/axios/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ const service = axios.create({
// 请求拦截器
service.interceptors.request.use(
config => {
if (!permission.access(config)) {
throw "403"
if (!permission.access(config, store)) {
throw {
type: '403',
config: config
}
}
loading.show(config)
// 在请求发送之前做一些处理
Expand Down Expand Up @@ -76,6 +79,7 @@ service.interceptors.response.use(
}
},
error => {
console.log(error.config)
loading.hide(error.config)
if (error.response && error.response.status === 401) {
util.cookies.get('remove')
Expand All @@ -95,7 +99,7 @@ service.interceptors.response.use(
errorLog(new Error(`系统错误!: ${error.config.url}`))
} else if (error.message && error.message.indexOf("timeout") > -1) {
errorLog(new Error(`网络超时!: ${error.config.url}`))
} else if (error === "403") {
} else if (error.type === "403") {
errorLog(new Error(`没有请求权限!: ${error.config.url}`))
} else {
errorLog(new Error(`网络错误!: ${error.config.url}`))
Expand Down
1 change: 1 addition & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ let fetchPermissionInfo = async () => {
permissionRouter = userPermissionInfo.accessRoutes
permission.functions = userPermissionInfo.userPermissions
permission.roles = userPermissionInfo.userRoles
permission.interfaces = userPermissionInfo.accessInterfaces
permission.isAdmin = userPermissionInfo.isAdmin == 1
} catch (ex) {

Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/d2admin/modules/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export default {
functions: [],
//角色编码
roles: [],
//接口
interfaces: [],
//是否管理员
isAdmin: false
},
Expand All @@ -13,6 +15,7 @@ export default {
state.functions = data.functions;
state.roles = data.roles;
state.isAdmin = data.isAdmin;
state.interfaces = data.interfaces;
}
}
}

0 comments on commit f074a58

Please sign in to comment.