@hlw-uni/mp-vue 2.2.7 → 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 +29 -9
- package/dist/index.mjs +29 -9
- package/dist/utils/ad/index.d.ts +7 -0
- package/dist/utils/device/index.d.ts +4 -6
- package/package.json +1 -1
- package/src/components/hlw-reward-ad/index.vue +9 -3
- package/src/utils/ad/index.ts +25 -0
- package/src/utils/device/index.ts +12 -32
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) {
|
|
@@ -685,9 +705,9 @@ var __publicField = (obj, key, value) => {
|
|
|
685
705
|
return {
|
|
686
706
|
appid: getAppid(device),
|
|
687
707
|
app_name: app.appName || "",
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
708
|
+
version: app.appVersion || "",
|
|
709
|
+
version_code: app.appVersionCode || "",
|
|
710
|
+
channel: app.appChannel || "",
|
|
691
711
|
device_brand: device.brand || "",
|
|
692
712
|
device_model: device.model || "",
|
|
693
713
|
device_id: device.deviceId || "",
|
|
@@ -709,8 +729,7 @@ var __publicField = (obj, key, value) => {
|
|
|
709
729
|
host_language: app.hostLanguage || "",
|
|
710
730
|
host_theme: app.hostTheme || "",
|
|
711
731
|
platform: device.platform || "",
|
|
712
|
-
language: app.language || ""
|
|
713
|
-
version: app.version || ""
|
|
732
|
+
language: app.language || ""
|
|
714
733
|
};
|
|
715
734
|
}
|
|
716
735
|
function getAppid(device) {
|
|
@@ -733,14 +752,14 @@ var __publicField = (obj, key, value) => {
|
|
|
733
752
|
platform: info.platform,
|
|
734
753
|
system: info.system,
|
|
735
754
|
os: info.os,
|
|
736
|
-
version: info.version,
|
|
737
755
|
sdk_version: info.sdk_version,
|
|
738
756
|
host_name: info.host_name,
|
|
739
757
|
host_version: info.host_version,
|
|
740
758
|
host_language: info.host_language,
|
|
741
759
|
language: info.language,
|
|
742
|
-
|
|
743
|
-
|
|
760
|
+
version: info.version,
|
|
761
|
+
version_code: info.version_code,
|
|
762
|
+
channel: info.channel,
|
|
744
763
|
screen_width: info.screen_width,
|
|
745
764
|
screen_height: info.screen_height
|
|
746
765
|
};
|
|
@@ -1164,6 +1183,7 @@ var __publicField = (obj, key, value) => {
|
|
|
1164
1183
|
exports2.confirmRewardAd = confirmRewardAd;
|
|
1165
1184
|
exports2.copy = copy;
|
|
1166
1185
|
exports2.cosAdapter = cosAdapter;
|
|
1186
|
+
exports2.destroyRewardAd = destroyRewardAd;
|
|
1167
1187
|
exports2.download = download;
|
|
1168
1188
|
exports2.fontFamilyPresets = fontFamilyPresets;
|
|
1169
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) {
|
|
@@ -684,9 +704,9 @@ function collectDevice() {
|
|
|
684
704
|
return {
|
|
685
705
|
appid: getAppid(device),
|
|
686
706
|
app_name: app.appName || "",
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
707
|
+
version: app.appVersion || "",
|
|
708
|
+
version_code: app.appVersionCode || "",
|
|
709
|
+
channel: app.appChannel || "",
|
|
690
710
|
device_brand: device.brand || "",
|
|
691
711
|
device_model: device.model || "",
|
|
692
712
|
device_id: device.deviceId || "",
|
|
@@ -708,8 +728,7 @@ function collectDevice() {
|
|
|
708
728
|
host_language: app.hostLanguage || "",
|
|
709
729
|
host_theme: app.hostTheme || "",
|
|
710
730
|
platform: device.platform || "",
|
|
711
|
-
language: app.language || ""
|
|
712
|
-
version: app.version || ""
|
|
731
|
+
language: app.language || ""
|
|
713
732
|
};
|
|
714
733
|
}
|
|
715
734
|
function getAppid(device) {
|
|
@@ -732,14 +751,14 @@ function getQueryInfo(info) {
|
|
|
732
751
|
platform: info.platform,
|
|
733
752
|
system: info.system,
|
|
734
753
|
os: info.os,
|
|
735
|
-
version: info.version,
|
|
736
754
|
sdk_version: info.sdk_version,
|
|
737
755
|
host_name: info.host_name,
|
|
738
756
|
host_version: info.host_version,
|
|
739
757
|
host_language: info.host_language,
|
|
740
758
|
language: info.language,
|
|
741
|
-
|
|
742
|
-
|
|
759
|
+
version: info.version,
|
|
760
|
+
version_code: info.version_code,
|
|
761
|
+
channel: info.channel,
|
|
743
762
|
screen_width: info.screen_width,
|
|
744
763
|
screen_height: info.screen_height
|
|
745
764
|
};
|
|
@@ -1164,6 +1183,7 @@ export {
|
|
|
1164
1183
|
confirmRewardAd,
|
|
1165
1184
|
copy,
|
|
1166
1185
|
cosAdapter,
|
|
1186
|
+
destroyRewardAd,
|
|
1167
1187
|
download,
|
|
1168
1188
|
fontFamilyPresets,
|
|
1169
1189
|
fontSizePresets,
|
package/dist/utils/ad/index.d.ts
CHANGED
|
@@ -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
|
};
|
|
@@ -7,11 +7,11 @@ export interface DeviceInfo {
|
|
|
7
7
|
/** 应用名称 */
|
|
8
8
|
app_name: string;
|
|
9
9
|
/** 小程序版本号(版本名称) */
|
|
10
|
-
|
|
10
|
+
version: string;
|
|
11
11
|
/** 小程序版本号(版本号) */
|
|
12
|
-
|
|
12
|
+
version_code: string;
|
|
13
13
|
/** 小程序来源渠道 */
|
|
14
|
-
|
|
14
|
+
channel: string;
|
|
15
15
|
/** 设备 brand。如:apple、huawei */
|
|
16
16
|
device_brand: string;
|
|
17
17
|
/** 设备型号 */
|
|
@@ -56,13 +56,11 @@ export interface DeviceInfo {
|
|
|
56
56
|
platform: string;
|
|
57
57
|
/** 客户端语言 */
|
|
58
58
|
language: string;
|
|
59
|
-
/** 客户端版本号 */
|
|
60
|
-
version: string;
|
|
61
59
|
}
|
|
62
60
|
/**
|
|
63
61
|
* 过滤后常用于接口公共请求 Query 的设备字段子集。
|
|
64
62
|
*/
|
|
65
|
-
export type DeviceQueryInfo = Pick<DeviceInfo, "appid" | "device_brand" | "device_model" | "device_id" | "device_type" | "device_orientation" | "platform" | "system" | "os" | "
|
|
63
|
+
export type DeviceQueryInfo = Pick<DeviceInfo, "appid" | "device_brand" | "device_model" | "device_id" | "device_type" | "device_orientation" | "platform" | "system" | "os" | "sdk_version" | "host_name" | "host_version" | "host_language" | "language" | "version" | "version_code" | "channel" | "screen_width" | "screen_height">;
|
|
66
64
|
/**
|
|
67
65
|
* 获取缓存后的设备信息数据。
|
|
68
66
|
*/
|
package/package.json
CHANGED
|
@@ -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>
|
package/src/utils/ad/index.ts
CHANGED
|
@@ -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
|
}
|
|
@@ -13,11 +13,11 @@ export interface DeviceInfo {
|
|
|
13
13
|
/** 应用名称 */
|
|
14
14
|
app_name: string;
|
|
15
15
|
/** 小程序版本号(版本名称) */
|
|
16
|
-
|
|
16
|
+
version: string;
|
|
17
17
|
/** 小程序版本号(版本号) */
|
|
18
|
-
|
|
18
|
+
version_code: string;
|
|
19
19
|
/** 小程序来源渠道 */
|
|
20
|
-
|
|
20
|
+
channel: string;
|
|
21
21
|
/** 设备 brand。如:apple、huawei */
|
|
22
22
|
device_brand: string;
|
|
23
23
|
/** 设备型号 */
|
|
@@ -62,33 +62,14 @@ export interface DeviceInfo {
|
|
|
62
62
|
platform: string;
|
|
63
63
|
/** 客户端语言 */
|
|
64
64
|
language: string;
|
|
65
|
-
/** 客户端版本号 */
|
|
66
|
-
version: string;
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
/**
|
|
70
68
|
* 过滤后常用于接口公共请求 Query 的设备字段子集。
|
|
71
69
|
*/
|
|
72
|
-
export type DeviceQueryInfo = Pick<
|
|
73
|
-
|
|
74
|
-
| "device_brand"
|
|
75
|
-
| "device_model"
|
|
76
|
-
| "device_id"
|
|
77
|
-
| "device_type"
|
|
78
|
-
| "device_orientation"
|
|
79
|
-
| "platform"
|
|
80
|
-
| "system"
|
|
81
|
-
| "os"
|
|
82
|
-
| "version"
|
|
83
|
-
| "sdk_version"
|
|
84
|
-
| "host_name"
|
|
85
|
-
| "host_version"
|
|
86
|
-
| "host_language"
|
|
87
|
-
| "language"
|
|
88
|
-
| "app_version"
|
|
89
|
-
| "app_version_code"
|
|
90
|
-
| "screen_width"
|
|
91
|
-
| "screen_height"
|
|
70
|
+
export type DeviceQueryInfo = Pick<
|
|
71
|
+
DeviceInfo,
|
|
72
|
+
"appid" | "device_brand" | "device_model" | "device_id" | "device_type" | "device_orientation" | "platform" | "system" | "os" | "sdk_version" | "host_name" | "host_version" | "host_language" | "language" | "version" | "version_code" | "channel" | "screen_width" | "screen_height"
|
|
92
73
|
>;
|
|
93
74
|
|
|
94
75
|
let deviceCache: DeviceInfo | null = null;
|
|
@@ -126,9 +107,9 @@ function collectDevice(): DeviceInfo {
|
|
|
126
107
|
return {
|
|
127
108
|
appid: getAppid(device),
|
|
128
109
|
app_name: (app.appName as string) || "",
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
110
|
+
version: (app.appVersion as string) || "",
|
|
111
|
+
version_code: (app.appVersionCode as string) || "",
|
|
112
|
+
channel: (app.appChannel as string) || "",
|
|
132
113
|
device_brand: (device.brand as string) || "",
|
|
133
114
|
device_model: (device.model as string) || "",
|
|
134
115
|
device_id: (device.deviceId as string) || "",
|
|
@@ -151,7 +132,6 @@ function collectDevice(): DeviceInfo {
|
|
|
151
132
|
host_theme: (app.hostTheme as string) || "",
|
|
152
133
|
platform: (device.platform as string) || "",
|
|
153
134
|
language: (app.language as string) || "",
|
|
154
|
-
version: (app.version as string) || "",
|
|
155
135
|
};
|
|
156
136
|
}
|
|
157
137
|
|
|
@@ -181,14 +161,14 @@ function getQueryInfo(info: DeviceInfo): DeviceQueryInfo {
|
|
|
181
161
|
platform: info.platform,
|
|
182
162
|
system: info.system,
|
|
183
163
|
os: info.os,
|
|
184
|
-
version: info.version,
|
|
185
164
|
sdk_version: info.sdk_version,
|
|
186
165
|
host_name: info.host_name,
|
|
187
166
|
host_version: info.host_version,
|
|
188
167
|
host_language: info.host_language,
|
|
189
168
|
language: info.language,
|
|
190
|
-
|
|
191
|
-
|
|
169
|
+
version: info.version,
|
|
170
|
+
version_code: info.version_code,
|
|
171
|
+
channel: info.channel,
|
|
192
172
|
screen_width: info.screen_width,
|
|
193
173
|
screen_height: info.screen_height,
|
|
194
174
|
};
|