/**
|
* 接口调用时传输统一的对象结构,定义如下
|
* {
|
* data:{},
|
* success: function(data),
|
* page: function(page, totalPage)
|
* fail: function(error)
|
* }
|
*/
|
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.1.106: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/"
|
|
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("--------------请求结果----------------" + fun.url);
|
console.log(res);
|
|
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'
|
})
|
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
|
}
|