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
| import {
| ONLINEHOST,
| QAHOST,
| } from "./env.js";
| // console.log(process.env.NODE_ENV)
| const BASE_URL = process.env.NODE_ENV === "production" ? ONLINEHOST : QAHOST; //公共请求头
|
|
| /*
| @parms url 接口地址
| @parms method 请求方式
| @parms data 参数
| */
| const request = (url,data, method='POST', contentType='application/x-www-form-urlencoded',config = { timeout:5000,isShowLoading:true }) => {
| return new Promise((resolve, reject) => {
| if(config.isShowLoading){
| uni.showLoading({
| title: '加载中',
| mask: true
| })
| }
| let model=uni.getStorageSync('model');
| uni.request({
| url: "http://"+model.udpAdress+":"+model.baoliu20 + url, //接口地址。
| data: data,
| method: method,
| header: { //请求头可自定义
| 'content-type': contentType,
| },
| timeout:config.timeout,//设置超时时间,默认5秒
| success: (rep) => { //具体捕获请看自己接口返回的形式
| // console.log(rep)
| let result = rep.data;
| uni.hideLoading();
| if ((rep.statusCode == 200 || rep.statusCode == 0)) {
| resolve(result)
| }
| },
| fail(error) {
| uni.hideLoading();
| uni.$u.toast('网络不通');
| reject(error)
| },
| complete() {
| uni.hideLoading();
| }
| });
| })
| }
|
| module.exports ={
| request, //向外暴露request
| BASE_URL
| }
|
|