doum
2025-09-26 9057e04efad1b7d61c77a72e5c37a504d0aee935
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { decryptedData } from '@/utils/decryption.js'
const install = (Vue, vm) => {
    // 是否正在刷新的标记
    let isRefreshing = false
    // 重试队列,每一项将是一个待执行的函数形式
    let requests = []
    
    // 请求拦截器
    uni.$u.http.interceptors.request.use((config) => {
        // if (!['mobile/chatLog/unReadMessageNum', 'mobile/Message/messageList'].includes(config.url)) {
        //     uni.showLoading({ title: '请求中' });
        // }
        uni.showLoading({ title: '请求中' });
        let Headtoken
        if (vm.$store.state.userInfo) {
            Headtoken = vm.$store.state.userInfo.token
        }
        if (Headtoken) {
            config.header['web_token'] = Headtoken;
        }
        return config
    }, config => {
        return Promise.reject(config)
    })
    
    // 响应拦截器
    uni.$u.http.interceptors.response.use((response) => {
        uni.hideLoading();
        // 登录过期
        if (response.data.code === 5112) {
            uni.showToast({
                title: '登录过期,正在重新跳转授权',
                icon: 'none',
                duration: 2000,
                success() {
                    setTimeout(() => {
                        let loc_href = encodeURIComponent("https://dmtest.ahapp.net/lianhelihua_web/")
                        let corpId = 'wweea8f71b54e3b835';
                        let agentId = '1000095';
                        let wxUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${corpId}&redirect_uri=${loc_href}&response_type=code&scope=snsapi_base&state=#wechat_redirect`
                        location.href = wxUrl;
                    }, 1500)
                }
            })
            return
        }
        if (response.data.code !== 200) {
            uni.showToast({
                title: response.data.message || response.data.msg,
                icon: "none",
                duration: 2000
            });
        }
        if (response.data.message) {
            const tm = response.data.message
            const list = tm.split(' ')
            let msg = list[0]
            if (list.length > 1 && response.data.data) {
              msg = decryptedData(list[1], list[0])
              response.data.data = decryptedData(list[1], response.data.data)
              console.log(response.data.data)
              response.data.message = msg
            }
        }
        return response.data;
    }, (response) => {
        return Promise.reject(response)
    })
}
 
export default { install }