jiangping
2025-06-06 a2299a6d4a6f99e9c11132138f5d3e9ec68f03ea
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
const install = (Vue, vm) => {
    // 请求拦截器
    uni.$u.http.interceptors.request.use((config) => {
        uni.showLoading({
            title: '加载中',
            mask: true
        });
        // const Headtoken = vm.$store.state.token || ''
        // if (Headtoken) {
        //     config.header['eva-auth-token'] = Headtoken;
        // }
        return config
    }, config => {
        return Promise.reject(config)
    })
    
    // 响应拦截器
    uni.$u.http.interceptors.response.use((response) => {
        uni.hideLoading();
        // 登录过期
        if (response.data.code === 401) {
            uni.navigateTo({
                url: '/packageA/loginAgain/loginAgain'
            });
        }
        if (response.data.code !== 200) {
            uni.showToast({
                title: response.data.message,
                icon: "none",
                duration: 2000
            });
        }
        return response.data;
    }, (response) => {
        uni.hideLoading();
        return Promise.reject(response)
    })
}
 
export default { install }