From cac35ecf4c754174f08d5c4f957499cd6c77880f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Wed, 1 Apr 2026 13:05:03 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useDialog.ts | 2 +- src/store/modules/permission.ts | 9 +++++---- src/utils/crypto.ts | 22 ++++++++++------------ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/hooks/useDialog.ts b/src/hooks/useDialog.ts index 547f199..ba41051 100644 --- a/src/hooks/useDialog.ts +++ b/src/hooks/useDialog.ts @@ -11,7 +11,7 @@ interface Return { } export default (ops?: Options): Return => { const visible = ref(false); - const title = ref(ops.title || ''); + const title = ref(ops?.title || ''); const openDialog = () => { visible.value = true; diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts index 1169cc8..065e6b1 100644 --- a/src/store/modules/permission.ts +++ b/src/store/modules/permission.ts @@ -48,9 +48,10 @@ export const usePermissionStore = defineStore('permission', () => { const generateRoutes = async (): Promise => { const res = await getRouters(); const { data } = res; - const sdata = JSON.parse(JSON.stringify(data)); - const rdata = JSON.parse(JSON.stringify(data)); - const defaultData = JSON.parse(JSON.stringify(data)); + let text = JSON.stringify(data); + const sdata = JSON.parse(text); + const rdata = JSON.parse(text); + const defaultData = JSON.parse(text); const sidebarRoutes = filterAsyncRouter(sdata); const rewriteRoutes = filterAsyncRouter(rdata, undefined, true); const defaultRoutes = filterAsyncRouter(defaultData); @@ -191,7 +192,7 @@ function duplicateRouteChecker(localRoutes: Route[], routes: Route[]) { const nameList: string[] = []; allRoutes.forEach((route) => { - const name = route.name.toString(); + const name = route.name?.toString() ?? ''; if (name && nameList.includes(name)) { const message = `路由名称: [${name}] 重复, 会造成 404`; console.error(message); diff --git a/src/utils/crypto.ts b/src/utils/crypto.ts index 2f3aa6e..6dd0db9 100644 --- a/src/utils/crypto.ts +++ b/src/utils/crypto.ts @@ -6,21 +6,19 @@ const CryptoJS = ('default' in CryptoJSModule ? CryptoJSModule.default : CryptoJ * 随机生成32位的字符串 * @returns {string} */ -const generateRandomString = () => { - const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - let result = ''; - const charactersLength = characters.length; - for (let i = 0; i < 32; i++) { - result += characters.charAt(Math.floor(Math.random() * charactersLength)); - } - return result; +const generateRandomString = (): string => { + const array = new Uint8Array(32); + crypto.getRandomValues(array); + return Array.from(array, (b) => b.toString(16).padStart(2, '0')) + .join('') + .slice(0, 32); }; /** * 随机生成aes 密钥 * @returns {string} */ -export const generateAesKey = () => { +export const generateAesKey = (): CryptoJSModule.lib.WordArray => { return CryptoJS.enc.Utf8.parse(generateRandomString()); }; @@ -28,7 +26,7 @@ export const generateAesKey = () => { * 加密base64 * @returns {string} */ -export const encryptBase64 = (str: CryptoJSModule.lib.WordArray) => { +export const encryptBase64 = (str: CryptoJSModule.lib.WordArray): string => { return CryptoJS.enc.Base64.stringify(str); }; @@ -45,7 +43,7 @@ export const decryptBase64 = (str: string) => { * @param aesKey * @returns {string} */ -export const encryptWithAes = (message: string, aesKey: CryptoJSModule.lib.WordArray) => { +export const encryptWithAes = (message: string, aesKey: CryptoJSModule.lib.WordArray): string => { const encrypted = CryptoJS.AES.encrypt(message, aesKey, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 @@ -59,7 +57,7 @@ export const encryptWithAes = (message: string, aesKey: CryptoJSModule.lib.WordA * @param aesKey * @returns {string} */ -export const decryptWithAes = (message: string, aesKey: CryptoJSModule.lib.WordArray) => { +export const decryptWithAes = (message: string, aesKey: CryptoJSModule.lib.WordArray): string => { const decrypted = CryptoJS.AES.decrypt(message, aesKey, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7