riku
2023-02-24 5d8e52e398bff7bc8f83e8f5b8a387175b958c98
service/baserequest.js
@@ -7,17 +7,22 @@
 * 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://127.0.0.1:8080"
const baseUrl = "http://192.168.0.106:8080"
// const baseUrl = "http://192.168.1.12:8080"
// const baseUrl = "https://fyami.com.cn:447"
// const basePicUrl = baseUrl + "/images/"
const basePicUrl = "https://fyami.com.cn:447/images/"
const baseFileUrl = baseUrl + "/meeting/file/"
const baseUrl = "https://fyami.com.cn"
function request(fun) {
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, hostUrl) {
  const bUrl = hostUrl ? hostUrl : baseUrl
  if (fun.params != undefined) {
    var param = ""
    Object.keys(fun.params).forEach(key => {
@@ -29,48 +34,62 @@
      }
    });
    var url = fun.url
    fun.url = baseUrl + url + "?" + param
  }else{
    fun.url = bUrl + url + "?" + param
  } else {
    var url = fun.url
    fun.url = baseUrl + url
    fun.url = bUrl + url
  }
  var fun1 = util.deepCopy(fun)
  fun1.success = function (res) {
    console.log("--------------请求结果----------------" + fun.url);
    console.log(res);
    fun.success(res.data)
    console.log("|------------------------------------------------------------------------------------------------------------");
    console.log("|--访问: ", fun.url);
    console.log("|--结果: ", res);
    if (res.statusCode == 200) {
      if (fun.onHead) {
        fun.onHead(res.header)
      }
      fun.success(res.data)
    } else {
      fun.fail(res.statusCode)
    }
    // 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)
    //   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'
      title: '请求失败',
      icon: 'none',
      duration: 2000
    })
    fun.fail(error)
    if (fun.fail) {
      fun.fail(error)
    }
  }
  fun1.complete = fun.complete
  wx.request(fun1)
}
module.exports = {
  get: function (fun) {
  get: function (fun, hostUrl) {
    fun['method'] = 'GET'
    request(fun)
    request(fun, hostUrl)
  },
  post: function (fun) {
  post: function (fun, hostUrl) {
    fun['method'] = 'POST'
    request(fun)
    request(fun, hostUrl)
  },
  basePicUrl:basePicUrl,
  baseUrl:baseUrl,
  baseFileUrl:baseFileUrl
  basePicUrl: basePicUrl,
  baseUrl: baseUrl,
  baseFileUrl: baseFileUrl,
  baseIconUrl: baseIconUrl
}