@hlw-uni/mp-vue 2.1.57 → 2.1.58

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.
Files changed (46) hide show
  1. package/dist/app.d.ts +12 -1
  2. package/dist/composables/ad/index.d.ts +26 -0
  3. package/dist/composables/device/index.d.ts +14 -0
  4. package/dist/composables/index.d.ts +1 -1
  5. package/dist/composables/msg/index.d.ts +44 -3
  6. package/dist/composables/navigator/index.d.ts +37 -1
  7. package/dist/composables/refs/index.d.ts +15 -1
  8. package/dist/composables/request/client.d.ts +87 -0
  9. package/dist/composables/request/service.d.ts +64 -0
  10. package/dist/composables/request/types.d.ts +50 -13
  11. package/dist/composables/share/index.d.ts +38 -0
  12. package/dist/composables/theme/appearance.d.ts +30 -4
  13. package/dist/composables/theme/font.d.ts +23 -0
  14. package/dist/composables/theme/index.d.ts +19 -6
  15. package/dist/composables/theme/palette.d.ts +23 -0
  16. package/dist/composables/theme/typography.d.ts +9 -1
  17. package/dist/composables/utils/index.d.ts +120 -13
  18. package/dist/directives/copy.d.ts +5 -0
  19. package/dist/hlw.d.ts +10 -0
  20. package/dist/index.js +305 -199
  21. package/dist/index.mjs +306 -200
  22. package/dist/stores/theme.d.ts +3 -0
  23. package/package.json +1 -1
  24. package/src/app.ts +20 -3
  25. package/src/components/hlw-add-mini/README.md +10 -11
  26. package/src/components/hlw-add-mini/index.vue +93 -66
  27. package/src/components/hlw-button/index.vue +33 -18
  28. package/src/composables/ad/index.ts +136 -62
  29. package/src/composables/device/index.ts +32 -2
  30. package/src/composables/index.ts +18 -1
  31. package/src/composables/msg/index.ts +70 -16
  32. package/src/composables/navigator/index.ts +45 -1
  33. package/src/composables/refs/index.ts +27 -4
  34. package/src/composables/request/client.ts +149 -0
  35. package/src/composables/request/service.ts +64 -0
  36. package/src/composables/request/types.ts +53 -13
  37. package/src/composables/share/index.ts +48 -0
  38. package/src/composables/theme/appearance.ts +31 -4
  39. package/src/composables/theme/font.ts +23 -0
  40. package/src/composables/theme/index.ts +23 -7
  41. package/src/composables/theme/palette.ts +32 -0
  42. package/src/composables/theme/typography.ts +9 -1
  43. package/src/composables/utils/index.ts +227 -127
  44. package/src/directives/copy.ts +31 -19
  45. package/src/hlw.ts +11 -0
  46. package/src/stores/theme.ts +28 -5
package/dist/index.mjs CHANGED
@@ -91,22 +91,37 @@ class UniRequestClient {
91
91
  __publicField(this, "baseURL", "");
92
92
  __publicField(this, "defaultHeaders", { "Content-Type": "application/json" });
93
93
  }
94
+ /**
95
+ * 设置全局基础请求 URL。
96
+ */
94
97
  setBaseURL(url) {
95
98
  this.baseURL = url;
96
99
  }
100
+ /**
101
+ * 注册一个请求拦截器。
102
+ */
97
103
  onRequest(fn) {
98
104
  this.reqInterceptors.push(fn);
99
105
  return () => this.remove(this.reqInterceptors, fn);
100
106
  }
107
+ /**
108
+ * 注册一个响应拦截器。
109
+ */
101
110
  onResponse(fn) {
102
111
  const item = fn;
103
112
  this.resInterceptors.push(item);
104
113
  return () => this.remove(this.resInterceptors, item);
105
114
  }
115
+ /**
116
+ * 注册一个错误拦截器。
117
+ */
106
118
  onError(fn) {
107
119
  this.errInterceptors.push(fn);
108
120
  return () => this.remove(this.errInterceptors, fn);
109
121
  }
122
+ /**
123
+ * 执行 HTTP 请求。
124
+ */
110
125
  async request(config) {
111
126
  let cfg = {
112
127
  method: "GET",
@@ -132,18 +147,33 @@ class UniRequestClient {
132
147
  throw err;
133
148
  }
134
149
  }
150
+ /**
151
+ * 发送 GET 请求。
152
+ */
135
153
  get(url, data) {
136
154
  return this.request({ url, method: "GET", data });
137
155
  }
156
+ /**
157
+ * 发送 POST 请求。
158
+ */
138
159
  post(url, data) {
139
160
  return this.request({ url, method: "POST", data });
140
161
  }
162
+ /**
163
+ * 发送 PUT 请求。
164
+ */
141
165
  put(url, data) {
142
166
  return this.request({ url, method: "PUT", data });
143
167
  }
168
+ /**
169
+ * 发送 DELETE 请求。
170
+ */
144
171
  del(url, data) {
145
172
  return this.request({ url, method: "DELETE", data });
146
173
  }
174
+ /**
175
+ * 上传本地文件,适配云存储(COS/OSS/七牛/Alist)或本地直传。
176
+ */
147
177
  upload(config) {
148
178
  const fileName = config.fileName ?? config.filePath.split("/").pop() ?? "file";
149
179
  const server = config.type === "local" && config.url ? config.url : config.server;
@@ -179,6 +209,9 @@ class UniRequestClient {
179
209
  });
180
210
  });
181
211
  }
212
+ /**
213
+ * 解析微服务风格的命名空间 URL。
214
+ */
182
215
  resolveServiceUrl(namespace, url, servicePrefix = "") {
183
216
  if (isAbsolute(url))
184
217
  return url;
@@ -188,11 +221,17 @@ class UniRequestClient {
188
221
  const prefix = [prefixValue, ns].filter(Boolean).join("/");
189
222
  return prefix ? `/${prefix}${path}` : path;
190
223
  }
224
+ /**
225
+ * 内部拼接基础 URL 与相对路径。
226
+ */
191
227
  resolveUrl(url) {
192
228
  if (isAbsolute(url))
193
229
  return url;
194
230
  return `${this.baseURL}${url}`;
195
231
  }
232
+ /**
233
+ * 内部基于 uni.request 发送网络请求的方法。
234
+ */
196
235
  send(url, cfg) {
197
236
  return new Promise((resolve, reject) => {
198
237
  uni.request({
@@ -213,6 +252,9 @@ class UniRequestClient {
213
252
  });
214
253
  });
215
254
  }
255
+ /**
256
+ * 从数组中安全移除某个拦截器实例。
257
+ */
216
258
  remove(items, item) {
217
259
  const index = items.indexOf(item);
218
260
  if (index > -1)
@@ -239,21 +281,46 @@ function useUpload() {
239
281
  return { uploading, upload };
240
282
  }
241
283
  class BaseService {
284
+ /**
285
+ * 发送服务请求。会自动拼接前缀与命名空间。
286
+ * @param options 请求配置项
287
+ * @returns 响应结果 Promise
288
+ */
242
289
  request(options) {
243
290
  return useRequest().request({
244
291
  ...options,
245
292
  url: useRequest().resolveServiceUrl(this.namespace ?? "", options.url, this.servicePrefix ?? "")
246
293
  });
247
294
  }
295
+ /**
296
+ * 快捷发送 GET 请求。
297
+ * @param url 请求相对路径
298
+ * @param data 请求参数
299
+ */
248
300
  get(url, data) {
249
301
  return this.request({ url, method: "GET", data });
250
302
  }
303
+ /**
304
+ * 快捷发送 POST 请求。
305
+ * @param url 请求相对路径
306
+ * @param data 请求携带的 body
307
+ */
251
308
  post(url, data) {
252
309
  return this.request({ url, method: "POST", data });
253
310
  }
311
+ /**
312
+ * 快捷发送 PUT 请求。
313
+ * @param url 请求相对路径
314
+ * @param data 请求携带的 body
315
+ */
254
316
  put(url, data) {
255
317
  return this.request({ url, method: "PUT", data });
256
318
  }
319
+ /**
320
+ * 快捷发送 DELETE 请求。
321
+ * @param url 请求相对路径
322
+ * @param data 请求参数
323
+ */
257
324
  del(url, data) {
258
325
  return this.request({ url, method: "DELETE", data });
259
326
  }
@@ -270,15 +337,29 @@ function ServicePrefix(value) {
270
337
  }
271
338
  function useMsg() {
272
339
  function toast(opts) {
273
- const normalized = typeof opts === "string" ? { message: opts } : opts;
274
- const { message, icon = "none", image, duration = 2e3, mask = false, position = "center" } = normalized;
275
- uni.showToast({ title: message, icon, image, duration, mask, position });
340
+ const {
341
+ message,
342
+ icon = "none",
343
+ image = void 0,
344
+ duration = 2e3,
345
+ mask = false,
346
+ position = "center"
347
+ } = typeof opts === "string" ? { message: opts } : opts;
348
+ const mappedIcon = icon === "fail" || icon === "exception" ? "error" : icon;
349
+ uni.showToast({
350
+ title: message,
351
+ icon: mappedIcon,
352
+ image,
353
+ duration,
354
+ mask,
355
+ position
356
+ });
276
357
  }
277
358
  function success(message) {
278
359
  uni.showToast({ title: message, icon: "success", duration: 2e3 });
279
360
  }
280
361
  function error(message) {
281
- uni.showToast({ title: message, icon: "fail", duration: 2e3 });
362
+ uni.showToast({ title: message, icon: "error", duration: 2e3 });
282
363
  }
283
364
  function showLoading(message = "加载中...") {
284
365
  uni.showLoading({ title: message, mask: true });
@@ -310,13 +391,11 @@ function useMsg() {
310
391
  });
311
392
  });
312
393
  }
313
- function modal(opts) {
314
- return confirm(opts);
315
- }
316
394
  function setLoadingBar(progress) {
317
395
  const clamped = Math.max(0, Math.min(100, progress));
396
+ const filled = Math.round(clamped / 2);
318
397
  uni.setNavigationBarTitle({
319
- title: `${"■".repeat(Math.round(clamped / 2))}${"□".repeat(50 - Math.round(clamped / 2))} ${clamped}%`
398
+ title: `${"■".repeat(filled)}${"□".repeat(50 - filled)} ${clamped}%`
320
399
  });
321
400
  }
322
401
  return {
@@ -327,7 +406,7 @@ function useMsg() {
327
406
  showLoading,
328
407
  hideLoading,
329
408
  confirm,
330
- modal,
409
+ modal: confirm,
331
410
  setLoadingBar
332
411
  };
333
412
  }
@@ -350,141 +429,141 @@ function toNumber(val, def) {
350
429
  function toBoolean(val, def) {
351
430
  if (typeof val === "boolean")
352
431
  return val;
353
- if (val === 0 || val === "0")
432
+ if (val === 0 || val === "0" || val === "false")
354
433
  return false;
355
- if (val === 1 || val === "1")
434
+ if (val === 1 || val === "1" || val === "true")
356
435
  return true;
357
436
  return def;
358
437
  }
359
- function useUtils() {
360
- function copy(text, tip = true) {
361
- return new Promise((ok) => {
362
- uni.setClipboardData({
363
- data: text,
364
- showToast: false,
365
- success: () => {
366
- if (tip) {
367
- uni.showToast({ title: "复制成功", icon: "none", duration: 1500 });
368
- }
369
- ok(true);
370
- },
371
- fail: () => ok(false)
372
- });
438
+ function copy(text, tip = true) {
439
+ return new Promise((resolve) => {
440
+ uni.setClipboardData({
441
+ data: text,
442
+ showToast: false,
443
+ success: () => {
444
+ if (tip) {
445
+ uni.showToast({ title: "复制成功", icon: "none", duration: 1500 });
446
+ }
447
+ resolve(true);
448
+ },
449
+ fail: () => resolve(false)
373
450
  });
374
- }
375
- function paste() {
376
- return new Promise((ok) => {
377
- uni.getClipboardData({
378
- success: (res) => ok(res.data),
379
- fail: () => ok("")
380
- });
451
+ });
452
+ }
453
+ function paste() {
454
+ return new Promise((resolve) => {
455
+ uni.getClipboardData({
456
+ success: (res) => resolve(res.data),
457
+ fail: () => resolve("")
381
458
  });
382
- }
383
- function auth() {
384
- uni.showModal({
385
- title: "提示",
386
- content: "需要授权相册权限",
387
- confirmText: "去设置",
388
- success: (res) => {
389
- if (res.confirm)
390
- uni.openSetting();
459
+ });
460
+ }
461
+ function auth() {
462
+ uni.showModal({
463
+ title: "提示",
464
+ content: "需要授权相册权限",
465
+ confirmText: "去设置",
466
+ success: (res) => {
467
+ if (res.confirm)
468
+ uni.openSetting();
469
+ }
470
+ });
471
+ }
472
+ function saveImage(path) {
473
+ return new Promise((resolve) => {
474
+ uni.saveImageToPhotosAlbum({
475
+ filePath: path,
476
+ success: () => {
477
+ uni.showToast({ title: "保存成功", icon: "success" });
478
+ resolve(true);
479
+ },
480
+ fail: (err) => {
481
+ const msg = String(err.errMsg || "");
482
+ if (msg.includes("auth deny") || msg.includes("authorize")) {
483
+ auth();
484
+ } else {
485
+ uni.showToast({ title: "保存失败", icon: "none" });
486
+ }
487
+ resolve(false);
391
488
  }
392
489
  });
393
- }
394
- function saveImage(path) {
395
- return new Promise((ok) => {
396
- uni.saveImageToPhotosAlbum({
397
- filePath: path,
398
- success: () => {
399
- uni.showToast({ title: "保存成功", icon: "success" });
400
- ok(true);
401
- },
402
- fail: (err) => {
403
- const msg = String(err.errMsg || "");
404
- if (msg.includes("auth deny") || msg.includes("authorize")) {
405
- auth();
406
- } else {
407
- uni.showToast({ title: "保存失败", icon: "none" });
408
- }
409
- ok(false);
490
+ });
491
+ }
492
+ function saveVideoFile(path) {
493
+ return new Promise((resolve) => {
494
+ uni.saveVideoToPhotosAlbum({
495
+ filePath: path,
496
+ success: () => {
497
+ uni.showToast({ title: "保存成功", icon: "success" });
498
+ resolve(true);
499
+ },
500
+ fail: (err) => {
501
+ const msg = String(err.errMsg || "");
502
+ if (msg.includes("auth deny") || msg.includes("authorize")) {
503
+ auth();
504
+ } else {
505
+ uni.showToast({ title: "保存失败", icon: "none" });
410
506
  }
411
- });
507
+ resolve(false);
508
+ }
412
509
  });
413
- }
414
- function saveVideo(path) {
415
- return new Promise((ok) => {
416
- uni.saveVideoToPhotosAlbum({
417
- filePath: path,
418
- success: () => {
419
- uni.showToast({ title: "保存成功", icon: "success" });
420
- ok(true);
421
- },
422
- fail: (err) => {
423
- const msg = String(err.errMsg || "");
424
- if (msg.includes("auth deny") || msg.includes("authorize")) {
425
- auth();
426
- } else {
427
- uni.showToast({ title: "保存失败", icon: "none" });
428
- }
429
- ok(false);
510
+ });
511
+ }
512
+ function download(opt) {
513
+ return new Promise((resolve) => {
514
+ const task = uni.downloadFile({
515
+ url: opt.url,
516
+ filePath: opt.path,
517
+ header: opt.header,
518
+ success: (res) => {
519
+ if (res.statusCode === 200) {
520
+ resolve({ ok: true, path: res.tempFilePath, code: res.statusCode });
521
+ } else {
522
+ resolve({ ok: false, code: res.statusCode, msg: `下载失败,状态码:${res.statusCode}` });
430
523
  }
431
- });
524
+ },
525
+ fail: (err) => resolve({ ok: false, msg: err.errMsg })
432
526
  });
433
- }
434
- function download(opt) {
435
- return new Promise((ok) => {
436
- const task = uni.downloadFile({
437
- url: opt.url,
438
- filePath: opt.path,
439
- header: opt.header,
440
- success: (res) => {
441
- if (res.statusCode === 200) {
442
- ok({ ok: true, path: res.tempFilePath, code: res.statusCode });
443
- } else {
444
- ok({ ok: false, code: res.statusCode, msg: `下载失败,状态码:${res.statusCode}` });
445
- }
446
- },
447
- fail: (err) => ok({ ok: false, msg: err.errMsg })
527
+ if (opt.progress) {
528
+ task.onProgressUpdate((res) => {
529
+ opt.progress(res.progress, res.totalBytesWritten, res.totalBytesExpectedToWrite);
448
530
  });
449
- if (opt.progress) {
450
- task.onProgressUpdate((res) => {
451
- opt.progress(res.progress, res.totalBytesWritten, res.totalBytesExpectedToWrite);
452
- });
453
- }
454
- });
455
- }
456
- async function saveImageUrl(url, progress) {
457
- try {
458
- uni.showLoading({ title: "下载中...", mask: true });
459
- const res = await download({ url, progress: progress ? (value) => progress(value) : void 0 });
460
- uni.hideLoading();
461
- if (!res.ok || !res.path) {
462
- uni.showToast({ title: res.msg || "下载失败", icon: "none" });
463
- return false;
464
- }
465
- return await saveImage(res.path);
466
- } catch {
467
- uni.hideLoading();
468
- uni.showToast({ title: "操作失败", icon: "none" });
531
+ }
532
+ });
533
+ }
534
+ async function saveImageUrl(url, progress) {
535
+ try {
536
+ uni.showLoading({ title: "下载中...", mask: true });
537
+ const res = await download({ url, progress: progress ? (value) => progress(value) : void 0 });
538
+ uni.hideLoading();
539
+ if (!res.ok || !res.path) {
540
+ uni.showToast({ title: res.msg || "下载失败", icon: "none" });
469
541
  return false;
470
542
  }
543
+ return await saveImage(res.path);
544
+ } catch {
545
+ uni.hideLoading();
546
+ uni.showToast({ title: "操作失败", icon: "none" });
547
+ return false;
471
548
  }
472
- async function saveVideoUrl(url, progress) {
473
- try {
474
- uni.showLoading({ title: "下载中...", mask: true });
475
- const res = await download({ url, progress: progress ? (value) => progress(value) : void 0 });
476
- uni.hideLoading();
477
- if (!res.ok || !res.path) {
478
- uni.showToast({ title: res.msg || "下载失败", icon: "none" });
479
- return false;
480
- }
481
- return await saveVideo(res.path);
482
- } catch {
483
- uni.hideLoading();
484
- uni.showToast({ title: "操作失败", icon: "none" });
549
+ }
550
+ async function saveVideoUrl(url, progress) {
551
+ try {
552
+ uni.showLoading({ title: "下载中...", mask: true });
553
+ const res = await download({ url, progress: progress ? (value) => progress(value) : void 0 });
554
+ uni.hideLoading();
555
+ if (!res.ok || !res.path) {
556
+ uni.showToast({ title: res.msg || "下载失败", icon: "none" });
485
557
  return false;
486
558
  }
559
+ return await saveVideoFile(res.path);
560
+ } catch {
561
+ uni.hideLoading();
562
+ uni.showToast({ title: "操作失败", icon: "none" });
563
+ return false;
487
564
  }
565
+ }
566
+ function useUtils() {
488
567
  return {
489
568
  withQuery,
490
569
  toQuery,
@@ -494,7 +573,7 @@ function useUtils() {
494
573
  copy,
495
574
  paste,
496
575
  saveImage,
497
- saveVideo,
576
+ saveVideoFile,
498
577
  download,
499
578
  saveImageUrl,
500
579
  saveVideoUrl
@@ -588,10 +667,9 @@ function getQueryInfo(info) {
588
667
  }
589
668
  function useDevice() {
590
669
  const info = getDevice();
591
- const { toQuery: toQuery2 } = useUtils();
592
670
  return {
593
671
  info,
594
- query: toQuery2(getQueryInfo(info))
672
+ query: toQuery(getQueryInfo(info))
595
673
  };
596
674
  }
597
675
  function clearDeviceCache() {
@@ -630,8 +708,8 @@ function buildPayload(base, extra) {
630
708
  }
631
709
  function showShareMenu() {
632
710
  var _a;
633
- const api2 = typeof uni !== "undefined" ? uni : void 0;
634
- (_a = api2 == null ? void 0 : api2.showShareMenu) == null ? void 0 : _a.call(api2, {
711
+ const api = typeof uni !== "undefined" ? uni : void 0;
712
+ (_a = api == null ? void 0 : api.showShareMenu) == null ? void 0 : _a.call(api, {
635
713
  withShareTicket: true,
636
714
  menus: ["shareAppMessage", "shareTimeline"],
637
715
  fail: () => void 0
@@ -670,18 +748,20 @@ function useShare(config = {}) {
670
748
  showShareMenu
671
749
  };
672
750
  }
673
- let popupAd = null;
751
+ const popupCache = /* @__PURE__ */ new Map();
752
+ const rewardCache = /* @__PURE__ */ new Map();
753
+ let activePopupAdId = "";
674
754
  let popupDone;
675
- let popupClose = null;
676
- let popupError = null;
677
- let rewardAd = null;
755
+ let activeRewardAdId = "";
678
756
  let rewardDone;
679
757
  let rewardPromise = null;
680
758
  let rewardResolve = null;
681
- let rewardClose = null;
682
- let rewardError = null;
683
- function api() {
684
- return typeof wx === "undefined" ? null : wx;
759
+ function getAdApi() {
760
+ if (typeof uni !== "undefined")
761
+ return uni;
762
+ if (typeof wx !== "undefined")
763
+ return wx;
764
+ return null;
685
765
  }
686
766
  function finish(res) {
687
767
  rewardDone == null ? void 0 : rewardDone(res);
@@ -689,53 +769,43 @@ function finish(res) {
689
769
  rewardResolve = null;
690
770
  rewardPromise = null;
691
771
  }
692
- function clearReward() {
693
- var _a, _b;
694
- if (!rewardAd)
695
- return;
696
- if (rewardClose)
697
- (_a = rewardAd.offClose) == null ? void 0 : _a.call(rewardAd, rewardClose);
698
- if (rewardError)
699
- (_b = rewardAd.offError) == null ? void 0 : _b.call(rewardAd, rewardError);
700
- rewardClose = null;
701
- rewardError = null;
702
- }
703
772
  function useHlwAd() {
704
- function clearPopup() {
705
- var _a, _b;
706
- if (!popupAd)
707
- return;
708
- if (popupClose)
709
- (_a = popupAd.offClose) == null ? void 0 : _a.call(popupAd, popupClose);
710
- if (popupError)
711
- (_b = popupAd.offError) == null ? void 0 : _b.call(popupAd, popupError);
712
- popupClose = null;
713
- popupError = null;
714
- }
715
773
  function setAdPopup(adId, done) {
716
774
  var _a, _b, _c;
717
775
  popupDone = done;
718
- const wxApi = api();
719
- if (!adId || !(wxApi == null ? void 0 : wxApi.createInterstitialAd))
776
+ if (!adId)
720
777
  return false;
721
- clearPopup();
722
- popupAd = wxApi.createInterstitialAd({ adUnitId: adId });
723
- (_a = popupAd.onLoad) == null ? void 0 : _a.call(popupAd, () => {
724
- });
725
- popupError = (err) => {
726
- console.error("插屏广告加载失败", err);
727
- popupDone == null ? void 0 : popupDone(false);
728
- };
729
- popupClose = () => {
730
- popupDone == null ? void 0 : popupDone(true);
731
- };
732
- (_b = popupAd.onError) == null ? void 0 : _b.call(popupAd, popupError);
733
- (_c = popupAd.onClose) == null ? void 0 : _c.call(popupAd, popupClose);
778
+ const api = getAdApi();
779
+ if (!(api == null ? void 0 : api.createInterstitialAd))
780
+ return false;
781
+ activePopupAdId = adId;
782
+ if (!popupCache.has(adId)) {
783
+ try {
784
+ const ad = api.createInterstitialAd({ adUnitId: adId });
785
+ (_a = ad.onLoad) == null ? void 0 : _a.call(ad, () => console.log(`[HlwAd] Interstitial loaded: ${adId}`));
786
+ (_b = ad.onError) == null ? void 0 : _b.call(ad, (err) => {
787
+ console.error("[HlwAd] Interstitial load error:", err);
788
+ if (activePopupAdId === adId) {
789
+ popupDone == null ? void 0 : popupDone(false);
790
+ }
791
+ });
792
+ (_c = ad.onClose) == null ? void 0 : _c.call(ad, () => {
793
+ if (activePopupAdId === adId) {
794
+ popupDone == null ? void 0 : popupDone(true);
795
+ }
796
+ });
797
+ popupCache.set(adId, ad);
798
+ } catch (e) {
799
+ console.error("[HlwAd] Interstitial creation failed:", e);
800
+ return false;
801
+ }
802
+ }
734
803
  return true;
735
804
  }
736
805
  function showAdPopup(delay = 3e3) {
737
806
  return new Promise((resolve) => {
738
- if (!popupAd) {
807
+ const ad = popupCache.get(activePopupAdId);
808
+ if (!ad) {
739
809
  resolve(false);
740
810
  return;
741
811
  }
@@ -745,8 +815,8 @@ function useHlwAd() {
745
815
  resolve(ok);
746
816
  };
747
817
  setTimeout(() => {
748
- popupAd.show().catch((err) => {
749
- console.error("插屏广告显示失败", err);
818
+ ad.show().catch((err) => {
819
+ console.error("[HlwAd] Interstitial show error:", err);
750
820
  popupDone == null ? void 0 : popupDone(false);
751
821
  });
752
822
  }, Math.max(0, delay));
@@ -758,37 +828,52 @@ function useHlwAd() {
758
828
  rewardPromise = new Promise((resolve) => {
759
829
  rewardResolve = resolve;
760
830
  });
761
- const wxApi = api();
762
- if (!adId || !(wxApi == null ? void 0 : wxApi.createRewardedVideoAd)) {
831
+ if (!adId) {
763
832
  finish({ ok: false });
764
833
  return rewardPromise;
765
834
  }
766
- clearReward();
767
- rewardAd = wxApi.createRewardedVideoAd({ adUnitId: adId });
768
- (_a = rewardAd.onLoad) == null ? void 0 : _a.call(rewardAd, () => {
769
- });
770
- rewardClose = (res) => {
771
- finish({ ok: !!(res == null ? void 0 : res.isEnded), isEnded: !!(res == null ? void 0 : res.isEnded) });
772
- };
773
- rewardError = (err) => {
774
- console.error("激励视频广告加载失败", err);
775
- finish({ ok: false, err });
776
- };
777
- (_b = rewardAd.onClose) == null ? void 0 : _b.call(rewardAd, rewardClose);
778
- (_c = rewardAd.onError) == null ? void 0 : _c.call(rewardAd, rewardError);
835
+ const api = getAdApi();
836
+ if (!(api == null ? void 0 : api.createRewardedVideoAd)) {
837
+ finish({ ok: false });
838
+ return rewardPromise;
839
+ }
840
+ activeRewardAdId = adId;
841
+ if (!rewardCache.has(adId)) {
842
+ try {
843
+ const ad = api.createRewardedVideoAd({ adUnitId: adId });
844
+ (_a = ad.onLoad) == null ? void 0 : _a.call(ad, () => console.log(`[HlwAd] Rewarded video loaded: ${adId}`));
845
+ (_b = ad.onError) == null ? void 0 : _b.call(ad, (err) => {
846
+ console.error("[HlwAd] Rewarded video load error:", err);
847
+ if (activeRewardAdId === adId) {
848
+ finish({ ok: false, err });
849
+ }
850
+ });
851
+ (_c = ad.onClose) == null ? void 0 : _c.call(ad, (res) => {
852
+ if (activeRewardAdId === adId) {
853
+ const isEnded = !!(res == null ? void 0 : res.isEnded);
854
+ finish({ ok: isEnded, isEnded });
855
+ }
856
+ });
857
+ rewardCache.set(adId, ad);
858
+ } catch (e) {
859
+ console.error("[HlwAd] Rewarded video creation failed:", e);
860
+ finish({ ok: false, err: e });
861
+ }
862
+ }
779
863
  return rewardPromise;
780
864
  }
781
865
  function showAdReward() {
782
- if (!rewardAd) {
866
+ const ad = rewardCache.get(activeRewardAdId);
867
+ if (!ad) {
783
868
  return Promise.resolve({ ok: false });
784
869
  }
785
870
  const current = rewardPromise || new Promise((resolve) => {
786
871
  rewardResolve = resolve;
787
872
  });
788
873
  rewardPromise = current;
789
- rewardAd.show().catch(() => {
790
- rewardAd.load().then(() => rewardAd.show()).catch((err) => {
791
- console.error("激励视频广告显示失败", err);
874
+ ad.show().catch(() => {
875
+ ad.load().then(() => ad.show()).catch((err) => {
876
+ console.error("[HlwAd] Rewarded video show error:", err);
792
877
  finish({ ok: false, err });
793
878
  });
794
879
  });
@@ -858,12 +943,19 @@ function navigate(type = "navigateTo", url = "", options = {}) {
858
943
  }
859
944
  function useNavigate() {
860
945
  return {
946
+ /** 核心底层路由分发函数 */
861
947
  navigate,
948
+ /** 保留当前页面,跳转到应用内的某个页面 */
862
949
  to: (url, options) => navigate("navigateTo", url, options),
950
+ /** 关闭当前页面,跳转到应用内的某个页面 */
863
951
  redirect: (url, options) => navigate("redirectTo", url, options),
952
+ /** 跳转到 switchTab 页面,并关闭其他所有非 tabBar 页面 */
864
953
  tab: (url, options) => navigate("switchTab", url, options),
954
+ /** 关闭所有页面,打开到应用内的某个页面 */
865
955
  reLaunch: (url, options) => navigate("reLaunch", url, options),
956
+ /** 关闭当前页面,返回上一页面或多级页面 */
866
957
  back: (delta = 1, options = {}) => navigate("navigateBack", "", { ...options, delta }),
958
+ /** 打开另一个小程序 */
867
959
  miniProgram: (appId, options) => navigate("miniprogram", appId, options)
868
960
  };
869
961
  }
@@ -1268,6 +1360,7 @@ function copyText(data) {
1268
1360
  uni.setClipboardData({
1269
1361
  data,
1270
1362
  showToast: false,
1363
+ // 禁用系统默认 Toast 提示,使用自定义的无图标 Toast
1271
1364
  success: () => uni.showToast({ title: "复制成功", icon: "none", duration: 1500 })
1272
1365
  });
1273
1366
  }
@@ -1286,13 +1379,13 @@ function injectTap(vnode, binding) {
1286
1379
  }
1287
1380
  const vCopy = {
1288
1381
  /**
1289
- * 在指令创建时注入点击事件。
1382
+ * 在指令创建时注入点击事件拦截器。
1290
1383
  */
1291
1384
  created(el, binding, vnode) {
1292
1385
  injectTap(vnode, binding);
1293
1386
  },
1294
1387
  /**
1295
- * 在绑定值更新前重新注入点击事件。
1388
+ * 在绑定值更新前重新注入点击事件拦截器,以获取最新的绑定值。
1296
1389
  */
1297
1390
  beforeUpdate(el, binding, vnode) {
1298
1391
  injectTap(vnode, binding);
@@ -1314,9 +1407,12 @@ export {
1314
1407
  TYPOGRAPHY_ROLES,
1315
1408
  adapters,
1316
1409
  alistAdapter,
1410
+ auth,
1317
1411
  buildThemeStyle,
1318
1412
  clearDeviceCache,
1413
+ copy,
1319
1414
  cosAdapter,
1415
+ download,
1320
1416
  getAdapter,
1321
1417
  getCurrentAppearance,
1322
1418
  getCurrentAppearanceMode,
@@ -1328,8 +1424,17 @@ export {
1328
1424
  getCurrentTypographyVars,
1329
1425
  hlw,
1330
1426
  ossAdapter,
1427
+ paste,
1331
1428
  qiniuAdapter,
1332
1429
  resolveAppearance,
1430
+ saveImage,
1431
+ saveImageUrl,
1432
+ saveVideoFile,
1433
+ saveVideoUrl,
1434
+ signText,
1435
+ toBoolean,
1436
+ toNumber,
1437
+ toQuery,
1333
1438
  useApp,
1334
1439
  useDevice,
1335
1440
  useHlwAd,
@@ -1342,5 +1447,6 @@ export {
1342
1447
  useThemeStore,
1343
1448
  useUpload,
1344
1449
  useUtils,
1345
- vCopy
1450
+ vCopy,
1451
+ withQuery
1346
1452
  };