Explorar el Código

fix(cjx): 修复抽幸运卡合成卡牌时的数据处理问题

- 在处理 totalDetail 数据时,增加了对 cards 数组长度的检查
- 仅在 cards 数组存在对应索引时,才进行数据赋值操作
- 优化了代码结构,提高了代码的可读性和稳定性
mws hace 4 meses
padre
commit
a924c79d62
Se han modificado 1 ficheros con 18 adiciones y 16 borrados
  1. 18 16
      pages/cjx/index/index.vue

+ 18 - 16
pages/cjx/index/index.vue

@@ -438,22 +438,24 @@
 					// 处理数据逻辑
 					that.totalDetail.splice(idx, 0, this.prizeJson);
 					that.saveData.index = idx;
-
-					for (let i = 0; i < that.totalDetail.length; i++) {
-						that.saveData['card' + i] = that.totalDetail[i];
-
-						that.cards[i].prizeType = that.totalDetail[i].prize_type == undefined ?
-							that.totalDetail[i].prizeType :
-							that.totalDetail[i].prize_type;
-						that.cards[i].img = that.totalDetail[i].img;
-
-						that.cards[i].price = that.totalDetail[i].price;
-						that.cards[i].money = that.totalDetail[i].money;
-						that.cards[i].point = that.totalDetail[i].point;
-						that.cards[i].prizeName = that.totalDetail[i].prizeName == undefined ?
-							that.totalDetail[i].prize_name :
-							that.totalDetail[i].prizeName;
-					}
+// 修改这段代码,添加数组长度检查
+          for (let i = 0; i < that.totalDetail.length; i++) {
+            // 确保 cards 数组在索引 i 处有元素
+            if (that.cards[i]) {
+              that.saveData['card' + i] = that.totalDetail[i];
+
+              that.cards[i].prizeType = that.totalDetail[i].prize_type == undefined ?
+                  that.totalDetail[i].prizeType :
+                  that.totalDetail[i].prize_type;
+              that.cards[i].img = that.totalDetail[i].img;
+              that.cards[i].price = that.totalDetail[i].price;
+              that.cards[i].money = that.totalDetail[i].money;
+              that.cards[i].point = that.totalDetail[i].point;
+              that.cards[i].prizeName = that.totalDetail[i].prizeName == undefined ?
+                  that.totalDetail[i].prize_name :
+                  that.totalDetail[i].prizeName;
+            }
+          }
 
 					that.saveAllCardData();
 				}, 100);