From 5f1aaa40d88efbcdb2ef0e65273f40b8cb6a6114 Mon Sep 17 00:00:00 2001 From: "meilin.huang" <954537473@qq.com> Date: Wed, 15 Mar 2023 11:41:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20pinia=E6=9B=BF=E6=8D=A2vuex,=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mayfly_go_web/.env.production | 2 +- mayfly_go_web/.eslintrc.js | 47 +- mayfly_go_web/package.json | 6 +- mayfly_go_web/plugins.d.ts | 1 - mayfly_go_web/src/App.vue | 125 ++- .../src/common/utils/authFunction.ts | 23 - mayfly_go_web/src/common/utils/format.ts | 120 +++ mayfly_go_web/src/common/utils/formatTime.ts | 119 --- mayfly_go_web/src/common/utils/mitt.ts | 8 + mayfly_go_web/src/components/auth/auth.vue | 5 +- mayfly_go_web/src/components/auth/authAll.vue | 5 +- mayfly_go_web/src/components/auth/auths.vue | 5 +- .../src/components/iconSelector/index.vue | 489 +++++----- .../src/components/iconSelector/list.vue | 84 ++ .../src/components/svgIcon/index.vue | 83 +- .../authDirective.ts => directive/auth.ts} | 16 +- .../utils/directive.ts => directive/index.ts} | 4 +- .../customDirective.ts => directive/waves.ts} | 0 mayfly_go_web/src/main.ts | 35 +- mayfly_go_web/src/router/imports.ts | 30 - mayfly_go_web/src/router/index.ts | 67 +- mayfly_go_web/src/router/route.ts | 2 +- mayfly_go_web/src/store/index.ts | 26 +- mayfly_go_web/src/store/keepAliveNames.ts | 35 + .../src/store/modules/keepAliveNames.ts | 24 - mayfly_go_web/src/store/modules/routesList.ts | 24 - mayfly_go_web/src/store/modules/userInfos.ts | 29 - mayfly_go_web/src/store/routesList.ts | 18 + .../src/store/{modules => }/themeConfig.ts | 32 +- mayfly_go_web/src/store/userInfo.ts | 19 + mayfly_go_web/src/theme/iconSelector.scss | 90 +- mayfly_go_web/src/types/env.d.ts | 5 + .../interface/index.ts => types/pinia.d.ts} | 47 +- mayfly_go_web/{ => src/types}/shim.d.ts | 11 +- mayfly_go_web/{ => src/types}/source.d.ts | 3 +- mayfly_go_web/src/views/home/Home.vue | 17 +- .../src/views/layout/component/aside.vue | 229 +++-- .../views/layout/component/columnsAside.vue | 226 +++-- .../src/views/layout/component/header.vue | 5 +- .../src/views/layout/component/main.vue | 144 ++- mayfly_go_web/src/views/layout/index.vue | 80 +- .../src/views/layout/lockScreen/index.vue | 608 +++++++------ mayfly_go_web/src/views/layout/logo/index.vue | 52 +- .../src/views/layout/main/classic.vue | 24 +- .../src/views/layout/main/columns.vue | 5 +- .../src/views/layout/main/defaults.vue | 5 +- .../layout/navBars/breadcrumb/breadcrumb.vue | 147 ++- .../views/layout/navBars/breadcrumb/index.vue | 177 ++-- .../layout/navBars/breadcrumb/search.vue | 184 ++-- .../layout/navBars/breadcrumb/setings.vue | 820 +++++++++-------- .../views/layout/navBars/breadcrumb/user.vue | 292 +++--- .../src/views/layout/navBars/index.vue | 5 +- .../layout/navBars/tagsView/tagsView.vue | 843 +++++++++--------- .../src/views/layout/navMenu/horizontal.vue | 179 ++-- .../src/views/layout/navMenu/vertical.vue | 92 +- .../src/views/layout/routerView/iframes.vue | 6 +- .../src/views/layout/routerView/parent.vue | 97 +- .../views/login/component/AccountLogin.vue | 17 +- mayfly_go_web/src/views/login/index.vue | 13 +- mayfly_go_web/src/views/ops/db/DbList.vue | 11 +- mayfly_go_web/src/views/ops/db/SqlExec.vue | 11 +- .../src/views/ops/db/component/tab/Query.vue | 53 +- .../views/ops/db/component/tab/TableData.vue | 2 +- .../src/views/ops/machine/MachineList.vue | 20 +- .../{ServiceManage.vue => ScriptManage.vue} | 0 .../src/views/ops/machine/SshTerminal.vue | 24 +- .../ops/machine/authcert/AuthCertList.vue | 2 +- .../ops/machine/authcert/AuthCertSelect.vue | 2 +- .../src/views/ops/mongo/MongoDataOp.vue | 5 +- .../src/views/ops/mongo/MongoInstanceTree.vue | 178 ---- .../src/views/ops/mongo/MongoList.vue | 2 +- .../src/views/ops/redis/DataOperation.vue | 15 +- .../src/views/ops/redis/HashValue.vue | 2 +- .../src/views/ops/redis/RedisList.vue | 2 +- .../src/views/ops/redis/SetValue.vue | 2 +- mayfly_go_web/src/views/personal/index.vue | 23 +- .../views/system/resource/ResourceEdit.vue | 85 +- .../views/system/resource/ResourceList.vue | 2 +- mayfly_go_web/tsconfig.json | 4 +- mayfly_go_web/vite.config.ts | 102 ++- mayfly_go_web/yarn.lock | 41 +- server/go.mod | 2 +- server/internal/db/application/db_sql_exec.go | 6 +- server/internal/redis/router/redis.go | 14 +- server/mayfly-go.sql | 154 ++-- 85 files changed, 3214 insertions(+), 3456 deletions(-) delete mode 100644 mayfly_go_web/plugins.d.ts delete mode 100644 mayfly_go_web/src/common/utils/authFunction.ts delete mode 100644 mayfly_go_web/src/common/utils/formatTime.ts create mode 100644 mayfly_go_web/src/common/utils/mitt.ts create mode 100644 mayfly_go_web/src/components/iconSelector/list.vue rename mayfly_go_web/src/{common/utils/authDirective.ts => directive/auth.ts} (68%) rename mayfly_go_web/src/{common/utils/directive.ts => directive/index.ts} (59%) rename mayfly_go_web/src/{common/utils/customDirective.ts => directive/waves.ts} (100%) delete mode 100644 mayfly_go_web/src/router/imports.ts create mode 100644 mayfly_go_web/src/store/keepAliveNames.ts delete mode 100644 mayfly_go_web/src/store/modules/keepAliveNames.ts delete mode 100644 mayfly_go_web/src/store/modules/routesList.ts delete mode 100644 mayfly_go_web/src/store/modules/userInfos.ts create mode 100644 mayfly_go_web/src/store/routesList.ts rename mayfly_go_web/src/store/{modules => }/themeConfig.ts (89%) create mode 100644 mayfly_go_web/src/store/userInfo.ts create mode 100644 mayfly_go_web/src/types/env.d.ts rename mayfly_go_web/src/{store/interface/index.ts => types/pinia.d.ts} (69%) rename mayfly_go_web/{ => src/types}/shim.d.ts (65%) rename mayfly_go_web/{ => src/types}/source.d.ts (62%) rename mayfly_go_web/src/views/ops/machine/{ServiceManage.vue => ScriptManage.vue} (100%) delete mode 100644 mayfly_go_web/src/views/ops/mongo/MongoInstanceTree.vue diff --git a/mayfly_go_web/.env.production b/mayfly_go_web/.env.production index e038d163..872886b0 100644 --- a/mayfly_go_web/.env.production +++ b/mayfly_go_web/.env.production @@ -2,4 +2,4 @@ ENV = 'production' # 线上环境接口地址 -VITE_API_URL = 'http://api.mayflygo.1yue.net/api' \ No newline at end of file +VITE_API_URL = '/api' \ No newline at end of file diff --git a/mayfly_go_web/.eslintrc.js b/mayfly_go_web/.eslintrc.js index 59bccd0f..bad6addb 100644 --- a/mayfly_go_web/.eslintrc.js +++ b/mayfly_go_web/.eslintrc.js @@ -11,21 +11,33 @@ module.exports = { parser: '@typescript-eslint/parser', sourceType: 'module', }, - extends: ['plugin:vue/essential'], - // plugins: ['vue', '@typescript-eslint'], + extends: ['plugin:vue/vue3-essential', 'plugin:vue/essential', 'eslint:recommended'], + plugins: ['vue', '@typescript-eslint'], + overrides: [ + { + files: ['*.ts', '*.tsx', '*.vue'], + rules: { + 'no-undef': 'off', + }, + }, + ], rules: { // http://eslint.cn/docs/rules/ // https://eslint.vuejs.org/rules/ - '@type-eslint/ban-ts-ignore': 'off', - '@type-eslint/explicit-function-return-type': 'off', - '@type-eslint/no-explicit-any': 'off', - '@type-eslint/no-var-requires': 'off', - '@type-eslint/no-empty-function': 'off', - '@type-eslint/no-use-before-define': 'off', - '@type-eslint/ban-ts-comment': 'off', - '@type-eslint/ban-types': 'off', - '@type-eslint/no-non-null-assertion': 'off', - '@type-eslint/explicit-module-boundary-types': 'off', + // https://typescript-eslint.io/rules/no-unused-vars/ + '@typescript-eslint/ban-ts-ignore': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-var-requires': 'off', + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/ban-types': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-redeclare': 'error', + '@typescript-eslint/no-non-null-asserted-optional-chain': 'off', + '@typescript-eslint/no-unused-vars': [2], 'vue/custom-event-name-casing': 'off', 'vue/attributes-order': 'off', 'vue/one-component-per-file': 'off', @@ -43,6 +55,12 @@ module.exports = { 'vue/no-v-html': 'off', 'vue/comment-directive': 'off', 'vue/no-parsing-error': 'off', + 'vue/no-deprecated-v-on-native-modifier': 'off', + 'vue/multi-word-component-names': 'off', + 'no-useless-escape': 'off', + 'no-sparse-arrays': 'off', + 'no-prototype-builtins': 'off', + 'no-constant-condition': 'off', 'no-use-before-define': 'off', 'no-restricted-globals': 'off', 'no-restricted-syntax': 'off', @@ -51,5 +69,8 @@ module.exports = { 'no-multiple-template-root': 'off', 'no-unused-vars': 'error', 'no-v-model-argument': 'off', + 'no-case-declarations': 'off', + 'no-console': 'error', + 'no-redeclare': 'off', }, -}; +}; \ No newline at end of file diff --git a/mayfly_go_web/package.json b/mayfly_go_web/package.json index c9a006ef..c54a6409 100644 --- a/mayfly_go_web/package.json +++ b/mayfly_go_web/package.json @@ -15,7 +15,7 @@ "countup.js": "^2.0.7", "cropperjs": "^1.5.11", "echarts": "^5.4.0", - "element-plus": "^2.2.33", + "element-plus": "^2.3.0", "jsencrypt": "^3.3.1", "lodash": "^4.17.21", "mitt": "^3.0.0", @@ -29,7 +29,7 @@ "vue": "^3.2.47", "vue-clipboard3": "^1.0.1", "vue-router": "^4.1.6", - "vuex": "^4.0.2", + "pinia": "^2.0.33", "xterm": "^5.1.0", "xterm-addon-fit": "^0.7.0" }, @@ -40,7 +40,7 @@ "@types/sortablejs": "^1.10.6", "@typescript-eslint/eslint-plugin": "^4.23.0", "@typescript-eslint/parser": "^4.23.0", - "@vitejs/plugin-vue": "^2.3.3", + "@vitejs/plugin-vue": "^4.0.0", "@vue/compiler-sfc": "^3.0.11", "dotenv": "^10.0.0", "eslint": "^8.35.0", diff --git a/mayfly_go_web/plugins.d.ts b/mayfly_go_web/plugins.d.ts deleted file mode 100644 index 8578ca42..00000000 --- a/mayfly_go_web/plugins.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'vue-grid-layout'; diff --git a/mayfly_go_web/src/App.vue b/mayfly_go_web/src/App.vue index f8d6e2fd..ad8b8586 100644 --- a/mayfly_go_web/src/App.vue +++ b/mayfly_go_web/src/App.vue @@ -1,74 +1,69 @@ - diff --git a/mayfly_go_web/src/common/utils/authFunction.ts b/mayfly_go_web/src/common/utils/authFunction.ts deleted file mode 100644 index 54797c16..00000000 --- a/mayfly_go_web/src/common/utils/authFunction.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { store } from '@/store/index.ts'; -import { judementSameArr } from '@/common/utils/arrayOperation.ts'; - -// 单个权限验证 -export function auth(value: string) { - return store.state.userInfos.userInfos.permissions.some((v: any) => v === value); -} - -// 多个权限验证,满足一个则为 true -export function auths(value: Array) { - let flag = false; - store.state.userInfos.userInfos.permissions.map((val: any) => { - value.map((v: any) => { - if (val === v) flag = true; - }); - }); - return flag; -} - -// 多个权限验证,全部满足则为 true -export function authAll(value: Array) { - return judementSameArr(value, store.state.userInfos.userInfos.permissions); -} diff --git a/mayfly_go_web/src/common/utils/format.ts b/mayfly_go_web/src/common/utils/format.ts index 25e3bc2b..430540b2 100644 --- a/mayfly_go_web/src/common/utils/format.ts +++ b/mayfly_go_web/src/common/utils/format.ts @@ -72,4 +72,124 @@ export function formatJsonString(txt: string, compress: boolean) { indent = 0; notify('', data, isLast, indent, false); return draw.join(''); +} + +/* + * 年(Y) 可用1-4个占位符 + * 月(m)、日(d)、小时(H)、分(M)、秒(S) 可用1-2个占位符 + * 星期(W) 可用1-3个占位符 + * 季度(q为阿拉伯数字,Q为中文数字)可用1或4个占位符 + * + * let date = new Date() + * formatDate(date, "YYYY-mm-dd HH:MM:SS") // 2020-02-09 14:04:23 + * formatDate(date, "YYYY-mm-dd HH:MM:SS Q") // 2020-02-09 14:09:03 一 + * formatDate(date, "YYYY-mm-dd HH:MM:SS WWW") // 2020-02-09 14:45:12 星期日 + * formatDate(date, "YYYY-mm-dd HH:MM:SS QQQQ") // 2020-02-09 14:09:36 第一季度 + * formatDate(date, "YYYY-mm-dd HH:MM:SS WWW QQQQ") // 2020-02-09 14:46:12 星期日 第一季度 + */ +export function formatDate(date: Date, format: string) { + let we = date.getDay(); // 星期 + let qut = Math.floor((date.getMonth() + 3) / 3).toString(); // 季度 + const opt: any = { + 'Y+': date.getFullYear().toString(), // 年 + 'm+': (date.getMonth() + 1).toString(), // 月(月份从0开始,要+1) + 'd+': date.getDate().toString(), // 日 + 'H+': date.getHours().toString(), // 时 + 'M+': date.getMinutes().toString(), // 分 + 'S+': date.getSeconds().toString(), // 秒 + 'q+': qut, // 季度 + }; + // 中文数字 (星期) + const week: any = { + '0': '日', + '1': '一', + '2': '二', + '3': '三', + '4': '四', + '5': '五', + '6': '六', + }; + // 中文数字(季度) + const quarter: any = { + '1': '一', + '2': '二', + '3': '三', + '4': '四', + }; + if (/(W+)/.test(format)) + format = format.replace(RegExp.$1, RegExp.$1.length > 1 ? (RegExp.$1.length > 2 ? '星期' + week[we] : '周' + week[we]) : week[we]); + if (/(Q+)/.test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 4 ? '第' + quarter[qut] + '季度' : quarter[qut]); + for (let k in opt) { + let r = new RegExp('(' + k + ')').exec(format); + // 若输入的长度不为1,则前面补零 + if (r) format = format.replace(r[1], RegExp.$1.length == 1 ? opt[k] : opt[k].padStart(RegExp.$1.length, '0')); + } + return format; +} + +/** + * 10秒: 10 * 1000 + * 1分: 60 * 1000 + * 1小时: 60 * 60 * 1000 + * 24小时:60 * 60 * 24 * 1000 + * 3天: 60 * 60* 24 * 1000 * 3 + * + * let data = new Date() + * formatPast(data) // 刚刚 + * formatPast(data - 11 * 1000) // 11秒前 + * formatPast(data - 2 * 60 * 1000) // 2分钟前 + * formatPast(data - 60 * 60 * 2 * 1000) // 2小时前 + * formatPast(data - 60 * 60 * 2 * 1000) // 2小时前 + * formatPast(data - 60 * 60 * 71 * 1000) // 2天前 + * formatPast("2020-06-01") // 2020-06-01 + * formatPast("2020-06-01", "YYYY-mm-dd HH:MM:SS WWW QQQQ") // 2020-06-01 08:00:00 星期一 第二季度 + */ +export function formatPast(param: any, format: string = 'YYYY-mm-dd') { + // 传入格式处理、存储转换值 + let t: any, s: any; + // 获取js 时间戳 + let time: any = new Date().getTime(); + // 是否是对象 + typeof param === 'string' || 'object' ? (t = new Date(param).getTime()) : (t = param); + // 当前时间戳 - 传入时间戳 + time = Number.parseInt(`${time - t}`); + if (time < 10000) { + // 10秒内 + return '刚刚'; + } else if (time < 60000 && time >= 10000) { + // 超过10秒少于1分钟内 + s = Math.floor(time / 1000); + return `${s}秒前`; + } else if (time < 3600000 && time >= 60000) { + // 超过1分钟少于1小时 + s = Math.floor(time / 60000); + return `${s}分钟前`; + } else if (time < 86400000 && time >= 3600000) { + // 超过1小时少于24小时 + s = Math.floor(time / 3600000); + return `${s}小时前`; + } else if (time < 259200000 && time >= 86400000) { + // 超过1天少于3天内 + s = Math.floor(time / 86400000); + return `${s}天前`; + } else { + // 超过3天 + let date = typeof param === 'string' || 'object' ? new Date(param) : param; + return formatDate(date, format); + } +} + +/** + * formatAxis(new Date()) // 上午好 + */ +export function formatAxis(param: any) { + let hour: number = new Date(param).getHours(); + if (hour < 6) return '凌晨好'; + else if (hour < 9) return '早上好'; + else if (hour < 12) return '上午好'; + else if (hour < 14) return '中午好'; + else if (hour < 17) return '下午好'; + else if (hour < 19) return '傍晚好'; + else if (hour < 22) return '晚上好'; + else return '夜里好'; } \ No newline at end of file diff --git a/mayfly_go_web/src/common/utils/formatTime.ts b/mayfly_go_web/src/common/utils/formatTime.ts deleted file mode 100644 index a1d803e4..00000000 --- a/mayfly_go_web/src/common/utils/formatTime.ts +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 年(Y) 可用1-4个占位符 - * 月(m)、日(d)、小时(H)、分(M)、秒(S) 可用1-2个占位符 - * 星期(W) 可用1-3个占位符 - * 季度(q为阿拉伯数字,Q为中文数字)可用1或4个占位符 - * - * let date = new Date() - * formatDate(date, "YYYY-mm-dd HH:MM:SS") // 2020-02-09 14:04:23 - * formatDate(date, "YYYY-mm-dd HH:MM:SS Q") // 2020-02-09 14:09:03 一 - * formatDate(date, "YYYY-mm-dd HH:MM:SS WWW") // 2020-02-09 14:45:12 星期日 - * formatDate(date, "YYYY-mm-dd HH:MM:SS QQQQ") // 2020-02-09 14:09:36 第一季度 - * formatDate(date, "YYYY-mm-dd HH:MM:SS WWW QQQQ") // 2020-02-09 14:46:12 星期日 第一季度 - */ -export function formatDate(date: Date, format: string) { - let we = date.getDay(); // 星期 - let qut = Math.floor((date.getMonth() + 3) / 3).toString(); // 季度 - const opt: any = { - 'Y+': date.getFullYear().toString(), // 年 - 'm+': (date.getMonth() + 1).toString(), // 月(月份从0开始,要+1) - 'd+': date.getDate().toString(), // 日 - 'H+': date.getHours().toString(), // 时 - 'M+': date.getMinutes().toString(), // 分 - 'S+': date.getSeconds().toString(), // 秒 - 'q+': qut, // 季度 - }; - // 中文数字 (星期) - const week: any = { - '0': '日', - '1': '一', - '2': '二', - '3': '三', - '4': '四', - '5': '五', - '6': '六', - }; - // 中文数字(季度) - const quarter: any = { - '1': '一', - '2': '二', - '3': '三', - '4': '四', - }; - if (/(W+)/.test(format)) - format = format.replace(RegExp.$1, RegExp.$1.length > 1 ? (RegExp.$1.length > 2 ? '星期' + week[we] : '周' + week[we]) : week[we]); - if (/(Q+)/.test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 4 ? '第' + quarter[qut] + '季度' : quarter[qut]); - for (let k in opt) { - let r = new RegExp('(' + k + ')').exec(format); - // 若输入的长度不为1,则前面补零 - if (r) format = format.replace(r[1], RegExp.$1.length == 1 ? opt[k] : opt[k].padStart(RegExp.$1.length, '0')); - } - return format; -} - -/** - * 10秒: 10 * 1000 - * 1分: 60 * 1000 - * 1小时: 60 * 60 * 1000 - * 24小时:60 * 60 * 24 * 1000 - * 3天: 60 * 60* 24 * 1000 * 3 - * - * let data = new Date() - * formatPast(data) // 刚刚 - * formatPast(data - 11 * 1000) // 11秒前 - * formatPast(data - 2 * 60 * 1000) // 2分钟前 - * formatPast(data - 60 * 60 * 2 * 1000) // 2小时前 - * formatPast(data - 60 * 60 * 2 * 1000) // 2小时前 - * formatPast(data - 60 * 60 * 71 * 1000) // 2天前 - * formatPast("2020-06-01") // 2020-06-01 - * formatPast("2020-06-01", "YYYY-mm-dd HH:MM:SS WWW QQQQ") // 2020-06-01 08:00:00 星期一 第二季度 - */ -export function formatPast(param: any, format: string = 'YYYY-mm-dd') { - // 传入格式处理、存储转换值 - let t: any, s: any; - // 获取js 时间戳 - let time: any = new Date().getTime(); - // 是否是对象 - typeof param === 'string' || 'object' ? (t = new Date(param).getTime()) : (t = param); - // 当前时间戳 - 传入时间戳 - time = Number.parseInt(`${time - t}`); - if (time < 10000) { - // 10秒内 - return '刚刚'; - } else if (time < 60000 && time >= 10000) { - // 超过10秒少于1分钟内 - s = Math.floor(time / 1000); - return `${s}秒前`; - } else if (time < 3600000 && time >= 60000) { - // 超过1分钟少于1小时 - s = Math.floor(time / 60000); - return `${s}分钟前`; - } else if (time < 86400000 && time >= 3600000) { - // 超过1小时少于24小时 - s = Math.floor(time / 3600000); - return `${s}小时前`; - } else if (time < 259200000 && time >= 86400000) { - // 超过1天少于3天内 - s = Math.floor(time / 86400000); - return `${s}天前`; - } else { - // 超过3天 - let date = typeof param === 'string' || 'object' ? new Date(param) : param; - return formatDate(date, format); - } -} - -/** - * formatAxis(new Date()) // 上午好 - */ -export function formatAxis(param: any) { - let hour: number = new Date(param).getHours(); - if (hour < 6) return '凌晨好'; - else if (hour < 9) return '早上好'; - else if (hour < 12) return '上午好'; - else if (hour < 14) return '中午好'; - else if (hour < 17) return '下午好'; - else if (hour < 19) return '傍晚好'; - else if (hour < 22) return '晚上好'; - else return '夜里好'; -} diff --git a/mayfly_go_web/src/common/utils/mitt.ts b/mayfly_go_web/src/common/utils/mitt.ts new file mode 100644 index 00000000..2e44d1b9 --- /dev/null +++ b/mayfly_go_web/src/common/utils/mitt.ts @@ -0,0 +1,8 @@ +// https://www.npmjs.com/package/mitt +import mitt, { Emitter } from 'mitt'; + +// 类型 +const emitter: Emitter = mitt(); + +// 导出 +export default emitter; \ No newline at end of file diff --git a/mayfly_go_web/src/components/auth/auth.vue b/mayfly_go_web/src/components/auth/auth.vue index ce260227..5c70edc6 100644 --- a/mayfly_go_web/src/components/auth/auth.vue +++ b/mayfly_go_web/src/components/auth/auth.vue @@ -6,7 +6,7 @@ \ No newline at end of file diff --git a/mayfly_go_web/src/components/iconSelector/list.vue b/mayfly_go_web/src/components/iconSelector/list.vue new file mode 100644 index 00000000..f44f14d6 --- /dev/null +++ b/mayfly_go_web/src/components/iconSelector/list.vue @@ -0,0 +1,84 @@ + + + + + \ No newline at end of file diff --git a/mayfly_go_web/src/components/svgIcon/index.vue b/mayfly_go_web/src/components/svgIcon/index.vue index 26309383..94f8c065 100644 --- a/mayfly_go_web/src/components/svgIcon/index.vue +++ b/mayfly_go_web/src/components/svgIcon/index.vue @@ -1,24 +1,67 @@ - \ No newline at end of file diff --git a/mayfly_go_web/src/common/utils/authDirective.ts b/mayfly_go_web/src/directive/auth.ts similarity index 68% rename from mayfly_go_web/src/common/utils/authDirective.ts rename to mayfly_go_web/src/directive/auth.ts index 8fabe31a..710850a6 100644 --- a/mayfly_go_web/src/common/utils/authDirective.ts +++ b/mayfly_go_web/src/directive/auth.ts @@ -1,12 +1,13 @@ import type { App } from 'vue'; -import { auth, auths, authAll } from './authFunction' +import { useUserInfo } from '@/store/userInfo'; +import { judementSameArr } from '@/common/utils/arrayOperation'; // 用户权限指令 export function authDirective(app: App) { // 单个权限验证(v-auth="xxx") app.directive('auth', { mounted(el, binding) { - if (!auth(binding.value)) { + if (!useUserInfo().userInfo.permissions.some((v: any) => v === binding.value)) { parseNoAuth(el, binding); }; }, @@ -14,7 +15,14 @@ export function authDirective(app: App) { // 多个权限验证,满足一个则显示(v-auths="[xxx,xxx]") app.directive('auths', { mounted(el, binding) { - if (!auths(binding.value)) { + const value = binding.value + let flag = false; + useUserInfo().userInfo.permissions.map((val: any) => { + value.map((v: any) => { + if (val === v) flag = true; + }); + }); + if (!flag) { parseNoAuth(el, binding); } }, @@ -22,7 +30,7 @@ export function authDirective(app: App) { // 多个权限验证,全部满足则显示(v-auth-all="[xxx,xxx]") app.directive('auth-all', { mounted(el, binding) { - if (!authAll(binding.value)) { + if (!judementSameArr(binding.value, useUserInfo().userInfo.permissions)) { parseNoAuth(el, binding); }; }, diff --git a/mayfly_go_web/src/common/utils/directive.ts b/mayfly_go_web/src/directive/index.ts similarity index 59% rename from mayfly_go_web/src/common/utils/directive.ts rename to mayfly_go_web/src/directive/index.ts index 3879136e..a0833b6a 100644 --- a/mayfly_go_web/src/common/utils/directive.ts +++ b/mayfly_go_web/src/directive/index.ts @@ -1,6 +1,6 @@ import type { App } from 'vue'; -import { authDirective } from '@/common/utils/authDirective.ts'; -import { wavesDirective } from '@/common/utils/customDirective.ts'; +import { authDirective } from './auth'; +import { wavesDirective } from './waves'; // 导出指令方法 export function directive(app: App) { diff --git a/mayfly_go_web/src/common/utils/customDirective.ts b/mayfly_go_web/src/directive/waves.ts similarity index 100% rename from mayfly_go_web/src/common/utils/customDirective.ts rename to mayfly_go_web/src/directive/waves.ts diff --git a/mayfly_go_web/src/main.ts b/mayfly_go_web/src/main.ts index e0fd47ad..f97feeaa 100644 --- a/mayfly_go_web/src/main.ts +++ b/mayfly_go_web/src/main.ts @@ -1,16 +1,14 @@ import { createApp } from 'vue'; -import App from './App.vue'; +import App from '@/App.vue'; import router from './router'; -import { store, key } from './store'; -import { directive } from '@/common/utils/directive.ts'; -import { globalComponentSize } from '@/common/utils/componentSize.ts'; -import { dateStrFormat } from '@/common/utils/date.ts' +import pinia from '@/store/index'; +import { directive } from '@/directive/index'; +import { globalComponentSize } from '@/common/utils/componentSize'; import ElementPlus from 'element-plus'; import 'element-plus/dist/index.css'; import zhCn from 'element-plus/es/locale/lang/zh-cn' import '@/theme/index.scss'; -import mitt from 'mitt'; import { ElMessage } from 'element-plus'; import * as svg from '@element-plus/icons-vue'; @@ -18,15 +16,13 @@ import SvgIcon from '@/components/svgIcon/index.vue'; import '@/assets/font/font.css' const app = createApp(App); -// 屏蔽警告信息 -app.config.warnHandler = () => null; /** * 导出全局注册 element plus svg 图标 * @param app vue 实例 * @description 使用:https://element-plus.gitee.io/zh-CN/component/icon.html */ - function elSvg(app: any) { +function elSvg(app: any) { const icons = svg as any; for (const i in icons) { app.component(`${icons[i].name}`, icons[i]); @@ -37,22 +33,13 @@ app.config.warnHandler = () => null; elSvg(app); directive(app); -app.use(router) - .use(store, key) - .use(ElementPlus, { size: globalComponentSize, locale: zhCn}) +app.use(pinia) + .use(router) + .use(ElementPlus, { size: globalComponentSize, locale: zhCn }) .mount('#app'); - -// 自定义全局过滤器 -app.config.globalProperties.$filters = { - dateFormat(value: any) { - if (!value) { - return "" - } - return dateStrFormat('yyyy-MM-dd HH:mm:ss', value) - } -} - +// 屏蔽警告信息 +app.config.warnHandler = () => null; // 全局error处理 app.config.errorHandler = function (err: any, vm, info) { // 如果是断言错误,则进行提示即可 @@ -62,5 +49,3 @@ app.config.errorHandler = function (err: any, vm, info) { console.error(err, info) } } - -app.config.globalProperties.mittBus = mitt(); diff --git a/mayfly_go_web/src/router/imports.ts b/mayfly_go_web/src/router/imports.ts deleted file mode 100644 index 50e71b93..00000000 --- a/mayfly_go_web/src/router/imports.ts +++ /dev/null @@ -1,30 +0,0 @@ -import RouterParent from '@/views/layout/routerView/parent.vue'; - -export const imports = { - 'RouterParent': RouterParent, - - "Home": () => import('@/views/home/Home.vue'), - 'Personal': () => import('@/views/personal/index.vue'), - // machine - "MachineList": () => import('@/views/ops/machine/MachineList.vue'), - "AuthCertList": () => import('@/views/ops/machine/authcert/AuthCertList.vue'), - // sys - "ResourceList": () => import('@/views/system/resource'), - "RoleList": () => import('@/views/system/role'), - "AccountList": () => import('@/views/system/account'), - "SyslogList": () => import('@/views/system/syslog/SyslogList.vue'), - "ConfigList": () => import('@/views/system/config/ConfigList.vue'), - // tag - "TagTreeList": () => import('@/views/ops/tag/TagTreeList.vue'), - "TeamList": () => import('@/views/ops/tag/TeamList.vue'), - // db - "DbList": () => import('@/views/ops/db/DbList.vue'), - "SqlExec": () => import('@/views/ops/db'), - // redis - "RedisList": () => import('@/views/ops/redis'), - "DataOperation": () => import('@/views/ops/redis/DataOperation.vue'), - // mongo - "MongoDataOp": () => import('@/views/ops/mongo/MongoDataOp.vue'), - // redis - "MongoList": () => import('@/views/ops/mongo/MongoList.vue'), -} \ No newline at end of file diff --git a/mayfly_go_web/src/router/index.ts b/mayfly_go_web/src/router/index.ts index 78f500f9..637d9b6e 100644 --- a/mayfly_go_web/src/router/index.ts +++ b/mayfly_go_web/src/router/index.ts @@ -1,14 +1,25 @@ import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'; import NProgress from 'nprogress'; import 'nprogress/nprogress.css'; -import { store } from '@/store/index.ts'; -import { getSession, clearSession } from '@/common/utils/storage.ts'; -import { templateResolve } from '@/common/utils/string.ts' -import { NextLoading } from '@/common/utils/loading.ts'; -import { dynamicRoutes, staticRoutes, pathMatch } from './route.ts' -import { imports } from './imports'; +import { getSession, clearSession } from '@/common/utils/storage'; +import { templateResolve } from '@/common/utils/string' +import { NextLoading } from '@/common/utils/loading'; +import { dynamicRoutes, staticRoutes, pathMatch } from './route' import openApi from '@/common/openApi'; import sockets from '@/common/sockets'; +import pinia from '@/store/index'; +import { useThemeConfig } from '@/store/themeConfig'; +import { useUserInfo } from '@/store/userInfo'; +import { useRoutesList } from '@/store/routesList'; +import { useKeepALiveNames } from '@/store/keepAliveNames'; + +/** + * 获取目录下的 .vue、.tsx 全部文件 + * @method import.meta.glob + * @link 参考:https://cn.vitejs.dev/guide/features.html#json + */ +const viewsModules: any = import.meta.glob('../views/**/*.{vue,tsx}'); +const dynamicViewsModules: Record = Object.assign({}, { ...viewsModules }); // 添加静态路由 const router = createRouter({ @@ -24,7 +35,7 @@ export function initAllFun() { // 无 token 停止执行下一步 return false } - store.dispatch('userInfos/setUserInfos'); // 触发初始化用户信息 + useUserInfo().setUserInfo({}); router.addRoute(pathMatch); // 添加404界面 resetRoute(); // 删除/重置路由 // 添加动态路由 @@ -32,7 +43,7 @@ export function initAllFun() { router.addRoute((route as unknown) as RouteRecordRaw); }); // 过滤权限菜单 - store.dispatch('routesList/setRoutesList', setFilterMenuFun(dynamicRoutes[0].children, store.state.userInfos.userInfos.menus)); + useRoutesList().setRoutesList(setFilterMenuFun(dynamicRoutes[0].children, useUserInfo().userInfo.menus)) } // 后端控制路由:模拟执行路由数据初始化 @@ -43,7 +54,7 @@ export function initBackEndControlRoutesFun() { // 无 token 停止执行下一步 return false } - store.dispatch('userInfos/setUserInfos'); // 触发初始化用户信息 + useUserInfo().setUserInfo({}); let menuRoute = getSession('menus') if (!menuRoute) { menuRoute = getBackEndControlRoutes(); // 获取路由 @@ -57,7 +68,7 @@ export function initBackEndControlRoutesFun() { formatTwoStageRoutes(formatFlatteningRoutes(dynamicRoutes)).forEach((route: any) => { router.addRoute((route as unknown) as RouteRecordRaw); }); - store.dispatch('routesList/setRoutesList', dynamicRoutes[0].children); + useRoutesList().setRoutesList(dynamicRoutes[0].children) } // 后端控制路由,isRequestRoutes 为 true,则开启后端控制路由 @@ -76,7 +87,7 @@ export function backEndRouterConverter(routes: any, parentPath: string = "/") { item.meta = JSON.parse(item.meta) // 将meta.comoponet 解析为route.component if (item.meta.component) { - item.component = imports[item.meta.component as string] + item.component = dynamicImport(dynamicViewsModules, item.meta.component) delete item.meta['component'] } // route.path == resource.code @@ -106,6 +117,27 @@ export function backEndRouterConverter(routes: any, parentPath: string = "/") { }); } +/** + * 后端路由 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) { + const matchKey = matchKeys[0]; + return dynamicViewsModules[matchKey]; + } + if (matchKeys?.length > 1) { + return false; + } +} + // 多级嵌套数组处理成一维数组 export function formatFlatteningRoutes(arr: any) { if (arr.length <= 0) return false; @@ -134,7 +166,8 @@ export function formatTwoStageRoutes(arr: any) { } } }); - store.dispatch('keepAliveNames/setCacheKeepAlive', cacheList); + useKeepALiveNames().setCacheKeepAlive(cacheList); + // store.dispatch('keepAliveNames/setCacheKeepAlive', cacheList); return newArr; } @@ -167,7 +200,7 @@ export function setFilterRoute(chil: any) { chil.forEach((route: any) => { // 如果路由需要拥有指定code才可访问,则校验该用户菜单是否存在该code if (route.meta.code) { - store.state.userInfos.userInfos.menus.forEach((m: any) => { + useUserInfo().userInfo.menus.forEach((m: any) => { if (route.meta.code == m) { filterRoute.push({ ...route }) } @@ -188,14 +221,14 @@ export function setFilterRouteEnd() { // 删除/重置路由 export function resetRoute() { - store.state.routesList.routesList.forEach((route: any) => { + useRoutesList().routesList.forEach((route: any) => { const { name } = route; router.hasRoute(name) && router.removeRoute(name); }); } // 初始化方法执行 -const { isRequestRoutes } = store.state.themeConfig.themeConfig; +const { isRequestRoutes } = useThemeConfig(pinia).themeConfig; if (!isRequestRoutes) { // 未开启后端控制路由 initAllFun(); @@ -214,7 +247,7 @@ router.beforeEach((to, from, next) => { // 如果有标题参数,则再原标题后加上参数来区别 if (to.meta.titleRename) { - to.meta.title = templateResolve(to.meta.title, to.query) + to.meta.title = templateResolve(to.meta.title as string, to.query) } const token = getSession('token'); @@ -245,7 +278,7 @@ router.beforeEach((to, from, next) => { if (!SysWs && to.path != '/machine/terminal') { SysWs = sockets.sysMsgSocket(); } - if (store.state.routesList.routesList.length > 0) { + if (useRoutesList().routesList.length > 0) { next(); } }); diff --git a/mayfly_go_web/src/router/route.ts b/mayfly_go_web/src/router/route.ts index 38d9928e..279533c0 100644 --- a/mayfly_go_web/src/router/route.ts +++ b/mayfly_go_web/src/router/route.ts @@ -1,6 +1,5 @@ import { RouteRecordRaw } from 'vue-router'; import Layout from '@/views/layout/index.vue' -// import RouterParent from '@/views/layout/routerView/parent.vue'; // 定义动态路由 export const dynamicRoutes = [ @@ -12,6 +11,7 @@ export const dynamicRoutes = [ meta: { isKeepAlive: true, }, + children: [] // children: [ // { // path: '/home', diff --git a/mayfly_go_web/src/store/index.ts b/mayfly_go_web/src/store/index.ts index 50e8e872..27c377ed 100644 --- a/mayfly_go_web/src/store/index.ts +++ b/mayfly_go_web/src/store/index.ts @@ -1,22 +1,8 @@ -import { InjectionKey } from 'vue'; -import { createStore, useStore as baseUseStore, Store } from 'vuex'; -import { RootStateTypes } from '@/store/interface/index'; -import themeConfig from '@/store/modules/themeConfig.ts'; -import routesList from '@/store/modules/routesList.ts'; -import keepAliveNames from '@/store/modules/keepAliveNames.ts'; -import userInfos from '@/store/modules/userInfos.ts'; +// https://pinia.vuejs.org/ +import { createPinia } from 'pinia'; -export const key: InjectionKey> = Symbol(); +// 创建 +const pinia = createPinia(); -export const store = createStore({ - modules: { - themeConfig, - routesList, - keepAliveNames, - userInfos, - }, -}); - -export function useStore() { - return baseUseStore(key); -} +// 导出 +export default pinia; diff --git a/mayfly_go_web/src/store/keepAliveNames.ts b/mayfly_go_web/src/store/keepAliveNames.ts new file mode 100644 index 00000000..981198f2 --- /dev/null +++ b/mayfly_go_web/src/store/keepAliveNames.ts @@ -0,0 +1,35 @@ +import { defineStore } from 'pinia'; + +/** + * 路由缓存列表 + * @methods setCacheKeepAlive 设置要缓存的路由 names(开启 Tagsview) + * @methods addCachedView 添加要缓存的路由 names(关闭 Tagsview) + * @methods delCachedView 删除要缓存的路由 names(关闭 Tagsview) + * @methods delOthersCachedViews 右键菜单`关闭其它`,删除要缓存的路由 names(关闭 Tagsview) + * @methods delAllCachedViews 右键菜单`全部关闭`,删除要缓存的路由 names(关闭 Tagsview) + */ +export const useKeepALiveNames = defineStore('keepALiveNames', { + state: (): KeepAliveNamesState => ({ + keepAliveNames: [], + cachedViews: [], + }), + actions: { + async setCacheKeepAlive(data: Array) { + this.keepAliveNames = data; + }, + async addCachedView(view: any) { + if (view.meta.isKeepAlive) this.cachedViews?.push(view.name); + }, + async delCachedView(view: any) { + const index = this.cachedViews.indexOf(view.name); + index > -1 && this.cachedViews.splice(index, 1); + }, + async delOthersCachedViews(view: any) { + if (view.meta.isKeepAlive) this.cachedViews = [view.name]; + else this.cachedViews = []; + }, + async delAllCachedViews() { + this.cachedViews = []; + }, + }, +}); diff --git a/mayfly_go_web/src/store/modules/keepAliveNames.ts b/mayfly_go_web/src/store/modules/keepAliveNames.ts deleted file mode 100644 index 113b83ed..00000000 --- a/mayfly_go_web/src/store/modules/keepAliveNames.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Module } from 'vuex'; -// 此处加上 `.ts` 后缀报错,具体原因不详 -import { KeepAliveNamesState, RootStateTypes } from '@/store/interface/index'; - -const keepAliveNamesModule: Module = { - namespaced: true, - state: { - keepAliveNames: [], - }, - mutations: { - // 设置路由缓存(name字段) - getCacheKeepAlive(state: any, data: Array) { - state.keepAliveNames = data; - }, - }, - actions: { - // 设置路由缓存(name字段) - async setCacheKeepAlive({ commit }, data: Array) { - commit('getCacheKeepAlive', data); - }, - }, -}; - -export default keepAliveNamesModule; diff --git a/mayfly_go_web/src/store/modules/routesList.ts b/mayfly_go_web/src/store/modules/routesList.ts deleted file mode 100644 index e88db78f..00000000 --- a/mayfly_go_web/src/store/modules/routesList.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Module } from 'vuex'; -// 此处加上 `.ts` 后缀报错,具体原因不详 -import { RoutesListState, RootStateTypes } from '@/store/interface/index'; - -const routesListModule: Module = { - namespaced: true, - state: { - routesList: [], - }, - mutations: { - // 设置路由,菜单中使用到 - getRoutesList(state: any, data: Array) { - state.routesList = data; - }, - }, - actions: { - // 设置路由,菜单中使用到 - async setRoutesList({ commit }, data: any) { - commit('getRoutesList', data); - }, - }, -}; - -export default routesListModule; diff --git a/mayfly_go_web/src/store/modules/userInfos.ts b/mayfly_go_web/src/store/modules/userInfos.ts deleted file mode 100644 index 99aa2777..00000000 --- a/mayfly_go_web/src/store/modules/userInfos.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Module } from 'vuex'; -import { getSession } from '@/common/utils/storage.ts'; -// 此处加上 `.ts` 后缀报错,具体原因不详 -import { UserInfosState, RootStateTypes } from '@/store/interface/index'; - -const userInfosModule: Module = { - namespaced: true, - state: { - userInfos: {}, - }, - mutations: { - // 设置用户信息 - getUserInfos(state: any, data: object) { - state.userInfos = data; - }, - }, - actions: { - // 设置用户信息 - async setUserInfos({ commit }, data: object) { - if (data) { - commit('getUserInfos', data); - } else { - if (getSession('userInfo')) commit('getUserInfos', getSession('userInfo')); - } - }, - }, -}; - -export default userInfosModule; diff --git a/mayfly_go_web/src/store/routesList.ts b/mayfly_go_web/src/store/routesList.ts new file mode 100644 index 00000000..9c908055 --- /dev/null +++ b/mayfly_go_web/src/store/routesList.ts @@ -0,0 +1,18 @@ +import { defineStore } from 'pinia'; + +/** + * 路由列表 + * @methods setRoutesList 设置路由数据 + * @methods setColumnsMenuHover 设置分栏布局菜单鼠标移入 boolean + * @methods setColumnsNavHover 设置分栏布局最左侧导航鼠标移入 boolean + */ +export const useRoutesList = defineStore('routesList', { + state: (): RoutesListState => ({ + routesList: [], + }), + actions: { + async setRoutesList(data: Array) { + this.routesList = data; + }, + }, +}); \ No newline at end of file diff --git a/mayfly_go_web/src/store/modules/themeConfig.ts b/mayfly_go_web/src/store/themeConfig.ts similarity index 89% rename from mayfly_go_web/src/store/modules/themeConfig.ts rename to mayfly_go_web/src/store/themeConfig.ts index 3f1e658f..76ee178a 100644 --- a/mayfly_go_web/src/store/modules/themeConfig.ts +++ b/mayfly_go_web/src/store/themeConfig.ts @@ -1,10 +1,7 @@ -import { Module } from 'vuex'; -// 此处加上 `.ts` 后缀报错,具体原因不详 -import { ThemeConfigState, RootStateTypes } from '@/store/interface/index'; +import { defineStore } from 'pinia'; -const themeConfigModule: Module = { - namespaced: true, - state: { +export const useThemeConfig = defineStore('themeConfig', { + state: (): ThemeConfigState => ({ themeConfig: { // 是否开启布局配置抽屉 isDrawer: false, @@ -73,12 +70,13 @@ const themeConfigModule: Module = { isBreadcrumb: true, // 是否开启 Tagsview isTagsview: true, + isShareTagsView: false, // 是否开启 Breadcrumb 图标 isBreadcrumbIcon: true, // 是否开启 Tagsview 图标 isTagsviewIcon: true, // 是否开启 TagsView 缓存 - isCacheTagsView: false, + isCacheTagsView: true, // 是否开启 TagsView 拖拽 isSortableTagsView: true, // 是否开启 Footer 底部版权信息 @@ -94,8 +92,8 @@ const themeConfigModule: Module = { /* 其它设置 ------------------------------- */ - // 默认 Tagsview 风格,可选 1、 tags-style-one 2、 tags-style-two 3、 tags-style-three 4、 tags-style-four - tagsStyle: 'tags-style-one', + // 默认 Tagsview 风格,可选 1、 tags-style-one 2、 tags-style-two 3、 tags-style-three + tagsStyle: 'tags-style-three', // 默认主页面切换动画,可选 1、 slide-right 2、 slide-left 3、 opacitys animation: 'slide-right', // 默认分栏高亮风格,可选 1、 圆角 columns-round 2、 卡片 columns-card @@ -135,19 +133,11 @@ const themeConfigModule: Module = { // 默认全局组件大小,可选值"<|large|default|small>",默认 '' globalComponentSize: '', }, - }, - mutations: { - // 设置布局配置 - getThemeConfig(state: any, data: object) { - state.themeConfig = data; - }, - }, + }), actions: { // 设置布局配置 - setThemeConfig({ commit }, data: object) { - commit('getThemeConfig', data); + setThemeConfig(data: ThemeConfigState) { + this.themeConfig = data.themeConfig; }, }, -}; - -export default themeConfigModule; +}) diff --git a/mayfly_go_web/src/store/userInfo.ts b/mayfly_go_web/src/store/userInfo.ts new file mode 100644 index 00000000..fae8ce99 --- /dev/null +++ b/mayfly_go_web/src/store/userInfo.ts @@ -0,0 +1,19 @@ +import { defineStore } from 'pinia'; +import { getSession } from '@/common/utils/storage.ts'; + +export const useUserInfo = defineStore('userInfo', { + state: (): UserInfoState => ({ + userInfo: {}, + }), + actions: { + // 设置用户信息 + async setUserInfo(data: object) { + const ui = getSession('userInfo') + if (ui) { + this.userInfo = ui; + } else { + this.userInfo = data; + } + }, + } +}) diff --git a/mayfly_go_web/src/theme/iconSelector.scss b/mayfly_go_web/src/theme/iconSelector.scss index afee8718..bb4af0dc 100644 --- a/mayfly_go_web/src/theme/iconSelector.scss +++ b/mayfly_go_web/src/theme/iconSelector.scss @@ -3,85 +3,29 @@ .icon-selector-popper { padding: 0 !important; .icon-selector-warp { + height: 260px; + overflow: hidden; + position: relative; .icon-selector-warp-title { + position: absolute; height: 40px; line-height: 40px; + left: 15px; + } + .el-tabs__header { + display: flex; + justify-content: flex-end; padding: 0 15px; - } - .icon-selector-warp-row { - max-height: 260px; - overflow-y: auto; - padding: 15px 15px 5px; - border-top: 1px solid #ebeef5; - .ele-col:nth-last-child(1), - .ele-col:nth-last-child(2) { - display: none; - } - .awe-col:nth-child(-n + 24) { - display: none; - } - .icon-selector-warp-item { - display: flex; - border: 1px solid #ebeef5; - padding: 10px; - border-radius: 5px; - margin-bottom: 10px; - transition: all 0.3s ease; - .icon-selector-warp-item-value { - transition: all 0.3s ease; - i { - font-size: 20px; - color: #606266; - } + border-bottom: 1px solid var(--el-border-color-light); + margin: 0 !important; + .el-tabs__nav-wrap { + &::after { + height: 0 !important; } - &:hover { - border: 1px solid var(--color-primary); - cursor: pointer; - transition: all 0.3s ease; - .icon-selector-warp-item-value { - i { - color: var(--color-primary); - transition: all 0.3s ease; - } - } - } - } - .icon-selector-active { - border: 1px solid var(--color-primary); - .icon-selector-warp-item-value { - i { - color: var(--color-primary); - } - } - } - } - .icon-selector-all { - .el-input { - padding: 0 15px; - margin-bottom: 10px; - } - &-tabs { - display: flex; - height: 30px; - line-height: 30px; - padding: 0 15px; - margin-bottom: 5px; - &-item { - flex: 1; - text-align: center; - cursor: pointer; - &:hover { - color: var(--color-primary); - } - } - &-active { - background: var(--color-primary); - border-radius: 5px; - .label { - color: #ffffff; - } + .el-tabs__item { + padding: 0 5px !important; } } } } -} +} \ No newline at end of file diff --git a/mayfly_go_web/src/types/env.d.ts b/mayfly_go_web/src/types/env.d.ts new file mode 100644 index 00000000..013cb8aa --- /dev/null +++ b/mayfly_go_web/src/types/env.d.ts @@ -0,0 +1,5 @@ +declare module '*.vue' { + import type { DefineComponent } from 'vue'; + const component: DefineComponent<{}, {}, any>; + export default component; +} \ No newline at end of file diff --git a/mayfly_go_web/src/store/interface/index.ts b/mayfly_go_web/src/types/pinia.d.ts similarity index 69% rename from mayfly_go_web/src/store/interface/index.ts rename to mayfly_go_web/src/types/pinia.d.ts index e335e69a..b4e767a8 100644 --- a/mayfly_go_web/src/store/interface/index.ts +++ b/mayfly_go_web/src/types/pinia.d.ts @@ -1,7 +1,8 @@ -// 接口类型声明 +declare interface UserInfoState { + userInfo: any +} -// 布局配置 -export interface ThemeConfigState { +declare interface ThemeConfigState { themeConfig: { isDrawer: boolean; primary: string; @@ -30,6 +31,7 @@ export interface ThemeConfigState { isShowLogoChange: boolean; isBreadcrumb: boolean; isTagsview: boolean; + isShareTagsView: boolean; isBreadcrumbIcon: boolean; isTagsviewIcon: boolean; isCacheTagsView: boolean; @@ -52,37 +54,24 @@ export interface ThemeConfigState { terminalBackground: string; terminalCursor: string; terminalFontSize: number; - terminalFontWeight: string; + terminalFontWeight: string | any; editorTheme: string; }; } +// TagsView 路由列表 +declare interface TagsViewRoutesState { + tagsViewRoutes: T[]; + isTagsViewCurrenFull: Boolean; +} + // 路由列表 -export interface RoutesListState { - routesList: Array; +declare interface RoutesListState { + routesList: T[]; } // 路由缓存列表 -export interface KeepAliveNamesState { - keepAliveNames: Array; -} - -// 用户信息 -export interface UserInfosState { - userInfos: object; -} - - -// 后端返回原始路由(未处理时) -// export interface RequestOldRoutesState { -// requestOldRoutes: Array; -// } - -// 主接口(顶级类型声明) -export interface RootStateTypes { - themeConfig: ThemeConfigState; - routesList: RoutesListState; - keepAliveNames: KeepAliveNamesState; - userInfos: UserInfosState; - // requestOldRoutes: RequestOldRoutesState; -} +declare interface KeepAliveNamesState { + keepAliveNames: string[]; + cachedViews: string[]; +} \ No newline at end of file diff --git a/mayfly_go_web/shim.d.ts b/mayfly_go_web/src/types/shim.d.ts similarity index 65% rename from mayfly_go_web/shim.d.ts rename to mayfly_go_web/src/types/shim.d.ts index 37cdf7f3..a284db65 100644 --- a/mayfly_go_web/shim.d.ts +++ b/mayfly_go_web/src/types/shim.d.ts @@ -1,21 +1,14 @@ /* eslint-disable */ import {IDisposable} from 'monaco-editor'; - -declare module '*.vue' { - import type { DefineComponent } from 'vue'; - const component: DefineComponent<{}, {}, any>; - export default component; -} - - declare global { interface Window { completionItemProvider?: IDisposable | undefined; } } - +// 申明外部 npm 插件模块 declare module 'sql-formatter'; declare module 'jsoneditor'; declare module 'asciinema-player'; declare module 'monaco-editor'; +declare module 'vue-grid-layout'; \ No newline at end of file diff --git a/mayfly_go_web/source.d.ts b/mayfly_go_web/src/types/source.d.ts similarity index 62% rename from mayfly_go_web/source.d.ts rename to mayfly_go_web/src/types/source.d.ts index 2f9c7682..d04f0da7 100644 --- a/mayfly_go_web/source.d.ts +++ b/mayfly_go_web/src/types/source.d.ts @@ -1,6 +1,7 @@ +// 声明一个模块,防止引入文件时报错 declare module '*.json'; declare module '*.png'; declare module '*.jpg'; declare module '*.scss'; declare module '*.ts'; -declare module '*.js'; +declare module '*.js'; \ No newline at end of file diff --git a/mayfly_go_web/src/views/home/Home.vue b/mayfly_go_web/src/views/home/Home.vue index 517be44a..6419c74b 100644 --- a/mayfly_go_web/src/views/home/Home.vue +++ b/mayfly_go_web/src/views/home/Home.vue @@ -4,10 +4,10 @@
- +
-
{{ `${currentTime}, ${getUserInfos.username}` +
{{ `${currentTime}, ${userInfo.username}` }}
@@ -29,15 +29,17 @@ + \ No newline at end of file diff --git a/mayfly_go_web/src/views/layout/logo/index.vue b/mayfly_go_web/src/views/layout/logo/index.vue index 1ff5d500..f8e83be6 100644 --- a/mayfly_go_web/src/views/layout/logo/index.vue +++ b/mayfly_go_web/src/views/layout/logo/index.vue @@ -2,7 +2,7 @@ @@ -11,37 +11,25 @@
- diff --git a/mayfly_go_web/src/views/layout/main/classic.vue b/mayfly_go_web/src/views/layout/main/classic.vue index 07a534ce..62b87c3d 100644 --- a/mayfly_go_web/src/views/layout/main/classic.vue +++ b/mayfly_go_web/src/views/layout/main/classic.vue @@ -4,7 +4,7 @@