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
| export default class Api {
| syncRequest = function(option){
| option.method = option.method || "GET"
| option.header = option.header || {}
| option.data = option.data || {}
| option.loading = option.loading ? true : false
| option.loadtext = option.loadtext || '加载中...'
| if(option.method == 'GET'){
| option.header['Content-Type'] = 'application/json;charset=UTF-8'
| }else{
| //option.header['Content-Type'] = 'application/x-www-form-urlencoded'
| option.header['Content-Type'] = 'application/json'
| }
| if(option.loading){
| uni.showLoading({
| mask: true,
| title: option.loadtext
| });
| }
| return new Promise((resolve,reject)=>{
| uni.request({
| url: option.url,
| method: option.method,
| header: option.header,
| data: option.data,
| success: (res)=>{
| if(option.loading){
| uni.hideLoading()
| }
| console.log(res)
| if(res.statusCode==200){
| resolve(res)
| }else{
| uni.showToast({
| icon: "none",
| title: "数据获取失败,请稍后重试"
| })
| }
| },
| fail: (err)=>{
| console.log(err)
| if (option.loading) {
| uni.hideLoading()
| }
| uni.showToast({
| icon: "none",
| title: "数据获取失败,请稍后重试"
| })
| reject(err)
| }
| })
| })
| }
| }
|
|