riku
2026-01-21 a2c5def7cf9562312a54216bc195a6ea071a26c5
service/baserequest.js
@@ -5,49 +5,63 @@
 * success: function(data),
 * page: function(page, totalPage)
 * fail: function(error)
 * }
 * }
 */
const { duration } = require("../utils/moment.min.js");
const util = require("../utils/util.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 baseUrl = "http://192.168.1.9:8082"
// const baseUrl = 'https://fyami.com.cn';
const bu = 'https://fyami.com.cn';
const basePicUrl = `${bu}/images/`;
const baseIconUrl = `${bu}/images/weixin/eplaw/`;
const baseFileUrl = `${bu}/meeting/file/`;
// 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/`
// 飞羽监管系统后台
const spUrl = "https://fyami.com.cn:447"
const spBu = "https://fyami.com.cn:447"
const spPicUrl = `${spBu}/images/`;
function request(fun) {
const mode = 'debug';
// const mode = 'prod';
function request(fun, hostUrl) {
  const bUrl = hostUrl ? hostUrl : baseUrl;
  if (fun.params != undefined) {
    var param = ""
    var param = '';
    Object.keys(fun.params).forEach(key => {
      var value = fun.params[key]
      if (param == "") {
        param += key + "=" + value
      var value = fun.params[key];
      if (param == '') {
        param += key + '=' + value;
      } else {
        param += "&" + key + "=" + value
        param += '&' + key + '=' + value;
      }
    });
    var url = fun.url
    fun.url = baseUrl + url + "?" + param
    var url = fun.url;
    fun.url = bUrl + url + '?' + param;
  } else {
    var url = fun.url
    fun.url = baseUrl + url
    var url = fun.url;
    fun.url = bUrl + url;
  }
  var fun1 = util.deepCopy(fun)
  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)
    if (mode == 'debug') {
      console.log(
        '|------------------------------------------------------------------------------------------------------------',
      );
      console.log('|--访问: ', fun.url);
      console.log('|--参数: ', fun.data);
      console.log('|--结果: ', res);
    }
    fun.success(res.data)
    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) {
@@ -57,34 +71,42 @@
    // } else {
    //   fun.fail(res.data)
    // }
  }
  };
  fun1.fail = function (error) {
    console.log("--------------请求错误----------------" + fun.url);
    console.log(error);
    wx.showToast({
      title: error.errMsg,
      icon: 'none',
      duration: 2000
    })
    if (fun.fail) {
      fun.fail(error)
    if (mode == 'debug') {
      console.log(
        '|------------------------------------------------------------------------------------------------------------',
      );
      console.log('|--访问: ', fun.url);
      console.log('|--参数: ', fun.data);
      console.log('|--错误: ', error);
    }
  }
  fun1.complete = fun.complete
  wx.request(fun1)
    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)
  get: function (fun, hostUrl) {
    fun['method'] = 'GET';
    request(fun, hostUrl);
  },
  post: function (fun) {
    fun['method'] = 'POST'
    request(fun)
  post: function (fun, hostUrl) {
    fun['method'] = 'POST';
    request(fun, hostUrl);
  },
  basePicUrl: basePicUrl,
  baseUrl: baseUrl,
  baseFileUrl: baseFileUrl,
  baseIconUrl: baseIconUrl
}
  baseIconUrl: baseIconUrl,
  spUrl: spUrl,
  spPicUrl: spPicUrl,
};