From 8e60a2ba47e5094538bda44bceab1a64211a22f9 Mon Sep 17 00:00:00 2001
From: zrg <z1873@LAPTOP-EAVL132E>
Date: 星期一, 26 一月 2026 20:21:55 +0800
Subject: [PATCH] Merge branch 'Dev' of http://101.37.171.70:10101/r/~jhz/STUWMS into Dev

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

diff --git a/utils/common.js b/utils/common.js
index 2ba726f..6905022 100644
--- a/utils/common.js
+++ b/utils/common.js
@@ -1,13 +1,22 @@
 class commonUtils {
     serverUrl
-
+    audioContext // 鍏ㄥ眬闊抽瀹炰緥
+    requestLock // 璇锋眰鎺у埗閿�(鍚屾)
     constructor() {
         this.serverUrl = uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API/';
+        this.audioContext = null;
+        this.requestLock = false
     }
 
     setServerUrl(url) {
         this.serverUrl = url
     }
+
+    getServerUrl() {
+        return this.serverUrl
+    }
+
+
 
     // 闃叉姈鍑芥暟
     debounce(func, delay, immediate = false) {
@@ -240,6 +249,131 @@
         })
     }
 
+    doRequest2({
+        url,
+        data,
+        resFunction,
+        errFunction,
+        method,
+        that
+    }) {
+        that = that || this;
+        let errorTip = null;
+        uni.showLoading({
+            title: '鍔犺浇涓�...'
+        })
+        uni.request({
+            method: method || "GET",
+            url: this.serverUrl + url,
+            data: data || "",
+            success: (res) => {
+                if (typeof resFunction === 'function') {
+                    resFunction.call(that, res)
+                } else if (typeof errFunction === 'undefined' || errFunction === null) {
+                    return
+                } else {
+                    throw new TypeError("璁块棶鎴愬姛鍥炶皟鍑芥暟绫诲瀷涓嶄负鍑芥暟鎴栬�呯┖!")
+                }
+            },
+            fail: (err) => {
+                console.error(err)
+                errorTip = () => {
+                    uni.showToast({
+                        icon: "none",
+                        title: err.errMsg || err.data.message || "鎺ュ彛寮傚父!",
+                        duration: 2000
+                    })
+                }
+                if (typeof errFunction === 'function') {
+                    errFunction.call(that, err)
+                } else if (typeof errFunction === 'undefined' || errFunction === null) {
+                    return
+                } else {
+                    throw new TypeError("璁块棶澶辫触鍥炶皟鍑芥暟绫诲瀷涓嶄负鍑芥暟鎴栬�呯┖!")
+                }
+
+            },
+            complete: () => {
+
+                setTimeout(() => {
+                    uni.hideLoading()
+                    if (errorTip != null) {
+                        errorTip()
+                    }
+                }, 1000)
+            }
+        })
+    }
+
+    // 鍚屾鎵ц璇锋眰 (閰嶅悎await鎴栬�卼hen)
+    async doRequest2Sync({
+        url,
+        data,
+        method,
+    }) {
+        if (this.requestLock) {
+            console.log("璇ヨ姹傝閿佸畾,涓嶈兘閲嶅璇锋眰!!!")
+            return
+        }
+        this.requestLock = true
+        return new Promise((resolve, reject) => {
+            // that = that || this;
+            let errorTip = null;
+            uni.showLoading({
+                title: '鍔犺浇涓�...'
+            })
+            uni.request({
+                method: method || "GET",
+                url: this.serverUrl + url,
+                data: data || "",
+                success: (res) => {
+                    resolve(res)
+                },
+                fail: (err) => {
+                    reject(err)
+                },
+                complete: () => {
+                    // 閲婃斁璇锋眰閿�
+                    this.requestLock = false
+                    uni.hideLoading()
+                }
+            })
+        })
+    }
+	//娌℃湁娣诲姞閿佺殑寮傛鏌ヨ
+    async doRequest2Async({
+        url,
+        data,
+        method,
+    }) {
+        return new Promise((resolve, reject) => {
+            // that = that || this;
+            let errorTip = null;
+            uni.showLoading({
+                title: '鍔犺浇涓�...'
+            })
+            uni.request({
+                method: method || "GET",
+                url: this.serverUrl + url,
+                data: data || "",
+                success: (res) => {
+                    resolve(res)
+                },
+                fail: (err) => {
+                    reject(err)
+                },
+                complete: () => {
+                    uni.hideLoading()
+                }
+            })
+        })
+    }
+
+    stringToBoolean(str) {
+        // 蹇界暐澶у皬鍐欑殑杞崲
+        return str?.toLowerCase() === "true";
+    }
+
     // uni-app 鎾斁闊抽灏佽
     playSound(e) {
         const innerAudioContext = uni.createInnerAudioContext();
@@ -249,6 +383,130 @@
             innerAudioContext.src = '/static/jingbao.wav';
         }
         innerAudioContext.play(); // 鎾斁闊抽
+
+        innerAudioContext.onPlay(() => {
+            console.log('寮�濮嬫挱鏀�');
+        });
+        innerAudioContext.onError((res) => {
+            console.log(res.errMsg);
+            console.log(res.errCode);
+        });
+        innerAudioContext.onPause(function() {
+            console.log('鎾斁鏆傚仠锛岄攢姣�');
+            innerAudioContext.destroy();
+        });
+		
+    }
+    // playSound(e) {
+    //     // 鍏ㄥ眬缁存姢涓�涓煶棰戝疄渚嬶紝闃叉缂撳瓨婧㈠嚭
+    //     if (this.audioContext) {
+    //         this.audioContext.destroy();
+    //     }
+    //     this.audioContext = uni.createInnerAudioContext();
+    //     if (e == 1) {
+    //         this.audioContext.src = '/static/success.wav';
+    //     } else {
+    //         this.audioContext.src = '/static/jingbao.wav';
+    //     }
+    //     this.audioContext.play(); // 鎾斁闊抽
+    // 
+    //     // 鎾斁缁撴潫鍚庨攢姣佸疄渚�
+    //     this.audioContext.onEnded(() => {
+    //         this.audioContext.destroy();
+    //         this.audioContext = null;
+    //     });
+    // 
+    //     // 閿欒澶勭悊
+    //     this.audioContext.onError((err) => {
+    //         uni.showToast({
+    //             icon: 'none',
+    //             title: `闊抽鎾斁閿欒: ${err}`
+    //         })
+    // 
+    //         this.audioContext.destroy();
+    //         this.audioContext = null;
+    //     });
+    // }
+
+
+    showTips({
+        type,
+        message,
+        title,
+        duration
+    }) {
+        if (!message) {
+            return
+        }
+
+        if (message.length < 20) {
+            return uni.showToast({
+                icon: type || 'none',
+                title: message
+            })
+        }
+
+        return uni.showModal({
+            title: title,
+            content: message,
+            showCancel: false
+        })
+    }
+
+    replaceWithFunction(str, handler) {
+        return str.replace(/\{(.+?)\}/g, (match, key) => {
+            // 璋冪敤澶勭悊鍑芥暟锛屼紶鍏ュ尮閰嶅埌鐨勯敭
+            return handler(key, match);
+        });
+    }
+    
+    fieldListFilterRole({FieldList, ExcludeKeys = [] ,RoleList = null}) {
+        if(!RoleList) {
+            RoleList = [
+                /^[a-zA-Z]+$/,
+                /id$/i
+            ]
+        }
+        if(!Array.isArray(RoleList)){
+            return {
+                status: false,
+                data: null,
+                Message: "杩囨护瀛楁鍒楄〃澶辫触锛岃鍒欏繀椤绘槸鏁扮粍銆�"
+            }
+        }
+        
+        let FieldListCache = Array(...FieldList)
+        
+        RoleList.forEach(role => {
+            FieldListCache = FieldListCache.filter(elem => !role.test(elem.ColmCols))
+        })
+        
+        FieldListCache = FieldListCache.filter(elem => !ExcludeKeys.includes(elem.ColmCols))
+        return {
+            status: true,
+            data: FieldListCache,
+            Message: ""
+        }
+    }
+    
+    emptyValueFilter(item, fieldList){
+        return fieldList.filter(e => {
+            return item[e.ColmCols]
+        })
+    }
+    
+    httpFormatWs(httpUrl=this.serverUrl) {
+        if(httpUrl.indexOf("http://") === 0){
+            httpUrl = httpUrl.replace("http://", "")
+            httpUrl = "ws://" + httpUrl.split(":")[0]+":8089/ws"
+        }else if(httpUrl.indexOf("https://") === 0) {
+            httpUrl = httpUrl.replace("https://", "")
+            httpUrl = "wss://" + httpUrl.split(":")[0]+":8089/ws"
+        }else{
+            // 鎻愮ず浼犲叆杩炴帴閿欒
+        }
+        
+        return httpUrl
     }
 }
 

--
Gitblit v1.9.1