import { TokenKey, RefreshToken, UsernameKey, SuccessRedirect, FailRedirect, customerIdKey, nameKey } from './status.config.js'; const SetStorage = (key) => (value) => uni.setStorageSync(key, value); export const setToken = SetStorage(TokenKey); export const setRefreshToken = SetStorage(RefreshToken); export const setUsernameKey = SetStorage(UsernameKey); export const setCustomerId = SetStorage(customerIdKey); export const setName = SetStorage(nameKey) export const redirectHome = (path) => { uni.switchTab({ url: path || SuccessRedirect }) } export const redirectLogin = (path) => { uni.clearStorageSync(); uni.reLaunch({ url: path || FailRedirect }) } // 获取用户状态 export const getStatesOne = (key) => uni.getStorageSync(key); function getStatus(name){ let status; if(name){ status = uni.getStorageSync(name); } else { status = uni.getStorageSync('userInfo'); } return status; } const customerId = getStatus('customerId') const roleType = getStatus('roleType'); const userInfo = getStatus('userInfo'); export { customerId, roleType, userInfo }