lanan-repair-app/utils/auth.js
2024-10-16 17:14:49 +08:00

45 lines
1002 B
JavaScript

const TokenKey = 'App-Token'
const UserInfo = 'customerInfo'
const TenantIdKey = 'TENANT_ID'
export function getToken() {
return uni.getStorageSync(TokenKey)
}
export function setToken(token) {
return uni.setStorageSync(TokenKey, token)
}
export function removeToken() {
return uni.removeStorageSync(TokenKey)
}
export function setTenantId(TenantId) {
return uni.setStorageSync(TenantIdKey, TenantId);
}
export function getTenantId(){
return uni.getStorageSync(TenantIdKey)
}
export function hasRole(roleCode) {
const roleList = uni.getStorageSync('role')
if (roleList && roleList.length > 0) {
const roleInfo = roleList.find(f => f.code === roleCode)
if (roleInfo) {
return true
}
}
return false
}
export function getUserInfo() {
if(uni.getStorageSync(UserInfo)){
return JSON.parse(uni.getStorageSync(UserInfo))
}else{
return undefined;
}
}
export function setUserInfo(dataObj) {
return uni.setStorageSync(UserInfo, JSON.stringify(dataObj))
}