fix: 优化工作流菜单权限

This commit is contained in:
XieYongHong 2023-11-07 17:31:50 +08:00
parent 0ffb6a92c9
commit a087566f4d
4 changed files with 266 additions and 21 deletions

View File

@ -1,2 +1,3 @@
ENV=develop ENV=develop
VITE_APP_BASE_API=/api VITE_APP_BASE_API=/api
VITE_TOKEN_KEY = X-Access-Token

View File

@ -1,2 +1,3 @@
ENV=production ENV=production
VITE_APP_BASE_API=/api VITE_APP_BASE_API=/api
VITE_TOKEN_KEY = X-Access-Token

View File

@ -172,17 +172,25 @@ const handleButtons = (buttons?: Buttons) => {
} }
const handleMeta = (item: MenuItem, isApp: boolean) => { const handleMeta = (item: MenuItem, isApp: boolean) => {
const meta = item.meta
return { return {
icon: item.icon, icon: item.icon,
title: item.name, title: meta?.title || item.name,
hideInMenu: item.isShow === false, hideInMenu: meta?.hideInMenu ?? item.isShow === false,
buttons: handleButtons(item.buttons), buttons: handleButtons(item.buttons),
isApp isApp
} }
} }
const findComponents = (code: string, level: number, isApp: boolean, components: any, mate: any, hasChildren: boolean) => { const findComponents = (code: string, level: number, isApp: boolean, components: any, mate: any, hasChildren: boolean, extraModules = {}) => {
const myComponents = components[code]
const allComponents = {
...components,
...extraModules
}
const myComponents = allComponents[code]
if (level === 1) { // BasicLayoutPage if (level === 1) { // BasicLayoutPage
if (myComponents && !hasChildren) { if (myComponents && !hasChildren) {
return mate?.hasLayout === false ? () => myComponents() : h(BasicLayoutPage, {}, () => [h(defineAsyncComponent(() => myComponents()), {})]) return mate?.hasLayout === false ? () => myComponents() : h(BasicLayoutPage, {}, () => [h(defineAsyncComponent(() => myComponents()), {})])
@ -197,6 +205,8 @@ const findComponents = (code: string, level: number, isApp: boolean, components:
return myComponents ? () => myComponents() : BlankLayoutPage return myComponents ? () => myComponents() : BlankLayoutPage
} else if(myComponents) { // components } else if(myComponents) { // components
return () => myComponents() return () => myComponents()
} else if(myComponents) { // components
return () => myComponents()
} }
// return components['demo'] // 开发测试用 // return components['demo'] // 开发测试用
return undefined return undefined
@ -268,7 +278,7 @@ export const handleMenus = (menuData: any[], components: any, level: number = 1,
children: item.children children: item.children
} }
route.component = findComponents(item.code, level, isApp, components, item.meta, !!item.chidlren?.length) route.component = findComponents(item.code, level, isApp, components, item.meta, !!item.chidlren?.length, extraModules)
const extraRoute = hasExtraChildren(item, extraRouteObj) const extraRoute = hasExtraChildren(item, extraRouteObj)
const detail_components = findDetailRouteItem(item, components) const detail_components = findDetailRouteItem(item, components)
@ -285,7 +295,7 @@ export const handleMenus = (menuData: any[], components: any, level: number = 1,
} }
if (route.children && route.children.length) { if (route.children && route.children.length) {
route.children = handleMenus(route.children, components, level + 1) route.children = handleMenus(route.children, components, level + 1, extraModules)
} }
const showChildren = route.children?.filter(r => !r.meta?.hideInMenu) || [] const showChildren = route.children?.filter(r => !r.meta?.hideInMenu) || []
@ -318,7 +328,13 @@ const hideInMenu = (code: string) => {
export const handleSiderMenu = (menuData: any[]) => { export const handleSiderMenu = (menuData: any[]) => {
if (menuData && menuData.length) { if (menuData && menuData.length) {
return menuData.map(item => { return menuData.filter(item => {
if (('isShow' in item.options && item.options.isShow === false) || item.meta?.hideInMenu === true) {
return false
}
return true
}).map(item => {
const { isApp, appUrl } = hasAppID(item) // 是否为第三方程序 const { isApp, appUrl } = hasAppID(item) // 是否为第三方程序
if ( item.options?.isShow !== undefined && item.isShow === undefined) { if ( item.options?.isShow !== undefined && item.isShow === undefined) {
item.isShow = item.options.isShow item.isShow = item.options.isShow

View File

@ -4667,11 +4667,47 @@ export default [
"value": "unsupported" "value": "unsupported"
}, },
"indirectMenus": [], "indirectMenus": [],
"children": [ "children": [
// {
// "path": "3nkE-n7lJ",
// "sortIndex": 1,
// "level": 2,
// "name": "工作流",
// "code": "process/home",
// "describe": "",
// "url": "/workflow/home",
// "icon": "UpCircleOutlined",
// showPage: ["process-form"],
// "permissions": [
// {
// "permission": "process-form",
// "actions": [
// "query"
// ]
// },
// {
// "permission": "low-code-info",
// "actions": [
// "query"
// ]
// },
// ],
// "accessSupport": {
// "text": "不支持",
// "value": "unsupported"
// },
// "indirectMenus": [],
// "buttons": [],
// "options": {
// "show": true
// },
// "creatorId": "1199596756811550720",
// "createTime": 1699263818795,
// "supportDataAccess": false
// },
{ {
"path": "3nkE-n7lJ", "path": "3nkE-n7lJ",
"sortIndex": 1, "sortIndex": 2,
"level": 2, "level": 2,
"name": "表单", "name": "表单",
"code": "process/form", "code": "process/form",
@ -4695,6 +4731,18 @@ export default [
"buttons": [ "buttons": [
{ {
"id": "add", "id": "add",
"name": "新增",
"permissions": [
{
"permission": "process-form",
"actions": [
"save"
]
}
]
},
{
"id": "save",
"name": "保存", "name": "保存",
"permissions": [ "permissions": [
{ {
@ -4739,7 +4787,7 @@ export default [
}, },
{ {
"path": "3nkE-ysKb", "path": "3nkE-ysKb",
"sortIndex": 2, "sortIndex": 3,
"level": 2, "level": 2,
"name": "流程模型", "name": "流程模型",
"code": "process/model", "code": "process/model",
@ -4831,7 +4879,7 @@ export default [
}, },
{ {
"path": "3nkE-fJkR", "path": "3nkE-fJkR",
"sortIndex": 3, "sortIndex": 4,
"level": 2, "level": 2,
"name": "流程实例", "name": "流程实例",
"code": "process/instance", "code": "process/instance",
@ -4900,7 +4948,7 @@ export default [
}, },
{ {
"path": "3nkE-i2nG", "path": "3nkE-i2nG",
"sortIndex": 4, "sortIndex": 5,
"level": 2, "level": 2,
"name": "发起流程", "name": "发起流程",
"code": "process/initiate", "code": "process/initiate",
@ -4908,7 +4956,38 @@ export default [
"url": "/workflow/initiate", "url": "/workflow/initiate",
"icon": "UpOutlined", "icon": "UpOutlined",
showPage: ["process-runtime"], showPage: ["process-runtime"],
"permissions": [], "permissions": [
{
"permission": "process-definition",
"actions": [
"query"
]
},
{
"permission": "process-deployment",
"actions": [
"query"
]
},
{
"permission": "process-form",
"actions": [
"query"
]
},
{
"permission": "process-runtime",
"actions": [
"reject",
"start",
"self",
"claim",
"complete",
"createAndStart",
"repeal"
]
}
],
"accessSupport": { "accessSupport": {
"text": "不支持", "text": "不支持",
"value": "unsupported" "value": "unsupported"
@ -4923,7 +5002,7 @@ export default [
}, },
{ {
"path": "3nkE-4T1D", "path": "3nkE-4T1D",
"sortIndex": 5, "sortIndex": 6,
"level": 2, "level": 2,
"name": "待办事项", "name": "待办事项",
"code": "process/me/todo", "code": "process/me/todo",
@ -4931,7 +5010,38 @@ export default [
"url": "/workflow/me/todo", "url": "/workflow/me/todo",
"icon": "UpCircleOutlined", "icon": "UpCircleOutlined",
showPage: ["process-runtime"], showPage: ["process-runtime"],
"permissions": [], "permissions": [
{
"permission": "process-definition",
"actions": [
"query"
]
},
{
"permission": "process-deployment",
"actions": [
"query"
]
},
{
"permission": "process-form",
"actions": [
"query"
]
},
{
"permission": "process-runtime",
"actions": [
"reject",
"start",
"self",
"claim",
"complete",
"createAndStart",
"repeal"
]
}
],
"accessSupport": { "accessSupport": {
"text": "不支持", "text": "不支持",
"value": "unsupported" "value": "unsupported"
@ -4946,7 +5056,7 @@ export default [
}, },
{ {
"path": "3nkE-RXP3", "path": "3nkE-RXP3",
"sortIndex": 6, "sortIndex": 7,
"level": 2, "level": 2,
"name": "已办事项", "name": "已办事项",
"code": "process/me", "code": "process/me",
@ -4954,7 +5064,38 @@ export default [
"url": "/workflow/me", "url": "/workflow/me",
"icon": "UpCircleOutlined", "icon": "UpCircleOutlined",
showPage: ["process-runtime"], showPage: ["process-runtime"],
"permissions": [], "permissions": [
{
"permission": "process-definition",
"actions": [
"query"
]
},
{
"permission": "process-deployment",
"actions": [
"query"
]
},
{
"permission": "process-form",
"actions": [
"query"
]
},
{
"permission": "process-runtime",
"actions": [
"reject",
"start",
"self",
"claim",
"complete",
"createAndStart",
"repeal"
]
}
],
"accessSupport": { "accessSupport": {
"text": "不支持", "text": "不支持",
"value": "unsupported" "value": "unsupported"
@ -4969,7 +5110,7 @@ export default [
}, },
{ {
"path": "3nkE-ibau", "path": "3nkE-ibau",
"sortIndex": 7, "sortIndex": 8,
"level": 2, "level": 2,
"name": "我发起的", "name": "我发起的",
"code": "process/me/initiate", "code": "process/me/initiate",
@ -4977,7 +5118,38 @@ export default [
"url": "/workflow/me/initiate", "url": "/workflow/me/initiate",
"icon": "UpCircleOutlined", "icon": "UpCircleOutlined",
showPage: ["process-runtime"], showPage: ["process-runtime"],
"permissions": [], "permissions": [
{
"permission": "process-definition",
"actions": [
"query"
]
},
{
"permission": "process-deployment",
"actions": [
"query"
]
},
{
"permission": "process-form",
"actions": [
"query"
]
},
{
"permission": "process-runtime",
"actions": [
"reject",
"start",
"self",
"claim",
"complete",
"createAndStart",
"repeal"
]
}
],
"accessSupport": { "accessSupport": {
"text": "不支持", "text": "不支持",
"value": "unsupported" "value": "unsupported"
@ -4989,6 +5161,61 @@ export default [
"creatorId": "1199596756811550720", "creatorId": "1199596756811550720",
"createTime": 1699269488928, "createTime": 1699269488928,
"supportDataAccess": false "supportDataAccess": false
},
{
"path": "3nkE-vCQb",
"sortIndex": 10,
"level": 2,
"name": "抄送给我",
"code": "process/me/cc",
"describe": "",
"url": "/workflow/me/cc",
"icon": "BorderInnerOutlined",
"status": 1,
showPage: ["process-runtime"],
"permissions": [
{
"permission": "process-definition",
"actions": [
"query"
]
},
{
"permission": "process-runtime",
"actions": [
"reject",
"start",
"self",
"claim",
"complete",
"createAndStart",
"repeal"
]
},
{
"permission": "process-deployment",
"actions": [
"query"
]
},
{
"permission": "process-form",
"actions": [
"query"
]
}
],
"accessSupport": {
"text": "不支持",
"value": "unsupported"
},
"indirectMenus": [],
"options": {
"show": true
},
"creatorId": "1199596756811550720",
"createTime": 1699348851779,
"supportDataAccess": false
} }
], ],
"creatorId": "8004214f8141f29cb951befdca3615f0", "creatorId": "8004214f8141f29cb951befdca3615f0",