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 } }