Kaynağa Gözat

fix(mallApp): 修复结算页图片事件与红包重复请求

- 避免懒加载图片事件名与 uni-app 生命周期冲突,恢复加载与失败回退处理
- 按门店去重可用红包请求,并在请求失败后允许重新拉取
shizhongqi 1 gün önce
ebeveyn
işleme
52fa3ea658

+ 12 - 6
mallApp/src/components/app-lazy-img.vue

@@ -20,8 +20,8 @@
     :src="displaySrc"
     :mode="mode"
     lazy-load
-    @error="onError"
-    @load="onLoad"
+    @error="handleImageError"
+    @load="handleImageLoad"
   />
 </template>
 
@@ -144,17 +144,23 @@ export default {
       }
     },
     /**
-     * 缩略图加载失败时先回退到不带 OSS 参数的原图,仍失败才向外抛
-     * 只回退一次,避免同一张图反复重试
+     * 缩略图加载失败时先回退到不带 OSS 参数的原图,仍失败才向外抛。
+     * 只回退一次,避免同一张图反复重试。
+     * 方法名不能叫 onError:那是 uni-app 应用级生命周期,编译后不会进组件 methods。
      */
-    onError(e) {
+    handleImageError(e) {
       if (!this.fallback && this.thumbWidth > 0) {
         this.fallback = true
         return
       }
       this.$emit('error', e)
     },
-    onLoad(e) {
+    /**
+     * 图片解码成功后把原生 load 事件转发出去,供轮播等调用方监听。
+     * 方法名不能叫 onLoad:那是页面生命周期,编译器会抽走,模板再绑就会报
+     * Component does not have a method "onLoad"。
+     */
+    handleImageLoad(e) {
       this.$emit('load', e)
     }
   }

+ 19 - 5
mallApp/src/pages/billing/affirmMix.vue

@@ -580,6 +580,8 @@ export default {
 			deliveryPolicyList: [],
 			validAddress: false,
 			hbData: [],
+			/** 已发起过可用红包请求的门店 id,避免 onShow/getInfo/currentInfo 各打一次 */
+			hbDataRequestedShopId: null,
 			selectedHbId: null,
 			selectedHb: null,
 			limitExceedProductId: "",
@@ -624,10 +626,6 @@ export default {
 		this.loadShopInfo();
 		this.loadSelectedAddress();
 		// 附加费在 loadPsMethods 中与配送方式一并批量返回
-		// 商品金额变化后刷新红包可用性(对齐 affirmGhs onShow)
-		if (this.shopInfo && this.shopInfo.id) {
-			this.getHbData();
-		}
 	},
 	watch: {
 		/** 商品总价变化时,剔除红包并批量刷新附加费缓存(不随购买方式切换重复请求) */
@@ -1308,6 +1306,8 @@ export default {
 			if (cached && typeof cached === "object") {
 				this.mergePickupShopInfo(cached);
 			}
+			// 缓存已有门店 id 时立即拉红包;getInfo/currentInfo 稍后若 id 相同会被拦住
+			this.getHbData();
 
 			getInfo({ hdId }).then((res) => {
 				if (res.code == 1 && res.data) {
@@ -2340,15 +2340,29 @@ export default {
 			}
 			return String(item.id) === String(this.limitExceedProductId);
 		},
+		/**
+		 * 拉取当前门店可用红包列表。
+		 * 同一 shopId 只请求一次:进页时缓存/getInfo/currentInfo 都可能拿到门店信息,
+		 * 若不拦截会连打三次 /hb/available-hb;失败时清标记以便重试。
+		 */
 		getHbData() {
 			if (!this.shopInfo || !this.shopInfo.id) {
 				return;
 			}
-			getAvailableHb({ shopId: this.shopInfo.id }).then((res) => {
+			const shopId = this.shopInfo.id;
+			if (this.hbDataRequestedShopId === shopId) {
+				return;
+			}
+			this.hbDataRequestedShopId = shopId;
+			getAvailableHb({ shopId }).then((res) => {
 				if (res.code == 1) {
 					this.hbData = res.data || [];
 					this.syncSelectedHbAfterPriceChange();
+					return;
 				}
+				this.hbDataRequestedShopId = null;
+			}).catch(() => {
+				this.hbDataRequestedShopId = null;
 			});
 		}
 	}