zh 11 месяцев назад
Родитель
Сommit
6e7bcb5321
3 измененных файлов с 226 добавлено и 142 удалено
  1. 0 95
      src/utils/android.ts
  2. 126 0
      src/utils/androidPiece.ts
  3. 100 47
      src/views/piece/dashboard/index.vue

+ 0 - 95
src/utils/android.ts

@@ -103,98 +103,3 @@ export function scanError(){
 
   }
 }
-
-/**
- * 重复扫描语音
- */
-export function scanRepeat(){
-  try {
-    // @ts-ignore
-    window.android.scanRepeatVib()
-  }catch (e){
-
-  }
-}
-/**
- * 获取版本号 - piece
- */
-export function getVersionName() : string {
-  try {
-    // @ts-ignore
-    return window.android.getVersionName()
-  }catch (e){
-    return '版本号获取失败!'
-  }
-}
-/**
- * 保存userId - piece
- */
-export function saveUserId(userId : string) : boolean {
-  try {
-    // @ts-ignore
-    return window.android.saveUserId(userId)
-  }catch (e){
-    return false
-  }
-}
-/**
- * 读取userId - piece
- */
-export function getUserId(): string {
-  try {
-    // @ts-ignore
-    return window.android.getUserId()
-  }catch (e){
-    return ''
-  }
-}
-/**
- * 保存mac地址 - piece
- */
-export function saveMacAddress(mac : string) : boolean {
-  try {
-    // @ts-ignore
-    return window.android.saveMacAddress(mac)
-  }catch (e){
-    return false
-  }
-}
-/**
- * 读取mac地址 - piece
- */
-export function readMacAddress(): string {
-  try {
-    // @ts-ignore
-    return window.android.readMacAddress()
-  }catch (e){
-    return ''
-  }
-}
-/**
- * 分页查询 - piece
- */
-export function pageDelivery(page : number, size : number): any {
-  try {
-    // @ts-ignore
-    const result = window.android.pageDelivery(page, size);
-    return JSON.parse(result)
-  }catch (e){
-    return ''
-  }
-}
-/**
- * 插入数据 - piece
- *
- * @param macAddress mac地址
- * @param deliveryNo 快递单号
- * @param userId 用户id
- */
-export function addDelivery(macAddress : string, deliveryNo : string, userId : string, userName : string): number {
-  try {
-    // @ts-ignore
-    return window.android.addDelivery(macAddress, deliveryNo, userId, userName)
-  }catch (e){
-    return -2
-  }
-}
-

+ 126 - 0
src/utils/androidPiece.ts

@@ -0,0 +1,126 @@
+/**
+ * 重复扫描语音
+ */
+export function scanRepeat(){
+  try {
+    // @ts-ignore
+    window.android.scanRepeatVib()
+  }catch (e){
+
+  }
+}
+/**
+ * 获取版本号 - piece
+ */
+export function getVersionName() : string {
+  try {
+    // @ts-ignore
+    return window.android.getVersionName()
+  }catch (e){
+    return '版本号获取失败!'
+  }
+}
+/**
+ * 检查版本更新 - piece
+ */
+export function checkUpdate() : void {
+  try {
+    // @ts-ignore
+    return window.android.checkUpdate()
+  }catch (e){
+  }
+}
+/**
+ * 保存userId - piece
+ */
+export function saveUserId(userId : string) : boolean {
+  try {
+    // @ts-ignore
+    return window.android.saveUserId(userId)
+  }catch (e){
+    return false
+  }
+}
+/**
+ * 读取userId - piece
+ */
+export function getUserId(): string {
+  try {
+    // @ts-ignore
+    return window.android.getUserId()
+  }catch (e){
+    return ''
+  }
+}
+/**
+ * 更新状态为失败 - piece
+ */
+export function updateDeliveryPushFail(code : string): number {
+  try {
+    // @ts-ignore
+    return window.android.updateDeliveryPushFail(code)
+  }catch (e){
+    return -1
+  }
+}
+/**
+ * 更新状态为成功 - piece
+ */
+export function markAsPushed(code : string): number {
+  try {
+    // @ts-ignore
+    return window.android.markAsPushed(code)
+  }catch (e){
+    return -1
+  }
+}
+/**
+ * 保存mac地址 - piece
+ */
+export function saveMacAddress(mac : string) : boolean {
+  try {
+    // @ts-ignore
+    return window.android.saveMacAddress(mac)
+  }catch (e){
+    return false
+  }
+}
+/**
+ * 读取mac地址 - piece
+ */
+export function readMacAddress(): string {
+  try {
+    // @ts-ignore
+    return window.android.readMacAddress()
+  }catch (e){
+    return ''
+  }
+}
+/**
+ * 分页查询 - piece
+ */
+export function pageDelivery(page : number, size : number): any {
+  try {
+    // @ts-ignore
+    const result = window.android.pageDelivery(page, size);
+    return JSON.parse(result)
+  }catch (e){
+    return ''
+  }
+}
+/**
+ * 插入数据 - piece
+ *
+ * @param macAddress mac地址
+ * @param deliveryNo 快递单号
+ * @param userId 用户id
+ */
+export function addDelivery(macAddress : string, deliveryNo : string, userId : string, userName : string): number {
+  try {
+    // @ts-ignore
+    return window.android.addDelivery(macAddress, deliveryNo, userId, userName)
+  }catch (e){
+    return -2
+  }
+}
+

+ 100 - 47
src/views/piece/dashboard/index.vue

@@ -21,6 +21,7 @@
           <div class="col time">时间</div>
           <div class="col operator">操作人</div>
           <div class="col content">操作内容</div>
+          <div class="col status">操作状态</div>
         </div>
 
         <!-- 表格主体 -->
@@ -39,57 +40,65 @@
             <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>
           </div>
         </van-list>
       </div>
     </van-col>
   </van-row>
   <van-button class="add" icon="setting-o" type="primary" @click="_openSetting" />
-  <van-dialog
-    v-model:show="setting.show"
-    title="设置"
-    class="setting-dialog"
-    show-cancel-button
-    :before-close="_verifyMac"
-    @confirm="_saveMac"
-    @closed="_closeSetting"
-    width="380px">
-
-    <van-notice-bar
-      wrapable
-      left-icon="volume-o"
-      :scrollable="false"
-      :text="hintMessage"
-    />
-
-    <van-cell-group inset>
-      <van-field
-        v-model="setting.mac"
-        label="MAC地址"
-        placeholder="请输入MAC地址"
+  <van-sticky>
+    <van-dialog
+      v-model:show="setting.show"
+      title="设置"
+      class="setting-dialog"
+      show-cancel-button
+      :before-close="_verifyMac"
+      @confirm="_saveMac"
+      @closed="_closeSetting"
+      width="380px">
+
+      <van-notice-bar
+        wrapable
+        left-icon="volume-o"
+        :scrollable="false"
+        :text="hintMessage"
       />
-      <van-field
-        v-model="setting.password"
-        type="password"
-        label="密码"
-        placeholder="设置密码"
-      />
-    </van-cell-group>
 
-    <van-notice-bar color="#1989fa" background="#ecf9ff" style="font-size: 16px; padding-left: 10px" left-icon="info-o">
-      {{ versionName }}
-    </van-notice-bar>
-  </van-dialog>
+      <van-cell-group inset>
+        <van-field
+          v-model="setting.mac"
+          label="MAC地址"
+          placeholder="请输入MAC地址"
+        />
+        <van-field
+          v-model="setting.password"
+          type="password"
+          label="密码"
+          placeholder="设置密码"
+        />
+      </van-cell-group>
+
+      <van-notice-bar color="#1989fa" background="#ecf9ff" @click="checkUpdate"
+                      style="font-size: 16px; padding-left: 10px" left-icon="info-o">
+        {{ versionName }} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(点击检查更新)
+      </van-notice-bar>
+    </van-dialog>
+  </van-sticky>
 </template>
 
 <script setup>
 import { onMounted, onUnmounted, ref } from 'vue'
 import { closeListener, openListener, scanInit } from '@/utils/keydownListener'
-import { getVersionName, saveUserId, getUserId, scanSuccess, scanError, scanRepeat, saveMacAddress, readMacAddress, pageDelivery, addDelivery } from '@/utils/android'
+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 { getUserIdByCert, getUserNameById } from '@/api/login/index.ts'
-import { receive } from '@/api/scan/index.ts'
-import { formatDateTime } from '@/utils/date.ts'
+import { getUserIdByCert, getUserNameById } from '@/api/login/index'
+import { receive } from '@/api/scan/index'
+import { formatDateTime } from '@/utils/date'
 
 // 在输入对话框或界面中添加提示文本
 const hintMessage = ref(`请前往:设置 → 关于平板电脑 → 设备WLAN MAC 地址 长按复制并粘贴到此处。`);
@@ -116,12 +125,13 @@ onMounted(() => {
   mac.value = readMacAddress()
   const userId = getUserId()
   if (userId) {
-    _handlerScan(userId)
+    userInfo.value.userId = userId
+    getUserName(userId)
   }
   if (mac.value) {
     _openScan()
   } else {
-    setting.value.show =  true
+    _openSetting()
   }
   // ip
   fetchIP()
@@ -136,6 +146,7 @@ const _openScan = () => {
 }
 const _handlerScan = (code) => {
   console.log(code)
+  code = fixDuplicateText(code)
   // 校验扫描的是否为登录二维码
   const regex = /\{"sign":"([^"]*)",\s*"identity":(\d+)\}/;
   if (code !== null && regex.test(code)) {
@@ -146,13 +157,7 @@ const _handlerScan = (code) => {
     getUserIdByCert({sign: sign, identity: identity}).then(res => {
       if (res && res.data) {
         userInfo.value.userId = res.data
-        getUserNameById(res.data).then(res => {
-          if (res && res.data) {
-            saveUserId(userInfo.value.userId)
-            userInfo.value.name = res.data
-            showNotify({ type: 'success', style: 'font-size: 30px !important;height:50px', message: '登录成功!' });
-          }
-        })
+        getUserName(res.data)
       } else {
         showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: '登录失败!' });
       }
@@ -194,7 +199,7 @@ const _handlerScan = (code) => {
       return
     }
     message.value = ''
-    const dto = { deliveryNo: code, machine: mac.value, operator: userInfo.value.userId, operationTime: currentTime, operatorName: userInfo.value.name }
+    const dto = { deliveryNo: code, machine: mac.value, operator: userInfo.value.userId, operationTime: currentTime, operatorName: userInfo.value.name, isPush: true }
     receive(dto).then(res => {
       console.log(res)
       scanSuccess()
@@ -203,11 +208,53 @@ const _handlerScan = (code) => {
     }).catch(err => {
       console.log(err)
       scanError()
+      updateDeliveryPushFail(code)
+      dto.isPush = false
+      list.value.unshift(dto)
       showNotify({ type: 'danger', style: 'font-size: 30px !important;height:50px', message: `扫描失败!${err.message}` });
     })
   }
 }
 
+function fixDuplicateText(input) {
+  // 改进版正则表达式(支持任意字符且精确匹配完全重复)
+  const regex = /^(.+?)\1$/; // 非贪婪模式防止误匹配
+  const match = input.match(regex);
+  // 返回处理逻辑
+  return match ? match[1] : input;
+}
+
+
+const _rePush = (item) => {
+  if (!item || item.isPush) {
+    return
+  }
+  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 getUserName = (userId) => {
+  getUserNameById(userId).then(res => {
+    if (res && res.data) {
+      saveUserId(userInfo.value.userId)
+      userInfo.value.name = res.data
+      showNotify({ type: 'success', style: 'font-size: 30px !important;height:50px', message: '登录成功!' });
+    }
+  })
+}
+
 const versionName = ref('')
 const _openSetting = () => {
   closeListener()
@@ -281,6 +328,8 @@ const onLoad = () => {
   const result = pageDelivery(page.value, size.value)
   if (result.size < size.value) {
     finished.value = true;
+  } else {
+    page.value += 1
   }
   list.value.push(...result)
   loading.value = false;
@@ -371,6 +420,10 @@ span
   min-width: 0 /* 允许内容换行 */
   white-space: normal /* 允许换行 */
 
+.status
+  flex: 0 0 50px
+  width: 50px
+
 /* 确保表体中的单元格与表头对齐 */
 :deep(.van-list)
   .van-cell