|
@@ -91,11 +91,13 @@ export function hasPriceAuth(authNode, priceOptions, userAuthCode){
|
|
const a = item.code.split('_')
|
|
const a = item.code.split('_')
|
|
const hasCode = priceOptions.find(k => k.value == a[a.length-1])
|
|
const hasCode = priceOptions.find(k => k.value == a[a.length-1])
|
|
const hasRoles = userAuthCode.includes(item.code)
|
|
const hasRoles = userAuthCode.includes(item.code)
|
|
|
|
+ // 获取当前用户的角色拥有的价格权限
|
|
if(hasCode && hasRoles){
|
|
if(hasCode && hasRoles){
|
|
codes.push(a[a.length-1])
|
|
codes.push(a[a.length-1])
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- // 生成权限参数
|
|
|
|
|
|
+ // 根据拥有的价格权限生成数组标记[1,0,1,0,0],每一位对应一个价格权限
|
|
|
|
+ // 有权限标记1,否则标记0
|
|
priceOptions.map(item => {
|
|
priceOptions.map(item => {
|
|
ret.push(codes.includes(item.value)?1:0)
|
|
ret.push(codes.includes(item.value)?1:0)
|
|
})
|
|
})
|
|
@@ -103,11 +105,16 @@ export function hasPriceAuth(authNode, priceOptions, userAuthCode){
|
|
}
|
|
}
|
|
// 获取接口对应的价格权限code
|
|
// 获取接口对应的价格权限code
|
|
export function getAuthPriceCode (config, router, store) {
|
|
export function getAuthPriceCode (config, router, store) {
|
|
- const permission = router.history.current.meta.permission
|
|
|
|
|
|
+ // 通过路由打开的页面的权限code
|
|
|
|
+ const permission = router.history.current.meta.permission
|
|
|
|
+ // 手动指定的权限code,如打开的弹框页面或导出、打印
|
|
|
|
+ // 手动指定的权限在使用完后需要清空,如在关闭弹框或导出、打印接口调用完成后清空
|
|
const curActionPermission = store.state.app.curActionPermission
|
|
const curActionPermission = store.state.app.curActionPermission
|
|
|
|
+ // 价格权限的所有选项,销售价、成本价、省、市、特约价
|
|
const priceOptions = store.state.app.priceAuthOptions
|
|
const priceOptions = store.state.app.priceAuthOptions
|
|
|
|
+ // 最终获取的权限code,手动指定的优先级高于路由打开的页面权限code
|
|
const authCode = curActionPermission || permission
|
|
const authCode = curActionPermission || permission
|
|
- // 当前角色的价格配置
|
|
|
|
|
|
+ // 当前角色的分配的价格权限,这里过滤非价格权限code
|
|
const roles = store.state.user.roles
|
|
const roles = store.state.user.roles
|
|
const userAuthCode = roles.permissionList.filter(item => {
|
|
const userAuthCode = roles.permissionList.filter(item => {
|
|
const a = item.split('_')
|
|
const a = item.split('_')
|
|
@@ -115,13 +122,18 @@ export function getAuthPriceCode (config, router, store) {
|
|
})
|
|
})
|
|
// console.log(userAuthCode)
|
|
// console.log(userAuthCode)
|
|
console.log(authCode)
|
|
console.log(authCode)
|
|
|
|
+ // 如果有权限code
|
|
if(authCode){
|
|
if(authCode){
|
|
|
|
+ // 当前正在调用的接口url
|
|
const url = config.url
|
|
const url = config.url
|
|
|
|
+ // 所有的权限菜单数据
|
|
const authTree = store.state.app.authMenusList
|
|
const authTree = store.state.app.authMenusList
|
|
|
|
+ // 从所有的权限菜单中查找当前权限code对应的权限菜单数据
|
|
const authNode = treeFind(authTree,(item)=>item.code == authCode)
|
|
const authNode = treeFind(authTree,(item)=>item.code == authCode)
|
|
console.log(authNode)
|
|
console.log(authNode)
|
|
|
|
+ // 从找到的对应权限菜单数据中判断当前调用接口的url是否存在,这里和权限菜单中的后台权限code比较
|
|
const hasReqUrl = authNode.permission.split(',').find(item => url.replace(/\//g,'_').indexOf(item)>=0)
|
|
const hasReqUrl = authNode.permission.split(',').find(item => url.replace(/\//g,'_').indexOf(item)>=0)
|
|
-
|
|
|
|
|
|
+ // 如果存在则返回一个如 [1,0,1,0,0] 的格式的价格权限字符串给后台接口
|
|
if(hasReqUrl&&authNode.children&&authNode.children.length){
|
|
if(hasReqUrl&&authNode.children&&authNode.children.length){
|
|
return hasPriceAuth(authNode.children,priceOptions,userAuthCode)
|
|
return hasPriceAuth(authNode.children,priceOptions,userAuthCode)
|
|
}
|
|
}
|