From cc66fcddf5f4e2b29513f9f0c71325e260d282ee Mon Sep 17 00:00:00 2001 From: "meilin.huang" <954537473@qq.com> Date: Mon, 9 Jun 2025 21:18:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=8A=A8=E6=80=81=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E8=B0=83=E6=95=B4&=E5=88=86=E9=9A=94=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E4=BD=BF=E7=94=A8element=E8=87=AA=E5=B8=A6=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/package.json | 15 +++-- frontend/src/i18n/en/system.ts | 3 +- frontend/src/i18n/zh-cn/system.ts | 2 +- frontend/src/main.ts | 2 - frontend/src/router/dynamicRouter.ts | 52 +++++----------- frontend/src/theme/index.scss | 3 +- frontend/src/theme/splitpanes.scss | 36 ----------- frontend/src/types/shim.d.ts | 1 - frontend/src/views/flow/route.ts | 5 ++ frontend/src/views/home/route.ts | 3 + frontend/src/views/msg/route.ts | 4 ++ .../views/ops/component/ResourceOpPanel.vue | 13 ++-- frontend/src/views/ops/db/DbSqlExecLog.vue | 19 ++++++ .../db/component/sqleditor/DbSqlEditor.vue | 59 +++++++++++-------- frontend/src/views/ops/db/route.ts | 6 ++ frontend/src/views/ops/es/route.ts | 4 ++ frontend/src/views/ops/machine/MachineOp.vue | 2 +- frontend/src/views/ops/machine/route.ts | 6 ++ frontend/src/views/ops/mongo/route.ts | 4 ++ .../src/views/ops/redis/DataOperation.vue | 13 ++-- frontend/src/views/ops/redis/route.ts | 4 ++ frontend/src/views/ops/tag/TagTreeList.vue | 15 +++-- frontend/src/views/ops/tag/route.ts | 5 ++ frontend/src/views/personal/index.vue | 4 ++ frontend/src/views/personal/route.ts | 3 + .../system/account/components/AccountInfo.vue | 2 +- .../views/system/resource/ResourceEdit.vue | 10 ---- .../views/system/resource/ResourceList.vue | 18 +++--- frontend/src/views/system/route.ts | 7 +++ server/go.mod | 12 ++-- server/internal/db/application/db_sql_exec.go | 11 ++-- server/internal/db/domain/entity/query.go | 3 + .../infrastructure/persistence/db_sql_exec.go | 3 + server/pkg/model/login_account.go | 4 +- 34 files changed, 179 insertions(+), 174 deletions(-) delete mode 100644 frontend/src/theme/splitpanes.scss create mode 100644 frontend/src/views/flow/route.ts create mode 100644 frontend/src/views/home/route.ts create mode 100644 frontend/src/views/msg/route.ts create mode 100644 frontend/src/views/ops/db/route.ts create mode 100644 frontend/src/views/ops/es/route.ts create mode 100644 frontend/src/views/ops/machine/route.ts create mode 100644 frontend/src/views/ops/mongo/route.ts create mode 100644 frontend/src/views/ops/redis/route.ts create mode 100644 frontend/src/views/ops/tag/route.ts create mode 100644 frontend/src/views/personal/route.ts create mode 100644 frontend/src/views/system/route.ts diff --git a/frontend/package.json b/frontend/package.json index aab7350d..f6659094 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -11,32 +11,31 @@ }, "dependencies": { "@element-plus/icons-vue": "^2.3.1", - "@logicflow/core": "^2.0.13", - "@logicflow/extension": "^2.0.18", + "@logicflow/core": "^2.0.15", + "@logicflow/extension": "^2.0.20", "@vueuse/core": "^13.3.0", "@xterm/addon-fit": "^0.10.0", "@xterm/addon-search": "^0.15.0", "@xterm/addon-web-links": "^0.11.0", "@xterm/xterm": "^5.5.0", - "asciinema-player": "^3.9.0", + "asciinema-player": "^3.10.0", "axios": "^1.6.2", "clipboard": "^2.0.11", "crypto-js": "^4.2.0", "dayjs": "^1.11.13", "echarts": "^5.6.0", - "element-plus": "^2.9.11", + "element-plus": "^2.10.1", "js-base64": "^3.7.7", "jsencrypt": "^3.3.2", "mitt": "^3.0.1", "monaco-editor": "^0.52.2", - "monaco-sql-languages": "^0.14.0", + "monaco-sql-languages": "^0.15.0", "monaco-themes": "^0.4.5", "nprogress": "^0.2.0", - "pinia": "^3.0.2", + "pinia": "^3.0.3", "qrcode.vue": "^3.6.0", "screenfull": "^6.0.2", "sortablejs": "^1.15.6", - "splitpanes": "^4.0.4", "sql-formatter": "^15.6.1", "trzsz": "^1.1.5", "uuid": "^9.0.1", @@ -62,7 +61,7 @@ "eslint-plugin-vue": "^10.1.0", "postcss": "^8.5.4", "prettier": "^3.5.3", - "sass": "^1.89.0", + "sass": "^1.89.1", "tailwindcss": "^4.1.8", "typescript": "^5.8.2", "vite": "^6.3.5", diff --git a/frontend/src/i18n/en/system.ts b/frontend/src/i18n/en/system.ts index 6d234efb..4ce63d77 100644 --- a/frontend/src/i18n/en/system.ts +++ b/frontend/src/i18n/en/system.ts @@ -25,7 +25,8 @@ export default { success: 'Success', menuCodeTips: `The menu type is the access path (if the menu path does not begin with '/', the access address will automatically concatenate the parent menu path), otherwise it is the unique code of the resource`, menuCodePlaceholder: `A menu that does not begin with '/' will automatically concatenate the parent menu path`, - routerNameTips: 'For component caching to work, match the vue component name, such as ResourceLis', + routerNameTips: + 'For component caching to work, the key for route.ts in the frontend module should match the vue component name, such as ResourceList', componentPathTips: 'Access path components, such as: ` system/resource/ResourceList `, default in ` views ` directory', isCacheTips: `If yes is selected, it will be 'keepalive' cached (reentering the page without refreshing the page and requesting data again), and needs the route name to match the vue component name`, isHideTips: diff --git a/frontend/src/i18n/zh-cn/system.ts b/frontend/src/i18n/zh-cn/system.ts index 94a45b8b..66575fa9 100644 --- a/frontend/src/i18n/zh-cn/system.ts +++ b/frontend/src/i18n/zh-cn/system.ts @@ -25,7 +25,7 @@ export default { success: '成功', menuCodeTips: `菜单类型则为访问路径(若菜单路径不以'/'开头则访问地址会自动拼接父菜单路径)、否则为资源唯一编码`, menuCodePlaceholder: `菜单不以'/'开头则自动拼接父菜单路径`, - routerNameTips: '与vue的组件名一致才可使组件缓存生效,如ResourceList', + routerNameTips: '前端模块下route.ts中对应的key,与vue的组件名一致才可使组件缓存生效,如ResourceList', componentPathTips: '访问的组件路径,如:`system/resource/ResourceList`,默认在`views`目录下', isCacheTips: '选择是则会被`keep-alive`缓存(重新进入页面不会刷新页面及重新请求数据),需要路由名与vue的组件名一致', isHideTips: '选择隐藏则路由将不会出现在菜单栏中,但仍然可以访问。禁用则不可访问与操作', diff --git a/frontend/src/main.ts b/frontend/src/main.ts index ca21559b..e2204c59 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -11,8 +11,6 @@ import 'element-plus/dist/index.css'; import 'element-plus/theme-chalk/dark/css-vars.css'; import { i18n } from '@/i18n/index'; -import 'splitpanes/dist/splitpanes.css'; - import '@/theme/index.scss'; import '@/theme/tailwind.css'; import '@/assets/font/font.css'; diff --git a/frontend/src/router/dynamicRouter.ts b/frontend/src/router/dynamicRouter.ts index 441f6d7b..6f356783 100644 --- a/frontend/src/router/dynamicRouter.ts +++ b/frontend/src/router/dynamicRouter.ts @@ -9,15 +9,21 @@ import { RouteRecordRaw } from 'vue-router'; import { LAYOUT_ROUTE_NAME } from './staticRouter'; /** - * 获取目录下的 .vue、.tsx 全部文件 + * 获取目录下的 route.ts 全部文件 * @method import.meta.glob * @link 参考:https://cn.vitejs.dev/guide/features.html#json */ -const viewsModules: Record = import.meta.glob(['../views/**/*.{vue,tsx}']); -const dynamicViewsModules: Record = Object.assign({}, { ...viewsModules }); +const routeModules: Record = import.meta.glob(['../views/**/route.{ts,js}'], { eager: true }); // 后端控制路由:执行路由数据初始化 export async function initBackendRoutes() { + let allModuleRoutes = {}; + for (const path in routeModules) { + // 获取默认导出的路由 + const routes = routeModules[path]?.default; + allModuleRoutes = { ...allModuleRoutes, ...routes }; + } + const token = getToken(); // 获取浏览器缓存 token 值 if (!token) { // 无 token 停止执行下一步 @@ -29,7 +35,7 @@ export async function initBackendRoutes() { const cacheList: Array = []; // 处理路由(component) - const routes = backEndRouterConverter(menuRoute, (router: any) => { + const routes = backEndRouterConverter(allModuleRoutes, menuRoute, (router: any) => { // 可能为false时不存在isKeepAlive属性 if (!router.meta.isKeepAlive) { router.meta.isKeepAlive = false; @@ -88,7 +94,7 @@ type RouterConvCallbackFunc = (router: any) => void; * @param meta.linkType ==> 外链类型, 内嵌: 以iframe展示、外链: 新标签打开 * @param meta.link ==> 外链地址 * */ -export function backEndRouterConverter(routes: any, callbackFunc: RouterConvCallbackFunc = null as any, parentPath: string = '/') { +export function backEndRouterConverter(allModuleRoutes: any, routes: any, callbackFunc: RouterConvCallbackFunc = null as any, parentPath: string = '/') { if (!routes) { return []; } @@ -101,12 +107,6 @@ export function backEndRouterConverter(routes: any, callbackFunc: RouterConvCall // 将json字符串的meta转为对象 item.meta = JSON.parse(item.meta); - // 将meta.comoponet 解析为route.component - if (item.meta.component) { - item.component = dynamicImport(dynamicViewsModules, item.meta.component); - delete item.meta['component']; - } - let path = item.code; // 如果不是以 / 开头,则路径需要拼接父路径 if (!path.startsWith('/')) { @@ -121,6 +121,8 @@ export function backEndRouterConverter(routes: any, callbackFunc: RouterConvCall // route.name == resource.meta.routeName item.name = item.meta.routeName; + // routerName == 模块下route.ts 字段key == 组件名 + item.component = allModuleRoutes[item.meta.routeName]; delete item.meta['routeName']; // route.redirect == resource.meta.redirect @@ -130,35 +132,9 @@ export function backEndRouterConverter(routes: any, callbackFunc: RouterConvCall } // 存在回调,则执行回调 callbackFunc && callbackFunc(item); - item.children && backEndRouterConverter(item.children, callbackFunc, item.path); + item.children && backEndRouterConverter(allModuleRoutes, item.children, callbackFunc, item.path); routeItems.push(item); } return routeItems; } - -/** - * 后端路由 component 转换函数 - * @param dynamicViewsModules 获取目录下的 .vue、.tsx 全部文件 - * @param component 当前要处理项 component - * @returns 返回处理成函数后的 component - */ -export function dynamicImport(dynamicViewsModules: Record, component: string) { - const keys = Object.keys(dynamicViewsModules); - const matchKeys = keys.filter((key) => { - const k = key.replace(/..\/views|../, ''); - return k.startsWith(`${component}`) || k.startsWith(`/${component}`); - }); - - if (matchKeys?.length === 1) { - return dynamicViewsModules[matchKeys[0]]; - } - - if (matchKeys?.length > 1) { - console.error('匹配到多个相似组件路径, 可添加后缀.vue或.tsx进行区分或者重命名组件名, 请调整...', matchKeys); - return null; - } - - console.warn(`未匹配到[${component}]组件名对应的组件文件`); - return null; -} diff --git a/frontend/src/theme/index.scss b/frontend/src/theme/index.scss index 07973d46..211cbc4f 100644 --- a/frontend/src/theme/index.scss +++ b/frontend/src/theme/index.scss @@ -4,5 +4,4 @@ @use './media/media.scss'; @use './waves.scss'; @use './dark.scss'; -@use './iconSelector.scss'; -@use './splitpanes.scss'; \ No newline at end of file +@use './iconSelector.scss'; \ No newline at end of file diff --git a/frontend/src/theme/splitpanes.scss b/frontend/src/theme/splitpanes.scss deleted file mode 100644 index 1cd54fd2..00000000 --- a/frontend/src/theme/splitpanes.scss +++ /dev/null @@ -1,36 +0,0 @@ -/** splitpanes **/ -.splitpanes.default-theme .splitpanes { - background: transparent !important; -} - -.splitpanes.default-theme .splitpanes__pane { - background: transparent !important; -} - -.default-theme.splitpanes--vertical>.splitpanes__splitter { - border-left: 1px solid var(--bg-main-color); -} - -.default-theme.splitpanes--horizontal>.splitpanes__splitter { - border-top: 1px solid var(--bg-main-color); -} - -// 竖线样式 -.splitpanes.default-theme .splitpanes__splitter::before, -.splitpanes.default-theme .splitpanes__splitter::after { - background-color: var(--el-color-info-light-5); -} - -.splitpanes.default-theme .splitpanes__splitter:hover::before, -.splitpanes.default-theme .splitpanes__splitter:hover::after { - background-color: var(--el-color-success); -} - -.splitpanes.default-theme .splitpanes__splitter { - min-width: 6px; - background: var(--el-color-info-light-8) !important; -} - -.splitpanes.default-theme .splitpanes__splitter:hover { - background: var(--el-color-success-light-8) !important; -} \ No newline at end of file diff --git a/frontend/src/types/shim.d.ts b/frontend/src/types/shim.d.ts index ecc00598..5bdf044e 100644 --- a/frontend/src/types/shim.d.ts +++ b/frontend/src/types/shim.d.ts @@ -2,5 +2,4 @@ declare module 'jsoneditor'; declare module 'asciinema-player'; declare module 'vue-grid-layout'; -declare module 'splitpanes'; declare module 'uuid'; diff --git a/frontend/src/views/flow/route.ts b/frontend/src/views/flow/route.ts new file mode 100644 index 00000000..9100ce31 --- /dev/null +++ b/frontend/src/views/flow/route.ts @@ -0,0 +1,5 @@ +export default { + ProcdefList: () => import('@/views/flow/ProcdefList.vue'), + ProcinstList: () => import('@/views/flow/ProcinstList.vue'), + ProcinstTaskList: () => import('@/views/flow/ProcinstTaskList.vue'), +}; diff --git a/frontend/src/views/home/route.ts b/frontend/src/views/home/route.ts new file mode 100644 index 00000000..12f5822d --- /dev/null +++ b/frontend/src/views/home/route.ts @@ -0,0 +1,3 @@ +export default { + Home: () => import('@/views/home/Home.vue'), +}; diff --git a/frontend/src/views/msg/route.ts b/frontend/src/views/msg/route.ts new file mode 100644 index 00000000..cf63c176 --- /dev/null +++ b/frontend/src/views/msg/route.ts @@ -0,0 +1,4 @@ +export default { + ChannelList: () => import('@/views/msg/channel/ChannelList.vue'), + TmplList: () => import('@/views/msg/tmpl/TmplList.vue'), +}; diff --git a/frontend/src/views/ops/component/ResourceOpPanel.vue b/frontend/src/views/ops/component/ResourceOpPanel.vue index dd73eb7f..09b385b6 100644 --- a/frontend/src/views/ops/component/ResourceOpPanel.vue +++ b/frontend/src/views/ops/component/ResourceOpPanel.vue @@ -1,17 +1,16 @@