You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

66 lines
1.3 KiB

/**
* auth管理
* author zhangwei
*/
import {
Base64
} from "js-base64/base64"
const USER_TOKEN = 'USER_TOKEN'
const USER_INFO = 'USER_INFO'
const APP_SETTING = 'APP_SETTING'
/**
* 设置用户授权token
* @param {String} token
*/
export function setToken(token) {
return uni.setStorageSync(USER_TOKEN, token)
}
/**
* 获取授权token
*/
export function getToken() {
return uni.getStorageSync(USER_TOKEN) || ''
}
/**
* 设置用户信息
*/
export function setUserInfo(data) {
uni.setStorageSync(USER_INFO, Base64.encode(JSON.stringify(data)))
}
/**
* 获取用户信息
*/
export function getUserInfo() {
const data = Base64.decode(uni.getStorageSync(USER_INFO) || '')
return data ? JSON.parse(data) : {}
}
/**
* 删除用户相关缓存信息
*/
export function removeAll() {
uni.clearStorageSync()
uni.removeStorage(USER_TOKEN)
uni.removeStorageSync(USER_INFO)
}
/**
* 获取用户本地缓存的设置信息
*/
export function getAppSetting() {
const data = uni.getStorageSync(APP_SETTING)
return data ? JSON.parse(data) : {}
}
/**
* 用户设置保存到浏览器缓存中
* @param {Object} state 用户设置相关信息
*/
export function setAppSetting(state) {
uni.setStorageSync(APP_SETTING, JSON.stringify(state))
}