@hlw-uni/mp-vue 2.1.11 → 2.1.13
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/composables/ad/index.d.ts +6 -16
- package/dist/composables/algo/index.d.ts +7 -0
- package/dist/composables/algo/uuid.d.ts +17 -0
- package/dist/composables/index.d.ts +1 -0
- package/dist/index.js +25 -3
- package/dist/index.mjs +25 -3
- package/package.json +1 -1
- package/src/composables/ad/index.ts +18 -4
- package/src/composables/algo/index.ts +7 -0
- package/src/composables/algo/uuid.ts +27 -0
- package/src/composables/index.ts +1 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AdapterPayload } from '../_internal/unwrap';
|
|
2
|
-
import { Ref } from 'vue';
|
|
2
|
+
import { ComputedRef, Ref } from 'vue';
|
|
3
3
|
|
|
4
4
|
/** 6 种广告类型 */
|
|
5
5
|
export type AdType = "banner" | "grid" | "custom" | "video" | "reward" | "popup";
|
|
@@ -11,6 +11,8 @@ export interface AdConfig {
|
|
|
11
11
|
video_unit_id: string;
|
|
12
12
|
reward_unit_id: string;
|
|
13
13
|
popup_unit_id: string;
|
|
14
|
+
/** VIP 屏蔽展示型广告(reward 除外):0=否,1=屏蔽 banner/grid/custom/video/popup */
|
|
15
|
+
vip_no_ad?: 0 | 1;
|
|
14
16
|
}
|
|
15
17
|
/** 广告错误对象(onError 回调参数) */
|
|
16
18
|
export interface AdError {
|
|
@@ -31,6 +33,8 @@ export interface AdAdapter {
|
|
|
31
33
|
getConfig: () => Promise<AdapterPayload<AdConfig>>;
|
|
32
34
|
/** 是否已登录;不传 = 不校验(showReward 调用前会问一次) */
|
|
33
35
|
isAuth?: () => boolean;
|
|
36
|
+
/** 是否 VIP;配合 config.vip_no_ad=1 时屏蔽展示型广告(reward 不受影响) */
|
|
37
|
+
isVip?: () => boolean;
|
|
34
38
|
}
|
|
35
39
|
/** 激励视频关闭回调返回 */
|
|
36
40
|
export interface AdCloseResult {
|
|
@@ -43,21 +47,7 @@ export interface AdCloseResult {
|
|
|
43
47
|
*/
|
|
44
48
|
export declare function setConfigAd(a: AdAdapter): void;
|
|
45
49
|
export declare function useAd(): {
|
|
46
|
-
config:
|
|
47
|
-
banner_unit_id: string;
|
|
48
|
-
grid_unit_id: string;
|
|
49
|
-
custom_unit_id: string;
|
|
50
|
-
video_unit_id: string;
|
|
51
|
-
reward_unit_id: string;
|
|
52
|
-
popup_unit_id: string;
|
|
53
|
-
}, AdConfig | {
|
|
54
|
-
banner_unit_id: string;
|
|
55
|
-
grid_unit_id: string;
|
|
56
|
-
custom_unit_id: string;
|
|
57
|
-
video_unit_id: string;
|
|
58
|
-
reward_unit_id: string;
|
|
59
|
-
popup_unit_id: string;
|
|
60
|
-
}>;
|
|
50
|
+
config: ComputedRef<AdConfig>;
|
|
61
51
|
loaded: Ref<boolean, boolean>;
|
|
62
52
|
loadConfig: (force?: boolean) => Promise<void>;
|
|
63
53
|
getUnitId: (type: AdType) => string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UUID v4 生成器(RFC 4122 v4 算法),返回 32 字符 hex(无连字符)。
|
|
3
|
+
*
|
|
4
|
+
* 用途:当 nonce、idempotency key、临时唯一标识用。
|
|
5
|
+
*
|
|
6
|
+
* 算法:
|
|
7
|
+
* 1. 生成 16 字节随机源
|
|
8
|
+
* 2. byte 6 高 4 位置成 0100 标版本号 v4
|
|
9
|
+
* 3. byte 8 高 2 位置成 10 标变体(RFC 4122)
|
|
10
|
+
* 4. 16 字节转 hex 拼成 32 字符串
|
|
11
|
+
*
|
|
12
|
+
* 注意:随机源用 Math.random(小程序兼容兜底),加密强度有限,
|
|
13
|
+
* 不能用于密钥派生 / token 签发,只能挡重放。
|
|
14
|
+
*/
|
|
15
|
+
export declare function useUuid(): {
|
|
16
|
+
v4: () => string;
|
|
17
|
+
};
|
|
@@ -16,6 +16,7 @@ export { useContact, setConfigContact, type ContactConfig, type ContactAdapter,
|
|
|
16
16
|
export { useUtils, type DownloadFileOptions, type DownloadFileResult, type TapEvent } from './utils';
|
|
17
17
|
export { useColor } from './color';
|
|
18
18
|
export { useRouter, type NavigateType, type NavigateOptions } from './navigator';
|
|
19
|
+
export { useUuid } from './algo';
|
|
19
20
|
export type { FontScale, FontPreset } from './theme';
|
|
20
21
|
export { FONT_SCALE_KEY, FONT_PRESETS, getCurrentFontScale, getCurrentFontVars, THEME_CHANGE_EVENT, buildThemeStyle, useThemePageStyle, } from './theme';
|
|
21
22
|
export type { ThemeColor } from './theme';
|
package/dist/index.js
CHANGED
|
@@ -637,7 +637,8 @@ var __publicField = (obj, key, value) => {
|
|
|
637
637
|
custom_unit_id: "",
|
|
638
638
|
video_unit_id: "",
|
|
639
639
|
reward_unit_id: "",
|
|
640
|
-
popup_unit_id: ""
|
|
640
|
+
popup_unit_id: "",
|
|
641
|
+
vip_no_ad: 0
|
|
641
642
|
};
|
|
642
643
|
let adapter$1 = null;
|
|
643
644
|
let pending$1 = null;
|
|
@@ -655,7 +656,15 @@ var __publicField = (obj, key, value) => {
|
|
|
655
656
|
const interstitialCache = /* @__PURE__ */ new Map();
|
|
656
657
|
function useAd() {
|
|
657
658
|
const store = useAdStore();
|
|
658
|
-
const {
|
|
659
|
+
const { loaded } = pinia.storeToRefs(store);
|
|
660
|
+
const config2 = vue.computed(() => {
|
|
661
|
+
var _a;
|
|
662
|
+
const raw = store.config;
|
|
663
|
+
if (raw.vip_no_ad === 1 && ((_a = adapter$1 == null ? void 0 : adapter$1.isVip) == null ? void 0 : _a.call(adapter$1))) {
|
|
664
|
+
return { ...EMPTY, reward_unit_id: raw.reward_unit_id, vip_no_ad: 1 };
|
|
665
|
+
}
|
|
666
|
+
return raw;
|
|
667
|
+
});
|
|
659
668
|
async function loadConfig2(force = false) {
|
|
660
669
|
if (loaded.value && !force)
|
|
661
670
|
return;
|
|
@@ -684,7 +693,7 @@ var __publicField = (obj, key, value) => {
|
|
|
684
693
|
return flight;
|
|
685
694
|
}
|
|
686
695
|
function getUnitId(type) {
|
|
687
|
-
return
|
|
696
|
+
return config2.value[`${type}_unit_id`] || "";
|
|
688
697
|
}
|
|
689
698
|
async function showReward(onClose) {
|
|
690
699
|
const unitId = getUnitId("reward");
|
|
@@ -1138,6 +1147,18 @@ var __publicField = (obj, key, value) => {
|
|
|
1138
1147
|
navigate: doNavigate
|
|
1139
1148
|
};
|
|
1140
1149
|
}
|
|
1150
|
+
function useUuid() {
|
|
1151
|
+
function v4() {
|
|
1152
|
+
const bytes = [];
|
|
1153
|
+
for (let i = 0; i < 16; i++) {
|
|
1154
|
+
bytes.push(Math.floor(Math.random() * 256));
|
|
1155
|
+
}
|
|
1156
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
1157
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
1158
|
+
return bytes.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1159
|
+
}
|
|
1160
|
+
return { v4 };
|
|
1161
|
+
}
|
|
1141
1162
|
const useThemeStore = pinia.defineStore(
|
|
1142
1163
|
"theme",
|
|
1143
1164
|
() => {
|
|
@@ -1940,6 +1961,7 @@ var __publicField = (obj, key, value) => {
|
|
|
1940
1961
|
exports2.useThemeStore = useThemeStore;
|
|
1941
1962
|
exports2.useUpload = useUpload;
|
|
1942
1963
|
exports2.useUtils = useUtils;
|
|
1964
|
+
exports2.useUuid = useUuid;
|
|
1943
1965
|
exports2.useValidate = useValidate;
|
|
1944
1966
|
exports2.vCopy = vCopy;
|
|
1945
1967
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
package/dist/index.mjs
CHANGED
|
@@ -636,7 +636,8 @@ const EMPTY = {
|
|
|
636
636
|
custom_unit_id: "",
|
|
637
637
|
video_unit_id: "",
|
|
638
638
|
reward_unit_id: "",
|
|
639
|
-
popup_unit_id: ""
|
|
639
|
+
popup_unit_id: "",
|
|
640
|
+
vip_no_ad: 0
|
|
640
641
|
};
|
|
641
642
|
let adapter$1 = null;
|
|
642
643
|
let pending$1 = null;
|
|
@@ -654,7 +655,15 @@ const rewardedCache = /* @__PURE__ */ new Map();
|
|
|
654
655
|
const interstitialCache = /* @__PURE__ */ new Map();
|
|
655
656
|
function useAd() {
|
|
656
657
|
const store = useAdStore();
|
|
657
|
-
const {
|
|
658
|
+
const { loaded } = storeToRefs(store);
|
|
659
|
+
const config2 = computed(() => {
|
|
660
|
+
var _a;
|
|
661
|
+
const raw = store.config;
|
|
662
|
+
if (raw.vip_no_ad === 1 && ((_a = adapter$1 == null ? void 0 : adapter$1.isVip) == null ? void 0 : _a.call(adapter$1))) {
|
|
663
|
+
return { ...EMPTY, reward_unit_id: raw.reward_unit_id, vip_no_ad: 1 };
|
|
664
|
+
}
|
|
665
|
+
return raw;
|
|
666
|
+
});
|
|
658
667
|
async function loadConfig2(force = false) {
|
|
659
668
|
if (loaded.value && !force)
|
|
660
669
|
return;
|
|
@@ -683,7 +692,7 @@ function useAd() {
|
|
|
683
692
|
return flight;
|
|
684
693
|
}
|
|
685
694
|
function getUnitId(type) {
|
|
686
|
-
return
|
|
695
|
+
return config2.value[`${type}_unit_id`] || "";
|
|
687
696
|
}
|
|
688
697
|
async function showReward(onClose) {
|
|
689
698
|
const unitId = getUnitId("reward");
|
|
@@ -1137,6 +1146,18 @@ function useRouter() {
|
|
|
1137
1146
|
navigate: doNavigate
|
|
1138
1147
|
};
|
|
1139
1148
|
}
|
|
1149
|
+
function useUuid() {
|
|
1150
|
+
function v4() {
|
|
1151
|
+
const bytes = [];
|
|
1152
|
+
for (let i = 0; i < 16; i++) {
|
|
1153
|
+
bytes.push(Math.floor(Math.random() * 256));
|
|
1154
|
+
}
|
|
1155
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
1156
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
1157
|
+
return bytes.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1158
|
+
}
|
|
1159
|
+
return { v4 };
|
|
1160
|
+
}
|
|
1140
1161
|
const useThemeStore = defineStore(
|
|
1141
1162
|
"theme",
|
|
1142
1163
|
() => {
|
|
@@ -1940,6 +1961,7 @@ export {
|
|
|
1940
1961
|
useThemeStore,
|
|
1941
1962
|
useUpload,
|
|
1942
1963
|
useUtils,
|
|
1964
|
+
useUuid,
|
|
1943
1965
|
useValidate,
|
|
1944
1966
|
vCopy
|
|
1945
1967
|
};
|
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
*/
|
|
44
44
|
|
|
45
45
|
import { defineStore, storeToRefs } from "pinia";
|
|
46
|
-
import { ref } from "vue";
|
|
46
|
+
import { ref, computed } from "vue";
|
|
47
47
|
import { useMsg, type HlwMsg } from "../msg";
|
|
48
48
|
import { unwrapPayload, type AdapterPayload } from "../_internal/unwrap";
|
|
49
49
|
|
|
@@ -61,6 +61,8 @@ export interface AdConfig {
|
|
|
61
61
|
video_unit_id: string;
|
|
62
62
|
reward_unit_id: string;
|
|
63
63
|
popup_unit_id: string;
|
|
64
|
+
/** VIP 屏蔽展示型广告(reward 除外):0=否,1=屏蔽 banner/grid/custom/video/popup */
|
|
65
|
+
vip_no_ad?: 0 | 1;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
/** 广告错误对象(onError 回调参数) */
|
|
@@ -83,6 +85,8 @@ export interface AdAdapter {
|
|
|
83
85
|
getConfig: () => Promise<AdapterPayload<AdConfig>>;
|
|
84
86
|
/** 是否已登录;不传 = 不校验(showReward 调用前会问一次) */
|
|
85
87
|
isAuth?: () => boolean;
|
|
88
|
+
/** 是否 VIP;配合 config.vip_no_ad=1 时屏蔽展示型广告(reward 不受影响) */
|
|
89
|
+
isVip?: () => boolean;
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
/** 激励视频关闭回调返回 */
|
|
@@ -98,6 +102,7 @@ const EMPTY: AdConfig = {
|
|
|
98
102
|
video_unit_id: "",
|
|
99
103
|
reward_unit_id: "",
|
|
100
104
|
popup_unit_id: "",
|
|
105
|
+
vip_no_ad: 0,
|
|
101
106
|
};
|
|
102
107
|
|
|
103
108
|
let adapter: AdAdapter | null = null;
|
|
@@ -140,7 +145,16 @@ const interstitialCache = new Map<string, any>();
|
|
|
140
145
|
|
|
141
146
|
export function useAd() {
|
|
142
147
|
const store = useAdStore();
|
|
143
|
-
const {
|
|
148
|
+
const { loaded } = storeToRefs(store);
|
|
149
|
+
|
|
150
|
+
/** 真实生效的广告配置:VIP + vip_no_ad=1 命中时屏蔽展示型 unit_id(reward 保留) */
|
|
151
|
+
const config = computed<AdConfig>(() => {
|
|
152
|
+
const raw = store.config;
|
|
153
|
+
if (raw.vip_no_ad === 1 && adapter?.isVip?.()) {
|
|
154
|
+
return { ...EMPTY, reward_unit_id: raw.reward_unit_id, vip_no_ad: 1 };
|
|
155
|
+
}
|
|
156
|
+
return raw;
|
|
157
|
+
});
|
|
144
158
|
|
|
145
159
|
/**
|
|
146
160
|
* 拉取广告配置(小程序冷启动后调一次即可)。
|
|
@@ -171,9 +185,9 @@ export function useAd() {
|
|
|
171
185
|
return flight;
|
|
172
186
|
}
|
|
173
187
|
|
|
174
|
-
/** 取指定类型的 unit_id(hlw-ad 组件 /
|
|
188
|
+
/** 取指定类型的 unit_id(hlw-ad 组件 / 业务直接调时用),自动应用 VIP 屏蔽 */
|
|
175
189
|
function getUnitId(type: AdType): string {
|
|
176
|
-
return
|
|
190
|
+
return (config.value[`${type}_unit_id` as keyof AdConfig] as string) || "";
|
|
177
191
|
}
|
|
178
192
|
|
|
179
193
|
/**
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UUID v4 生成器(RFC 4122 v4 算法),返回 32 字符 hex(无连字符)。
|
|
3
|
+
*
|
|
4
|
+
* 用途:当 nonce、idempotency key、临时唯一标识用。
|
|
5
|
+
*
|
|
6
|
+
* 算法:
|
|
7
|
+
* 1. 生成 16 字节随机源
|
|
8
|
+
* 2. byte 6 高 4 位置成 0100 标版本号 v4
|
|
9
|
+
* 3. byte 8 高 2 位置成 10 标变体(RFC 4122)
|
|
10
|
+
* 4. 16 字节转 hex 拼成 32 字符串
|
|
11
|
+
*
|
|
12
|
+
* 注意:随机源用 Math.random(小程序兼容兜底),加密强度有限,
|
|
13
|
+
* 不能用于密钥派生 / token 签发,只能挡重放。
|
|
14
|
+
*/
|
|
15
|
+
export function useUuid() {
|
|
16
|
+
function v4(): string {
|
|
17
|
+
const bytes: number[] = [];
|
|
18
|
+
for (let i = 0; i < 16; i++) {
|
|
19
|
+
bytes.push(Math.floor(Math.random() * 256));
|
|
20
|
+
}
|
|
21
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
22
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
23
|
+
return bytes.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { v4 };
|
|
27
|
+
}
|
package/src/composables/index.ts
CHANGED
|
@@ -45,6 +45,7 @@ export {
|
|
|
45
45
|
export { useUtils, type DownloadFileOptions, type DownloadFileResult, type TapEvent } from "./utils";
|
|
46
46
|
export { useColor } from "./color";
|
|
47
47
|
export { useRouter, type NavigateType, type NavigateOptions } from "./navigator";
|
|
48
|
+
export { useUuid } from "./algo";
|
|
48
49
|
|
|
49
50
|
// Theme(mp-vue 自带)
|
|
50
51
|
export type { FontScale, FontPreset } from "./theme";
|