From 9b09d13712c0c005891450a3bf4b6d848ec0ff37 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 29 十一月 2023 10:28:24 +0800
Subject: [PATCH] 2023.11.29
---
service/baserequest.js | 110 ++++++++++++++++++++++++++++++++++---------------------
1 files changed, 68 insertions(+), 42 deletions(-)
diff --git a/service/baserequest.js b/service/baserequest.js
index e05ce6b..77324b1 100644
--- a/service/baserequest.js
+++ b/service/baserequest.js
@@ -5,40 +5,58 @@
* success: function(data),
* page: function(page, totalPage)
* fail: function(error)
- * }
+ * }
*/
-const util = require("../utils/util.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.116:8080"
-// const baseUrl = "https://fyami.com.cn:447/"
-const basePicUrl = baseUrl + "images/"
-const baseFileUrl = baseUrl + "meeting/file/"
+// const baseUrl = "http://192.168.0.123:8080"
+// const baseUrl = "https://fyami.com.cn:447"
+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/`;
+// 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
- }else{
- var url = fun.url
- fun.url = baseUrl + url
+ var url = fun.url;
+ fun.url = bUrl + url + '?' + param;
+ } else {
+ var url = fun.url;
+ fun.url = bUrl + url;
}
- var fun1 = util.deepCopy(fun)
+ var fun1 = util.deepCopy(fun);
fun1.success = function (res) {
- console.log("--------------璇锋眰缁撴灉----------------" + fun.url);
- console.log(res);
-
- fun.success(res.data)
+ if (mode == 'debug') {
+ 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) {
@@ -48,28 +66,36 @@
// } else {
// fun.fail(res.data)
// }
- }
+ };
fun1.fail = function (error) {
+ if (mode == 'debug') {
+ console.log('--------------璇锋眰閿欒----------------' + fun.url);
+ console.log(error);
+ }
wx.showToast({
- title: '缃戠粶杩炴帴澶辫触',
- icon: 'none'
- })
- fun.fail(error)
- }
- fun1.complete = fun.complete
- wx.request(fun1)
+ 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
-}
\ No newline at end of file
+ basePicUrl: basePicUrl,
+ baseUrl: baseUrl,
+ baseFileUrl: baseFileUrl,
+ baseIconUrl: baseIconUrl,
+};
--
Gitblit v1.9.3