qingyiay
2023-10-10 d393b6dd9964bd22d4ab91c37a3bfb6116fd9fca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
}