#
zhou zhou
2026-01-14 e2f68c49d0f9d8b1b3ddba36bdaf70d1c2326f2d
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
/**
 * @param {string} url url地址
 * @param {any} postData 参数
 * @param {string} method 请求方式
 * @param {boolean} hideLoading 是否load
 * @description: 格式化时间
 */
export function request(url, postData, method = 'POST', hideLoading = 'false') {
    if (!hideLoading) {
        uni.showLoading({
            title: '请稍候...',
            mask: true
        })
    }
    return new Promise((resolve, reject) => {
        const token = uni.getStorageSync('token');
        // const URL = 'http://47.76.147.249:8080/rsf-server/pda' + url;
        // const URL = 'http://test.zoneyung.net:8080/rsf-server/pda' + url;
        const URL = 'http://127.0.0.1:8085/rsf-server/pda' + url;
        uni.request({
            url: URL,
            data: postData,
            header: {
                'content-type': 'application/json',
                'authorization': token
            },
            method: method, //'GET','POST'
            dataType: 'json',
            timeout: 30000, // 30秒超时
            success: (res) => {
                !hideLoading && uni.hideLoading()
                resolve(res.data)
 
            },
            fail: (res) => {
                !hideLoading && uni.hideLoading()
                // 判断是否为超时错误
                const isTimeout = res.errMsg && (res.errMsg.includes('timeout') || res.errMsg.includes('超时'))
                uni.showToast({
                    title: isTimeout ? '网络请求超时,请检查网络连接' : '网络请求失败,请稍后重试',
                    icon: 'none',
                    duration: 3000
                })
                reject(res)
            }
        })
    })
}