From ca1eab1cf8a8050e5668eb7e78faea2a821c5cb2 Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期二, 08 七月 2025 12:11:04 +0800
Subject: [PATCH] 12

---
 utils/common.js |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/utils/common.js b/utils/common.js
index 7c94684..65ea5c2 100644
--- a/utils/common.js
+++ b/utils/common.js
@@ -1,4 +1,10 @@
 class commonUtils {
+	serverUrl
+	
+	constructor() {
+		this.serverUrl = uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API';
+	}
+	
 	// 闃叉姈鍑芥暟
 	debounce(func, delay, immediate = false) {
 		let timer = null;
@@ -82,6 +88,41 @@
 		return /^\d+$/.test(str);
 	}
 	
+	// uni-app 浣跨敤 灏佽璇锋眰鍑芥暟
+	doRequest(url, data, resFunction, errFunction, method) {
+		uni.showLoading({
+			title: '鍔犺浇涓�...'
+		})
+		uni.request({
+			method: method || "GET",
+			url: this.serverUrl + url,
+			data: data || "",
+			success: (res) => {
+				if (typeof resFunction === 'function') {
+					resFunction.call(this, res)
+				} else if (typeof errFunction === 'undefined') {
+					return
+				} else {
+					throw new TypeError("璁块棶鎴愬姛鍥炶皟鍑芥暟绫诲瀷寮傚父!")
+				}
+			},
+			fail: (err) => {
+				uni.showToast({
+					icon: "error",
+					title: "鎺ュ彛璁块棶寮傚父!",
+					duration: 2000
+				})
+				if (typeof errFunction === 'function') {
+					errFunction.call(this, err)
+				} else if (typeof errFunction === 'undefined') {
+					return
+				} else {
+					throw new TypeError("璁块棶澶辫触鍥炶皟鍑芥暟绫诲瀷寮傚父!")
+				}
+			}
+		})
+		uni.hideLoading()
+	}
 }
 
 export const CommonUtils =  Object.freeze(new commonUtils());
\ No newline at end of file

--
Gitblit v1.9.1