@hlw-uni/mp-vue 2.2.8 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -410,6 +410,25 @@ var __publicField = (obj, key, value) => {
410
410
  });
411
411
  return current;
412
412
  }
413
+ function destroyRewardAd(adId) {
414
+ var _a;
415
+ const ad = adInstances.get(adId);
416
+ if (ad) {
417
+ try {
418
+ (_a = ad.destroy) == null ? void 0 : _a.call(ad);
419
+ console.log(`[Ad] Rewarded video destroyed: ${adId}`);
420
+ } catch (e) {
421
+ console.error("[Ad] Rewarded video destroy error:", e);
422
+ }
423
+ adInstances.delete(adId);
424
+ }
425
+ if (activeRewardId === adId) {
426
+ activeRewardId = "";
427
+ rewardCallback = void 0;
428
+ rewardResolve = null;
429
+ rewardPromise = null;
430
+ }
431
+ }
413
432
  function confirmRewardAd() {
414
433
  return new Promise((resolve) => {
415
434
  uni.showModal({
@@ -434,7 +453,8 @@ var __publicField = (obj, key, value) => {
434
453
  showPopupAd,
435
454
  setRewardAd,
436
455
  showRewardAd,
437
- confirmRewardAd
456
+ confirmRewardAd,
457
+ destroyRewardAd
438
458
  };
439
459
  }
440
460
  function withQuery(url, qs) {
@@ -1163,6 +1183,7 @@ var __publicField = (obj, key, value) => {
1163
1183
  exports2.confirmRewardAd = confirmRewardAd;
1164
1184
  exports2.copy = copy;
1165
1185
  exports2.cosAdapter = cosAdapter;
1186
+ exports2.destroyRewardAd = destroyRewardAd;
1166
1187
  exports2.download = download;
1167
1188
  exports2.fontFamilyPresets = fontFamilyPresets;
1168
1189
  exports2.fontSizePresets = fontSizePresets;
package/dist/index.mjs CHANGED
@@ -409,6 +409,25 @@ function showRewardAd(onShowSuccess) {
409
409
  });
410
410
  return current;
411
411
  }
412
+ function destroyRewardAd(adId) {
413
+ var _a;
414
+ const ad = adInstances.get(adId);
415
+ if (ad) {
416
+ try {
417
+ (_a = ad.destroy) == null ? void 0 : _a.call(ad);
418
+ console.log(`[Ad] Rewarded video destroyed: ${adId}`);
419
+ } catch (e) {
420
+ console.error("[Ad] Rewarded video destroy error:", e);
421
+ }
422
+ adInstances.delete(adId);
423
+ }
424
+ if (activeRewardId === adId) {
425
+ activeRewardId = "";
426
+ rewardCallback = void 0;
427
+ rewardResolve = null;
428
+ rewardPromise = null;
429
+ }
430
+ }
412
431
  function confirmRewardAd() {
413
432
  return new Promise((resolve) => {
414
433
  uni.showModal({
@@ -433,7 +452,8 @@ function useHlwAd() {
433
452
  showPopupAd,
434
453
  setRewardAd,
435
454
  showRewardAd,
436
- confirmRewardAd
455
+ confirmRewardAd,
456
+ destroyRewardAd
437
457
  };
438
458
  }
439
459
  function withQuery(url, qs) {
@@ -1163,6 +1183,7 @@ export {
1163
1183
  confirmRewardAd,
1164
1184
  copy,
1165
1185
  cosAdapter,
1186
+ destroyRewardAd,
1166
1187
  download,
1167
1188
  fontFamilyPresets,
1168
1189
  fontSizePresets,
@@ -43,6 +43,12 @@ export declare function setRewardAd(adId: string, done?: (res: AdRes) => void):
43
43
  * @returns 返回 Promise<AdRes>,指示广告是否正常播放完毕
44
44
  */
45
45
  export declare function showRewardAd(onShowSuccess?: () => void): Promise<AdRes>;
46
+ /**
47
+ * 销毁指定 Unit ID 的激励视频广告实例,释放内存与原生渲染层绑定并清除缓存。
48
+ *
49
+ * @param adId 广告单元 ID
50
+ */
51
+ export declare function destroyRewardAd(adId: string): void;
46
52
  /**
47
53
  * 弹窗提示需要看完广告才有奖励。
48
54
  * 提供“继续观看”和“取消”按钮。
@@ -58,4 +64,5 @@ export declare function useHlwAd(): {
58
64
  setRewardAd: typeof setRewardAd;
59
65
  showRewardAd: typeof showRewardAd;
60
66
  confirmRewardAd: typeof confirmRewardAd;
67
+ destroyRewardAd: typeof destroyRewardAd;
61
68
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni/mp-vue",
3
- "version": "2.2.8",
3
+ "version": "2.3.0",
4
4
  "description": "hlw-uni 小程序运行时 — Vue 组件 + composables + theme + http + 工具集(合并自原 mp-core)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -5,8 +5,8 @@
5
5
  </template>
6
6
 
7
7
  <script setup lang="ts">
8
- import { ref, onMounted, watch } from "vue";
9
- import { setRewardAd, showRewardAd, confirmRewardAd } from "../../utils/ad";
8
+ import { ref, onMounted, watch, onUnmounted } from "vue";
9
+ import { setRewardAd, showRewardAd, confirmRewardAd, destroyRewardAd } from "../../utils/ad";
10
10
 
11
11
  defineOptions({ name: "HlwRewardAd" });
12
12
 
@@ -18,7 +18,7 @@ interface Props {
18
18
  const props = defineProps<Props>();
19
19
 
20
20
  const emit = defineEmits<{
21
- (e: "onHandle", res: { success: boolean; isEnded: boolean; err?: any }): void;
21
+ (e: "onHandle", res: { success: boolean; isEnded: boolean; loadFailed?: boolean; err?: any }): void;
22
22
  }>();
23
23
 
24
24
  // 点击锁定状态,防止连续多次点击重复触发广告
@@ -84,6 +84,7 @@ async function playRewardAdFlow(): Promise<void> {
84
84
  emit("onHandle", {
85
85
  success: false,
86
86
  isEnded: false,
87
+ loadFailed: true,
87
88
  err: res.err,
88
89
  });
89
90
  } else {
@@ -105,6 +106,7 @@ async function playRewardAdFlow(): Promise<void> {
105
106
  emit("onHandle", {
106
107
  success: false,
107
108
  isEnded: false,
109
+ loadFailed: true,
108
110
  err: e,
109
111
  });
110
112
  }
@@ -146,6 +148,10 @@ defineExpose({
146
148
  }
147
149
  }
148
150
  });
151
+
152
+ onUnmounted(() => {
153
+ destroyRewardAd(props.unitId);
154
+ });
149
155
  </script>
150
156
 
151
157
  <style scoped>
@@ -196,6 +196,30 @@ export function showRewardAd(onShowSuccess?: () => void): Promise<AdRes> {
196
196
  return current;
197
197
  }
198
198
 
199
+ /**
200
+ * 销毁指定 Unit ID 的激励视频广告实例,释放内存与原生渲染层绑定并清除缓存。
201
+ *
202
+ * @param adId 广告单元 ID
203
+ */
204
+ export function destroyRewardAd(adId: string) {
205
+ const ad = adInstances.get(adId);
206
+ if (ad) {
207
+ try {
208
+ ad.destroy?.();
209
+ console.log(`[Ad] Rewarded video destroyed: ${adId}`);
210
+ } catch (e) {
211
+ console.error("[Ad] Rewarded video destroy error:", e);
212
+ }
213
+ adInstances.delete(adId);
214
+ }
215
+ if (activeRewardId === adId) {
216
+ activeRewardId = "";
217
+ rewardCallback = undefined;
218
+ rewardResolve = null;
219
+ rewardPromise = null;
220
+ }
221
+ }
222
+
199
223
  /**
200
224
  * 弹窗提示需要看完广告才有奖励。
201
225
  * 提供“继续观看”和“取消”按钮。
@@ -230,5 +254,6 @@ export function useHlwAd() {
230
254
  setRewardAd,
231
255
  showRewardAd,
232
256
  confirmRewardAd,
257
+ destroyRewardAd,
233
258
  };
234
259
  }