From ba04983aaf5cbb0d57c4ec3530ee1663f0f83115 Mon Sep 17 00:00:00 2001
From: qq_41295110 <qq_41295110@noreply.gitcode.com>
Date: 星期二, 15 七月 2025 17:16:02 +0800
Subject: [PATCH] 生产领料更新

---
 utils/common.js |   85 ++++++++++++++++++++++++++++++++++--------
 1 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/utils/common.js b/utils/common.js
index 65ea5c2..8846e12 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;
@@ -88,8 +88,48 @@
 		return /^\d+$/.test(str);
 	}
 	
-	// uni-app 浣跨敤 灏佽璇锋眰鍑芥暟
-	doRequest(url, data, resFunction, errFunction, method) {
+	isJson(str) {
+		try{
+			JSON.parse(str)
+			return true
+		}catch{
+			return false
+		}
+	}
+	
+	timeClock(callback, delay) {
+	    let timeoutId;
+	    let isRunning = false;
+	
+	    function interval() {
+	        timeoutId = setTimeout(() => {
+	            callback();
+				clearTimeout(timeoutId); // 绔嬪嵆娓呴櫎褰撳墠瀹氭椂鍣↖D
+	            if (isRunning) {
+	                interval();
+	            }
+	        }, delay);
+	    }
+	
+	    return {
+	        start() {
+	            if (!isRunning) {
+	                isRunning = true;
+	                interval();
+	            }
+	        },
+	        stop() {
+	            if (isRunning) {
+	                isRunning = false;
+	                clearTimeout(timeoutId);
+	            }
+	        }
+	    };
+	}
+	// uni-app 浣跨敤 灏佽璇锋眰鍑芥暟 浣跨敤浼犵粺鍑芥暟褰撲綔鍥炶皟闇�瑕佷紶that锛岀澶村嚱鏁颁笉闇�瑕�
+	doRequest(url, data, resFunction, errFunction, method, that) {
+		that = that || this;
+		let errorTip = null;
 		uni.showLoading({
 			title: '鍔犺浇涓�...'
 		})
@@ -99,30 +139,41 @@
 			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("璁块棶澶辫触鍥炶皟鍑芥暟绫诲瀷涓嶄负鍑芥暟鎴栬�呯┖!")
 				}
+				
+			},complete() {
+				setTimeout(() => {
+					uni.hideLoading()
+					if (errorTip != null) {
+						errorTip()
+					}
+				}, 1000)
 			}
 		})
-		uni.hideLoading()
+		
 	}
 }
 
-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