From 237edb87d149115c7b60909cfde23e38ed42e79d Mon Sep 17 00:00:00 2001 From: aeizzz Date: Fri, 3 Mar 2023 16:58:51 +0800 Subject: [PATCH 1/4] =?UTF-8?q?:bug:=20Fixing=20a=20bug.=20tagsViewName?= =?UTF-8?q?=E6=AD=A3=E5=88=99=E5=8C=B9=E9=85=8D=E9=94=99=E8=AF=AF=EF=BC=8C?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=88=B0=E5=90=ABen=E5=8D=95=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/other.ts | 125 ++++++++++++++++++++++--------------------- src/utils/storage.ts | 28 +++++----- 2 files changed, 79 insertions(+), 74 deletions(-) diff --git a/src/utils/other.ts b/src/utils/other.ts index 71770548..d27db5c5 100644 --- a/src/utils/other.ts +++ b/src/utils/other.ts @@ -8,10 +8,10 @@ import { useThemeConfig } from '/@/stores/themeConfig'; import { i18n } from '/@/i18n/index'; import { Local } from '/@/utils/storage'; import { verifyUrl } from '/@/utils/toolsValidate'; -import request from "/@/utils/request"; -import { useMessage } from "/@/hooks/message"; +import request from '/@/utils/request'; +import { useMessage } from '/@/hooks/message'; // @ts-ignore -import * as CryptoJS from "crypto-js"; +import * as CryptoJS from 'crypto-js'; // 引入组件 const SvgIcon = defineAsyncComponent(() => import('/@/components/svgIcon/index.vue')); @@ -57,8 +57,10 @@ export function useTitle() { export function setTagsViewNameI18n(item: any) { let tagsViewName: string = ''; const { query, params, meta } = item; + //修复tagsViewName匹配到其他含下列单词的路由 + const pattern = /^\{("(zh-cn|en|zh-tw)":"[^,]+",?){1,3}}$/; if (query?.tagsViewName || params?.tagsViewName) { - if (/\/zh-cn|en|zh-tw\//.test(query?.tagsViewName) || /\/zh-cn|en|zh-tw\//.test(params?.tagsViewName)) { + if (pattern.test(query?.tagsViewName) || pattern.test(params?.tagsViewName)) { // 国际化 const urlTagsParams = (query?.tagsViewName && JSON.parse(query?.tagsViewName)) || (params?.tagsViewName && JSON.parse(params?.tagsViewName)); tagsViewName = urlTagsParams[i18n.global.locale.value]; @@ -180,35 +182,29 @@ export function handleOpenLink(val: RouteItem) { */ export const openWindow = (url: string, title: string, w: number, h: number) => { // Fixes dual-screen position Most browsers Firefox - const dualScreenLeft = - window.screenLeft !== undefined ? window.screenLeft : screen.left; - const dualScreenTop = - window.screenTop !== undefined ? window.screenTop : screen.top; + const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left; + const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top; - const width = window.innerWidth - ? window.innerWidth - : document.documentElement.clientWidth - ? document.documentElement.clientWidth - : screen.width; + const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight - ? document.documentElement.clientHeight - : screen.height; + ? document.documentElement.clientHeight + : screen.height; const left = width / 2 - w / 2 + dualScreenLeft; const top = height / 2 - h / 2 + dualScreenTop; return window.open( url, title, - "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=" + - w + - ", height=" + - h + - ", top=" + - top + - ", left=" + - left + 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=' + + w + + ', height=' + + h + + ', top=' + + top + + ', left=' + + left ); }; /** @@ -217,7 +213,7 @@ export const openWindow = (url: string, title: string, w: number, h: number) => export function encryption(params: any) { let { data, type, param, key } = params; const result = JSON.parse(JSON.stringify(data)); - if (type === "Base64") { + if (type === 'Base64') { param.forEach((ele: any) => { result[ele] = btoa(result[ele]); }); @@ -230,7 +226,7 @@ export function encryption(params: any) { var encrypted = CryptoJS.AES.encrypt(data, key, { iv: iv, mode: CryptoJS.mode.CFB, - padding: CryptoJS.pad.NoPadding + padding: CryptoJS.pad.NoPadding, }); result[ele] = encrypted.toString(); }); @@ -248,27 +244,27 @@ export function encryption(params: any) { export function downBlobFile(url: any, query: any, fileName: string) { return request({ url: url, - method: "get", - responseType: "blob", - params: query - }).then(response => { - handleBlobFile(response, fileName) + method: 'get', + responseType: 'blob', + params: query, + }).then((response) => { + handleBlobFile(response, fileName); }); } /** * blob 文件刘处理 - * @param response 响应结果 - * @returns + * @param response 响应结果 + * @returns */ export function handleBlobFile(response: any, fileName: string) { // 处理返回的文件流 const blob = response; if (blob && blob.size === 0) { - useMessage().error("内容为空,无法下载"); + useMessage().error('内容为空,无法下载'); return; } - const link = document.createElement("a"); + const link = document.createElement('a'); // 兼容一下 入参不是 File Blob 类型情况 var binaryData = [] as any; @@ -325,37 +321,37 @@ const other = { handleOpenLink(val); }, encryption: (data: any) => { - return encryption(data) + return encryption(data); }, downBlobFile: (url: any, query: any, fileName: string) => { - return downBlobFile(url, query, fileName) + return downBlobFile(url, query, fileName); }, toUnderline: (str: string) => { - return toUnderline(str) + return toUnderline(str); }, openWindow: (url: string, title: string, w: number, h: number) => { - return openWindow(url, title, w, h) + return openWindow(url, title, w, h); }, getQueryString: (url: string, paraName: string) => { - return getQueryString(url, paraName) - } + return getQueryString(url, paraName); + }, }; export function getQueryString(url: string, paraName: string) { - const arrObj = url.split("?"); + const arrObj = url.split('?'); if (arrObj.length > 1) { - const arrPara = arrObj[1].split("&"); + const arrPara = arrObj[1].split('&'); let arr; for (let i = 0; i < arrPara.length; i++) { - arr = arrPara[i].split("="); + arr = arrPara[i].split('='); // eslint-disable-next-line eqeqeq if (arr != null && arr[0] == paraName) { return arr[1]; } } - return ""; + return ''; } else { - return ""; + return ''; } } @@ -369,25 +365,31 @@ export function getQueryString(url: string, paraName: string) { * @returns {*} */ export function handleTree(data, id, parentId, children, rootId) { - id = id || 'id' - parentId = parentId || 'parentId' - children = children || 'children' - rootId = rootId || Math.min.apply(Math, data.map(item => { - return item[parentId] - })) || 0 + id = id || 'id'; + parentId = parentId || 'parentId'; + children = children || 'children'; + rootId = + rootId || + Math.min.apply( + Math, + data.map((item) => { + return item[parentId]; + }) + ) || + 0; //对源数据深度克隆 - const cloneData = JSON.parse(JSON.stringify(data)) + const cloneData = JSON.parse(JSON.stringify(data)); //循环所有项 - const treeData = cloneData.filter(father => { - const branchArr = cloneData.filter(child => { + const treeData = cloneData.filter((father) => { + const branchArr = cloneData.filter((child) => { //返回每一项的子级数组 - return father[id] === child[parentId] - }) - branchArr.length > 0 ? father[children] = branchArr : '' + return father[id] === child[parentId]; + }); + branchArr.length > 0 ? (father[children] = branchArr) : ''; //返回第一层 - return father[parentId] === rootId - }) - return treeData !== '' ? treeData : data + return father[parentId] === rootId; + }); + return treeData !== '' ? treeData : data; } /** @@ -396,9 +398,8 @@ export function handleTree(data, id, parentId, children, rootId) { * @returns 下划线 */ export function toUnderline(str: string) { - return str.replace(/([A-Z])/g, "_$1").toLowerCase() + return str.replace(/([A-Z])/g, '_$1').toLowerCase(); } - // 统一批量导出 export default other; diff --git a/src/utils/storage.ts b/src/utils/storage.ts index a5760d9c..09213b4e 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -8,18 +8,23 @@ import Cookies from 'js-cookie'; * @method clear 移除全部永久缓存 */ export const Local = { + // 查看 v2.4.3版本更新日志 + setKey(key: string) { + // @ts-ignore + return `${__NEXT_NAME__}:${key}`; + }, // 设置永久缓存 - set(key: string, val: any) { - window.localStorage.setItem(key, JSON.stringify(val)); + set(key: string, val: T) { + window.localStorage.setItem(Local.setKey(key), JSON.stringify(val)); }, // 获取永久缓存 get(key: string) { - let json = window.localStorage.getItem(key); + let json = window.localStorage.getItem(Local.setKey(key)); return JSON.parse(json); }, // 移除永久缓存 remove(key: string) { - window.localStorage.removeItem(key); + window.localStorage.removeItem(Local.setKey(key)); }, // 移除全部永久缓存 clear() { @@ -36,25 +41,24 @@ export const Local = { */ export const Session = { // 设置临时缓存 - set(key: string, val: any) { - if (key === 'token' || key === 'refresh_token') return Cookies.set(key, val); - window.sessionStorage.setItem(key, JSON.stringify(val)); + set(key: string, val: T) { + if (key === 'token') return Cookies.set(key, val); + window.sessionStorage.setItem(Local.setKey(key), JSON.stringify(val)); }, // 获取临时缓存 get(key: string) { - if (key === 'token' || key === 'refresh_token') return Cookies.get(key); - let json = window.sessionStorage.getItem(key); + if (key === 'token') return Cookies.get(key); + let json = window.sessionStorage.getItem(Local.setKey(key)); return JSON.parse(json); }, // 移除临时缓存 remove(key: string) { - if (key === 'token' || key === 'refresh_token') return Cookies.remove(key); - window.sessionStorage.removeItem(key); + if (key === 'token') return Cookies.remove(key); + window.sessionStorage.removeItem(Local.setKey(key)); }, // 移除全部临时缓存 clear() { Cookies.remove('token'); - Cookies.remove('refresh_token'); window.sessionStorage.clear(); }, }; From 0ca34f6b57682ccf337d98d1d89b210a1f8189cc Mon Sep 17 00:00:00 2001 From: aeizzz Date: Fri, 3 Mar 2023 17:12:53 +0800 Subject: [PATCH 2/4] =?UTF-8?q?:bug:=20Fixing=20a=20bug.=20tagsViewName=20?= =?UTF-8?q?=E6=AD=A3=E5=88=99=E5=8C=B9=E9=85=8D=E9=94=99=E8=AF=AF=EF=BC=8C?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=88=B0=E5=90=ABen=E5=8D=95=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 28 ++++++++++++++-------------- src/App.vue | 11 ++++++++++- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 06d2115e..98043212 100644 --- a/package.json +++ b/package.json @@ -15,21 +15,21 @@ "@highlightjs/vue-plugin": "^2.1.0", "@wangeditor/editor": "^5.1.23", "@wangeditor/editor-for-vue": "^5.1.12", - "axios": "^1.2.1", + "axios": "^1.3.3", "crypto-js": "^3.1.9-1", "echarts": "^5.4.1", - "element-plus": "^2.2.26", + "element-plus": "^2.2.32", "form-designer": "^0.0.2", "highlight.js": "^11.7.0", "js-cookie": "^3.0.1", "mitt": "^3.0.0", "nprogress": "^0.2.0", - "pinia": "^2.0.28", + "pinia": "^2.0.32", "qrcode": "1.5.1", "qs": "^6.11.0", "screenfull": "^6.0.2", "sortablejs": "^1.15.0", - "vue": "3.2.47", + "vue": "^3.2.47", "vue-clipboard3": "^2.0.0", "vue-i18n": "^9.2.2", "vue-router": "^4.1.6", @@ -37,22 +37,22 @@ "xe-utils": "^3.5.4" }, "devDependencies": { - "@types/node": "^18.11.13", + "@types/node": "^18.14.0", "@types/nprogress": "^0.2.0", "@types/sortablejs": "^1.15.0", - "@typescript-eslint/eslint-plugin": "^5.46.0", - "@typescript-eslint/parser": "^5.46.0", + "@typescript-eslint/eslint-plugin": "^5.53.0", + "@typescript-eslint/parser": "^5.53.0", "@vitejs/plugin-vue": "^4.0.0", - "@vue/compiler-sfc": "^3.2.45", + "@vue/compiler-sfc": "^3.2.47", "consola": "^2.15.3", - "eslint": "8.22.0", - "eslint-plugin-vue": "^9.8.0", + "eslint": "^8.34.0", + "eslint-plugin-vue": "^9.9.0", "pinia-plugin-persist": "^1.0.0", - "prettier": "^2.8.1", - "sass": "^1.56.2", - "typescript": "^4.9.4", + "prettier": "^2.8.4", + "sass": "^1.58.3", + "typescript": "^4.9.5", "unplugin-auto-import": "^0.13.0", - "vite": "^4.0.0", + "vite": "^4.1.4", "vite-plugin-compression": "^0.5.1", "vite-plugin-style-import": "^2.0.0", "vite-plugin-top-level-await": "^1.2.4", diff --git a/src/App.vue b/src/App.vue index 1d4cfc9b..9b640279 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,6 @@