From 9a68eabcf262f9dbb29a72713879b5e8deeca756 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Fri, 25 Apr 2025 16:21:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E3=80=BD=EF=B8=8F=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E8=8F=9C=E5=8D=95=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/info.ts | 78 ++--- build/plugins.ts | 88 +++--- eslint.config.js | 8 +- src/App.vue | 2 +- src/api/service/request.ts | 2 +- src/api/v1/menu/menu.ts | 19 +- src/api/v1/menu/menuIcon.ts | 4 +- src/api/v1/system/system.ts | 4 +- src/components/BaseDialog/SimpleDialog.vue | 85 ------ .../index.ts | 0 .../src/animate.ts | 0 .../src/index.vue | 0 src/components/{Auth => ReAuth}/index.ts | 0 src/components/{Auth => ReAuth}/src/auth.tsx | 0 .../{MyCol => ReCol}/SystemCardItem.vue | 0 src/components/{MyCol => ReCol}/index.ts | 0 .../{BaseDialog => ReDialog}/index.ts | 0 .../{BaseDialog => ReDialog}/index.vue | 0 .../{BaseDialog => ReDialog}/type.ts | 0 .../{CommonIcon => ReIcon}/index.ts | 0 .../{SelectIcon => ReIcon/src}/Select.vue | 15 +- .../{CommonIcon => ReIcon}/src/hooks.ts | 0 .../{CommonIcon => ReIcon}/src/iconfont.ts | 0 .../src/iconifyIconOffline.ts | 0 .../src/iconifyIconOnline.ts | 0 .../{CommonIcon => ReIcon}/src/offlineIcon.ts | 0 .../{CommonIcon => ReIcon}/src/types.ts | 9 + .../{Segmented => ReSegmented}/index.ts | 0 .../{Segmented => ReSegmented}/src/index.css | 1 - .../{Segmented => ReSegmented}/src/index.tsx | 14 +- .../{Segmented => ReSegmented}/src/type.ts | 6 +- src/components/{Text => ReText}/index.ts | 0 src/components/{Text => ReText}/src/index.vue | 0 src/components/SelectIcon/types.ts | 8 - src/components/Table/ResetPasswords.vue | 2 +- src/components/Table/Userinfo/columns.tsx | 2 +- src/components/TableBar/src/TablePlusBar.vue | 2 +- src/enums/baseConstant.ts | 2 +- src/enums/index.ts | 8 +- src/enums/menu.ts | 95 ++++++ .../components/SearchHistoryItem.vue | 2 +- .../lay-search/components/SearchResult.vue | 2 +- src/layout/components/lay-setting/index.vue | 2 +- src/layout/components/lay-sidebar/NavMix.vue | 2 +- .../components/SidebarExtraIcon.vue | 2 +- .../lay-sidebar/components/SidebarItem.vue | 4 +- src/layout/index.vue | 2 +- src/main.ts | 6 +- src/router/utils.ts | 12 +- src/store/configuration/menuIcon.ts | 4 +- src/store/system/menu.ts | 35 +-- src/types/global-components.d.ts | 10 +- src/utils/sso.ts | 2 +- .../{ => components}/account-management.vue | 33 +- .../{ => components}/profile.vue | 7 +- .../{ => components}/security-log.vue | 0 src/views/account-settings/index.vue | 2 +- src/views/account-settings/utils/columns.ts | 14 +- src/views/account-settings/utils/hooks.tsx | 3 +- .../email-template-dialog.vue | 5 +- .../configuration/email-template/index.vue | 12 +- .../email-template/utils/columns.tsx | 2 + .../email-template/utils/hooks.tsx | 14 +- src/views/configuration/email-user/index.vue | 12 +- .../configuration/email-user/utils/hooks.tsx | 2 +- src/views/configuration/menu-icon/index.vue | 12 +- .../menu-icon/menu-icon-dialog.vue | 2 +- .../configuration/menu-icon/utils/hooks.tsx | 2 +- .../configuration/web-configuration/index.vue | 4 +- src/views/i18n/i18n-setting/index.vue | 16 +- src/views/i18n/i18n-setting/utils/hooks.tsx | 2 +- .../i18n-type-setting/i18n-type-dialog.vue | 2 +- src/views/i18n/i18n-type-setting/index.vue | 4 +- .../i18n/i18n-type-setting/utils/hooks.tsx | 2 +- src/views/login/login-email.vue | 2 +- src/views/login/login-form.vue | 2 +- .../message-detail/detail-type.vue | 2 +- .../message-manger/message-received/index.vue | 16 +- .../message-received/utils/hooks.ts | 2 +- .../message-manger/message-send/index.vue | 10 +- .../message-send/utils/hooks.ts | 2 +- .../message-manger/message-type/index.vue | 12 +- .../message-type/utils/hooks.ts | 2 +- .../monitor/scheduler-execute-log/index.vue | 10 +- .../scheduler-execute-log/utils/hooks.ts | 2 +- .../monitor/server/component/system-cpu.vue | 4 +- .../monitor/server/component/system-info.vue | 4 +- .../server/component/system-jvm-cpu.vue | 4 +- .../server/component/system-server.vue | 2 +- src/views/monitor/server/list-card.vue | 2 +- src/views/monitor/user-login-log/index.vue | 8 +- .../monitor/user-login-log/utils/hooks.ts | 2 +- .../scheduler/schedulers-group/index.vue | 12 +- .../scheduler/schedulers-group/utils/hooks.ts | 2 +- src/views/scheduler/schedulers/index.vue | 17 +- src/views/scheduler/schedulers/utils/hooks.ts | 2 +- .../system/admin-user/admin-user-dialog.vue | 2 +- src/views/system/admin-user/index.vue | 12 +- src/views/system/admin-user/tree.vue | 2 +- src/views/system/admin-user/utils/hooks.tsx | 2 +- src/views/system/dept/index.vue | 12 +- src/views/system/dept/utils/hooks.ts | 2 +- src/views/system/files/index.vue | 15 +- src/views/system/files/utils/hooks.tsx | 8 +- .../system/menu/assign-router-to-role.vue | 53 ---- .../system/menu/components/menu-dialog.vue | 281 ++++++++++++++++++ src/views/system/menu/index.vue | 79 ++--- src/views/system/menu/menu-dialog.vue | 108 ------- src/views/system/menu/utils/index.ts | 8 +- .../system/menu/utils/{ => modules}/auth.ts | 2 +- .../menu/utils/{ => modules}/columns.tsx | 52 +++- .../system/menu/utils/{ => modules}/hooks.tsx | 231 ++++++-------- .../system/menu/utils/{ => modules}/types.ts | 13 +- src/views/system/power/index.vue | 15 +- src/views/system/power/utils/hooks.tsx | 2 +- src/views/system/role/index.vue | 12 +- src/views/system/role/utils/hooks.ts | 2 +- src/views/welcome/index.vue | 2 +- tailwind.config.ts | 22 +- vite.config.ts | 44 +-- 120 files changed, 922 insertions(+), 871 deletions(-) delete mode 100644 src/components/BaseDialog/SimpleDialog.vue rename src/components/{AnimateSelector => ReAnimateSelector}/index.ts (100%) rename src/components/{AnimateSelector => ReAnimateSelector}/src/animate.ts (100%) rename src/components/{AnimateSelector => ReAnimateSelector}/src/index.vue (100%) rename src/components/{Auth => ReAuth}/index.ts (100%) rename src/components/{Auth => ReAuth}/src/auth.tsx (100%) rename src/components/{MyCol => ReCol}/SystemCardItem.vue (100%) rename src/components/{MyCol => ReCol}/index.ts (100%) rename src/components/{BaseDialog => ReDialog}/index.ts (100%) rename src/components/{BaseDialog => ReDialog}/index.vue (100%) rename src/components/{BaseDialog => ReDialog}/type.ts (100%) rename src/components/{CommonIcon => ReIcon}/index.ts (100%) rename src/components/{SelectIcon => ReIcon/src}/Select.vue (90%) rename src/components/{CommonIcon => ReIcon}/src/hooks.ts (100%) rename src/components/{CommonIcon => ReIcon}/src/iconfont.ts (100%) rename src/components/{CommonIcon => ReIcon}/src/iconifyIconOffline.ts (100%) rename src/components/{CommonIcon => ReIcon}/src/iconifyIconOnline.ts (100%) rename src/components/{CommonIcon => ReIcon}/src/offlineIcon.ts (100%) rename src/components/{CommonIcon => ReIcon}/src/types.ts (71%) rename src/components/{Segmented => ReSegmented}/index.ts (100%) rename src/components/{Segmented => ReSegmented}/src/index.css (99%) rename src/components/{Segmented => ReSegmented}/src/index.tsx (95%) rename src/components/{Segmented => ReSegmented}/src/type.ts (60%) rename src/components/{Text => ReText}/index.ts (100%) rename src/components/{Text => ReText}/src/index.vue (100%) delete mode 100644 src/components/SelectIcon/types.ts create mode 100644 src/enums/menu.ts rename src/views/account-settings/{ => components}/account-management.vue (81%) rename src/views/account-settings/{ => components}/profile.vue (98%) rename src/views/account-settings/{ => components}/security-log.vue (100%) rename src/views/configuration/email-template/{ => components}/email-template-dialog.vue (99%) delete mode 100644 src/views/system/menu/assign-router-to-role.vue create mode 100644 src/views/system/menu/components/menu-dialog.vue delete mode 100644 src/views/system/menu/menu-dialog.vue rename src/views/system/menu/utils/{ => modules}/auth.ts (93%) rename src/views/system/menu/utils/{ => modules}/columns.tsx (68%) rename src/views/system/menu/utils/{ => modules}/hooks.tsx (51%) rename src/views/system/menu/utils/{ => modules}/types.ts (61%) diff --git a/build/info.ts b/build/info.ts index a1cd3b2..af5aa8d 100644 --- a/build/info.ts +++ b/build/info.ts @@ -8,46 +8,52 @@ import boxen, { type Options as BoxenOptions } from 'boxen'; dayjs.extend(duration); const welcomeMessage = (VITE_PORT: number) => { - return gradientString('cyan', 'magenta').multiline( - `您好! 欢迎使用 bunny 系列开发模板 -项目访问地址如下: -http://localhost:${VITE_PORT}`, - ); + return gradientString('cyan', 'magenta').multiline( + `您好! 欢迎使用 bunny 系列开发模板项目访问地址如下: +http://localhost:${VITE_PORT}` + ); }; const boxenOptions: BoxenOptions = { - padding: 0.5, - borderColor: 'cyan', - borderStyle: 'round', + padding: 0.5, + borderColor: 'cyan', + borderStyle: 'round', }; export function viteBuildInfo(VITE_PORT: number): Plugin { - let config: { command: string }; - let startTime: Dayjs; - let endTime: Dayjs; - let outDir: string; - return { - name: 'vite:buildInfo', - configResolved(resolvedConfig) { - config = resolvedConfig; - outDir = resolvedConfig.build?.outDir ?? 'dist'; - }, - buildStart() { - console.log(boxen(welcomeMessage(VITE_PORT), boxenOptions)); - if (config.command === 'build') { - startTime = dayjs(new Date()); - } - }, - closeBundle() { - if (config.command === 'build') { - endTime = dayjs(new Date()); - getPackageSize({ - folder: outDir, - callback: (size: string) => { - console.log(boxen(gradientString('cyan', 'magenta').multiline(`🎉 恭喜打包完成(总用时${dayjs.duration(endTime.diff(startTime)).format('mm分ss秒')},打包后的大小为${size})`), boxenOptions)); - }, - }); - } - }, - }; + let config: { command: string }; + let startTime: Dayjs; + let endTime: Dayjs; + let outDir: string; + return { + name: 'vite:buildInfo', + configResolved(resolvedConfig) { + config = resolvedConfig; + outDir = resolvedConfig.build?.outDir ?? 'dist'; + }, + buildStart() { + console.log(boxen(welcomeMessage(VITE_PORT), boxenOptions)); + if (config.command === 'build') { + startTime = dayjs(new Date()); + } + }, + closeBundle() { + if (config.command === 'build') { + endTime = dayjs(new Date()); + getPackageSize({ + folder: outDir, + callback: (size: string) => { + console.log( + boxen( + gradientString('cyan', 'magenta').multiline( + `🎉 恭喜打包完成(总用时${dayjs.duration(endTime.diff(startTime)).format('mm分ss秒')},打包后的大小为${size})` + ), + boxenOptions + ) + ); + }, + }); + } + }, + }; } diff --git a/build/plugins.ts b/build/plugins.ts index 2898260..fcac796 100644 --- a/build/plugins.ts +++ b/build/plugins.ts @@ -16,46 +16,50 @@ import { genScssMultipleScopeVars } from '../src/layout/theme'; // import { vitePluginFakeServer } from 'vite-plugin-fake-server'; -export function getPluginsList(VITE_CDN: boolean, VITE_COMPRESSION: ViteCompression, VITE_PORT: number): PluginOption[] { - const lifecycle = process.env.npm_lifecycle_event; - return [ - vue(), - // jsx、tsx语法支持 - vueJsx(), - VueI18nPlugin({ - jitCompilation: false, - include: [pathResolve('../locales/**')], - }), - // 按下Command(⌘)+Shift(⇧),然后点击页面元素会自动打开本地IDE并跳转到对应的代码位置 - Inspector(), - viteBuildInfo(VITE_PORT), - /** - * 开发环境下移除非必要的vue-router动态路由警告No match found for location with path - * 非必要具体看 https://github.com/vuejs/router/issues/521 和 https://github.com/vuejs/router/issues/359 - * vite-plugin-router-warn只在开发环境下启用,只处理vue-router文件并且只在服务启动或重启时运行一次,性能消耗可忽略不计 - */ - removeNoMatch(), - // // mock支持 - // vitePluginFakeServer({ - // logger: false, - // include: 'mock', - // infixName: false, - // enableProd: true,// 线上支持mock - // }), - // 自定义主题 - themePreprocessorPlugin({ - scss: { - multipleScopeVars: genScssMultipleScopeVars(), - extract: true, - }, - }), - // svg组件化支持 - svgLoader(), - VITE_CDN ? cdn : null, - configCompressPlugin(VITE_COMPRESSION), - // 线上环境删除console - removeConsole({ external: ['src/assets/iconfont/iconfont.js'] }), - // 打包分析 - lifecycle === 'report' ? visualizer({ open: true, brotliSize: true, filename: 'report.html' }) : (null as any), - ]; +export function getPluginsList( + VITE_CDN: boolean, + VITE_COMPRESSION: ViteCompression, + VITE_PORT: number +): PluginOption[] { + const lifecycle = process.env.npm_lifecycle_event; + return [ + vue(), + // jsx、tsx语法支持 + vueJsx(), + VueI18nPlugin({ + jitCompilation: false, + // include: [pathResolve('../locales/**')], + }), + // 按下Command(⌘)+Shift(⇧),然后点击页面元素会自动打开本地IDE并跳转到对应的代码位置 + Inspector(), + viteBuildInfo(VITE_PORT), + /** + * 开发环境下移除非必要的vue-router动态路由警告No match found for location with path + * 非必要具体看 https://github.com/vuejs/router/issues/521 和 https://github.com/vuejs/router/issues/359 + * vite-plugin-router-warn只在开发环境下启用,只处理vue-router文件并且只在服务启动或重启时运行一次,性能消耗可忽略不计 + */ + removeNoMatch(), + // // mock支持 + // vitePluginFakeServer({ + // logger: false, + // include: 'mock', + // infixName: false, + // enableProd: true,// 线上支持mock + // }), + // 自定义主题 + themePreprocessorPlugin({ + scss: { + multipleScopeVars: genScssMultipleScopeVars(), + extract: true, + }, + }), + // svg组件化支持 + svgLoader(), + VITE_CDN ? cdn : null, + configCompressPlugin(VITE_COMPRESSION), + // 线上环境删除console + removeConsole({ external: ['src/assets/iconfont/iconfont.js'] }), + // 打包分析 + lifecycle === 'report' ? visualizer({ open: true, brotliSize: true, filename: 'report.html' }) : (null as any), + ]; } diff --git a/eslint.config.js b/eslint.config.js index 006fda4..eea217a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -89,6 +89,7 @@ export default defineFlatConfig([ '@typescript-eslint/no-import-type-side-effects': 'error', '@typescript-eslint/prefer-literal-enum-member': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-unused-vars': 'off', '@typescript-eslint/consistent-type-imports': [ 'error', { @@ -96,13 +97,6 @@ export default defineFlatConfig([ fixStyle: 'inline-type-imports', }, ], - '@typescript-eslint/no-unused-vars': [ - 'error', - { - argsIgnorePattern: '^_', - varsIgnorePattern: '^_', - }, - ], }, }, { diff --git a/src/App.vue b/src/App.vue index 50aeeb1..b355e0b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -8,7 +8,7 @@ - - diff --git a/src/components/AnimateSelector/index.ts b/src/components/ReAnimateSelector/index.ts similarity index 100% rename from src/components/AnimateSelector/index.ts rename to src/components/ReAnimateSelector/index.ts diff --git a/src/components/AnimateSelector/src/animate.ts b/src/components/ReAnimateSelector/src/animate.ts similarity index 100% rename from src/components/AnimateSelector/src/animate.ts rename to src/components/ReAnimateSelector/src/animate.ts diff --git a/src/components/AnimateSelector/src/index.vue b/src/components/ReAnimateSelector/src/index.vue similarity index 100% rename from src/components/AnimateSelector/src/index.vue rename to src/components/ReAnimateSelector/src/index.vue diff --git a/src/components/Auth/index.ts b/src/components/ReAuth/index.ts similarity index 100% rename from src/components/Auth/index.ts rename to src/components/ReAuth/index.ts diff --git a/src/components/Auth/src/auth.tsx b/src/components/ReAuth/src/auth.tsx similarity index 100% rename from src/components/Auth/src/auth.tsx rename to src/components/ReAuth/src/auth.tsx diff --git a/src/components/MyCol/SystemCardItem.vue b/src/components/ReCol/SystemCardItem.vue similarity index 100% rename from src/components/MyCol/SystemCardItem.vue rename to src/components/ReCol/SystemCardItem.vue diff --git a/src/components/MyCol/index.ts b/src/components/ReCol/index.ts similarity index 100% rename from src/components/MyCol/index.ts rename to src/components/ReCol/index.ts diff --git a/src/components/BaseDialog/index.ts b/src/components/ReDialog/index.ts similarity index 100% rename from src/components/BaseDialog/index.ts rename to src/components/ReDialog/index.ts diff --git a/src/components/BaseDialog/index.vue b/src/components/ReDialog/index.vue similarity index 100% rename from src/components/BaseDialog/index.vue rename to src/components/ReDialog/index.vue diff --git a/src/components/BaseDialog/type.ts b/src/components/ReDialog/type.ts similarity index 100% rename from src/components/BaseDialog/type.ts rename to src/components/ReDialog/type.ts diff --git a/src/components/CommonIcon/index.ts b/src/components/ReIcon/index.ts similarity index 100% rename from src/components/CommonIcon/index.ts rename to src/components/ReIcon/index.ts diff --git a/src/components/SelectIcon/Select.vue b/src/components/ReIcon/src/Select.vue similarity index 90% rename from src/components/SelectIcon/Select.vue rename to src/components/ReIcon/src/Select.vue index afffe4b..6e95314 100644 --- a/src/components/SelectIcon/Select.vue +++ b/src/components/ReIcon/src/Select.vue @@ -1,7 +1,7 @@ diff --git a/src/views/system/menu/menu-dialog.vue b/src/views/system/menu/menu-dialog.vue deleted file mode 100644 index 07ca9b3..0000000 --- a/src/views/system/menu/menu-dialog.vue +++ /dev/null @@ -1,108 +0,0 @@ - - - diff --git a/src/views/system/menu/utils/index.ts b/src/views/system/menu/utils/index.ts index 9a543d7..d53ecda 100644 --- a/src/views/system/menu/utils/index.ts +++ b/src/views/system/menu/utils/index.ts @@ -1,4 +1,4 @@ -export * from './columns'; -export * from './auth'; -export * from './hooks'; -export * from './types'; +export * from './modules/columns'; +export * from './modules/auth'; +export * from './modules/hooks'; +export * from './modules/types'; diff --git a/src/views/system/menu/utils/auth.ts b/src/views/system/menu/utils/modules/auth.ts similarity index 93% rename from src/views/system/menu/utils/auth.ts rename to src/views/system/menu/utils/modules/auth.ts index 3c3316f..cf23901 100644 --- a/src/views/system/menu/utils/auth.ts +++ b/src/views/system/menu/utils/modules/auth.ts @@ -4,7 +4,7 @@ export const auth = { // 添加操作 add: ['router::addMenu'], // 分页查询 - search: ['router::getMenusList'], + search: ['router::menuList'], // 删除操作 deleted: ['router::deletedMenuByIds'], // 为菜单分配角色 diff --git a/src/views/system/menu/utils/columns.tsx b/src/views/system/menu/utils/modules/columns.tsx similarity index 68% rename from src/views/system/menu/utils/columns.tsx rename to src/views/system/menu/utils/modules/columns.tsx index fd057c7..ad6fe94 100644 --- a/src/views/system/menu/utils/columns.tsx +++ b/src/views/system/menu/utils/modules/columns.tsx @@ -1,15 +1,15 @@ -import { h, reactive } from 'vue'; -import type { FormRules } from 'element-plus'; -import { ElTag } from 'element-plus'; +import { useRenderIcon } from '@/components/ReIcon/src/hooks'; import { $t } from '@/plugins/i18n'; import { isAllEmpty } from '@pureadmin/utils'; -import { useRenderIcon } from '@/components/CommonIcon/src/hooks'; +import { ElLink, ElTag, type FormRules } from 'element-plus'; +import { h, reactive } from 'vue'; +import { mergeArgs } from '@/views/system/menu/utils'; +import { messageBox } from '@/utils/message'; +import { userMenuStore } from '@/store/system/menu'; -/** - * 标签栏菜单类型匹配 - * @param type - * @param text - */ +const menuStore = userMenuStore(); + +/* 标签栏菜单类型匹配 */ const getMenuType = (type: number, text: boolean = false): any => { switch (type) { case 0: @@ -33,8 +33,26 @@ export const formatHigherMenuOptions = (treeList: any) => { return newTreeList; }; +/* 更新是否显示菜单 */ +const onChangeShowLink = async (row: any) => { + // 是否确认 + let result = await messageBox({ + title: $t('confirm_update_status'), + showMessage: false, + confirmMessage: undefined, + cancelMessage: $t('cancel'), + }); + if (!result) return; + + // 确认后进行修改 + row.showLink = !row.showLink; + const data = mergeArgs(row); + await menuStore.updateMenu(data); +}; + export const columns: TableColumnList = [ { type: 'selection', align: 'left' }, + // 显示标题 { label: $t('menuName'), prop: 'title', @@ -51,6 +69,7 @@ export const columns: TableColumnList = [ ), minWidth: 170, }, + // 菜单类型 { label: $t('menuType'), prop: 'menuType', @@ -62,19 +81,30 @@ export const columns: TableColumnList = [ ), }, { label: $t('routerPath'), prop: 'path', minWidth: 230 }, + // 组件路径 { label: $t('componentPath'), prop: 'component', formatter: ({ path, component }) => (isAllEmpty(component) ? path : component), minWidth: 200, }, + // 路由等级 { label: $t('sort'), prop: 'rank', minWidth: 80, slot: 'rank' }, - { label: $t('visible'), prop: 'visible', slot: 'visible', minWidth: 100 }, + // 是否i按时 + { + label: $t('visible'), + prop: 'showLink', + cellRenderer: ({ row }) => ( + onChangeShowLink(row)}> + {row.showLink ? $t('show') : $t('hidden')} + + ), + }, { label: $t('table.updateTime'), prop: 'updateTime', sortable: true, minWidth: 160 }, { label: $t('table.createTime'), prop: 'createTime', sortable: true, minWidth: 160 }, { label: $t('table.createUser'), prop: 'createUser', slot: 'createUser', minWidth: 130 }, { label: $t('table.updateUser'), prop: 'updateUser', slot: 'updateUser', minWidth: 130 }, - { label: $t('table.operation'), fixed: 'right', minWidth: 310, slot: 'operation' }, + { label: $t('table.operation'), fixed: 'right', minWidth: 150, slot: 'operation' }, ]; /** 自定义表单规则校验 */ diff --git a/src/views/system/menu/utils/hooks.tsx b/src/views/system/menu/utils/modules/hooks.tsx similarity index 51% rename from src/views/system/menu/utils/hooks.tsx rename to src/views/system/menu/utils/modules/hooks.tsx index b3681fe..428e156 100644 --- a/src/views/system/menu/utils/hooks.tsx +++ b/src/views/system/menu/utils/modules/hooks.tsx @@ -1,34 +1,30 @@ -import editForm from '../menu-dialog.vue'; +import editForm from '@/views/system/menu/components/menu-dialog.vue'; import { $t } from '@/plugins/i18n'; -import { addDialog, closeAllDialog } from '@/components/BaseDialog/index'; +import { addDialog, closeAllDialog } from '@/components/ReDialog/index'; import { h, ref } from 'vue'; import type { FormItemProps } from './types'; import { cloneDeep, deviceDetection } from '@pureadmin/utils'; import { userMenuStore } from '@/store/system/menu'; -import AssignRouterToRole from '@/views/system/menu/assign-router-to-role.vue'; import { messageBox } from '@/utils/message'; -import { formatHigherMenuOptions } from '@/views/system/menu/utils/columns'; +import { formatHigherMenuOptions } from '@/views/system/menu/utils/modules/columns'; import { ElText } from 'element-plus'; -// 用户是否停用加载集合 -export const switchLoadMap = ref({}); +const menuStore = userMenuStore(); + // 选择多行 export const selectIds = ref([]); export const tableRef = ref(); -const assignRouterToRolesRef = ref(); const dialogFormRef = ref(); -const menuStore = userMenuStore(); -const routerStore = userMenuStore(); /** 获取菜单数据 */ -export const onSearch = async () => { +async function onSearch() { menuStore.loading = true; await menuStore.getMenuList(); menuStore.loading = false; -}; +} /** 添加菜单 */ -export function onAdd(parentId: any = 0) { +function onAdd(parentId: any = 0) { addDialog({ title: $t('addNew') + $t('menu'), props: { @@ -42,8 +38,20 @@ export function onAdd(parentId: any = 0) { component: '', rank: 99, icon: '', + id: '', + extraIcon: '', + enterTransition: 'fade', + leaveTransition: 'fade', + activePath: '', + redirect: '', + roles: [], frameSrc: '', - visible: true, + frameLoading: true, + keepAlive: false, + hiddenTag: false, + fixedTag: false, + showLink: true, + showParent: false, }, }, width: '45%', @@ -58,7 +66,8 @@ export function onAdd(parentId: any = 0) { if (!valid) return; delete curData.higherMenuOptions; - const result = await menuStore.addMenu(curData); + const data = mergeArgs(curData); + const result = await menuStore.addMenu(data); // 刷新表格数据 if (result) { done(); @@ -69,15 +78,13 @@ export function onAdd(parentId: any = 0) { }); } -/** - * * 更新菜单 - * @param row - */ -export const onUpdate = (row?: FormItemProps) => { +/* 更新菜单 */ +function onUpdate(row?: FormItemProps) { addDialog({ title: $t('update') + $t('menu'), props: { formInline: { + id: row?.id, menuType: row?.menuType, higherMenuOptions: formatHigherMenuOptions(cloneDeep(menuStore.datalist)), parentId: row?.parentId, @@ -88,7 +95,19 @@ export const onUpdate = (row?: FormItemProps) => { rank: row?.rank, icon: row?.icon, frameSrc: row?.frameSrc, - visible: row.visible, + extraIcon: row?.extraIcon, + // 因为要使用动画需要在前面加上 animate__ 修改时需要手动去除 + enterTransition: row?.enterTransition?.replace('animate__', ''), + // 因为要使用动画需要在前面加上 animate__ 修改时需要手动去除 + leaveTransition: row?.leaveTransition?.replace('animate__', ''), + activePath: row?.activePath, + frameLoading: row?.frameLoading, + keepAlive: row?.keepAlive, + hiddenTag: row?.hiddenTag, + fixedTag: row?.fixedTag, + showLink: row?.showLink, + showParent: row?.showParent, + redirect: row?.redirect, }, }, width: '45%', @@ -107,7 +126,10 @@ export const onUpdate = (row?: FormItemProps) => { if (!valid) return; curData.parentId = curData.parentId ?? 0; curData.id = row.id; - const result = await menuStore.updateMenu(curData); + + // 整理后端需要的参数 + const data = mergeArgs(curData); + const result = await menuStore.updateMenu(data); // 刷新表格数据 if (result) { @@ -117,13 +139,10 @@ export const onUpdate = (row?: FormItemProps) => { }); }, }); -}; +} -/** - * * 删除菜单 - * @param row - */ -export const onDelete = async (row) => { +/* 删除菜单 */ +async function onDelete(row: any) { // 是否确认删除 const result = await messageBox({ title: $t('confirmDelete'), @@ -135,124 +154,7 @@ export const onDelete = async (row) => { await menuStore.deletedMenuByIds([row.id]); await onSearch(); -}; - -/** - * * 修改菜单是否显示 - * @param row - * @param index - */ -export const onchangeVisible = async (row: any, index: number) => { - // 点击时开始loading加载 - switchLoadMap.value[index] = Object.assign({}, switchLoadMap.value[index], { - loading: true, - }); - - // 是否确认修改显示状态 - const confirm = await messageBox({ - title: $t('confirm_update_status'), - showMessage: false, - confirmMessage: undefined, - cancelMessage: $t('cancel'), - }); - - // 取消修改 - if (!confirm) { - row.visible = !row.visible; - switchLoadMap.value[index] = Object.assign({}, switchLoadMap.value[index], { - loading: false, - }); - return; - } - - // 确认修改 - const data = { - id: row.id, - visible: row.visible, - menuType: row.menuType, - title: row.title, - name: row.name, - path: row.path, - }; - await routerStore.updateMenu(data); - await onSearch(); - - switchLoadMap.value[index] = Object.assign({}, switchLoadMap.value[index], { - loading: false, - }); -}; - -/** - * * 更新菜单排序 - * @param row - */ -export const onChangeMenuRank = async (row: any) => { - const data = { id: row.id, rank: row.rank }; - - // 是否确认修改显示状态 - const confirm = await messageBox({ - title: $t('confirm_update_sort'), - showMessage: false, - confirmMessage: undefined, - cancelMessage: $t('cancel'), - }); - - // 取消修改 - if (!confirm) return; - - await routerStore.updateMenuByIdWithRank(data); - await onSearch(); -}; - -/** - * 为路由分配角色 - * @param row - */ -export const assignRolesToRouter = (row: any) => { - addDialog({ - title: `${$t('for')} 【${$t(row.title)}】 ${$t('assign_roles')}`, - width: '45%', - draggable: true, - closeOnClickModal: false, - fullscreenIcon: true, - contentRenderer: () => , - beforeSure: async (done: any) => { - // 分配用户角色 - const data = { routerIds: [row.id], roleIds: assignRouterToRolesRef.value.assignRoles }; - const result = await menuStore.assignRolesToRouter(data); - - // 更新成功关闭弹窗 - if (!result) return; - done(); - }, - }); -}; - -/** 批量为路由分配角色 */ -export const assignBatchRolesToRouter = () => { - addDialog({ - title: $t('assignBatchRolesToRouter'), - width: '45%', - draggable: true, - closeOnClickModal: false, - fullscreenIcon: true, - // props: { warning: $t('assignBatchRolesToRouterTip') }, - contentRenderer: () => , - beforeSure: async (done: any) => { - // 表格功能 - const { clearSelection } = tableRef.value.getTableRef(); - - // 分配用户角色 - const data = { routerIds: selectIds.value, roleIds: assignRouterToRolesRef.value.assignRoles }; - const result = await menuStore.assignAddBatchRolesToRouter(data); - - // 更新成功关闭弹窗 - if (!result) return; - clearSelection(); - done(); - }, - }); -}; +} /** 清除选中所以角色 */ export const clearAllRolesSelect = async () => { @@ -287,3 +189,42 @@ export const clearAllRolesSelect = async () => { }, }); }; + +/* 更新是整理后端参数 */ +export const mergeArgs = (curData: any) => { + // 判断 入场 和 离场动画是否添加 + let transition = { enterTransition: 'fade', leaveTransition: 'fade' }; + const enterTransition = curData.enterTransition; + const leaveTransition = curData.leaveTransition; + + transition.enterTransition = enterTransition ? `animate__${enterTransition}` : 'fade'; + transition.leaveTransition = leaveTransition ? `animate__${leaveTransition}` : 'fade'; + + // 整理参数返回后端 + return { + id: curData.id, + parentId: curData.parentId, + path: curData.path, + routeName: curData.name, + redirect: curData.redirect, + component: curData.component, + menuType: curData.menuType ?? 0, + meta: { + title: curData.title, + icon: curData.icon, + showLink: curData.showLink, + showParent: curData.showParent, + roles: curData.roles, + keepAlive: curData.keepAlive, + frameSrc: curData.frameSrc, + frameLoading: curData.frameLoading, + rank: curData.rank, + hiddenTag: curData.hiddenTag, + fixedTag: curData.fixedTag, + activePath: curData.activePath, + transition, + }, + }; +}; + +export { onSearch, onAdd, onUpdate, onDelete }; diff --git a/src/views/system/menu/utils/types.ts b/src/views/system/menu/utils/modules/types.ts similarity index 61% rename from src/views/system/menu/utils/types.ts rename to src/views/system/menu/utils/modules/types.ts index 358c44f..0e94f80 100644 --- a/src/views/system/menu/utils/types.ts +++ b/src/views/system/menu/utils/modules/types.ts @@ -11,7 +11,18 @@ interface FormItemProps { rank: number; icon: string; frameSrc: string; - visible: boolean; + extraIcon: string; + enterTransition: string; + leaveTransition: string; + redirect: string; + activePath: string; + roles: Array; + frameLoading: boolean; + keepAlive: boolean; + hiddenTag: boolean; + fixedTag: boolean; + showLink: boolean; + showParent: boolean; } interface FormProps { diff --git a/src/views/system/power/index.vue b/src/views/system/power/index.vue index 03ea8b0..45cb0c9 100644 --- a/src/views/system/power/index.vue +++ b/src/views/system/power/index.vue @@ -20,10 +20,11 @@ import Refresh from '@iconify-icons/ep/refresh'; import { selectUserinfo } from '@/components/Table/Userinfo/columns'; import { $t } from '@/plugins/i18n'; import { usePowerStore } from '@/store/system/power'; -import { useRenderIcon } from '@/components/CommonIcon/src/hooks'; +import { useRenderIcon } from '@/components/ReIcon/src/hooks'; import { handleTree } from '@pureadmin/utils'; import { FormInstance } from 'element-plus'; import { hasAuth } from '@/router/utils'; +import ReAuth from '@/components/ReAuth/src/auth'; const tableRef = ref(); const formRef = ref(); @@ -72,7 +73,7 @@ onMounted(() => {