From 5d8e52e398bff7bc8f83e8f5b8a387175b958c98 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 24 二月 2023 10:20:18 +0800
Subject: [PATCH] 2023.2.24

---
 service/baserequest.js |   52 +++++++++++++++++++++++++++++++---------------------
 1 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/service/baserequest.js b/service/baserequest.js
index 20db2fc..35bca96 100644
--- a/service/baserequest.js
+++ b/service/baserequest.js
@@ -7,18 +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.105: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 baseIconUrl = "https://fyami.com.cn:447/images/weixin/eplaw/"
-const baseFileUrl = "https://fyami.com.cn:447/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 => {
@@ -30,26 +34,31 @@
       }
     });
     var url = fun.url
-    fun.url = baseUrl + url + "?" + param
+    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);
+    console.log("|------------------------------------------------------------------------------------------------------------");
+    console.log("|--璁块棶: ", fun.url);
+    console.log("|--缁撴灉: ", res);
 
-    if (fun.onHead) {
-      fun.onHead(res.header)
+    if (res.statusCode == 200) {
+      if (fun.onHead) {
+        fun.onHead(res.header)
+      }
+      fun.success(res.data) 
+    } else {
+      fun.fail(res.statusCode)
     }
-    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)
+    //   fun.success(res.data.data)                                                                                                                           
     // } else {
     //   fun.fail(res.data)
     // }
@@ -58,8 +67,9 @@
     console.log("--------------璇锋眰閿欒----------------" + fun.url);
     console.log(error);
     wx.showToast({
-      title: '缃戠粶杩炴帴澶辫触',
-      icon: 'none'
+      title: '璇锋眰澶辫触',
+      icon: 'none',
+      duration: 2000
     })
     if (fun.fail) {
       fun.fail(error)
@@ -70,13 +80,13 @@
 }
 
 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,

--
Gitblit v1.9.3