zhao_js
2023-11-15 b44e169dd8a6e0f15d3788970176922e96aec6e1
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import config from './config.js';
 
var requestheader;
var TOKEN;
var request = {}
var mobileInfo;
var appVersion;
// #ifdef APP-PLUS
mobileInfo = plus.os.name
appVersion = plus.runtime.version;
// #endif
 
/**** 此文件说明请看注释 
 
 
淘宝客技术支持 https://www.jiuduoyun.net/ 
git开源地址 https://gitee.com/s55555/taobao-customer-uniapp-version
禁止二次售卖
 
*****/
request.post = function(url, data, requestheader, showlaoding, complete) {
    uni.getNetworkType({
        success: res => {
            console.log(res.networkType);
            if(res.networkType=='none'){
                uni.navigateTo({
                    url:'/pages/index/noNet'
                })
            }
        }
    })
    requestheader = requestheader || "application/x-www-form-urlencoded";
    console.log("POST-URL:" + url, data);
    if (showlaoding) {
        uni.showLoading({
            title: ''
        })
    }
    try {
        const value = uni.getStorageSync('userInfo');
        if (value.token) {
            TOKEN = value.token
        } else {
            TOKEN = ''
        }
    } catch (e) {
        TOKEN = ''
    }
    //TOKEN='fba93d1f-9bbe-49e7-9df7-074ddaba8790';
    var startTime = new Date();
    return new Promise((succ, error) => {
        uni.request({
            url: config.httpUrl + url,
            data: data,
            method: "POST",
            header: {
                "content-type": requestheader,
                "token": TOKEN,
                "mobileInfo":mobileInfo,
                "appVersion":appVersion
            },
            success: function(result) {
                console.log(result)
                if (typeof succ == "function") {
                    // console.log(result.data);
                    if (result.data.code == 0 ) {
                        succ(result.data.data)
                    } else if (result.data.code == 401) {
                        console.log('dosomething');
                    } else {
                        error(result.data.data)
                        uni.showToast({
                            title: result.data.message,
                            icon: 'none',
                            position: 'bottom',
                            duration: 3000
                        });
                    }
                }
            },
            fail: function(e) {
                console.log(e);
                if (typeof error == "function") {
                    error(e)
                }
            },
            complete: function(c) {
                uni.hideLoading()
                var endTime = new Date();
                // console.log('request time ' + new Date(endTime - startTime).getTime());
                if (typeof complete == "function") {
                    complete(c);
                }
            }
        })
    })
}
 
 
request.get = function(url, data, showlaoding) {
    requestheader = requestheader || "application/x-www-form-urlencoded";
    if (showlaoding) {
        uni.showLoading({
            title: ''
        })
    }
    try {
        const value = uni.getStorageSync('userInfo');
        if (value.token) {
            TOKEN = value.token
        } else {
            TOKEN = ''
        }
    } catch (e) {
        TOKEN = ''
    }
    return new Promise((succ, error) => {
        uni.request({
            url: config.httpUrl + url,
            data: data,
            method: "GET",
            header: {
                "content-type": requestheader,
                "token": TOKEN,
                "mobileInfo":mobileInfo,
                "appVersion":appVersion
            },
            success: function(result) {
                uni.hideLoading()
                if (typeof succ == "function") {
                    succ(result.data.data)
                }
            },
            fail: function(e) {
                uni.hideLoading()
                if (typeof error == "function") {
                    error(e)
                }
            },
        })
    })
}
 
export default request