riku
2022-10-21 0f2fdf16f47bd2d1d8fee86449c3a5095ccc8c23
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
/**
 * 接口调用时传输统一的对象结构,定义如下
 * {
 * data:{},
 * success: function(data),
 * page: function(page, totalPage)
 * fail: function(error)
 * } 
 */
const { duration } = require("../utils/moment.min.js");
const util = require("../utils/util.js")
 
const originProperties = ['url', 'data', 'header', 'method', 'success', 'fail', 'complete'];
// const baseUrl = "http://192.168.0.137:8080"
// const baseUrl = "https://fyami.com.cn:447"
const baseUrl = "https://fyami.com.cn"
 
const bu = "https://fyami.com.cn"
// const bu = "https://fyami.com.cn:447"
const basePicUrl = `${bu}/images/`
const baseIconUrl = `${bu}/images/weixin/eplaw/`
const baseFileUrl = `${bu}/meeting/file/`
 
function request(fun) {
  if (fun.params != undefined) {
    var param = ""
    Object.keys(fun.params).forEach(key => {
      var value = fun.params[key]
      if (param == "") {
        param += key + "=" + value
      } else {
        param += "&" + key + "=" + value
      }
    });
    var url = fun.url
    fun.url = baseUrl + url + "?" + param
  } else {
    var url = fun.url
    fun.url = baseUrl + url
  }
  var fun1 = util.deepCopy(fun)
  fun1.success = function (res) {
    console.log("|------------------------------------------------------------------------------------------------------------");
    console.log("|--访问: ", fun.url);
    console.log("|--结果: ", res);
 
    if (fun.onHead) {
      fun.onHead(res.header)
    }
    fun.success(res.data)
    // if(res.data.success) {
    //   var head = res.data['head']
    //   if (head != undefined && fun.page != undefined) {
    //     fun.page(head.page, head.totalPage)
    //   }
    //   fun.success(res.data.data)
    // } else {
    //   fun.fail(res.data)
    // }
  }
  fun1.fail = function (error) {
    console.log("--------------请求错误----------------" + fun.url);
    console.log(error);
    wx.showToast({
      title: '请求失败',
      icon: 'none',
      duration: 2000
    })
    if (fun.fail) {
      fun.fail(error)
    }
  }
  fun1.complete = fun.complete
  wx.request(fun1)
}
 
module.exports = {
  get: function (fun) {
    fun['method'] = 'GET'
    request(fun)
  },
  post: function (fun) {
    fun['method'] = 'POST'
    request(fun)
  },
  basePicUrl: basePicUrl,
  baseUrl: baseUrl,
  baseFileUrl: baseFileUrl,
  baseIconUrl: baseIconUrl
}