zh 10 месяцев назад
Родитель
Сommit
330c70e46c
2 измененных файлов с 119 добавлено и 5 удалено
  1. 22 0
      src/utils/androidPiece.ts
  2. 97 5
      src/views/piece/dashboard/index.vue

+ 22 - 0
src/utils/androidPiece.ts

@@ -52,6 +52,28 @@ export function getUserId(): string {
     return ''
   }
 }
+/**
+ * 获取异常的数量 - piece
+ */
+export function getErrRecordsCount(): number {
+  try {
+    // @ts-ignore
+    return window.android.getErrRecordsCount()
+  }catch (e){
+    return 0
+  }
+}
+/**
+ * 获取异常的数据 - piece
+ */
+export function listErrRecords(): string {
+  try {
+    // @ts-ignore
+    return window.android.listErrRecords()
+  }catch (e){
+    return ''
+  }
+}
 /**
  * 更新状态为失败 - piece
  */

+ 97 - 5
src/views/piece/dashboard/index.vue

@@ -22,6 +22,14 @@
         <van-col span="24"><span>IP:</span> {{ ipAddress || '获取中...' }}</van-col>
         <van-col span="24"><span>MAC:</span> {{ mac }}</van-col>
       </van-row>
+      <van-row justify="center" :gutter="[0, 23]" style="margin-top: 23px">
+        <van-col span="24">
+          错误数量:<span style="color: red">{{ errNum }}</span>
+        </van-col>
+        <van-col span="24">
+          <van-button style="width: 100px" v-if="errNum > 0" plain :loading="isOnePush" :disabled="isOnePush" loading-text="加载中..." type="danger" @click="_one_click_push">一键重传</van-button>
+        </van-col>
+      </van-row>
     </van-col>
     <van-col span="18" class="table-container">
       <van-cell-group class="custom-cell-group">
@@ -116,9 +124,9 @@
 import { onMounted, onUnmounted, ref, watch } from 'vue'
 import { closeListener, openListener, scanInit } from '@/utils/keydownListener'
 import { scanSuccess, scanError } from '@/utils/android'
-import { getVersionName, checkUpdate, saveUserId, getUserId, scanRepeat, saveMacAddress,
-  readMacAddress, pageDelivery, addDelivery, updateDeliveryPushFail, markAsPushed } from '@/utils/androidPiece'
-import { showNotify } from 'vant'
+import { getVersionName, checkUpdate, saveUserId, getUserId, scanRepeat, saveMacAddress, listErrRecords,
+   readMacAddress, pageDelivery, addDelivery, updateDeliveryPushFail, markAsPushed, getErrRecordsCount } from '@/utils/androidPiece'
+import { showLoadingToast, showNotify } from 'vant'
 import { getUserIdByCert, getUserNameById } from '@/api/login/index'
 import { receive } from '@/api/scan/index'
 import { formatDateTime } from '@/utils/date'
@@ -139,6 +147,7 @@ const message = ref('')
 const list = ref([])
 const loading = ref(false)
 const finished = ref(false)
+const errNum = ref(0)
 
 
 const isOnline = ref(navigator.onLine)
@@ -193,6 +202,8 @@ onMounted(() => {
   }
   // ip
   fetchIP()
+  // err数量
+  errNum.value = getErrNum()
 })
 
 
@@ -271,6 +282,7 @@ const _handlerScan = (code) => {
       scanError()
       updateDeliveryPushFail(code)
       list.value.unshift(dto)
+      errNum.value += 1
       showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: `扫描失败!${err.message}` });
     })
   }
@@ -302,7 +314,12 @@ const debounce = (func, wait = 500) => {
 // 修改后的推送函数
 const _rePush = (item) => {
   if (!item || item.isPush === 1) return;
-
+  let status = false
+  showLoadingToast({
+    message: '上传中...',
+    forbidClick: true,
+    closeToast: status
+  });
   // 初始化当前单据的防抖状态
   if (!debounceMap.has(item.deliveryNo)) {
     debounceMap.set(item.deliveryNo, {
@@ -325,6 +342,8 @@ const _rePush = (item) => {
           entry.isPushing = false;  // 请求完成解锁
           item.isPush = 1;
           scanSuccess();
+          status = true
+          errNum.value -= 1
           showNotify({
             type: 'success',
             style: 'font-size: 30px !important;height:50px',
@@ -333,10 +352,11 @@ const _rePush = (item) => {
         }).catch(err => {
           entry.isPushing = false;  // 请求失败解锁
           scanError();
+          status = true
           showNotify({
             type: 'danger',
             style: 'font-size: 30px !important;height:50px',
-            message: `扫描失败!${err.message}`
+            message: `推单失败!${err.message}`
           });
         });
       }, 500)  // 500ms防抖时间
@@ -425,6 +445,10 @@ const fetchIP = async () => {
   }
 }
 
+const getErrNum = () => {
+  return getErrRecordsCount()
+}
+
 const page = ref(1)
 const size = ref(10)
 // 模拟数据加载
@@ -453,6 +477,74 @@ const onRefresh = () => {
   page.value = 1
   onLoad();
 };
+const isOnePush = ref(false)
+const _one_click_push = () => {
+  isOnePush.value = true
+  const result = listErrRecords()
+  if (result && result != '[]') {
+    const records = JSON.parse(result);
+    const promises = []; // 收集所有请求的Promise
+
+    records.forEach(item => {
+      // 初始化当前单据的防抖状态
+      if (!debounceMap.has(item.deliveryNo)) {
+        const debounceEntry = {
+          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
+            };
+
+            // 将请求包装成Promise并收集
+            const promise = receive(dto)
+              .then(res => {
+                const result = markAsPushed(item.deliveryNo);
+                list.value.filter(entry => entry.deliveryNo === item.deliveryNo).forEach(entry => {
+                  entry.isPush = 1;
+                })
+                errNum.value -= 1
+              })
+              .finally(() => {
+                entry.isPushing = false; // 无论成功失败都解锁
+              });
+
+            promises.push(promise); // 添加到Promise数组
+            return promise;
+          }, 500)
+        };
+        debounceMap.set(item.deliveryNo, debounceEntry);
+      }
+
+      // 立即执行防抖函数并收集Promise
+      const promise = debounceMap.get(item.deliveryNo).debouncedFn();
+      if (promise) promises.push(promise);
+    });
+
+    // 所有请求完成后重置状态
+    Promise.allSettled(promises)
+      .then(_ => {
+        scanSuccess();
+        showNotify({ type: 'success', style: 'font-size: 30px !important;height:50px', message: '数据已推送!' });
+      })
+      .catch(_ => {
+        scanError();
+        showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: '存在数据推送失败!' });
+      }).finally(() => {
+      isOnePush.value = false;
+    });
+  } else {
+    showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: '暂无异常数据!' });
+    isOnePush.value = false; // 没有数据时立即重置
+  }
+}
 </script>
 
 <style scoped lang="sass">