lanan-repair/utils/auth.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-09-22 15:07:01 +08:00
const TokenKey = 'App-Token'
2024-09-27 17:21:10 +08:00
const UserInfo = 'customerInfo'
2024-09-22 15:07:01 +08:00
const TenantIdKey = 'TENANT_ID'
2024-10-15 18:47:56 +08:00
const InviteIdKey = 'INVITE_ID'
2024-09-22 15:07:01 +08:00
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)
}
2024-10-15 18:47:56 +08:00
export function setInviteId(InviteId) {
return uni.setStorageSync(InviteIdKey, InviteId);
}
export function getInviteId(){
return uni.getStorageSync(InviteIdKey)
}
export function removeInviteId(){
return uni.removeStorageSync(InviteIdKey)
}
2024-09-22 15:07:01 +08:00
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
}
2024-09-27 17:21:10 +08:00
export function getUserInfo() {
return uni.getStorageSync(UserInfo)
}
export function setUserInfo(userInfo) {
return uni.setStorageSync(UserInfo, userInfo)
}
2024-10-11 20:50:05 +08:00
export function getJSONData(keyStr) {
if(uni.getStorageSync(keyStr)){
return JSON.parse(uni.getStorageSync(keyStr))
}else{
return "";
}
}
export function setJSONData(keyStr,dataObj) {
return uni.setStorageSync(keyStr, JSON.stringify(dataObj))
}