@hlw-uni/mp-vue 2.1.12 → 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.
@@ -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: Ref<{
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;
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 { config: config2, loaded } = pinia.storeToRefs(store);
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 store.config[`${type}_unit_id`] || "";
696
+ return config2.value[`${type}_unit_id`] || "";
688
697
  }
689
698
  async function showReward(onClose) {
690
699
  const unitId = getUnitId("reward");
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 { config: config2, loaded } = storeToRefs(store);
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 store.config[`${type}_unit_id`] || "";
695
+ return config2.value[`${type}_unit_id`] || "";
687
696
  }
688
697
  async function showReward(onClose) {
689
698
  const unitId = getUnitId("reward");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni/mp-vue",
3
- "version": "2.1.12",
3
+ "version": "2.1.13",
4
4
  "description": "hlw-uni 小程序运行时 — Vue 组件 + composables + theme + http + 工具集(合并自原 mp-core)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -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 { config, loaded } = storeToRefs(store);
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 store.config[`${type}_unit_id` as keyof AdConfig] || "";
190
+ return (config.value[`${type}_unit_id` as keyof AdConfig] as string) || "";
177
191
  }
178
192
 
179
193
  /**