From bbae990ed1f4574fa954753faeae159052d03fba Mon Sep 17 00:00:00 2001
From: llj <132905093+newwwwwwtree@users.noreply.github.com>
Date: 星期二, 27 一月 2026 16:14:06 +0800
Subject: [PATCH] 待我审核增加销售订单,采购订单
---
utils/common.js | 619 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 497 insertions(+), 122 deletions(-)
diff --git a/utils/common.js b/utils/common.js
index 011f958..6905022 100644
--- a/utils/common.js
+++ b/utils/common.js
@@ -1,138 +1,513 @@
class commonUtils {
- serverUrl
+ serverUrl
+ audioContext // 鍏ㄥ眬闊抽瀹炰緥
+ requestLock // 璇锋眰鎺у埗閿�(鍚屾)
+ constructor() {
+ this.serverUrl = uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API/';
+ this.audioContext = null;
+ this.requestLock = false
+ }
- constructor() {
- this.serverUrl = uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API';
- }
+ setServerUrl(url) {
+ this.serverUrl = url
+ }
- // 闃叉姈鍑芥暟
- debounce(func, delay, immediate = false) {
- let timer = null;
- return function() {
- const context = this;
- const args = arguments;
+ getServerUrl() {
+ return this.serverUrl
+ }
- const callNow = immediate && !timer;
- // 濡傛灉瀹氭椂鍣ㄥ凡缁忓瓨鍦紝娓呴櫎瀹�
- if (timer) {
- clearTimeout(timer);
- }
- // 璁剧疆涓�涓柊鐨勫畾鏃跺櫒
- timer = setTimeout(() => {
- if (!immediate) {
- func.apply(context, args);
- }
- timer = null;
- }, delay);
- // 閰嶇疆绔嬪嵆鎵ц
- if (callNow == true) {
- func.apply(context, args)
- }
- };
- }
+ // 闃叉姈鍑芥暟
+ debounce(func, delay, immediate = false) {
+ let timer = null;
+ return function() {
+ const context = this;
+ const args = arguments;
- // 鍒ょ┖鍑芥暟
- isEmpty(value, zeroIsEmpty = false, falseIsEmpty = false) {
- let val = value
- // 妫�鏌ユ槸鍚︿负null 鎴栬�� undefind
- if (val === null || val === undefined) {
- return true;
- }
- //濡傛灉瀛楃涓插叏閮ㄦ槸鐢辨暟瀛楁瀯鎴愮殑锛屽垯杞寲涓烘暟瀛楀瀷
- if (this.isAllDigits(val) === true) {
- val = Number(val)
- }
+ const callNow = immediate && !timer;
+ // 濡傛灉瀹氭椂鍣ㄥ凡缁忓瓨鍦紝娓呴櫎瀹�
+ if (timer) {
+ clearTimeout(timer);
+ }
- // 鏄惁鏄瓧绗︿覆绫诲瀷
- if (typeof val === 'string') {
- return val.trim().length === 0;
- }
+ // 璁剧疆涓�涓柊鐨勫畾鏃跺櫒
+ timer = setTimeout(() => {
+ if (!immediate) {
+ func.apply(context, args);
+ }
+ timer = null;
+ }, delay);
- // 鏄惁鏄暟缁�
- if (Array.isArray(val)) {
- return val.length === 0;
- }
+ // 閰嶇疆绔嬪嵆鎵ц
+ if (callNow == true) {
+ func.apply(context, args)
+ }
+ };
+ }
- //鏄惁鏄璞�
- if (typeof val === 'object') {
- return Object.keys(val).length === 0;
- }
+ // 鍒ょ┖鍑芥暟
+ isEmpty(value, zeroIsEmpty = false, falseIsEmpty = false) {
+ let val = value
+ // 妫�鏌ユ槸鍚︿负null 鎴栬�� undefind
+ if (val === null || val === undefined) {
+ return true;
+ }
+ //濡傛灉瀛楃涓插叏閮ㄦ槸鐢辨暟瀛楁瀯鎴愮殑锛屽垯杞寲涓烘暟瀛楀瀷
+ if (this.isAllDigits(val) === true) {
+ val = Number(val)
+ }
- // 鏁板瓧绫诲瀷榛樿涓嶄负绌�
- if (typeof val === 'number') {
- // 鏁板瓧涓�0瑙嗕负绌�
- if (zeroIsEmpty == true) {
- if (val === 0) {
- return true
- }
- }
- return false
- }
+ // 鏄惁鏄瓧绗︿覆绫诲瀷
+ if (typeof val === 'string') {
+ return val.trim().length === 0;
+ }
- // 甯冨皵绫诲瀷榛樿涓嶄负绌�
- if (typeof val === 'boolean') {
- // false鍊艰涓虹┖
- if (falseIsEmpty == true) {
- if (val === 0) {
- return true
- }
- }
- return false;
- }
- }
+ // 鏄惁鏄暟缁�
+ if (Array.isArray(val)) {
+ return val.length === 0;
+ }
- // 鍒ゆ柇鏄惁鍏ㄦ槸鏁板瓧
- isAllDigits(str) {
- return /^\d+$/.test(str);
- }
+ //鏄惁鏄璞�
+ if (typeof val === 'object') {
+ return Object.keys(val).length === 0;
+ }
- // uni-app 浣跨敤 灏佽璇锋眰鍑芥暟 浣跨敤浼犵粺鍑芥暟褰撲綔鍥炶皟闇�瑕佷紶that锛岀澶村嚱鏁颁笉闇�瑕�
- doRequest(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("璁块棶澶辫触鍥炶皟鍑芥暟绫诲瀷涓嶄负鍑芥暟鎴栬�呯┖!")
- }
- }
- })
- setTimeout(() => {
- uni.hideLoading()
- if (errorTip != null) {
- errorTip()
- }
- }, 1000)
- }
+ // 鏁板瓧绫诲瀷榛樿涓嶄负绌�
+ if (typeof val === 'number') {
+ // 鏁板瓧涓�0瑙嗕负绌�
+ if (zeroIsEmpty == true) {
+ if (val === 0) {
+ return true
+ }
+ }
+ return false
+ }
+
+ // 甯冨皵绫诲瀷榛樿涓嶄负绌�
+ if (typeof val === 'boolean') {
+ // false鍊艰涓虹┖
+ if (falseIsEmpty == true) {
+ if (val === 0) {
+ return true
+ }
+ }
+ return false;
+ }
+ }
+
+ // 鍒ゆ柇鏄惁鍏ㄦ槸鏁板瓧
+ isAllDigits(str) {
+ return /^\d+$/.test(str);
+ }
+
+ 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);
+ }
+ }
+ };
+ }
+
+ deepClone(target, map = new WeakMap()) {
+ // 澶勭悊鍘熷鍊煎拰鍑芥暟(typeof 鏁扮粍浼氳繑鍥瀘bject)
+ if (typeof target !== 'object' || target === null) {
+ return target;
+ }
+
+ // 澶勭悊寰幆寮曠敤
+ if (map.has(target)) {
+ return map.get(target);
+ }
+
+ let clone;
+
+ // 澶勭悊鏁扮粍
+ if (Array.isArray(target)) {
+ clone = [];
+ map.set(target, clone);
+ target.forEach((item, index) => {
+ clone[index] = deepClone(item, map);
+ });
+ return clone;
+ }
+
+ // 澶勭悊鏃ユ湡瀵硅薄
+ if (target instanceof Date) {
+ clone = new Date(target.getTime());
+ map.set(target, clone);
+ return clone;
+ }
+
+ // 澶勭悊姝e垯琛ㄨ揪寮�
+ if (target instanceof RegExp) {
+ clone = new RegExp(target);
+ map.set(target, clone);
+ return clone;
+ }
+
+ // 澶勭悊鍑芥暟 (鐩存帴浣跨敤鍑芥暟鐨勫紩鐢�)
+ if (typeof target === 'function') {
+ return target;
+ }
+
+ // 澶勭悊鍏朵粬瀵硅薄锛堟櫘閫氬璞°�佺被瀹炰緥绛夛級
+ clone = Object.create(Object.getPrototypeOf(target));
+ map.set(target, clone);
+
+ // 鑾峰彇鎵�鏈夊睘鎬э紙鍖呮嫭 Symbol 绫诲瀷锛�
+ const allKeys = [...Object.getOwnPropertyNames(target), ...Object.getOwnPropertySymbols(target)];
+
+ allKeys.forEach(key => {
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
+ if (descriptor && descriptor.enumerable) {
+ // 閫掑綊澶嶅埗灞炴�у��
+ clone[key] = deepClone(target[key], map);
+ }
+ });
+
+ return clone;
+ }
+
+ // uni-app 浣跨敤 灏佽璇锋眰鍑芥暟 浣跨敤浼犵粺鍑芥暟褰撲綔鍥炶皟闇�瑕佷紶that锛岀澶村嚱鏁颁笉闇�瑕�
+ doRequest(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)
+ }
+ })
+ }
+
+ 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();
+ if (e == 1) {
+ innerAudioContext.src = '/static/success.wav';
+ } else {
+ 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
+ }
}
-export const CommonUtils = Object.freeze(new commonUtils());
\ No newline at end of file
+export const CommonUtils = new commonUtils()
\ No newline at end of file
--
Gitblit v1.9.1