@hlw-uni/mp-vue 2.0.6 → 2.0.7

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
@@ -802,6 +802,11 @@ var __publicField = (obj, key, value) => {
802
802
  var _a;
803
803
  let ad = interstitialCache.get(unitId);
804
804
  if (!ad) {
805
+ if (typeof uni.createInterstitialAd !== "function") {
806
+ console.warn("[useAd] 当前基础库不支持插屏广告");
807
+ resolve(false);
808
+ return;
809
+ }
805
810
  ad = uni.createInterstitialAd({ adUnitId: unitId });
806
811
  if (!ad) {
807
812
  resolve(false);
@@ -812,12 +817,9 @@ var __publicField = (obj, key, value) => {
812
817
  });
813
818
  interstitialCache.set(unitId, ad);
814
819
  }
815
- ad.show().then(() => resolve(true)).catch(() => {
816
- if (typeof ad.load !== "function") {
817
- resolve(false);
818
- return;
819
- }
820
- ad.load().then(() => ad.show()).then(() => resolve(true)).catch(() => resolve(false));
820
+ ad.show().then(() => resolve(true)).catch((err) => {
821
+ console.warn(`[useAd] popup show error (${unitId})`, err);
822
+ resolve(false);
821
823
  });
822
824
  });
823
825
  }
package/dist/index.mjs CHANGED
@@ -801,6 +801,11 @@ function showInterstitialAd(unitId) {
801
801
  var _a;
802
802
  let ad = interstitialCache.get(unitId);
803
803
  if (!ad) {
804
+ if (typeof uni.createInterstitialAd !== "function") {
805
+ console.warn("[useAd] 当前基础库不支持插屏广告");
806
+ resolve(false);
807
+ return;
808
+ }
804
809
  ad = uni.createInterstitialAd({ adUnitId: unitId });
805
810
  if (!ad) {
806
811
  resolve(false);
@@ -811,12 +816,9 @@ function showInterstitialAd(unitId) {
811
816
  });
812
817
  interstitialCache.set(unitId, ad);
813
818
  }
814
- ad.show().then(() => resolve(true)).catch(() => {
815
- if (typeof ad.load !== "function") {
816
- resolve(false);
817
- return;
818
- }
819
- ad.load().then(() => ad.show()).then(() => resolve(true)).catch(() => resolve(false));
819
+ ad.show().then(() => resolve(true)).catch((err) => {
820
+ console.warn(`[useAd] popup show error (${unitId})`, err);
821
+ resolve(false);
820
822
  });
821
823
  });
822
824
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni/mp-vue",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "hlw-uni 小程序运行时 — Vue 组件 + composables + theme + http + 工具集(合并自原 mp-core)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -0,0 +1,238 @@
1
+ <template>
2
+ <view v-if="mounted" class="hlw-notice-mask" :class="{ 'hlw-notice-mask--in': visible }" @tap.self>
3
+ <view class="hlw-notice-card" :class="{ 'hlw-notice-card--in': visible }" @tap.stop>
4
+ <view class="hlw-notice-head">
5
+ <view class="hlw-notice-icon" :style="{ background: iconTint }">
6
+ <view class="hlw-notice-icon-i" :class="iconClass" :style="{ color: iconColor }" />
7
+ </view>
8
+ <text class="hlw-notice-title">{{ title }}</text>
9
+ </view>
10
+
11
+ <scroll-view
12
+ class="hlw-notice-body"
13
+ scroll-y
14
+ :show-scrollbar="false"
15
+ :enhanced="true"
16
+ >
17
+ <rich-text class="hlw-notice-text" :nodes="contentNodes" />
18
+ </scroll-view>
19
+
20
+ <view
21
+ class="hlw-notice-btn"
22
+ :style="{ background: iconColor }"
23
+ hover-class="hlw-notice-btn--hover"
24
+ @tap="onConfirm"
25
+ >
26
+ <text class="hlw-notice-btn-text">{{ confirmText }}</text>
27
+ </view>
28
+
29
+ <view
30
+ v-if="showCancel"
31
+ class="hlw-notice-dismiss"
32
+ hover-class="hlw-notice-dismiss--hover"
33
+ @tap="onCancel"
34
+ >
35
+ <text class="hlw-notice-dismiss-text">{{ cancelText }}</text>
36
+ </view>
37
+ </view>
38
+ </view>
39
+ </template>
40
+
41
+ <script setup lang="ts">
42
+ import { computed, nextTick, ref, watch } from "vue";
43
+
44
+ interface Props {
45
+ show?: boolean;
46
+ title?: string;
47
+ /** 内容:HTML 原样渲染,纯文本自动 \n -> <br/> */
48
+ content?: string;
49
+ /** iconify class,例:i-fa6-solid-bell */
50
+ iconClass?: string;
51
+ /** 图标 + 主按钮颜色 */
52
+ iconColor?: string;
53
+ /** 图标背景色 */
54
+ iconTint?: string;
55
+ confirmText?: string;
56
+ cancelText?: string;
57
+ showCancel?: boolean;
58
+ /** 进出场动画时长(ms),需与 CSS transition 一致 */
59
+ animMs?: number;
60
+ }
61
+
62
+ const props = withDefaults(defineProps<Props>(), {
63
+ show: false,
64
+ title: "",
65
+ content: "",
66
+ iconClass: "i-fa6-solid-bell",
67
+ iconColor: "#1C1C1E",
68
+ iconTint: "#F2F2F7",
69
+ confirmText: "我知道了",
70
+ cancelText: "稍后再看",
71
+ showCancel: false,
72
+ animMs: 260,
73
+ });
74
+
75
+ const emit = defineEmits<{ confirm: []; cancel: [] }>();
76
+
77
+ const mounted = ref(false);
78
+ const visible = ref(false);
79
+ let timer: ReturnType<typeof setTimeout> | null = null;
80
+
81
+ const contentNodes = computed(() => {
82
+ const raw = props.content;
83
+ return /<[a-z][\s\S]*>/i.test(raw) ? raw : raw.replace(/\n/g, "<br/>");
84
+ });
85
+
86
+ watch(
87
+ () => props.show,
88
+ async (next) => {
89
+ if (timer) {
90
+ clearTimeout(timer);
91
+ timer = null;
92
+ }
93
+ if (next) {
94
+ mounted.value = true;
95
+ await nextTick();
96
+ visible.value = true;
97
+ } else {
98
+ visible.value = false;
99
+ timer = setTimeout(() => {
100
+ mounted.value = false;
101
+ timer = null;
102
+ }, props.animMs);
103
+ }
104
+ },
105
+ { immediate: true },
106
+ );
107
+
108
+ function onConfirm() {
109
+ emit("confirm");
110
+ }
111
+
112
+ function onCancel() {
113
+ emit("cancel");
114
+ }
115
+ </script>
116
+
117
+ <style lang="scss" scoped>
118
+ .hlw-notice-mask {
119
+ position: fixed;
120
+ inset: 0;
121
+ z-index: 1000;
122
+ display: flex;
123
+ align-items: center;
124
+ justify-content: center;
125
+ padding: 40rpx;
126
+ background: rgba(0, 0, 0, 0);
127
+ transition: background 0.25s ease-out;
128
+
129
+ &--in {
130
+ background: rgba(0, 0, 0, 0.4);
131
+ }
132
+ }
133
+
134
+ .hlw-notice-card {
135
+ width: 100%;
136
+ max-width: 540rpx;
137
+ background: var(--surface-card, #ffffff);
138
+ border-radius: var(--radius-xl, 36rpx);
139
+ padding: 40rpx 36rpx 32rpx;
140
+ box-shadow: 0 40rpx 80rpx rgba(0, 0, 0, 0.1);
141
+ transform: scale(0.92);
142
+ opacity: 0;
143
+ transition: transform 0.28s cubic-bezier(0.34, 1.2, 0.64, 1), opacity 0.22s ease-out;
144
+
145
+ &--in {
146
+ transform: scale(1);
147
+ opacity: 1;
148
+ }
149
+ }
150
+
151
+ .hlw-notice-head {
152
+ display: flex;
153
+ align-items: center;
154
+ justify-content: center;
155
+ gap: 14rpx;
156
+ margin-bottom: 24rpx;
157
+ }
158
+
159
+ .hlw-notice-icon {
160
+ width: 48rpx;
161
+ height: 48rpx;
162
+ border-radius: var(--radius-sm, 12rpx);
163
+ display: flex;
164
+ align-items: center;
165
+ justify-content: center;
166
+ flex-shrink: 0;
167
+ }
168
+
169
+ .hlw-notice-icon-i {
170
+ font-size: 24rpx;
171
+ }
172
+
173
+ .hlw-notice-title {
174
+ font-size: var(--font-md, 30rpx);
175
+ font-weight: 700;
176
+ color: var(--text-primary, #1c1c1e);
177
+ line-height: 1.3;
178
+ word-break: break-word;
179
+ }
180
+
181
+ .hlw-notice-body {
182
+ width: 100%;
183
+ max-height: 560rpx;
184
+ margin-bottom: 36rpx;
185
+ padding-right: 6rpx;
186
+ }
187
+
188
+ .hlw-notice-text {
189
+ display: block;
190
+ font-size: var(--font-sm, 26rpx);
191
+ line-height: 1.65;
192
+ color: var(--text-secondary, #5c5c5e);
193
+ text-align: left;
194
+ white-space: pre-wrap;
195
+ word-break: break-word;
196
+ }
197
+
198
+ .hlw-notice-btn {
199
+ width: 100%;
200
+ padding: 22rpx 0;
201
+ border-radius: 9999rpx;
202
+ display: flex;
203
+ align-items: center;
204
+ justify-content: center;
205
+ box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
206
+ transition: transform 0.15s ease-out, filter 0.15s ease-out;
207
+
208
+ &--hover {
209
+ transform: scale(0.97);
210
+ filter: brightness(0.92);
211
+ }
212
+ }
213
+
214
+ .hlw-notice-btn-text {
215
+ color: #ffffff;
216
+ font-size: var(--font-base, 28rpx);
217
+ font-weight: 600;
218
+ letter-spacing: 1rpx;
219
+ }
220
+
221
+ .hlw-notice-dismiss {
222
+ margin-top: 16rpx;
223
+ padding: 10rpx 0;
224
+ display: flex;
225
+ align-items: center;
226
+ justify-content: center;
227
+
228
+ &--hover {
229
+ opacity: 0.5;
230
+ }
231
+ }
232
+
233
+ .hlw-notice-dismiss-text {
234
+ font-size: var(--font-xs, 24rpx);
235
+ color: var(--text-muted, #8e8e93);
236
+ font-weight: 500;
237
+ }
238
+ </style>
@@ -316,11 +316,17 @@ function showRewardedAd(unitId: string, hooks?: { onShown?: () => void }): Promi
316
316
  });
317
317
  }
318
318
 
319
- /** 底层插屏广告包装:show 失败兜底 load show */
319
+ /** 底层插屏广告包装:实例按 unitId 缓存复用,show 失败 console.warn 不重试(频控/网络等失败重试也救不了) */
320
320
  function showInterstitialAd(unitId: string): Promise<boolean> {
321
321
  return new Promise((resolve) => {
322
322
  let ad: any = interstitialCache.get(unitId);
323
323
  if (!ad) {
324
+ // 老基础库可能没有这个 API(对应官方 if (wx.createInterstitialAd))
325
+ if (typeof uni.createInterstitialAd !== "function") {
326
+ console.warn("[useAd] 当前基础库不支持插屏广告");
327
+ resolve(false);
328
+ return;
329
+ }
324
330
  ad = uni.createInterstitialAd({ adUnitId: unitId });
325
331
  if (!ad) { resolve(false); return; }
326
332
  ad.onError?.((err: AdError) => {
@@ -328,15 +334,11 @@ function showInterstitialAd(unitId: string): Promise<boolean> {
328
334
  });
329
335
  interstitialCache.set(unitId, ad);
330
336
  }
331
-
332
337
  ad.show()
333
338
  .then(() => resolve(true))
334
- .catch(() => {
335
- if (typeof ad.load !== "function") { resolve(false); return; }
336
- ad.load()
337
- .then(() => ad.show())
338
- .then(() => resolve(true))
339
- .catch(() => resolve(false));
339
+ .catch((err: any) => {
340
+ console.warn(`[useAd] popup show error (${unitId})`, err);
341
+ resolve(false);
340
342
  });
341
343
  });
342
344
  }