Bladeren bron

修复扫货成功列表序号重复问题,优化排序逻辑

wuzilong 6 maanden geleden
bovenliggende
commit
a97c94214e
2 gewijzigde bestanden met toevoegingen van 15 en 3 verwijderingen
  1. 14 2
      client-tauri/src/views/BuffSelectionView.vue
  2. 1 1
      client-tauri/src/views/HomeView.vue

+ 14 - 2
client-tauri/src/views/BuffSelectionView.vue

@@ -1718,7 +1718,15 @@ function getSelectionItemId(record: any): number | null {
 }
 
 function sweepRowKey(record: any) {
-  if (record?.id != null) return record.id
+  // 优先使用 listing_id 作为唯一行键(每个购买记录的唯一标识)
+  if (record?.listing_id) {
+    return record.listing_id
+  }
+  // 其次使用 selection_item_id + created_at 组合(选品ID + 购买时间)
+  if (record?.selection_item_id && record?.created_at) {
+    return `${record.selection_item_id}-${record.created_at}`
+  }
+  // 兜底方案:使用 goods_id + created_at + purchase_price_usd
   if (record?.goods_id) {
     return `${record.goods_id}-${record.created_at ?? ''}-${record.purchase_price_usd ?? ''}`
   }
@@ -2682,9 +2690,13 @@ async function fetchSweepResult(showLoading = false): Promise<string | null> {
     if (res.code === 200 && res.data) {
       const nextItemsRaw = Array.isArray(res.data.items) ? res.data.items : []
       const nextItems = [...nextItemsRaw].sort((a: any, b: any) => {
+        // 主要排序:按 created_at 时间倒序(最新在前)
         const byTime = parseLogTimestamp(b?.created_at) - parseLogTimestamp(a?.created_at)
         if (byTime !== 0) return byTime
-        return Number(b?.id ?? 0) - Number(a?.id ?? 0)
+        // 次要排序:按 listing_id 倒序(字符串比较,保持顺序一致性)
+        const idA = a?.listing_id ?? ''
+        const idB = b?.listing_id ?? ''
+        return idB.localeCompare(idA)
       })
       // 与选品列表一致:每次拉取后整体替换,轮询时 showLoading=false,表格无整表 loading 闪烁。
       // 限制数组大小,防止内存泄漏

+ 1 - 1
client-tauri/src/views/HomeView.vue

@@ -66,7 +66,7 @@
               </a-menu-item>
               <a-menu-divider />
               <a-menu-item key="version" disabled style="color: #999; cursor: default;">
-                <span style="font-size: 12px;">版本 V1.0.3.B</span>
+                <span style="font-size: 12px;">版本 V1.0.4.B</span>
               </a-menu-item>
               <a-menu-item key="logout">
                 <LogoutOutlined /> 退出登录