From 5463ae9d7ed140fab43337c50781f5c8a0d042cd Mon Sep 17 00:00:00 2001 From: "meilin.huang" <954537473@qq.com> Date: Thu, 6 Jul 2023 20:59:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=89=8D=E7=AB=AF=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E4=BD=BF=E7=94=A8prettier=E6=A0=BC=E5=BC=8F=E5=8C=96&?= =?UTF-8?q?=E6=9E=9A=E4=B8=BE=E5=80=BC=E7=BB=9F=E4=B8=80=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mayfly_go_web/.prettierrc.js | 74 +-- mayfly_go_web/src/App.vue | 4 +- mayfly_go_web/src/common/Api.ts | 23 +- mayfly_go_web/src/common/Enum.ts | 101 ++- mayfly_go_web/src/common/SocketBuilder.ts | 83 ++- mayfly_go_web/src/common/assert.ts | 32 +- mayfly_go_web/src/common/config.ts | 6 +- .../src/common/echarts/useEcharts.ts | 55 +- mayfly_go_web/src/common/enums.ts | 22 +- mayfly_go_web/src/common/openApi.ts | 20 +- mayfly_go_web/src/common/request.ts | 90 +-- mayfly_go_web/src/common/rsa.ts | 32 +- mayfly_go_web/src/common/sockets.ts | 16 +- mayfly_go_web/src/common/sysconfig.ts | 42 +- mayfly_go_web/src/common/utils/date.ts | 22 +- mayfly_go_web/src/common/utils/export.ts | 7 +- mayfly_go_web/src/common/utils/format.ts | 7 +- mayfly_go_web/src/common/utils/loading.ts | 2 +- mayfly_go_web/src/common/utils/mitt.ts | 2 +- mayfly_go_web/src/common/utils/setIconfont.ts | 50 +- mayfly_go_web/src/common/utils/storage.ts | 12 +- mayfly_go_web/src/common/utils/string.ts | 51 +- mayfly_go_web/src/common/utils/svgIcons.ts | 26 +- .../src/common/utils/toolsValidate.ts | 9 +- mayfly_go_web/src/common/utils/wartermark.ts | 12 +- mayfly_go_web/src/components/auth/auth.ts | 4 +- .../src/components/contextmenu/index.vue | 30 +- .../src/components/enumtag/EnumTag.vue | 56 ++ .../src/components/iconSelector/index.vue | 333 +++++----- .../src/components/iconSelector/list.vue | 130 ++-- .../src/components/monaco/MonacoEditor.vue | 92 +-- .../src/components/pagetable/PageTable.vue | 126 +++- .../src/components/pagetable/index.ts | 103 ++- .../src/components/svgIcon/index.vue | 14 +- mayfly_go_web/src/directive/auth.ts | 12 +- mayfly_go_web/src/directive/waves.ts | 2 +- mayfly_go_web/src/main.ts | 17 +- mayfly_go_web/src/router/index.ts | 66 +- mayfly_go_web/src/router/route.ts | 210 +++--- mayfly_go_web/src/store/keepAliveNames.ts | 46 +- mayfly_go_web/src/store/routesList.ts | 18 +- mayfly_go_web/src/store/themeConfig.ts | 3 +- mayfly_go_web/src/store/userInfo.ts | 16 +- .../views/login/component/AccountLogin.vue | 104 +-- .../src/views/login/component/MobileLogin.vue | 3 +- mayfly_go_web/src/views/login/index.vue | 6 +- .../views/ops/component/SshTunnelSelect.vue | 26 +- .../src/views/ops/component/TagInfo.vue | 20 +- .../src/views/ops/component/TagSelect.vue | 29 +- .../src/views/ops/component/TagTree.vue | 80 ++- mayfly_go_web/src/views/ops/component/tag.ts | 8 +- .../src/views/ops/db/CreateTable.vue | 435 ++++++------ mayfly_go_web/src/views/ops/db/DbEdit.vue | 63 +- mayfly_go_web/src/views/ops/db/DbList.vue | 35 +- mayfly_go_web/src/views/ops/db/SqlExec.vue | 620 +++++++++--------- mayfly_go_web/src/views/ops/db/TableEdit.vue | 15 +- mayfly_go_web/src/views/ops/db/api.ts | 38 +- .../src/views/ops/db/component/DbTable.vue | 37 +- .../src/views/ops/db/component/SqlExecBox.ts | 44 +- .../views/ops/db/component/SqlExecDialog.vue | 13 +- .../src/views/ops/db/component/tab/Query.vue | 192 +++--- .../views/ops/db/component/tab/TableData.vue | 174 +++-- mayfly_go_web/src/views/ops/db/db.ts | 129 ++-- mayfly_go_web/src/views/ops/db/enums.ts | 21 +- mayfly_go_web/src/views/ops/db/index.ts | 2 +- mayfly_go_web/src/views/ops/db/service.ts | 100 ++- .../src/views/ops/machine/FileManage.vue | 184 +++--- .../src/views/ops/machine/MachineEdit.vue | 55 +- .../src/views/ops/machine/MachineList.vue | 186 +++--- .../src/views/ops/machine/MachineRec.vue | 18 +- .../src/views/ops/machine/MachineStats.vue | 31 +- .../src/views/ops/machine/ProcessList.vue | 23 +- .../src/views/ops/machine/ScriptEdit.vue | 37 +- .../src/views/ops/machine/ScriptManage.vue | 169 ++--- .../src/views/ops/machine/SshTerminal.vue | 8 +- .../src/views/ops/machine/SshTerminalPage.vue | 9 +- mayfly_go_web/src/views/ops/machine/api.ts | 68 +- .../ops/machine/authcert/AuthCertEdit.vue | 26 +- .../ops/machine/authcert/AuthCertList.vue | 71 +- .../ops/machine/authcert/AuthCertSelect.vue | 26 +- mayfly_go_web/src/views/ops/machine/enums.ts | 32 +- mayfly_go_web/src/views/ops/machine/index.ts | 2 +- .../src/views/ops/mongo/MongoDataOp.vue | 85 ++- .../src/views/ops/mongo/MongoEdit.vue | 27 +- .../src/views/ops/mongo/MongoList.vue | 86 ++- mayfly_go_web/src/views/ops/mongo/api.ts | 22 +- .../src/views/ops/redis/DataOperation.vue | 168 +++-- .../src/views/ops/redis/FormatViewer.vue | 39 +- mayfly_go_web/src/views/ops/redis/Info.vue | 54 +- .../src/views/ops/redis/KeyDetail.vue | 48 +- .../src/views/ops/redis/KeyHeader.vue | 66 +- .../src/views/ops/redis/KeyValueHash.vue | 86 ++- .../src/views/ops/redis/KeyValueList.vue | 77 +-- .../src/views/ops/redis/KeyValueSet.vue | 94 ++- .../src/views/ops/redis/KeyValueString.vue | 27 +- .../src/views/ops/redis/KeyValueZset.vue | 123 ++-- .../src/views/ops/redis/RedisEdit.vue | 74 ++- .../src/views/ops/redis/RedisList.vue | 128 ++-- .../src/views/ops/redis/ViewerJson.vue | 21 +- .../src/views/ops/redis/ViewerText.vue | 17 +- mayfly_go_web/src/views/ops/redis/api.ts | 76 +-- mayfly_go_web/src/views/ops/redis/index.ts | 2 +- .../src/views/ops/tag/TagTreeList.vue | 55 +- mayfly_go_web/src/views/ops/tag/TeamList.vue | 140 ++-- mayfly_go_web/src/views/ops/tag/api.ts | 28 +- mayfly_go_web/src/views/personal/api.ts | 9 +- mayfly_go_web/src/views/personal/index.vue | 30 +- .../src/views/system/account/AccountEdit.vue | 28 +- .../src/views/system/account/AccountList.vue | 129 ++-- .../src/views/system/account/RoleEdit.vue | 34 +- .../src/views/system/account/index.ts | 2 +- mayfly_go_web/src/views/system/api.ts | 66 +- .../src/views/system/config/ConfigEdit.vue | 15 +- .../src/views/system/config/ConfigList.vue | 90 +-- mayfly_go_web/src/views/system/enums.ts | 26 +- .../views/system/resource/ResourceEdit.vue | 53 +- .../views/system/resource/ResourceList.vue | 126 ++-- .../src/views/system/resource/index.ts | 2 +- .../src/views/system/role/ResourceEdit.vue | 61 +- .../src/views/system/role/RoleEdit.vue | 20 +- .../src/views/system/role/RoleList.vue | 100 +-- .../src/views/system/role/ShowResource.vue | 42 +- mayfly_go_web/src/views/system/role/index.ts | 2 +- .../src/views/system/syslog/SyslogList.vue | 66 +- server/go.mod | 6 +- 125 files changed, 3932 insertions(+), 3735 deletions(-) create mode 100644 mayfly_go_web/src/components/enumtag/EnumTag.vue diff --git a/mayfly_go_web/.prettierrc.js b/mayfly_go_web/.prettierrc.js index c5697f86..44dd863f 100644 --- a/mayfly_go_web/.prettierrc.js +++ b/mayfly_go_web/.prettierrc.js @@ -1,39 +1,39 @@ module.exports = { - // 一行最多多少个字符 - printWidth: 150, - // 指定每个缩进级别的空格数 - tabWidth: 4, - // 使用制表符而不是空格缩进行 - useTabs: false, - // 在语句末尾打印分号 - semi: true, - // 使用单引号而不是双引号 - singleQuote: true, - // 更改引用对象属性的时间 可选值"" - quoteProps: 'as-needed', - // 在JSX中使用单引号而不是双引号 - jsxSingleQuote: false, - // 多行时尽可能打印尾随逗号。(例如,单行数组永远不会出现逗号结尾。) 可选值"",默认none - trailingComma: 'es5', - // 在对象文字中的括号之间打印空格 - bracketSpacing: true, - // jsx 标签的反尖括号需要换行 - jsxBracketSameLine: false, - // 在单独的箭头函数参数周围包括括号 always:(x) => x \ avoid:x => x - arrowParens: 'always', - // 这两个选项可用于格式化以给定字符偏移量(分别包括和不包括)开始和结束的代码 - rangeStart: 0, - rangeEnd: Infinity, - // 指定要使用的解析器,不需要写文件开头的 @prettier - requirePragma: false, - // 不需要自动在文件开头插入 @prettier - insertPragma: false, - // 使用默认的折行标准 always\never\preserve - proseWrap: 'preserve', - // 指定HTML文件的全局空格敏感度 css\strict\ignore - htmlWhitespaceSensitivity: 'css', - // Vue文件脚本和样式标签缩进 - vueIndentScriptAndStyle: false, - // 换行符使用 lf 结尾是 可选值"" - endOfLine: 'lf', + // 一行最多多少个字符 + printWidth: 160, + // 指定每个缩进级别的空格数 + tabWidth: 4, + // 使用制表符而不是空格缩进行 + useTabs: false, + // 在语句末尾打印分号 + semi: true, + // 使用单引号而不是双引号 + singleQuote: true, + // 更改引用对象属性的时间 可选值"" + quoteProps: 'as-needed', + // 在JSX中使用单引号而不是双引号 + jsxSingleQuote: false, + // 多行时尽可能打印尾随逗号。(例如,单行数组永远不会出现逗号结尾。) 可选值"",默认none + trailingComma: 'es5', + // 在对象文字中的括号之间打印空格 + bracketSpacing: true, + // jsx 标签的反尖括号需要换行 + jsxBracketSameLine: false, + // 在单独的箭头函数参数周围包括括号 always:(x) => x \ avoid:x => x + arrowParens: 'always', + // 这两个选项可用于格式化以给定字符偏移量(分别包括和不包括)开始和结束的代码 + rangeStart: 0, + rangeEnd: Infinity, + // 指定要使用的解析器,不需要写文件开头的 @prettier + requirePragma: false, + // 不需要自动在文件开头插入 @prettier + insertPragma: false, + // 使用默认的折行标准 always\never\preserve + proseWrap: 'preserve', + // 指定HTML文件的全局空格敏感度 css\strict\ignore + htmlWhitespaceSensitivity: 'css', + // Vue文件脚本和样式标签缩进 + vueIndentScriptAndStyle: false, + // 换行符使用 lf 结尾是 可选值"" + endOfLine: 'lf', }; diff --git a/mayfly_go_web/src/App.vue b/mayfly_go_web/src/App.vue index ad8b8586..debf6a5c 100644 --- a/mayfly_go_web/src/App.vue +++ b/mayfly_go_web/src/App.vue @@ -44,7 +44,7 @@ onMounted(() => { }); // 获取缓存中的布局配置 if (getLocal('themeConfig')) { - themeConfigStores.setThemeConfig({ themeConfig: getLocal('themeConfig') }) + themeConfigStores.setThemeConfig({ themeConfig: getLocal('themeConfig') }); document.documentElement.style.cssText = getLocal('themeConfigStyle'); } }); @@ -52,7 +52,7 @@ onMounted(() => { // 页面销毁时,关闭监听布局配置 onUnmounted(() => { - mittBus.off('openSetingsDrawer', () => { }); + mittBus.off('openSetingsDrawer', () => {}); }); // 监听路由的变化,设置网站标题 diff --git a/mayfly_go_web/src/common/Api.ts b/mayfly_go_web/src/common/Api.ts index 62b55efd..b0b51c87 100644 --- a/mayfly_go_web/src/common/Api.ts +++ b/mayfly_go_web/src/common/Api.ts @@ -1,4 +1,4 @@ -import request from './request' +import request from './request'; /** * 可用于各模块定义各自api请求 @@ -27,23 +27,13 @@ class Api { } /** - * 操作该权限,即请求对应的url + * 请求对应的该api * @param {Object} param 请求该api的参数 */ - request(param: any = null, options: any = null): Promise { - return request.send(this, param, options); + request(param: any = null, options: any = null, headers: any = null): Promise { + return request.request(this.method, this.url, param, headers, options); } - /** - * 操作该权限,即请求对应的url - * @param {Object} param 请求该api的参数 - * @param headers headers - */ - requestWithHeaders(param: any, headers: any): Promise { - return request.sendWithHeaders(this, param, headers); - } - - /** 静态方法 **/ /** @@ -51,7 +41,7 @@ class Api { * @param url url * @param method 请求方法(get,post,put,delete...) */ - static create(url: string, method: string) :Api { + static create(url: string, method: string): Api { return new Api(url, method); } @@ -88,5 +78,4 @@ class Api { } } - -export default Api +export default Api; diff --git a/mayfly_go_web/src/common/Enum.ts b/mayfly_go_web/src/common/Enum.ts index 5eb79c61..609c36d3 100644 --- a/mayfly_go_web/src/common/Enum.ts +++ b/mayfly_go_web/src/common/Enum.ts @@ -1,37 +1,90 @@ +export interface EnumValueTag { + color?: string; + type?: string; +} + /** - * 枚举类 - * @author meilin.huang + * 枚举值 */ -export class Enum { +export class EnumValue { /** - * 添加枚举字段 - * - * @param {string} field 枚举字段名 - * @param {string} label 枚举名称 - * @param {Object} value 枚举值 + * 枚举值 */ - add(field: string, label: string, value: any) { - this[field] = { label, value } - return this + value: any; + + /** + * 枚举描述 + */ + label: string; + + /** + * 展示的标签信息 + */ + tag: EnumValueTag; + + constructor(value: any, label: string) { + this.value = value; + this.label = label; + } + + setTagType(type: string = 'primary'): EnumValue { + this.tag = { type }; + return this; + } + + tagTypeSuccess(): EnumValue { + return this.setTagType('success'); + } + + tagTypeDanger(): EnumValue { + return this.setTagType('danger'); + } + + tagTypeWarning(): EnumValue { + return this.setTagType('warning'); + } + + setTagColor(color: string): EnumValue { + this.tag = { color }; + return this; + } + + public static of(value: any, label: string): EnumValue { + return new EnumValue(value, label); } /** - * 根据枚举value获取其label - * - * @param {Object} value + * 根据枚举值获取指定枚举值对象 + * + * @param enumValues 所有枚举值 + * @param value 需要匹配的枚举值 + * @returns 枚举值对象 */ - getLabelByValue(value: any) { - // 字段不存在返回‘’ - if (value === undefined || value === null) { - return '' - } - for (const i in this) { - const e: any = this[i] - if (e && e.value === value) { - return e.label + static getEnumByValue(enumValues: EnumValue[], value: any): EnumValue | null { + for (let enumValue of enumValues) { + if (enumValue.value == value) { + return enumValue; } } + return null; + } - return '' + /** + * 根据枚举值获取枚举描述 + * + * @param enums 枚举对象 + * @param value 枚举值 + * @returns 枚举描述 + */ + static getLabelByValue(enums: any, value: any) { + const enumValues = Object.values(enums) as any; + for (let enumValue of enumValues) { + if (enumValue['value'] == value) { + return enumValue['label']; + } + } + return ''; } } + +export default EnumValue; diff --git a/mayfly_go_web/src/common/SocketBuilder.ts b/mayfly_go_web/src/common/SocketBuilder.ts index ba856555..63592b51 100644 --- a/mayfly_go_web/src/common/SocketBuilder.ts +++ b/mayfly_go_web/src/common/SocketBuilder.ts @@ -1,46 +1,43 @@ class SocketBuilder { - websocket: WebSocket; - - constructor(url: string) { - if (typeof (WebSocket) === "undefined") { - throw new Error('不支持websocket'); - } - if (!url) { - throw new Error('websocket url不能为空'); - } - this.websocket = new WebSocket(url); - } - - static builder(url: string) { - return new SocketBuilder(url); - } - - open(onopen: any) { - this.websocket.onopen = onopen; - return this; - } - - error(onerror: any) { - this.websocket.onerror = onerror; - return this; - } - - message(onmessage: any) { - this.websocket.onmessage = onmessage; - return this; - } - - close(onclose: any) { - this.websocket.onclose = onclose; - return this; - } - - build() { - return this.websocket; - } - } - - export default SocketBuilder; - \ No newline at end of file + constructor(url: string) { + if (typeof WebSocket === 'undefined') { + throw new Error('不支持websocket'); + } + if (!url) { + throw new Error('websocket url不能为空'); + } + this.websocket = new WebSocket(url); + } + + static builder(url: string) { + return new SocketBuilder(url); + } + + open(onopen: any) { + this.websocket.onopen = onopen; + return this; + } + + error(onerror: any) { + this.websocket.onerror = onerror; + return this; + } + + message(onmessage: any) { + this.websocket.onmessage = onmessage; + return this; + } + + close(onclose: any) { + this.websocket.onclose = onclose; + return this; + } + + build() { + return this.websocket; + } +} + +export default SocketBuilder; diff --git a/mayfly_go_web/src/common/assert.ts b/mayfly_go_web/src/common/assert.ts index 5620179c..4d17a631 100644 --- a/mayfly_go_web/src/common/assert.ts +++ b/mayfly_go_web/src/common/assert.ts @@ -5,17 +5,17 @@ class AssertError extends Error { constructor(message: string) { super(message); // 错误类名 - this.name = "AssertError"; + this.name = 'AssertError'; } } /** * 断言表达式为true - * + * * @param condition 条件表达式 * @param msg 错误消息 */ - export function isTrue(condition: boolean, msg: string) { +export function isTrue(condition: boolean, msg: string) { if (!condition) { throw new AssertError(msg); } @@ -23,45 +23,45 @@ class AssertError extends Error { /** * 断言不能为空值,即null,0,''等 - * + * * @param obj 对象1 * @param msg 错误消息 */ - export function notBlank(obj: any, msg: string) { - isTrue(obj, msg) +export function notBlank(obj: any, msg: string) { + isTrue(obj, msg); } /** * 断言两对象相等 - * + * * @param obj1 对象1 * @param obj2 对象2 * @param msg 错误消息 */ - export function isEquals(obj1: any, obj2: any, msg: string) { +export function isEquals(obj1: any, obj2: any, msg: string) { isTrue(obj1 === obj2, msg); } /** * 断言对象不为null或undefiend - * + * * @param obj 对象 * @param msg 错误提示 */ export function notNull(obj: any, msg: string) { if (obj == null || obj == undefined) { - throw new AssertError(msg) + throw new AssertError(msg); } } /** -* 断言字符串不能为空 -* -* @param str 字符串 -* @param msg 错误提示 -*/ + * 断言字符串不能为空 + * + * @param str 字符串 + * @param msg 错误提示 + */ export function notEmpty(str: string, msg: string) { if (str == null || str == undefined || str == '') { throw new AssertError(msg); } -} \ No newline at end of file +} diff --git a/mayfly_go_web/src/common/config.ts b/mayfly_go_web/src/common/config.ts index deec4790..361623b3 100644 --- a/mayfly_go_web/src/common/config.ts +++ b/mayfly_go_web/src/common/config.ts @@ -11,7 +11,7 @@ const config = { baseWsUrl: `${(window as any).globalConfig.BaseWsUrl || `${location.protocol == 'https:' ? 'wss:' : 'ws:'}//${getBaseApiUrl()}`}/api`, // 系统版本 - version: 'v1.4.4' -} + version: 'v1.4.4', +}; -export default config \ No newline at end of file +export default config; diff --git a/mayfly_go_web/src/common/echarts/useEcharts.ts b/mayfly_go_web/src/common/echarts/useEcharts.ts index 89b2f4f0..a02fb0cd 100644 --- a/mayfly_go_web/src/common/echarts/useEcharts.ts +++ b/mayfly_go_web/src/common/echarts/useEcharts.ts @@ -1,45 +1,38 @@ // import * as echarts from 'echarts' // 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。 -import * as echarts from "echarts/core"; - +import * as echarts from 'echarts/core'; + /** 图表后缀都为 Chart */ -import { PieChart } from "echarts/charts"; - +import { PieChart } from 'echarts/charts'; + // 引入提示框,标题,直角坐标系,数据集,内置数据转换器组件,组件后缀都为 Component -import { - TitleComponent, - TooltipComponent, - GridComponent, - DatasetComponent, - TransformComponent, - LegendComponent, -} from "echarts/components"; - +import { TitleComponent, TooltipComponent, GridComponent, DatasetComponent, TransformComponent, LegendComponent } from 'echarts/components'; + // 标签自动布局,全局过渡动画等特性 -import { LabelLayout, UniversalTransition } from "echarts/features"; - +import { LabelLayout, UniversalTransition } from 'echarts/features'; + // 引入 Canvas 渲染器,注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步 -import { CanvasRenderer } from "echarts/renderers"; - +import { CanvasRenderer } from 'echarts/renderers'; + // 注册必须的组件 echarts.use([ - TitleComponent, - TooltipComponent, - GridComponent, - DatasetComponent, - TransformComponent, - LegendComponent, -// BarChart, - LabelLayout, - UniversalTransition, - CanvasRenderer, -// LineChart, - PieChart, + TitleComponent, + TooltipComponent, + GridComponent, + DatasetComponent, + TransformComponent, + LegendComponent, + // BarChart, + LabelLayout, + UniversalTransition, + CanvasRenderer, + // LineChart, + PieChart, ]); -export default function(dom: any, theme: any = null, option: any) { +export default function (dom: any, theme: any = null, option: any) { let chart = echarts.init(dom, theme); chart.setOption(option); return chart; -} \ No newline at end of file +} diff --git a/mayfly_go_web/src/common/enums.ts b/mayfly_go_web/src/common/enums.ts index 32c6c766..fa42f3cf 100644 --- a/mayfly_go_web/src/common/enums.ts +++ b/mayfly_go_web/src/common/enums.ts @@ -1,27 +1,7 @@ -interface BaseEnum { - name: string - value: any -} - -const success: BaseEnum = { - name: 'success', - value: 200 -} - export enum ResultEnum { SUCCESS = 200, ERROR = 400, PARAM_ERROR = 405, SERVER_ERROR = 500, - NO_PERMISSION = 501 + NO_PERMISSION = 501, } -// /** -// * 全局公共枚举类 -// */ -// export default { -// // uri请求方法 -// requestMethod: new Enum().add('GET', 'GET', 1).add('POST', 'POST', 2).add('PUT', 'PUT', 3).add('DELETE', 'DELETE', 4), -// // 结果枚举 -// ResultEnum: new Enum().add('SUCCESS', '操作成功', 200).add('ERROR', '操作失败', 400).add('PARAM_ERROR', '参数错误', 405).add('SERVER_ERROR', '服务器异常', 500) -// .add('NO_PERMISSION', '没有权限', 501) -// } \ No newline at end of file diff --git a/mayfly_go_web/src/common/openApi.ts b/mayfly_go_web/src/common/openApi.ts index 44694164..d7404881 100644 --- a/mayfly_go_web/src/common/openApi.ts +++ b/mayfly_go_web/src/common/openApi.ts @@ -1,12 +1,12 @@ -import Api from './Api' +import request from './request'; export default { - login: Api.newPost("/sys/accounts/login"), - otpVerify: Api.newPost("/sys/accounts/otp-verify"), - changePwd: Api.newPost("/sys/accounts/change-pwd"), - getPublicKey: Api.newGet("/common/public-key"), - getConfigValue: Api.newGet("/sys/configs/value"), - captcha: Api.newGet("/sys/captcha"), - logout: Api.newPost("/sys/accounts/logout/{token}"), - getPermissions: Api.newGet("/sys/accounts/permissions") -} \ No newline at end of file + login: (param: any) => request.post('/sys/accounts/login', param), + otpVerify: (param: any) => request.post('/sys/accounts/otp-verify', param), + changePwd: (param: any) => request.post('/sys/accounts/change-pwd', param), + getPublicKey: () => request.get('/common/public-key'), + getConfigValue: (params: any) => request.get('/sys/configs/value', params), + captcha: () => request.get('/sys/captcha'), + logout: () => request.post('/sys/accounts/logout/{token}'), + getPermissions: () => request.get('/sys/accounts/permissions'), +}; diff --git a/mayfly_go_web/src/common/request.ts b/mayfly_go_web/src/common/request.ts index a0ae7aad..b125fa88 100755 --- a/mayfly_go_web/src/common/request.ts +++ b/mayfly_go_web/src/common/request.ts @@ -1,7 +1,6 @@ -import router from "../router"; +import router from '../router'; import Axios from 'axios'; -import { ResultEnum } from './enums' -import Api from './Api'; +import { ResultEnum } from './enums'; import config from './config'; import { getSession } from './utils/storage'; import { templateResolve } from './utils/string'; @@ -22,8 +21,8 @@ export interface Result { data?: any; } -const baseUrl: string = config.baseApiUrl -const baseWsUrl: string = config.baseWsUrl +const baseUrl: string = config.baseApiUrl; +const baseWsUrl: string = config.baseWsUrl; /** * 通知错误消息 @@ -37,28 +36,28 @@ function notifyErrorMsg(msg: string) { // create an axios instance const service = Axios.create({ baseURL: baseUrl, // url = base url + request url - timeout: 20000 // request timeout -}) + timeout: 20000, // request timeout +}); // request interceptor service.interceptors.request.use( (config: any) => { // do something before request is sent - const token = getSession("token") + const token = getSession('token'); if (token) { // 设置token - config.headers['Authorization'] = token + config.headers['Authorization'] = token; } - return config + return config; }, - error => { - return Promise.reject(error) + (error) => { + return Promise.reject(error); } -) +); // response interceptor service.interceptors.response.use( - response => { + (response) => { // 获取请求返回结果 const data: Result = response.data; // 如果提示没有权限,则移除token,使其重新登录 @@ -88,32 +87,31 @@ service.interceptors.response.use( } } - return Promise.reject(e) + return Promise.reject(e); } -) +); /** * 请求uri * 该方法已处理请求结果中code != 200的message提示,如需其他错误处理(取消加载状态,重置对象状态等等),可catch继续处理 - * + * * @param {Object} method 请求方法(GET,POST,PUT,DELTE等) * @param {Object} uri uri * @param {Object} params 参数 */ function request(method: string, url: string, params: any = null, headers: any = null, options: any = null): Promise { - if (!url) - throw new Error('请求url不能为空'); + if (!url) throw new Error('请求url不能为空'); // 简单判断该url是否是restful风格 - if (url.indexOf("{") != -1) { + if (url.indexOf('{') != -1) { url = templateResolve(url, params); } const query: any = { method, url: url, - ...options + ...options, }; if (headers) { - query.headers = headers + query.headers = headers; } // post和put使用json格式传参 @@ -122,32 +120,39 @@ function request(method: string, url: string, params: any = null, headers: any = } else { query.params = params; } - return service.request(query).then(res => res) - .catch(e => { + return service + .request(query) + .then((res) => res) + .catch((e) => { // 如果返回的code不为成功,则会返回对应的错误msg,则直接统一通知即可 if (e.msg) { - notifyErrorMsg(e.msg) + notifyErrorMsg(e.msg); } return Promise.reject(e); }); } /** - * 根据api执行对应接口 - * @param api Api实例 - * @param params 请求参数 + * get请求uri + * 该方法已处理请求结果中code != 200的message提示,如需其他错误处理(取消加载状态,重置对象状态等等),可catch继续处理 + * + * @param {Object} url uri + * @param {Object} params 参数 */ -function send(api: Api, params: any, options: any): Promise { - return request(api.method, api.url, params, null, options); +function get(url: string, params: any = null, headers: any = null, options: any = null): Promise { + return request('get', url, params, headers, options); } -/** - * 根据api执行对应接口 - * @param api Api实例 - * @param params 请求参数 - */ -function sendWithHeaders(api: Api, params: any, headers: any): Promise { - return request(api.method, api.url, params, headers, null); +function post(url: string, params: any = null, headers: any = null, options: any = null): Promise { + return request('post', url, params, headers, options); +} + +function put(url: string, params: any = null, headers: any = null, options: any = null): Promise { + return request('put', url, params, headers, options); +} + +function del(url: string, params: any = null, headers: any = null, options: any = null): Promise { + return request('delete', url, params, headers, options); } function getApiUrl(url: string) { @@ -155,10 +160,11 @@ function getApiUrl(url: string) { return baseUrl + url + '?token=' + getSession('token'); } - export default { request, - send, - sendWithHeaders, - getApiUrl -} + get, + post, + put, + del, + getApiUrl, +}; diff --git a/mayfly_go_web/src/common/rsa.ts b/mayfly_go_web/src/common/rsa.ts index 691435df..ef5b2a51 100644 --- a/mayfly_go_web/src/common/rsa.ts +++ b/mayfly_go_web/src/common/rsa.ts @@ -1,36 +1,36 @@ import openApi from './openApi'; -import JSEncrypt from 'jsencrypt' +import JSEncrypt from 'jsencrypt'; import { notBlank } from './assert'; -var encryptor: any = null +var encryptor: any = null; export async function getRsaPublicKey() { - let publicKey = sessionStorage.getItem('RsaPublicKey') + let publicKey = sessionStorage.getItem('RsaPublicKey'); if (publicKey) { - return publicKey + return publicKey; } - publicKey = await openApi.getPublicKey.request() as string - sessionStorage.setItem('RsaPublicKey', publicKey) - return publicKey + publicKey = (await openApi.getPublicKey()) as string; + sessionStorage.setItem('RsaPublicKey', publicKey); + return publicKey; } /** * 公钥加密指定值 - * + * * @param value value * @returns 加密后的值 */ export async function RsaEncrypt(value: any) { // 不存在则返回空值 if (!value) { - return "" + return ''; } if (encryptor != null) { - return encryptor.encrypt(value) + return encryptor.encrypt(value); } - encryptor = new JSEncrypt() - const publicKey = await getRsaPublicKey() as string; - notBlank(publicKey, "获取公钥失败") - encryptor.setPublicKey(publicKey)//设置公钥 - return encryptor.encrypt(value) -} \ No newline at end of file + encryptor = new JSEncrypt(); + const publicKey = (await getRsaPublicKey()) as string; + notBlank(publicKey, '获取公钥失败'); + encryptor.setPublicKey(publicKey); //设置公钥 + return encryptor.encrypt(value); +} diff --git a/mayfly_go_web/src/common/sockets.ts b/mayfly_go_web/src/common/sockets.ts index c5ab840f..171360f5 100644 --- a/mayfly_go_web/src/common/sockets.ts +++ b/mayfly_go_web/src/common/sockets.ts @@ -1,8 +1,7 @@ - -import Config from './config' -import { ElNotification } from 'element-plus' +import Config from './config'; +import { ElNotification } from 'element-plus'; import SocketBuilder from './SocketBuilder'; -import { getSession } from '@/common/utils/storage.ts'; +import { getSession } from '@/common/utils/storage'; export default { /** @@ -38,8 +37,9 @@ export default { title: message.title, message: message.msg, type: mtype as any, - }) + }); }) - .open((event: any) => console.log(event)).build(); - } -} + .open((event: any) => console.log(event)) + .build(); + }, +}; diff --git a/mayfly_go_web/src/common/sysconfig.ts b/mayfly_go_web/src/common/sysconfig.ts index 1891b352..8feacddc 100644 --- a/mayfly_go_web/src/common/sysconfig.ts +++ b/mayfly_go_web/src/common/sysconfig.ts @@ -1,38 +1,38 @@ import openApi from './openApi'; // 登录是否使用验证码配置key -const AccountLoginSecurity = "AccountLoginSecurity" -const UseLoginCaptchaConfigKey = "UseLoginCaptcha" -const UseWartermarkConfigKey = "UseWartermark" +const AccountLoginSecurity = 'AccountLoginSecurity'; +const UseLoginCaptchaConfigKey = 'UseLoginCaptcha'; +const UseWartermarkConfigKey = 'UseWartermark'; /** * 获取系统配置值 - * + * * @param key 配置key * @returns 配置值 */ -export async function getConfigValue(key: string) : Promise { - return await openApi.getConfigValue.request({key}) as string +export async function getConfigValue(key: string): Promise { + return (await openApi.getConfigValue({ key })) as string; } /** * 获取bool类型系统配置值 - * + * * @param key 配置key * @param defaultValue 默认值 * @returns 是否为ture,1: true;其他: false */ -export async function getBoolConfigValue(key :string, defaultValue :boolean) : Promise { +export async function getBoolConfigValue(key: string, defaultValue: boolean): Promise { const value = await getConfigValue(key); return convertBool(value, defaultValue); } /** * 获取账号登录安全配置 - * - * @returns + * + * @returns */ -export async function getAccountLoginSecurity() : Promise { +export async function getAccountLoginSecurity(): Promise { const value = await getConfigValue(AccountLoginSecurity); if (!value) { return null; @@ -45,25 +45,25 @@ export async function getAccountLoginSecurity() : Promise { /** * 是否使用登录验证码 - * - * @returns + * + * @returns */ -export async function useLoginCaptcha() : Promise { - return await getBoolConfigValue(UseLoginCaptchaConfigKey, true) +export async function useLoginCaptcha(): Promise { + return await getBoolConfigValue(UseLoginCaptchaConfigKey, true); } /** * 是否启用水印 - * - * @returns + * + * @returns */ - export async function useWartermark() : Promise { - return await getBoolConfigValue(UseWartermarkConfigKey, true) +export async function useWartermark(): Promise { + return await getBoolConfigValue(UseWartermarkConfigKey, true); } function convertBool(value: string, defaultValue: boolean) { if (!value) { return defaultValue; } - return value == "1" || value == "true"; -} \ No newline at end of file + return value == '1' || value == 'true'; +} diff --git a/mayfly_go_web/src/common/utils/date.ts b/mayfly_go_web/src/common/utils/date.ts index 65dae102..684b3044 100644 --- a/mayfly_go_web/src/common/utils/date.ts +++ b/mayfly_go_web/src/common/utils/date.ts @@ -1,27 +1,27 @@ export function dateFormat2(fmt: string, date: Date) { let ret; const opt = { - "y+": date.getFullYear().toString(), // 年 - "M+": (date.getMonth() + 1).toString(), // 月 - "d+": date.getDate().toString(), // 日 - "H+": date.getHours().toString(), // 时 - "m+": date.getMinutes().toString(), // 分 - "s+": date.getSeconds().toString() // 秒 + 'y+': date.getFullYear().toString(), // 年 + 'M+': (date.getMonth() + 1).toString(), // 月 + 'd+': date.getDate().toString(), // 日 + 'H+': date.getHours().toString(), // 时 + 'm+': date.getMinutes().toString(), // 分 + 's+': date.getSeconds().toString(), // 秒 // 有其他格式化字符需求可以继续添加,必须转化成字符串 }; for (const k in opt) { - ret = new RegExp("(" + k + ")").exec(fmt); + ret = new RegExp('(' + k + ')').exec(fmt); if (ret) { - fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) + fmt = fmt.replace(ret[1], ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0')); } } return fmt; } export function dateStrFormat(fmt: string, dateStr: string) { - return dateFormat2(fmt, new Date(dateStr)) + return dateFormat2(fmt, new Date(dateStr)); } export function dateFormat(dateStr: string) { - return dateFormat2('yyyy-MM-dd HH:mm:ss',new Date(dateStr)) -} \ No newline at end of file + return dateFormat2('yyyy-MM-dd HH:mm:ss', new Date(dateStr)); +} diff --git a/mayfly_go_web/src/common/utils/export.ts b/mayfly_go_web/src/common/utils/export.ts index 9cbc05f7..c77c6ebc 100644 --- a/mayfly_go_web/src/common/utils/export.ts +++ b/mayfly_go_web/src/common/utils/export.ts @@ -7,11 +7,11 @@ export function exportCsv(filename: string, columns: string[], datas: []) { for (let column of columns) { let val: any = data[column]; if (typeof val == 'string' && val) { - // csv格式如果有逗号,整体用双引号括起来;如果里面还有双引号就替换成两个双引号,这样导出来的格式就不会有问题了 + // csv格式如果有逗号,整体用双引号括起来;如果里面还有双引号就替换成两个双引号,这样导出来的格式就不会有问题了 if (val.indexOf(',') != -1) { // 如果还有双引号,先将双引号转义,避免两边加了双引号后转义错误 if (val.indexOf('"') != -1) { - val = val.replace(/\"/g, "\"\""); + val = val.replace(/\"/g, '""'); } // 再将逗号转义 val = `"${val}"`; @@ -20,7 +20,6 @@ export function exportCsv(filename: string, columns: string[], datas: []) { } else { dataValueArr.push(val); } - } cvsData.push(dataValueArr); } @@ -36,4 +35,4 @@ export function exportCsv(filename: string, columns: string[], datas: []) { link.setAttribute('download', `${filename}.csv`); document.body.appendChild(link); link.click(); -} \ No newline at end of file +} diff --git a/mayfly_go_web/src/common/utils/format.ts b/mayfly_go_web/src/common/utils/format.ts index 430540b2..2cdbab3d 100644 --- a/mayfly_go_web/src/common/utils/format.ts +++ b/mayfly_go_web/src/common/utils/format.ts @@ -1,7 +1,7 @@ /** * 格式化字节单位 * @param size byte size - * @returns + * @returns */ export function formatByteSize(size: any) { const value = Number(size); @@ -116,8 +116,7 @@ export function formatDate(date: Date, format: string) { '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 (/(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); @@ -192,4 +191,4 @@ export function formatAxis(param: any) { 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/loading.ts b/mayfly_go_web/src/common/utils/loading.ts index 257ef3e8..e29a2d30 100644 --- a/mayfly_go_web/src/common/utils/loading.ts +++ b/mayfly_go_web/src/common/utils/loading.ts @@ -1,5 +1,5 @@ import { nextTick } from 'vue'; -import loadingCss from "@/theme/loading.scss?inline" +import loadingCss from '@/theme/loading.scss?inline'; // 定义方法 export const NextLoading = { diff --git a/mayfly_go_web/src/common/utils/mitt.ts b/mayfly_go_web/src/common/utils/mitt.ts index 2e44d1b9..fb76ef52 100644 --- a/mayfly_go_web/src/common/utils/mitt.ts +++ b/mayfly_go_web/src/common/utils/mitt.ts @@ -5,4 +5,4 @@ import mitt, { Emitter } from 'mitt'; const emitter: Emitter = mitt(); // 导出 -export default emitter; \ No newline at end of file +export default emitter; diff --git a/mayfly_go_web/src/common/utils/setIconfont.ts b/mayfly_go_web/src/common/utils/setIconfont.ts index b05fd51f..19339cf7 100644 --- a/mayfly_go_web/src/common/utils/setIconfont.ts +++ b/mayfly_go_web/src/common/utils/setIconfont.ts @@ -1,30 +1,28 @@ // 字体图标 url -const cssCdnUrlList: Array = [ - -]; +const cssCdnUrlList: Array = []; // 第三方 js url const jsCdnUrlList: Array = []; // 动态批量设置字体图标 export function setCssCdn() { - if (cssCdnUrlList.length <= 0) return false; - cssCdnUrlList.map((v) => { - let link = document.createElement('link'); - link.rel = 'stylesheet'; - link.href = v; - link.crossOrigin = 'anonymous'; - document.getElementsByTagName('head')[0].appendChild(link); - }); + if (cssCdnUrlList.length <= 0) return false; + cssCdnUrlList.map((v) => { + let link = document.createElement('link'); + link.rel = 'stylesheet'; + link.href = v; + link.crossOrigin = 'anonymous'; + document.getElementsByTagName('head')[0].appendChild(link); + }); } // 动态批量设置第三方js export function setJsCdn() { - if (jsCdnUrlList.length <= 0) return false; - jsCdnUrlList.map((v) => { - let link = document.createElement('script'); - link.src = v; - document.body.appendChild(link); - }); + if (jsCdnUrlList.length <= 0) return false; + jsCdnUrlList.map((v) => { + let link = document.createElement('script'); + link.src = v; + document.body.appendChild(link); + }); } /** @@ -33,15 +31,15 @@ export function setJsCdn() { * @method jsCdn 动态批量设置第三方js */ const setIntroduction = { - // 设置css - cssCdn: () => { - setCssCdn(); - }, - // 设置js - jsCdn: () => { - setJsCdn(); - }, + // 设置css + cssCdn: () => { + setCssCdn(); + }, + // 设置js + jsCdn: () => { + setJsCdn(); + }, }; // 导出函数方法 -export default setIntroduction; \ No newline at end of file +export default setIntroduction; diff --git a/mayfly_go_web/src/common/utils/storage.ts b/mayfly_go_web/src/common/utils/storage.ts index 6259e0c3..5ff91b4f 100644 --- a/mayfly_go_web/src/common/utils/storage.ts +++ b/mayfly_go_web/src/common/utils/storage.ts @@ -36,21 +36,19 @@ export function clearSession() { window.sessionStorage.clear(); } - - export function getUserInfo4Session() { - return getSession("userInfo") + return getSession('userInfo'); } export function setUserInfo2Session(userinfo: any) { - setSession("userInfo", userinfo) + setSession('userInfo', userinfo); } // 获取是否开启水印 export function getUseWatermark4Session() { - return getSession("useWatermark") + return getSession('useWatermark'); } export function setUseWatermark2Session(useWatermark: boolean) { - setSession("useWatermark", useWatermark) -} \ No newline at end of file + setSession('useWatermark', useWatermark); +} diff --git a/mayfly_go_web/src/common/utils/string.ts b/mayfly_go_web/src/common/utils/string.ts index 12d3e3db..b0405b25 100644 --- a/mayfly_go_web/src/common/utils/string.ts +++ b/mayfly_go_web/src/common/utils/string.ts @@ -3,7 +3,7 @@ * 解析后为 hahahahh_1 * @param template 模板字符串 * @param param 参数占位符 - * @returns + * @returns */ export function templateResolve(template: string, param: any) { return template.replace(/\{\w+\}/g, (word) => { @@ -12,7 +12,7 @@ export function templateResolve(template: string, param: any) { if (value != null || value != undefined) { return value; } - return ""; + return ''; }); } @@ -21,11 +21,34 @@ export function letterAvatar(name: string, size = 60, color = '') { name = name || ''; size = size || 60; var colours = [ - "#1abc9c", "#2ecc71", "#3498db", "#9b59b6", "#34495e", "#16a085", "#27ae60", "#2980b9", "#8e44ad", "#2c3e50", - "#f1c40f", "#e67e22", "#e74c3c", "#00bcd4", "#95a5a6", "#f39c12", "#d35400", "#c0392b", "#bdc3c7", "#7f8c8d" - ], + '#1abc9c', + '#2ecc71', + '#3498db', + '#9b59b6', + '#34495e', + '#16a085', + '#27ae60', + '#2980b9', + '#8e44ad', + '#2c3e50', + '#f1c40f', + '#e67e22', + '#e74c3c', + '#00bcd4', + '#95a5a6', + '#f39c12', + '#d35400', + '#c0392b', + '#bdc3c7', + '#7f8c8d', + ], nameSplit = String(name).split(' '), - initials, charIndex, colourIndex, canvas, context, dataURI; + initials, + charIndex, + colourIndex, + canvas, + context, + dataURI; if (nameSplit.length == 1) { initials = nameSplit[0] ? nameSplit[0].charAt(0) : '?'; @@ -33,26 +56,26 @@ export function letterAvatar(name: string, size = 60, color = '') { initials = nameSplit[0].charAt(0) + nameSplit[1].charAt(0); } if (window.devicePixelRatio) { - size = (size * window.devicePixelRatio); + size = size * window.devicePixelRatio; } - initials = initials.toLocaleUpperCase() + initials = initials.toLocaleUpperCase(); charIndex = (initials == '?' ? 72 : initials.charCodeAt(0)) - 64; colourIndex = charIndex % 20; canvas = document.createElement('canvas'); canvas.width = size; canvas.height = size; - context = canvas.getContext("2d") as any; + context = canvas.getContext('2d') as any; context.fillStyle = color ? color : colours[colourIndex - 1]; context.fillRect(0, 0, canvas.width, canvas.height); context.font = Math.round(canvas.width / 2) + "px 'Microsoft Yahei'"; - context.textAlign = "center"; - context.fillStyle = "#FFF"; + context.textAlign = 'center'; + context.fillStyle = '#FFF'; context.fillText(initials, size / 2, size / 1.5); dataURI = canvas.toDataURL(); canvas = null; return dataURI; -}; +} /** * 计算文本所占用的宽度(px) -> 该种方式较为准确 @@ -72,7 +95,7 @@ export function getTextWidth(str: string) { /** * 获取内容所需要占用的宽度 -*/ + */ export function getContentWidth(content: any): number { if (!content) { return 50; @@ -105,4 +128,4 @@ export function getContentWidth(content: any): number { // flexWidth = 450; // } return flexWidth; -}; \ No newline at end of file +} diff --git a/mayfly_go_web/src/common/utils/svgIcons.ts b/mayfly_go_web/src/common/utils/svgIcons.ts index e789a7c1..616b3021 100644 --- a/mayfly_go_web/src/common/utils/svgIcons.ts +++ b/mayfly_go_web/src/common/utils/svgIcons.ts @@ -1,6 +1,6 @@ import { nextTick } from 'vue'; import * as svg from '@element-plus/icons-vue'; -import iconfontJson from '@/assets/iconfont/iconfont.json' +import iconfontJson from '@/assets/iconfont/iconfont.json'; import SvgIcon from '@/components/svgIcon/index.vue'; /** @@ -52,21 +52,21 @@ const getLocalAliIconfont = () => { resolve(iconfontJson.glyphs.map((x: any) => prefix + x.font_class)); }); }); -} +}; // 初始化获取 css 样式,获取 element plus 自带图标 const elementPlusIconfont = () => { return new Promise((resolve, reject) => { - nextTick(() => { - const icons = svg as any; - const sheetsIconList = []; - for (const i in icons) { - sheetsIconList.push(`${icons[i].name}`); - } - if (sheetsIconList.length > 0) resolve(sheetsIconList); - else reject('未获取到值,请刷新重试'); - }); - }); + nextTick(() => { + const icons = svg as any; + const sheetsIconList = []; + for (const i in icons) { + sheetsIconList.push(`${icons[i].name}`); + } + if (sheetsIconList.length > 0) resolve(sheetsIconList); + else reject('未获取到值,请刷新重试'); + }); + }); }; // 初始化获取 css 样式,这里使用 fontawesome 的图标 @@ -103,7 +103,7 @@ const awesomeIconfont = () => { // 定义导出方法集合 const initIconfont = { ali: () => { - return getLocalAliIconfont(); + return getLocalAliIconfont(); }, ele: () => { return elementPlusIconfont(); diff --git a/mayfly_go_web/src/common/utils/toolsValidate.ts b/mayfly_go_web/src/common/utils/toolsValidate.ts index 58f1ea01..b0e26184 100644 --- a/mayfly_go_web/src/common/utils/toolsValidate.ts +++ b/mayfly_go_web/src/common/utils/toolsValidate.ts @@ -163,8 +163,7 @@ export function verifyPasswordStrength(val: string) { // 中:字母+数字,字母+特殊字符,数字+特殊字符 if (/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) v = '中'; // 强:字母+数字+特殊字符 - if (/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&\.*]+$)(?![\d!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) - v = '强'; + if (/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&\.*]+$)(?![\d!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*]{6,16}$/.test(val)) v = '强'; // 返回结果 return v; } @@ -172,11 +171,7 @@ export function verifyPasswordStrength(val: string) { // IP地址 export function verifyIPAddress(val: string) { // false: IP地址不正确 - if ( - !/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test( - val - ) - ) + if (!/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(val)) return false; // true: IP地址正确 else return true; diff --git a/mayfly_go_web/src/common/utils/wartermark.ts b/mayfly_go_web/src/common/utils/wartermark.ts index 1680fe99..e62bd40c 100644 --- a/mayfly_go_web/src/common/utils/wartermark.ts +++ b/mayfly_go_web/src/common/utils/wartermark.ts @@ -1,5 +1,5 @@ -import { getUseWatermark4Session, getUserInfo4Session } from '@/common/utils/storage.ts'; -import { dateFormat2 } from '@/common/utils/date.ts' +import { getUseWatermark4Session, getUserInfo4Session } from '@/common/utils/storage'; +import { dateFormat2 } from '@/common/utils/date'; // 页面添加水印效果 const setWatermark = (str: any) => { @@ -44,17 +44,17 @@ function del() { const watermark = { use: () => { setTimeout(() => { - const userinfo = getUserInfo4Session() + const userinfo = getUserInfo4Session(); if (userinfo && getUseWatermark4Session()) { - set(`${userinfo.username} ${dateFormat2('yyyy-MM-dd HH:mm:ss', new Date())}`) + set(`${userinfo.username} ${dateFormat2('yyyy-MM-dd HH:mm:ss', new Date())}`); } else { del(); } - }, 1500) + }, 1500); }, // 设置水印 set: (str: any) => { - set(str) + set(str); }, // 删除水印 del: () => { diff --git a/mayfly_go_web/src/components/auth/auth.ts b/mayfly_go_web/src/components/auth/auth.ts index 29001b39..30df92d4 100644 --- a/mayfly_go_web/src/components/auth/auth.ts +++ b/mayfly_go_web/src/components/auth/auth.ts @@ -3,7 +3,7 @@ import { useUserInfo } from '@/store/userInfo'; /** * 判断当前用户是否拥有指定权限 * @param code 权限code - * @returns + * @returns */ export function hasPerm(code: string) { return useUserInfo().userInfo.permissions.some((v: any) => v === code); @@ -22,4 +22,4 @@ export function hasPerms(permCodes: any[]) { } } return res; -} \ No newline at end of file +} diff --git a/mayfly_go_web/src/components/contextmenu/index.vue b/mayfly_go_web/src/components/contextmenu/index.vue index 90bc2393..a10fb226 100644 --- a/mayfly_go_web/src/components/contextmenu/index.vue +++ b/mayfly_go_web/src/components/contextmenu/index.vue @@ -1,12 +1,24 @@