schangxiang@126.com
2025-07-30 a16904bd86f89e97a5e507e08003506c5dd8642e
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
import {requestOption} from './init.js'
import store from '../store/index.js'
export  function request(option) {
    return new Promise((resolve, reject) => {
        //请求头
        const header = option.header || {
            'Content-Type': option.contentType || 'application/json',
            // 'token': uni.getStorageSync('token'),
        };    
        uni.showLoading({
            title: '加载中...'
        });
        uni.request({
            url: `http://${store.state.user.ip}:${store.state.user.port}/pda/${option.url}`, 
            // url: requestOption.HOST + option.url,
            data: option.data || {},
            method: option.method || 'GET',
            header: header,
            timeout: requestOption.timeout,
            success: ((res) => {
                
                if (res.statusCode===200) {
                    if (res.data) {
                        if (res.data.status===200) {
                            let ress = {data:res.data.date};
                            for (let key in res.data) {
                                if (key!=='msg'&&key!=='date'&&key!=='status') {
                                    ress[key] = res.data[key]
                                }
                            }
                            resolve(ress)
                        } else {
                            let emsg = res.data.msg;
                            if (!emsg) emsg="请求错误"
                            uni.showToast({
                                title:emsg,
                                //icon: 'error',
                                icon: 'none' //用于文字的全部显示 【EditBy shaocx,2022-03-23】
                            })
                            reject(res)
                        }
                    } else {
                        resolve(res)
                    }
                } else {
                    uni.showToast({
                        title:'请求错误-'+res.statusCode,
                        icon: 'error'
                    })
                    reject(res)
                }
            }),
            fail: ((err) => {
                uni.showToast({
                    title:'请求失败',
                    icon: 'error'
                })
                reject(err)
            }),
            complete() {
                setTimeout(()=>{
                    uni.hideLoading()
                },300)    
            }
        })
    })
}