update 优化 代码小问题
This commit is contained in:
@@ -11,7 +11,7 @@ interface Return {
|
|||||||
}
|
}
|
||||||
export default (ops?: Options): Return => {
|
export default (ops?: Options): Return => {
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
const title = ref(ops.title || '');
|
const title = ref(ops?.title || '');
|
||||||
|
|
||||||
const openDialog = () => {
|
const openDialog = () => {
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
|
|||||||
@@ -48,9 +48,10 @@ export const usePermissionStore = defineStore('permission', () => {
|
|||||||
const generateRoutes = async (): Promise<RouteRecordRaw[]> => {
|
const generateRoutes = async (): Promise<RouteRecordRaw[]> => {
|
||||||
const res = await getRouters();
|
const res = await getRouters();
|
||||||
const { data } = res;
|
const { data } = res;
|
||||||
const sdata = JSON.parse(JSON.stringify(data));
|
let text = JSON.stringify(data);
|
||||||
const rdata = JSON.parse(JSON.stringify(data));
|
const sdata = JSON.parse(text);
|
||||||
const defaultData = JSON.parse(JSON.stringify(data));
|
const rdata = JSON.parse(text);
|
||||||
|
const defaultData = JSON.parse(text);
|
||||||
const sidebarRoutes = filterAsyncRouter(sdata);
|
const sidebarRoutes = filterAsyncRouter(sdata);
|
||||||
const rewriteRoutes = filterAsyncRouter(rdata, undefined, true);
|
const rewriteRoutes = filterAsyncRouter(rdata, undefined, true);
|
||||||
const defaultRoutes = filterAsyncRouter(defaultData);
|
const defaultRoutes = filterAsyncRouter(defaultData);
|
||||||
@@ -191,7 +192,7 @@ function duplicateRouteChecker(localRoutes: Route[], routes: Route[]) {
|
|||||||
|
|
||||||
const nameList: string[] = [];
|
const nameList: string[] = [];
|
||||||
allRoutes.forEach((route) => {
|
allRoutes.forEach((route) => {
|
||||||
const name = route.name.toString();
|
const name = route.name?.toString() ?? '';
|
||||||
if (name && nameList.includes(name)) {
|
if (name && nameList.includes(name)) {
|
||||||
const message = `路由名称: [${name}] 重复, 会造成 404`;
|
const message = `路由名称: [${name}] 重复, 会造成 404`;
|
||||||
console.error(message);
|
console.error(message);
|
||||||
|
|||||||
+10
-12
@@ -6,21 +6,19 @@ const CryptoJS = ('default' in CryptoJSModule ? CryptoJSModule.default : CryptoJ
|
|||||||
* 随机生成32位的字符串
|
* 随机生成32位的字符串
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
const generateRandomString = () => {
|
const generateRandomString = (): string => {
|
||||||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
const array = new Uint8Array(32);
|
||||||
let result = '';
|
crypto.getRandomValues(array);
|
||||||
const charactersLength = characters.length;
|
return Array.from(array, (b) => b.toString(16).padStart(2, '0'))
|
||||||
for (let i = 0; i < 32; i++) {
|
.join('')
|
||||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
.slice(0, 32);
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 随机生成aes 密钥
|
* 随机生成aes 密钥
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export const generateAesKey = () => {
|
export const generateAesKey = (): CryptoJSModule.lib.WordArray => {
|
||||||
return CryptoJS.enc.Utf8.parse(generateRandomString());
|
return CryptoJS.enc.Utf8.parse(generateRandomString());
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -28,7 +26,7 @@ export const generateAesKey = () => {
|
|||||||
* 加密base64
|
* 加密base64
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export const encryptBase64 = (str: CryptoJSModule.lib.WordArray) => {
|
export const encryptBase64 = (str: CryptoJSModule.lib.WordArray): string => {
|
||||||
return CryptoJS.enc.Base64.stringify(str);
|
return CryptoJS.enc.Base64.stringify(str);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -45,7 +43,7 @@ export const decryptBase64 = (str: string) => {
|
|||||||
* @param aesKey
|
* @param aesKey
|
||||||
* @returns {string}
|
* @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, {
|
const encrypted = CryptoJS.AES.encrypt(message, aesKey, {
|
||||||
mode: CryptoJS.mode.ECB,
|
mode: CryptoJS.mode.ECB,
|
||||||
padding: CryptoJS.pad.Pkcs7
|
padding: CryptoJS.pad.Pkcs7
|
||||||
@@ -59,7 +57,7 @@ export const encryptWithAes = (message: string, aesKey: CryptoJSModule.lib.WordA
|
|||||||
* @param aesKey
|
* @param aesKey
|
||||||
* @returns {string}
|
* @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, {
|
const decrypted = CryptoJS.AES.decrypt(message, aesKey, {
|
||||||
mode: CryptoJS.mode.ECB,
|
mode: CryptoJS.mode.ECB,
|
||||||
padding: CryptoJS.pad.Pkcs7
|
padding: CryptoJS.pad.Pkcs7
|
||||||
|
|||||||
Reference in New Issue
Block a user