初始化

This commit is contained in:
hezhidong
2025-03-28 09:19:45 +08:00
parent a920f6f06a
commit 91514490ea
25 changed files with 7952 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
import { encryptDes , decryptDes } from "./cryptoJs.js" //des加密 解密
export default {
/*设置本地缓存 返回加密后的值*/
setCacheToken(key, value){
//转为json字符串
var info = JSON.stringify(value);
try {
uni.setStorageSync(key, encryptDes(info,key))
return {info:"保存成功", status:1}
} catch (error) {
return {info:error, status:0}
}
},
/*获取本地缓存 返回解密后的值*/
getCacheToken(key){
var info = decryptDes(uni.getStorageSync(key),key)
//json字符串长度
if(Object.keys(info).length > 1){
//json转为对象数组
return JSON.parse(info)
}
return info
},
/**
* 是否登录
* @param {bool} isToNav 是否跳转
*/
isLogin(isToNav){
isToNav = isToNav || false
//用户信息
const userInfo = this.getCacheToken("userInfo")
//如果未登录, 跳转到登录
if(!userInfo){
uni.showToast({ title: "请登陆后操作", icon: "none" });
if(isToNav){
setTimeout(()=>{uni.reLaunch({ url: "/pages/user/user" })}, 1000)
}
return false
}
return true
}
}
+25
View File
@@ -0,0 +1,25 @@
//import CryptoJS from '@/../node_modules/crypto-js/crypto-js.js'
import CryptoJS from "./js/crypto-js.js";
// DES加密
export const encryptDes = (message, key) => {
const keyHex = CryptoJS.enc.Utf8.parse(key);
const encrypted = CryptoJS.DES.encrypt(message, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
// DES解密
export const decryptDes = (ciphertext, key) => {
const keyHex = CryptoJS.enc.Utf8.parse(key);
// direct decrypt ciphertext
const decrypted = CryptoJS.DES.decrypt({
ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
}, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return decrypted.toString(CryptoJS.enc.Utf8);
}
File diff suppressed because it is too large Load Diff