From 94cfe8943459fb434ea2a6971ee660ccc13f1ee5 Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期六, 11 十月 2025 09:14:00 +0800
Subject: [PATCH] Merge branch 'Dev' of http://101.37.171.70:10101/r/~jhz/STUWMS into Dev

---
 utils/common.js |  177 ++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 115 insertions(+), 62 deletions(-)

diff --git a/utils/common.js b/utils/common.js
index 43c3331..1f3191b 100644
--- a/utils/common.js
+++ b/utils/common.js
@@ -1,19 +1,20 @@
 class commonUtils {
     serverUrl
-
+    audioContext // 鍏ㄥ眬闊抽瀹炰緥
     constructor() {
         this.serverUrl = uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API/';
+        this.audioContext = null;
     }
 
     setServerUrl(url) {
         this.serverUrl = url
     }
-    
+
     getServerUrl() {
         return this.serverUrl
     }
-    
-    
+
+
 
     // 闃叉姈鍑芥暟
     debounce(func, delay, immediate = false) {
@@ -245,59 +246,67 @@
             }
         })
     }
-	
-	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)
-		    }
-		})
-	}
-	
-	stringToBoolean(str) {
-	  // 蹇界暐澶у皬鍐欑殑杞崲
-	  return str?.toLowerCase() === "true";
-	}
+
+    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)
+            }
+        })
+    }
+
+    stringToBoolean(str) {
+        // 蹇界暐澶у皬鍐欑殑杞崲
+        return str?.toLowerCase() === "true";
+    }
 
     // uni-app 鎾斁闊抽灏佽
     playSound(e) {
@@ -308,13 +317,57 @@
             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;
+    //     });
+    // }
+
+
+
     replaceWithFunction(str, handler) {
-      return str.replace(/\{(.+?)\}/g, (match, key) => {
-        // 璋冪敤澶勭悊鍑芥暟锛屼紶鍏ュ尮閰嶅埌鐨勯敭
-        return handler(key, match);
-      });
+        return str.replace(/\{(.+?)\}/g, (match, key) => {
+            // 璋冪敤澶勭悊鍑芥暟锛屼紶鍏ュ尮閰嶅埌鐨勯敭
+            return handler(key, match);
+        });
     }
 }
 

--
Gitblit v1.9.1