zh 10 месяцев назад
Родитель
Сommit
910f725292
1 измененных файлов с 68 добавлено и 21 удалено
  1. 68 21
      src/views/piece/dashboard/index.vue

+ 68 - 21
src/views/piece/dashboard/index.vue

@@ -40,8 +40,10 @@
             <div class="col time">{{ item.operationTime }}</div>
             <div class="col operator">{{ item.operatorName }}</div>
             <div class="col content">{{ item.deliveryNo }}</div>
-            <div class="col status" :style="{ color: item.isPush ? '#333' : '#FF0202FF'}" @click="_rePush(item)">
-              {{ item.isPush ? '已上传' : '上传失败' }}
+            <div class="col status"
+                 :style="{ color: item.isPush === 0 ? '#333' : item.isPush === 1 ? '#67C23A' : '#F56C6C' }"
+                 @click="_rePush(item)">
+              {{ item.isPush === 0 ? '待上传' : item.isPush === 1 ? '上传成功' : '上传失败' }}
             </div>
           </div>
         </van-list>
@@ -199,17 +201,19 @@ const _handlerScan = (code) => {
       return
     }
     message.value = ''
-    const dto = { deliveryNo: code, machine: mac.value, operator: userInfo.value.userId, operationTime: currentTime, operatorName: userInfo.value.name, isPush: true }
+    const dto = { deliveryNo: code, machine: mac.value, operator: userInfo.value.userId, operationTime: currentTime, operatorName: userInfo.value.name, isPush: 0 }
     receive(dto).then(res => {
       console.log(res)
+      dto.isPush = 1
       scanSuccess()
+      markAsPushed(code);
       list.value.unshift(dto)
       showNotify({ type: 'success', style: 'font-size: 30px !important;height:50px', message: '扫描成功!' });
     }).catch(err => {
       console.log(err)
+      dto.isPush = 2
       scanError()
       updateDeliveryPushFail(code)
-      dto.isPush = false
       list.value.unshift(dto)
       showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: `扫描失败!${err.message}` });
     })
@@ -225,25 +229,67 @@ function fixDuplicateText(input) {
 }
 
 
+// 在外部定义一个防抖函数映射表,用于跟踪每个单据的防抖状态
+const debounceMap = new Map();
+
+// 防抖函数封装
+const debounce = (func, wait = 500) => {
+  let timer;
+  return (...args) => {
+    clearTimeout(timer);
+    timer = setTimeout(() => {
+      func.apply(this, args);
+    }, wait);
+  };
+};
+
+// 修改后的推送函数
 const _rePush = (item) => {
-  if (!item || item.isPush) {
-    return
+  if (!item || item.isPush === 1) return;
+
+  // 初始化当前单据的防抖状态
+  if (!debounceMap.has(item.deliveryNo)) {
+    debounceMap.set(item.deliveryNo, {
+      isPushing: false,  // 请求状态锁
+      debouncedFn: debounce(() => {
+        const entry = debounceMap.get(item.deliveryNo);
+        if (!entry || entry.isPushing) return;
+
+        entry.isPushing = true;  // 加锁
+
+        const dto = {
+          deliveryNo: item.deliveryNo,
+          machine: item.machine,
+          operator: item.operator,
+          operationTime: item.operationTime
+        };
+
+        receive(dto).then(res => {
+          const result = markAsPushed(item.deliveryNo);
+          entry.isPushing = false;  // 请求完成解锁
+          item.isPush = 1;
+          showNotify({
+            type: 'success',
+            style: 'font-size: 30px !important;height:50px',
+            message: '推送成功!'
+          });
+        }).catch(err => {
+          entry.isPushing = false;  // 请求失败解锁
+          scanError();
+          showNotify({
+            type: 'danger',
+            style: 'font-size: 30px !important;height:50px',
+            message: `扫描失败!${err.message}`
+          });
+        });
+      }, 500)  // 500ms防抖时间
+    });
   }
-  const dto = { deliveryNo: item.deliveryNo, machine: item.machine, operator: item.operator, operationTime: item.operationTime }
-  receive(dto).then(res => {
-    const result = markAsPushed(item.deliveryNo)
-    console.log(result)
-    if (result === 1) {
-      item.isPush = true
-      showNotify({ type: 'success', style: 'font-size: 30px !important;height:50px', message: '推送成功!' });
-    } else {
-      showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: '推送失败!' });
-    }
-  }).catch(err => {
-    scanError()
-    showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: `扫描失败!${err.message}` });
-  })
-}
+
+  // 执行防抖函数
+  const { debouncedFn } = debounceMap.get(item.deliveryNo);
+  debouncedFn();
+};
 
 const getUserName = (userId) => {
   getUserNameById(userId).then(res => {
@@ -262,6 +308,7 @@ const _openSetting = () => {
   versionName.value = "版本号:" + getVersionName()
 }
 
+
 // 校验mac地址是否已配置
 const _verifyMac = (done) => {
   if (!mac.value) {