From 602aac5bf03e4872ec017a86ae03320e49725365 Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Sun, 6 Nov 2022 22:27:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=81=9A=E5=90=88=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E7=9A=84=E5=9C=B0=E5=9D=80=E6=97=B6=EF=BC=8C=E6=8A=A5?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=B7=B2=E5=AD=98=E5=9C=A8=E8=AF=A5=E5=80=BC?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/helper/menuHelper.ts | 1 + src/router/types.ts | 4 ++++ src/views/system/menu/menu.api.ts | 36 ++++++++++++++++++++++++++++++ src/views/system/menu/menu.data.ts | 10 ++++----- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/router/helper/menuHelper.ts b/src/router/helper/menuHelper.ts index a130712..a9ec60f 100644 --- a/src/router/helper/menuHelper.ts +++ b/src/router/helper/menuHelper.ts @@ -61,6 +61,7 @@ export function transformRouteToMenu(routeModList: AppRouteModule[], routerMappi meta: node.meta, name: title, hideMenu, + alwaysShow:node.alwaysShow||false, path: node.path, ...(node.redirect ? { redirect: node.redirect } : {}), }; diff --git a/src/router/types.ts b/src/router/types.ts index 116755b..5be6ce6 100644 --- a/src/router/types.ts +++ b/src/router/types.ts @@ -13,6 +13,7 @@ export interface AppRouteRecordRaw extends Omit { children?: AppRouteRecordRaw[]; props?: Recordable; fullPath?: string; + alwaysShow?: boolean; } export interface MenuTag { @@ -44,6 +45,9 @@ export interface Menu { tag?: MenuTag; hideMenu?: boolean; + + alwaysShow?: boolean; + } export interface MenuModule { diff --git a/src/views/system/menu/menu.api.ts b/src/views/system/menu/menu.api.ts index b2f3637..0daec11 100644 --- a/src/views/system/menu/menu.api.ts +++ b/src/views/system/menu/menu.api.ts @@ -11,6 +11,7 @@ enum Api { ruleSave = '/sys/permission/addPermissionRule', ruleEdit = '/sys/permission/editPermissionRule', ruleDelete = '/sys/permission/deletePermissionRule', + checkPermDuplication = '/sys/permission/checkPermDuplication', } /** @@ -81,3 +82,38 @@ export const deleteRule = (params, handleSuccess) => { * @param params */ export const ajaxGetDictItems = (params) => defHttp.get({ url: `/sys/dict/getDictItems/${params.code}` }); + +/** + * 唯一校验 + * @param params + */ +export const getCheckPermDuplication = (params) => defHttp.get({ url: Api.checkPermDuplication, params }, { isTransformResponse: false }); + +/** + * 校验菜单是否存在 + * @param model + * @param schema + * @param required + */ +export const checkPermDuplication=(model, schema, required?)=>{ + return [ + { + validator: (_, value) => { + if (!value && required) { + return Promise.reject(`请输入${schema.label}`); + } + return new Promise((resolve, reject) => { + getCheckPermDuplication({ + id: model.id, + url:model.url, + alwaysShow:model.alwaysShow + }).then((res) => { + res.success ? resolve() : reject(res.message || '校验失败'); + }).catch((err) => { + reject(err.message || '验证失败'); + }); + }); + }, + }, + ]; +} diff --git a/src/views/system/menu/menu.data.ts b/src/views/system/menu/menu.data.ts index 4329650..f2da9db 100644 --- a/src/views/system/menu/menu.data.ts +++ b/src/views/system/menu/menu.data.ts @@ -3,10 +3,8 @@ import { FormSchema } from '/@/components/Table'; import { h } from 'vue'; import { Icon } from '/@/components/Icon'; import { duplicateCheck } from '../user/user.api'; -import { ajaxGetDictItems } from './menu.api'; +import { ajaxGetDictItems ,checkPermDuplication } from './menu.api'; import { render } from '/@/utils/common/renderUtils'; -import { Select } from 'ant-design-vue'; -import { rules } from '/@/utils/helper/validator'; const isDir = (type) => type === 0; const isMenu = (type) => type === 1; @@ -142,9 +140,11 @@ export const formSchema: FormSchema[] = [ component: 'Input', required: true, ifShow: ({ values }) => !(values.component === ComponentTypes.IFrame && values.internalOrExternal) && values.menuType !== 2, - dynamicRules: ({ model, schema }) => { - return rules.duplicateCheckRule('sys_permission', 'url', model, schema, true); + //update-begin-author:zyf date:2022-11-02 for: 聚合路由允许路径重复 + dynamicRules: ({ model, schema }) => { + return checkPermDuplication(model, schema, true); }, + //update-end-author:zyf date:2022-11-02 for: 聚合路由允许路径重复 }, { field: 'component',