update 优化 代码小问题
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -48,9 +48,10 @@ export const usePermissionStore = defineStore('permission', () => {
|
||||
const generateRoutes = async (): Promise<RouteRecordRaw[]> => {
|
||||
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);
|
||||
|
||||
+10
-12
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user