xuruiqian
2025-06-04 17ce21955b4e3402d3d5868b52e50bfdd55bc572
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import validator from '../common/validator';
 
const request = (url, options) => {
    uni.showNavigationBarLoading()
    return new Promise((resolve, reject) => {
        uni.request({
            url: `${url}`,
            method: options.method,
            data: options.method === 'GET' || options.header ===
            'application/x-www-form-urlencoded' ? options.data : JSON.stringify(options.data),
            header: {
                'Content-Type': options.header,
                'Authorization': uni.getStorageSync('token'),
                'Referer': 'https://drptest.koreano.cn'
            },
            //https://servicewechat.com/wx1e7526eb4d9cf91c/devtools/page-frame.html
            success(request) {
                uni.stopPullDownRefresh()
                if (request.data.status == 10 || request.data.status == 11) {
                    uni.setStorageSync('token', '')
                    let token = uni.getStorageSync('token')
                    if (validator.checkEmpty(token)) {
                        refLogin(url, options).then(res => {
                            if (res) {
                                resolve(res)
                            } else {
                                resolve({
                                    tokenStatus: false,
                                    status: 1
                                })
                            }
                        })
                    }
                } else {
                    if (request.statusCode === 200 || request.data.status) {
                        resolve(request.data)
                    } else {
                        reject(request.data)
                    }
                }
                uni.hideNavigationBarLoading()
            },
            fail(error) {
                console.log('---------网络连接错误------------')
                uni.showToast({
                    icon: 'none',
                    title: '网络连接错误'
                })
                uni.hideNavigationBarLoading()
                reject({
                    status: 1,
                    data: error.data
                })
            },
        })
    }).catch(function (reason) {
        console.log('---------网络调用错误------------' + reason)
        uni.showToast({
            icon: 'none',
            title: '网络调用错误'
        })
        uni.redirectTo({
            url: '/pages/common/code_error/index?code=10002',
        })
        uni.hideNavigationBarLoading()
    });
}
 
export const get = (url, options = {}) => {
    return request(url, {
        method: 'GET',
        data: options,
        header: 'application/json; charset=UTF-8'
    })
}
 
export const post = (url, options) => {
    return request(url, {
        method: 'POST',
        data: options,
        header: 'application/json; charset=UTF-8'
    })
}
 
export const put = (url, options) => {
    return request(url, {
        method: 'PUT',
        data: options,
        header: 'application/json; charset=UTF-8'
    })
}
 
export const postF = (url, options) => {
    return request(url, {
        method: 'POST',
        data: options,
        header: 'application/x-www-form-urlencoded'
    })
}
 
export const putF = (url, options) => {
    return request(url, {
        method: 'PUT',
        data: options,
        header: 'application/x-www-form-urlencoded'
    })
}
 
export const remove = (url, options) => {
    return request(url, {
        method: 'DELETE',
        data: options,
        header: 'application/json; charset=UTF-8'
    })
}