schangxiang@126.com
2025-09-19 a68302033da081f9ad5e82268a01892c3e129cc1
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
function req(obj) {
    return new Promise((resolve, reject) => {
        //这个地址是 给 分拣配置的地址 
        //const HOST = 'http://192.168.0.191:8001' // 正式生产线上地址
        const HOST = 'http://127.0.0.1:8001' // 本地地址
        var method = obj.method || "GET";
        var url = HOST + obj.url || "";
        if (obj.url.indexOf('http') != -1) {
            url = obj.url;
        }
        var data = obj.data || {};
        var header = obj.header || {
            'Content-Type': obj.contentType || 'application/json',
            'token': uni.getStorageSync('token'),
            'appType': 'OPEN'
        };
        var success = obj.success; // 成功回调函数
        var fail = obj.fail; //表示失败后,要执行的回调函数
        uni.showLoading({
            title: '加载中...',
            mask: true
        });
        console.log('xxxxx',obj)
        uni.request({
            url: url,
            data: data,
            method: method,
            header: header,
            success: ((res) => {
                console.log('success',res)
                uni.hideLoading();
                if (res.statusCode == 403 || res.statusCode == 401) {
                    // 错误处理,返回登录页
                    uni.reLaunch({
                        url: '/pages/Login/index'
                    })
                } else if (res.data.message == '用户未登录,请先登录程序') {
                    uni.showToast({
                        title: '用户登陆状态失效',
                        icon: 'none',
                        duration: 2000,
                        success: function(res) {
                            setTimeout(() => {
                                uni.reLaunch({
                                    url: '/pages/login/index'
                                })
                            }, 1000)
                        }
                    });
                } else if (res.statusCode == 200) {
                    resolve(res)
                    uni.hideLoading();
                } else {
                    let msg = res.errMsg || `接口调用出错:${res.statusCode}`
                    uni.showModal({
                        title:'系统提示',
                        content:msg,
                        showCancel:false
                    })
                    reject(res)
                    uni.hideLoading();
                }
            }),
            fail: ((err) => {
                console.log('fail',err)
                uni.hideLoading();
                reject(err)
            }),
            complete: (e) => {
                console.log('complete')
                uni.hideLoading();
            }
        })
    })
}
export default req