页面按钮权限
This commit is contained in:
+36
-11
@@ -36,22 +36,36 @@ export const useMenuStore = defineStore('menu', () => {
|
||||
const menuProwerList = ref([])
|
||||
|
||||
/**
|
||||
* 岗位权限校验:现场人员(UserType=3)按 WorkPostName 硬编码限制(见 constant.js postMenuPermissions),
|
||||
* 其余用户不限制
|
||||
* @param {string} funcKey 功能 key;空表示非扫码类菜单(pipe 管理应用),对现场人员一律隐藏
|
||||
* 取岗位某功能的数据权限级别(仅按 WorkPostName)
|
||||
* @returns {'view'|'edit'|null} null 表示无菜单权限
|
||||
* - WorkPostName 在权限表中:按表配置
|
||||
* - 不在表中:不限制(edit)
|
||||
*/
|
||||
const hasPostPermission = (funcKey) => {
|
||||
const getPostFuncLevel = (funcKey) => {
|
||||
if (!funcKey) return null
|
||||
const userStore = useUserStore()
|
||||
const info = userStore.userInfo
|
||||
if (String(info?.UserType) !== '3') return true
|
||||
if (!funcKey) return false
|
||||
const allows = postMenuPermissions[info?.WorkPostName]
|
||||
return !!allows && allows.includes(funcKey)
|
||||
const postName = String(userStore.userInfo?.WorkPostName || '').trim()
|
||||
const map = postMenuPermissions[postName]
|
||||
if (!map) return 'edit'
|
||||
return map[funcKey] || null
|
||||
}
|
||||
|
||||
/**
|
||||
* 岗位菜单权限(仅按 WorkPostName)
|
||||
* @param {string} funcKey 功能 key;空表示非扫码类(pipe),不按岗位拦截,走后端 menuId
|
||||
*/
|
||||
const hasPostPermission = (funcKey) => {
|
||||
if (!funcKey) return true
|
||||
return !!getPostFuncLevel(funcKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* 岗位数据权限:是否可编辑(提交/保存);仅可查看时返回 false
|
||||
*/
|
||||
const canEditFunc = (funcKey) => getPostFuncLevel(funcKey) === 'edit'
|
||||
|
||||
/**
|
||||
* 校验扫码跳转的页面路径是否有岗位权限(非扫码类路径不限制)
|
||||
* @param {string} path 页面路径
|
||||
*/
|
||||
const canAccessPath = (path) => {
|
||||
const funcKey = scanPathFuncKeyMap[path]
|
||||
@@ -59,6 +73,15 @@ export const useMenuStore = defineStore('menu', () => {
|
||||
return hasPostPermission(funcKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验页面路径是否可编辑
|
||||
*/
|
||||
const canEditPath = (path) => {
|
||||
const funcKey = scanPathFuncKeyMap[path]
|
||||
if (!funcKey) return true
|
||||
return canEditFunc(funcKey)
|
||||
}
|
||||
|
||||
// 应用是否可见:后端菜单权限 + 岗位权限双重过滤
|
||||
const appVisible = (app) => hasMenuPermission(app.menuId) && hasPostPermission(app.funcKey)
|
||||
|
||||
@@ -131,7 +154,9 @@ export const useMenuStore = defineStore('menu', () => {
|
||||
fetchMenuPowerList,
|
||||
hasMenuPermission,
|
||||
hasPostPermission,
|
||||
canAccessPath
|
||||
canEditFunc,
|
||||
canAccessPath,
|
||||
canEditPath
|
||||
}
|
||||
}, {
|
||||
persist: {
|
||||
|
||||
Reference in New Issue
Block a user