@hlw-uni/mp-vue 2.3.1 → 2.3.2
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hlw-uni/mp-vue",
|
|
3
|
-
"version": "2.3.
|
|
4
|
-
"description": "hlw-uni
|
|
3
|
+
"version": "2.3.2",
|
|
4
|
+
"description": "hlw-uni工具集",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
|
-
import { ref,
|
|
8
|
+
import { ref, onUnmounted } from "vue";
|
|
9
9
|
import { setRewardAd, showRewardAd, confirmRewardAd, destroyRewardAd } from "../../utils/ad";
|
|
10
10
|
|
|
11
11
|
defineOptions({ name: "HlwRewardAd" });
|
|
@@ -24,30 +24,6 @@ const emit = defineEmits<{
|
|
|
24
24
|
// 点击锁定状态,防止连续多次点击重复触发广告
|
|
25
25
|
const isClicked = ref(false);
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* 提前初始化并静默加载广告实例的辅助方法。
|
|
29
|
-
*/
|
|
30
|
-
function preloadAd(id: string) {
|
|
31
|
-
if (!id) return;
|
|
32
|
-
// 异步静默加载,不使用 await 阻塞组件渲染或生命周期
|
|
33
|
-
setRewardAd(id).catch((err) => {
|
|
34
|
-
console.warn("[HlwRewardAd] Preload error:", err);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 组件挂载时,提前执行激励视频广告的初始化与加载
|
|
39
|
-
onMounted(() => {
|
|
40
|
-
preloadAd(props.unitId);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// 监听 unitId 的变化,确保广告单元 ID 动态改变时能够重新静默加载
|
|
44
|
-
watch(
|
|
45
|
-
() => props.unitId,
|
|
46
|
-
(newId) => {
|
|
47
|
-
preloadAd(newId);
|
|
48
|
-
},
|
|
49
|
-
);
|
|
50
|
-
|
|
51
27
|
async function playRewardAdFlow(): Promise<void> {
|
|
52
28
|
// 弹出全局模态 Loading 状态
|
|
53
29
|
let hidden = false;
|
|
@@ -75,6 +51,9 @@ async function playRewardAdFlow(): Promise<void> {
|
|
|
75
51
|
// 播放流结束后(不管成功或退出),立刻关闭 Loading 状态
|
|
76
52
|
hide();
|
|
77
53
|
|
|
54
|
+
// 播放结束后,立即清理本地缓存引用,以防状态重叠
|
|
55
|
+
destroyRewardAd(props.unitId);
|
|
56
|
+
|
|
78
57
|
if (res.success && res.isEnded) {
|
|
79
58
|
emit("onHandle", {
|
|
80
59
|
success: true,
|
|
@@ -102,6 +81,7 @@ async function playRewardAdFlow(): Promise<void> {
|
|
|
102
81
|
}
|
|
103
82
|
} catch (e) {
|
|
104
83
|
hide();
|
|
84
|
+
destroyRewardAd(props.unitId);
|
|
105
85
|
console.error("[HlwRewardAd] Failed to show reward ad:", e);
|
|
106
86
|
emit("onHandle", {
|
|
107
87
|
success: false,
|