From 4a85c4baa43cd65e9c2a3fa755ca11c36b6004ef Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期三, 09 七月 2025 14:09:12 +0800
Subject: [PATCH] 添加 其他入库页面 其他出库页面 蓝牙连接组件

---
 utils/common.js |   46 ++++++++++++++++++++++++++++------------------
 1 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/utils/common.js b/utils/common.js
index 65ea5c2..011f958 100644
--- a/utils/common.js
+++ b/utils/common.js
@@ -1,10 +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;
@@ -87,9 +87,11 @@
 	isAllDigits(str) {
 		return /^\d+$/.test(str);
 	}
-	
-	// uni-app 浣跨敤 灏佽璇锋眰鍑芥暟
-	doRequest(url, data, resFunction, errFunction, method) {
+
+	// uni-app 浣跨敤 灏佽璇锋眰鍑芥暟 浣跨敤浼犵粺鍑芥暟褰撲綔鍥炶皟闇�瑕佷紶that锛岀澶村嚱鏁颁笉闇�瑕�
+	doRequest(url, data, resFunction, errFunction, method, that) {
+		that = that || this;
+		let errorTip = null;
 		uni.showLoading({
 			title: '鍔犺浇涓�...'
 		})
@@ -99,30 +101,38 @@
 			data: data || "",
 			success: (res) => {
 				if (typeof resFunction === 'function') {
-					resFunction.call(this, res)
-				} else if (typeof errFunction === 'undefined') {
+					resFunction.call(that, res)
+				} else if (typeof errFunction === 'undefined' || errFunction === null) {
 					return
 				} else {
-					throw new TypeError("璁块棶鎴愬姛鍥炶皟鍑芥暟绫诲瀷寮傚父!")
+					throw new TypeError("璁块棶鎴愬姛鍥炶皟鍑芥暟绫诲瀷涓嶄负鍑芥暟鎴栬�呯┖!")
 				}
 			},
 			fail: (err) => {
-				uni.showToast({
-					icon: "error",
-					title: "鎺ュ彛璁块棶寮傚父!",
-					duration: 2000
-				})
+				console.error(err)
+				errorTip = () => {
+					uni.showToast({
+						icon: "none",
+						title: err.errMsg || err.data.message || "鎺ュ彛寮傚父!",
+						duration: 2000
+					})
+				}
 				if (typeof errFunction === 'function') {
-					errFunction.call(this, err)
-				} else if (typeof errFunction === 'undefined') {
+					errFunction.call(that, err)
+				} else if (typeof errFunction === 'undefined' || errFunction === null) {
 					return
 				} else {
-					throw new TypeError("璁块棶澶辫触鍥炶皟鍑芥暟绫诲瀷寮傚父!")
+					throw new TypeError("璁块棶澶辫触鍥炶皟鍑芥暟绫诲瀷涓嶄负鍑芥暟鎴栬�呯┖!")
 				}
 			}
 		})
-		uni.hideLoading()
+		setTimeout(() => {
+			uni.hideLoading()
+			if (errorTip != null) {
+				errorTip()
+			}
+		}, 1000)
 	}
 }
 
-export const CommonUtils =  Object.freeze(new commonUtils());
\ No newline at end of file
+export const CommonUtils = Object.freeze(new commonUtils());
\ No newline at end of file

--
Gitblit v1.9.1