Browse Source

图片更新

wangxy 1 tuần trước cách đây
mục cha
commit
1702148dad
3 tập tin đã thay đổi với 76 bổ sung31 xóa
  1. 24 15
      pages/admin/Hetong/Hetong.vue
  2. 24 16
      pages/admin/Hetong/HetongInfo.vue
  3. 28 0
      utils/common.js

+ 24 - 15
pages/admin/Hetong/Hetong.vue

@@ -40,6 +40,7 @@
 		onLoad
 	} from "@dcloudio/uni-app"
 	import writeSign from "@/components/writeSign/index.vue"
+  import {throttleAdvanced} from "@/utils/common.js"
 
 	const pdfUrl1 = ref('');
 	const info = ref({})
@@ -78,6 +79,28 @@
 		popupRef.value.open()
 	}
 
+  const  handleQM = throttleAdvanced((img) => {
+    uni.showToast({
+      title: "签名提交中..."
+    })
+
+    httpApi.getHetongQianming({
+      id: info.value.id,
+      fuzeren: img.replace(/^data:image\/\w+;base64,/, '')
+    }).then(res => {
+      if (res.data) {
+        uni.showToast({
+          title: "签名成功",
+          duration: 2000,
+          mask: true,
+          success() {
+            setTimeout(() => uni.navigateBack(),2000)
+          }
+        })
+      }
+    })
+  }, 5000)
+
 	function getBase64(img) {
 		if (!img) {
 			uni.showToast({
@@ -85,21 +108,7 @@
 			})
 			return;
 		}
-		httpApi.getHetongQianming({
-			id: info.value.id,
-			fuzeren: img.replace(/^data:image\/\w+;base64,/, '')
-		}).then(res => {
-			if (res.data) {
-				uni.showToast({
-					title: "签名成功",
-          duration: 2000,
-          mask: true,
-					success() {
-            setTimeout(() => uni.navigateBack(),2000)
-					}
-				})
-			}
-		})
+    handleQM(img)
 	}
 
 	function goback2() {

+ 24 - 16
pages/admin/Hetong/HetongInfo.vue

@@ -36,6 +36,7 @@ import {
   onLoad
 } from "@dcloudio/uni-app"
 import writeSign from "@/components/writeSign/index.vue"
+import {throttleAdvanced} from "@/utils/common.js"
 
 const tId = ref(null)
 const pdfUrl1 = ref(null)
@@ -64,6 +65,28 @@ function goUpPage() {
   uni.navigateBack()
 }
 
+const  handleQM = throttleAdvanced((img) => {
+  uni.showToast({
+    title: "签名提交中..."
+  })
+
+  httpApi.getHetongQianming({
+    id: tId.value,
+    fuzeren: img.replace(/^data:image\/\w+;base64,/,'')
+  }).then(res => {
+    if (res.data) {
+      uni.showToast({
+        title: "签名成功",
+        duration: 2000,
+        mask: true,
+        success() {
+          setTimeout(() => goUpPage(),2000)
+        }
+      })
+    }
+  })
+})
+
 function getBase64(img) {
 	if (!img) {
 		uni.showToast({
@@ -71,23 +94,8 @@ function getBase64(img) {
 		})
 		return;
 	}
-	
-	httpApi.getHetongQianming({
-		id: tId.value,
-		fuzeren: img.replace(/^data:image\/\w+;base64,/,'')
-	}).then(res => {
-		if (res.data) {
-			uni.showToast({
-				title: "签名成功",
-				duration: 2000,
-        mask: true,
-				success() {
-          setTimeout(() => goUpPage(),2000)
+  handleQM(img)
 
-				}
-			})
-		}
-	})
 }
 
 

+ 28 - 0
utils/common.js

@@ -169,3 +169,31 @@ export function jsonp2(url, params, callbackName = 'jsonp_callback') {
       document.body.appendChild(script);
     });
 }
+
+
+export function throttleAdvanced(fn, delay) {
+    let timer = null;
+    let lastExecTime = 0;
+
+    return function(...args) {
+        const context = this;
+        const now = Date.now();
+        const remaining = delay - (now - lastExecTime); // 计算剩余时间
+
+        // 清除计划中的下一次执行(如果有)
+        clearTimeout(timer);
+
+        if (remaining <= 0) {
+            // 剩余时间已到,立即执行
+            fn.apply(context, args);
+            lastExecTime = now;
+        } else {
+            // 否则,设置一个定时器,确保在剩余时间结束后还会执行一次
+            timer = setTimeout(() => {
+                fn.apply(context, args);
+                lastExecTime = Date.now();
+                timer = null;
+            }, remaining);
+        }
+    };
+}