This commit is contained in:
zk
2023-12-18 18:34:19 +08:00
parent 2cc8886c2d
commit 580a4fc5c6
50 changed files with 2343 additions and 223 deletions
+18
View File
@@ -0,0 +1,18 @@
import { isJSON } from '/@/utils/is.ts';
export function getAuthCache(key) {
let v = localStorage.getItem(key);
if (!isJSON(v)) {
return v;
} else {
return JSON.parse(v);
}
}
export function setAuthCache(key, value) {
if (!isJSON(value)) {
return localStorage.setItem(key, value);
} else {
return localStorage.setItem(key, JSON.stringify(value));
}
}
+9
View File
@@ -10,3 +10,12 @@ export const isString = (val: any) => typeof val === 'string';
export const isSymbol = (val: any) => typeof val === 'symbol';
export const isObject = (val: null) => val !== null && typeof val === 'object';
export const isPromise = (val: any) => isObject(val) && isFunction(val.then) && isFunction(val.catch);
export function isJSON(str) {
try {
JSON.parse(str);
return true;
} catch (e) {
return false;
}
}
+20
View File
@@ -0,0 +1,20 @@
import { JSEncrypt } from 'jsencrypt';
// 公钥
export const publicKey =
'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmZfR/bA9X3vp86y1aEpvwzXJYKRRF1fLau2+05/ZtaITLpV8bhkmSf3neSy/Q9gAdvG75Fr73E+GWE+K5b0BpvIS1jDGo319+PpZR39SaZTKZ27XFXrosmJTZutN79t819HS1VseleunHAFgMVufE9U5jP6LGzl/wbkSy01GhzwIDAQAB';
/**
* @Description:密码加密
* @date 2023/8/21
* @param password
*/
export function encipher(password): string | undefined {
if (password) {
// 新建JSEncrypt对象
const encryptor = new JSEncrypt();
// 设置公钥
encryptor.setPublicKey(publicKey);
// 加密数据
return encryptor.encrypt(password) as string;
}
}