@hlw-uni/mp-vue 2.1.57 → 2.1.59

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 (49) 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/index.d.ts +1 -1
  10. package/dist/composables/request/service.d.ts +73 -0
  11. package/dist/composables/request/types.d.ts +50 -13
  12. package/dist/composables/share/index.d.ts +38 -0
  13. package/dist/composables/theme/appearance.d.ts +30 -4
  14. package/dist/composables/theme/font.d.ts +23 -0
  15. package/dist/composables/theme/index.d.ts +19 -6
  16. package/dist/composables/theme/palette.d.ts +23 -0
  17. package/dist/composables/theme/typography.d.ts +9 -1
  18. package/dist/composables/utils/index.d.ts +120 -13
  19. package/dist/directives/copy.d.ts +5 -0
  20. package/dist/hlw.d.ts +10 -0
  21. package/dist/index.js +310 -199
  22. package/dist/index.mjs +311 -200
  23. package/dist/stores/theme.d.ts +3 -0
  24. package/package.json +2 -2
  25. package/src/app.ts +20 -3
  26. package/src/components/hlw-add-mini/README.md +10 -11
  27. package/src/components/hlw-add-mini/index.vue +93 -66
  28. package/src/components/hlw-button/index.vue +33 -18
  29. package/src/components/hlw-custom/hlw-custom.vue +118 -0
  30. package/src/composables/ad/index.ts +136 -62
  31. package/src/composables/device/index.ts +32 -2
  32. package/src/composables/index.ts +18 -1
  33. package/src/composables/msg/index.ts +70 -16
  34. package/src/composables/navigator/index.ts +45 -1
  35. package/src/composables/refs/index.ts +27 -4
  36. package/src/composables/request/client.ts +149 -0
  37. package/src/composables/request/index.ts +1 -1
  38. package/src/composables/request/service.ts +72 -0
  39. package/src/composables/request/types.ts +53 -13
  40. package/src/composables/share/index.ts +48 -0
  41. package/src/composables/theme/appearance.ts +31 -4
  42. package/src/composables/theme/font.ts +23 -0
  43. package/src/composables/theme/index.ts +23 -7
  44. package/src/composables/theme/palette.ts +32 -0
  45. package/src/composables/theme/typography.ts +9 -1
  46. package/src/composables/utils/index.ts +227 -127
  47. package/src/directives/copy.ts +31 -19
  48. package/src/hlw.ts +11 -0
  49. 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)
@@ -238,22 +280,48 @@ function useUpload() {
238
280
  }
239
281
  return { uploading, upload };
240
282
  }
283
+ var define_import_meta_env_default = {};
241
284
  class BaseService {
285
+ /**
286
+ * 发送服务请求。会自动拼接前缀与命名空间。
287
+ * @param options 请求配置项
288
+ * @returns 响应结果 Promise
289
+ */
242
290
  request(options) {
243
291
  return useRequest().request({
244
292
  ...options,
245
293
  url: useRequest().resolveServiceUrl(this.namespace ?? "", options.url, this.servicePrefix ?? "")
246
294
  });
247
295
  }
296
+ /**
297
+ * 快捷发送 GET 请求。
298
+ * @param url 请求相对路径
299
+ * @param data 请求参数
300
+ */
248
301
  get(url, data) {
249
302
  return this.request({ url, method: "GET", data });
250
303
  }
304
+ /**
305
+ * 快捷发送 POST 请求。
306
+ * @param url 请求相对路径
307
+ * @param data 请求携带的 body
308
+ */
251
309
  post(url, data) {
252
310
  return this.request({ url, method: "POST", data });
253
311
  }
312
+ /**
313
+ * 快捷发送 PUT 请求。
314
+ * @param url 请求相对路径
315
+ * @param data 请求携带的 body
316
+ */
254
317
  put(url, data) {
255
318
  return this.request({ url, method: "PUT", data });
256
319
  }
320
+ /**
321
+ * 快捷发送 DELETE 请求。
322
+ * @param url 请求相对路径
323
+ * @param data 请求参数
324
+ */
257
325
  del(url, data) {
258
326
  return this.request({ url, method: "DELETE", data });
259
327
  }
@@ -268,17 +336,34 @@ function ServicePrefix(value) {
268
336
  target.prototype.servicePrefix = typeof value === "string" ? value : value.prefix;
269
337
  };
270
338
  }
339
+ function PluginService(target) {
340
+ target.prototype.servicePrefix = define_import_meta_env_default.VITE_PLUGIN_NAME || "";
341
+ }
271
342
  function useMsg() {
272
343
  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 });
344
+ const {
345
+ message,
346
+ icon = "none",
347
+ image = void 0,
348
+ duration = 2e3,
349
+ mask = false,
350
+ position = "center"
351
+ } = typeof opts === "string" ? { message: opts } : opts;
352
+ const mappedIcon = icon === "fail" || icon === "exception" ? "error" : icon;
353
+ uni.showToast({
354
+ title: message,
355
+ icon: mappedIcon,
356
+ image,
357
+ duration,
358
+ mask,
359
+ position
360
+ });
276
361
  }
277
362
  function success(message) {
278
363
  uni.showToast({ title: message, icon: "success", duration: 2e3 });
279
364
  }
280
365
  function error(message) {
281
- uni.showToast({ title: message, icon: "fail", duration: 2e3 });
366
+ uni.showToast({ title: message, icon: "error", duration: 2e3 });
282
367
  }
283
368
  function showLoading(message = "加载中...") {
284
369
  uni.showLoading({ title: message, mask: true });
@@ -310,13 +395,11 @@ function useMsg() {
310
395
  });
311
396
  });
312
397
  }
313
- function modal(opts) {
314
- return confirm(opts);
315
- }
316
398
  function setLoadingBar(progress) {
317
399
  const clamped = Math.max(0, Math.min(100, progress));
400
+ const filled = Math.round(clamped / 2);
318
401
  uni.setNavigationBarTitle({
319
- title: `${"■".repeat(Math.round(clamped / 2))}${"□".repeat(50 - Math.round(clamped / 2))} ${clamped}%`
402
+ title: `${"■".repeat(filled)}${"□".repeat(50 - filled)} ${clamped}%`
320
403
  });
321
404
  }
322
405
  return {
@@ -327,7 +410,7 @@ function useMsg() {
327
410
  showLoading,
328
411
  hideLoading,
329
412
  confirm,
330
- modal,
413
+ modal: confirm,
331
414
  setLoadingBar
332
415
  };
333
416
  }
@@ -350,141 +433,141 @@ function toNumber(val, def) {
350
433
  function toBoolean(val, def) {
351
434
  if (typeof val === "boolean")
352
435
  return val;
353
- if (val === 0 || val === "0")
436
+ if (val === 0 || val === "0" || val === "false")
354
437
  return false;
355
- if (val === 1 || val === "1")
438
+ if (val === 1 || val === "1" || val === "true")
356
439
  return true;
357
440
  return def;
358
441
  }
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
- });
442
+ function copy(text, tip = true) {
443
+ return new Promise((resolve) => {
444
+ uni.setClipboardData({
445
+ data: text,
446
+ showToast: false,
447
+ success: () => {
448
+ if (tip) {
449
+ uni.showToast({ title: "复制成功", icon: "none", duration: 1500 });
450
+ }
451
+ resolve(true);
452
+ },
453
+ fail: () => resolve(false)
373
454
  });
374
- }
375
- function paste() {
376
- return new Promise((ok) => {
377
- uni.getClipboardData({
378
- success: (res) => ok(res.data),
379
- fail: () => ok("")
380
- });
455
+ });
456
+ }
457
+ function paste() {
458
+ return new Promise((resolve) => {
459
+ uni.getClipboardData({
460
+ success: (res) => resolve(res.data),
461
+ fail: () => resolve("")
381
462
  });
382
- }
383
- function auth() {
384
- uni.showModal({
385
- title: "提示",
386
- content: "需要授权相册权限",
387
- confirmText: "去设置",
388
- success: (res) => {
389
- if (res.confirm)
390
- uni.openSetting();
463
+ });
464
+ }
465
+ function auth() {
466
+ uni.showModal({
467
+ title: "提示",
468
+ content: "需要授权相册权限",
469
+ confirmText: "去设置",
470
+ success: (res) => {
471
+ if (res.confirm)
472
+ uni.openSetting();
473
+ }
474
+ });
475
+ }
476
+ function saveImage(path) {
477
+ return new Promise((resolve) => {
478
+ uni.saveImageToPhotosAlbum({
479
+ filePath: path,
480
+ success: () => {
481
+ uni.showToast({ title: "保存成功", icon: "success" });
482
+ resolve(true);
483
+ },
484
+ fail: (err) => {
485
+ const msg = String(err.errMsg || "");
486
+ if (msg.includes("auth deny") || msg.includes("authorize")) {
487
+ auth();
488
+ } else {
489
+ uni.showToast({ title: "保存失败", icon: "none" });
490
+ }
491
+ resolve(false);
391
492
  }
392
493
  });
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);
494
+ });
495
+ }
496
+ function saveVideoFile(path) {
497
+ return new Promise((resolve) => {
498
+ uni.saveVideoToPhotosAlbum({
499
+ filePath: path,
500
+ success: () => {
501
+ uni.showToast({ title: "保存成功", icon: "success" });
502
+ resolve(true);
503
+ },
504
+ fail: (err) => {
505
+ const msg = String(err.errMsg || "");
506
+ if (msg.includes("auth deny") || msg.includes("authorize")) {
507
+ auth();
508
+ } else {
509
+ uni.showToast({ title: "保存失败", icon: "none" });
410
510
  }
411
- });
511
+ resolve(false);
512
+ }
412
513
  });
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);
514
+ });
515
+ }
516
+ function download(opt) {
517
+ return new Promise((resolve) => {
518
+ const task = uni.downloadFile({
519
+ url: opt.url,
520
+ filePath: opt.path,
521
+ header: opt.header,
522
+ success: (res) => {
523
+ if (res.statusCode === 200) {
524
+ resolve({ ok: true, path: res.tempFilePath, code: res.statusCode });
525
+ } else {
526
+ resolve({ ok: false, code: res.statusCode, msg: `下载失败,状态码:${res.statusCode}` });
430
527
  }
431
- });
528
+ },
529
+ fail: (err) => resolve({ ok: false, msg: err.errMsg })
432
530
  });
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 })
531
+ if (opt.progress) {
532
+ task.onProgressUpdate((res) => {
533
+ opt.progress(res.progress, res.totalBytesWritten, res.totalBytesExpectedToWrite);
448
534
  });
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" });
535
+ }
536
+ });
537
+ }
538
+ async function saveImageUrl(url, progress) {
539
+ try {
540
+ uni.showLoading({ title: "下载中...", mask: true });
541
+ const res = await download({ url, progress: progress ? (value) => progress(value) : void 0 });
542
+ uni.hideLoading();
543
+ if (!res.ok || !res.path) {
544
+ uni.showToast({ title: res.msg || "下载失败", icon: "none" });
469
545
  return false;
470
546
  }
547
+ return await saveImage(res.path);
548
+ } catch {
549
+ uni.hideLoading();
550
+ uni.showToast({ title: "操作失败", icon: "none" });
551
+ return false;
471
552
  }
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" });
553
+ }
554
+ async function saveVideoUrl(url, progress) {
555
+ try {
556
+ uni.showLoading({ title: "下载中...", mask: true });
557
+ const res = await download({ url, progress: progress ? (value) => progress(value) : void 0 });
558
+ uni.hideLoading();
559
+ if (!res.ok || !res.path) {
560
+ uni.showToast({ title: res.msg || "下载失败", icon: "none" });
485
561
  return false;
486
562
  }
563
+ return await saveVideoFile(res.path);
564
+ } catch {
565
+ uni.hideLoading();
566
+ uni.showToast({ title: "操作失败", icon: "none" });
567
+ return false;
487
568
  }
569
+ }
570
+ function useUtils() {
488
571
  return {
489
572
  withQuery,
490
573
  toQuery,
@@ -494,7 +577,7 @@ function useUtils() {
494
577
  copy,
495
578
  paste,
496
579
  saveImage,
497
- saveVideo,
580
+ saveVideoFile,
498
581
  download,
499
582
  saveImageUrl,
500
583
  saveVideoUrl
@@ -588,10 +671,9 @@ function getQueryInfo(info) {
588
671
  }
589
672
  function useDevice() {
590
673
  const info = getDevice();
591
- const { toQuery: toQuery2 } = useUtils();
592
674
  return {
593
675
  info,
594
- query: toQuery2(getQueryInfo(info))
676
+ query: toQuery(getQueryInfo(info))
595
677
  };
596
678
  }
597
679
  function clearDeviceCache() {
@@ -630,8 +712,8 @@ function buildPayload(base, extra) {
630
712
  }
631
713
  function showShareMenu() {
632
714
  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, {
715
+ const api = typeof uni !== "undefined" ? uni : void 0;
716
+ (_a = api == null ? void 0 : api.showShareMenu) == null ? void 0 : _a.call(api, {
635
717
  withShareTicket: true,
636
718
  menus: ["shareAppMessage", "shareTimeline"],
637
719
  fail: () => void 0
@@ -670,18 +752,20 @@ function useShare(config = {}) {
670
752
  showShareMenu
671
753
  };
672
754
  }
673
- let popupAd = null;
755
+ const popupCache = /* @__PURE__ */ new Map();
756
+ const rewardCache = /* @__PURE__ */ new Map();
757
+ let activePopupAdId = "";
674
758
  let popupDone;
675
- let popupClose = null;
676
- let popupError = null;
677
- let rewardAd = null;
759
+ let activeRewardAdId = "";
678
760
  let rewardDone;
679
761
  let rewardPromise = null;
680
762
  let rewardResolve = null;
681
- let rewardClose = null;
682
- let rewardError = null;
683
- function api() {
684
- return typeof wx === "undefined" ? null : wx;
763
+ function getAdApi() {
764
+ if (typeof uni !== "undefined")
765
+ return uni;
766
+ if (typeof wx !== "undefined")
767
+ return wx;
768
+ return null;
685
769
  }
686
770
  function finish(res) {
687
771
  rewardDone == null ? void 0 : rewardDone(res);
@@ -689,53 +773,43 @@ function finish(res) {
689
773
  rewardResolve = null;
690
774
  rewardPromise = null;
691
775
  }
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
776
  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
777
  function setAdPopup(adId, done) {
716
778
  var _a, _b, _c;
717
779
  popupDone = done;
718
- const wxApi = api();
719
- if (!adId || !(wxApi == null ? void 0 : wxApi.createInterstitialAd))
780
+ if (!adId)
720
781
  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);
782
+ const api = getAdApi();
783
+ if (!(api == null ? void 0 : api.createInterstitialAd))
784
+ return false;
785
+ activePopupAdId = adId;
786
+ if (!popupCache.has(adId)) {
787
+ try {
788
+ const ad = api.createInterstitialAd({ adUnitId: adId });
789
+ (_a = ad.onLoad) == null ? void 0 : _a.call(ad, () => console.log(`[HlwAd] Interstitial loaded: ${adId}`));
790
+ (_b = ad.onError) == null ? void 0 : _b.call(ad, (err) => {
791
+ console.error("[HlwAd] Interstitial load error:", err);
792
+ if (activePopupAdId === adId) {
793
+ popupDone == null ? void 0 : popupDone(false);
794
+ }
795
+ });
796
+ (_c = ad.onClose) == null ? void 0 : _c.call(ad, () => {
797
+ if (activePopupAdId === adId) {
798
+ popupDone == null ? void 0 : popupDone(true);
799
+ }
800
+ });
801
+ popupCache.set(adId, ad);
802
+ } catch (e) {
803
+ console.error("[HlwAd] Interstitial creation failed:", e);
804
+ return false;
805
+ }
806
+ }
734
807
  return true;
735
808
  }
736
809
  function showAdPopup(delay = 3e3) {
737
810
  return new Promise((resolve) => {
738
- if (!popupAd) {
811
+ const ad = popupCache.get(activePopupAdId);
812
+ if (!ad) {
739
813
  resolve(false);
740
814
  return;
741
815
  }
@@ -745,8 +819,8 @@ function useHlwAd() {
745
819
  resolve(ok);
746
820
  };
747
821
  setTimeout(() => {
748
- popupAd.show().catch((err) => {
749
- console.error("插屏广告显示失败", err);
822
+ ad.show().catch((err) => {
823
+ console.error("[HlwAd] Interstitial show error:", err);
750
824
  popupDone == null ? void 0 : popupDone(false);
751
825
  });
752
826
  }, Math.max(0, delay));
@@ -758,37 +832,52 @@ function useHlwAd() {
758
832
  rewardPromise = new Promise((resolve) => {
759
833
  rewardResolve = resolve;
760
834
  });
761
- const wxApi = api();
762
- if (!adId || !(wxApi == null ? void 0 : wxApi.createRewardedVideoAd)) {
835
+ if (!adId) {
763
836
  finish({ ok: false });
764
837
  return rewardPromise;
765
838
  }
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);
839
+ const api = getAdApi();
840
+ if (!(api == null ? void 0 : api.createRewardedVideoAd)) {
841
+ finish({ ok: false });
842
+ return rewardPromise;
843
+ }
844
+ activeRewardAdId = adId;
845
+ if (!rewardCache.has(adId)) {
846
+ try {
847
+ const ad = api.createRewardedVideoAd({ adUnitId: adId });
848
+ (_a = ad.onLoad) == null ? void 0 : _a.call(ad, () => console.log(`[HlwAd] Rewarded video loaded: ${adId}`));
849
+ (_b = ad.onError) == null ? void 0 : _b.call(ad, (err) => {
850
+ console.error("[HlwAd] Rewarded video load error:", err);
851
+ if (activeRewardAdId === adId) {
852
+ finish({ ok: false, err });
853
+ }
854
+ });
855
+ (_c = ad.onClose) == null ? void 0 : _c.call(ad, (res) => {
856
+ if (activeRewardAdId === adId) {
857
+ const isEnded = !!(res == null ? void 0 : res.isEnded);
858
+ finish({ ok: isEnded, isEnded });
859
+ }
860
+ });
861
+ rewardCache.set(adId, ad);
862
+ } catch (e) {
863
+ console.error("[HlwAd] Rewarded video creation failed:", e);
864
+ finish({ ok: false, err: e });
865
+ }
866
+ }
779
867
  return rewardPromise;
780
868
  }
781
869
  function showAdReward() {
782
- if (!rewardAd) {
870
+ const ad = rewardCache.get(activeRewardAdId);
871
+ if (!ad) {
783
872
  return Promise.resolve({ ok: false });
784
873
  }
785
874
  const current = rewardPromise || new Promise((resolve) => {
786
875
  rewardResolve = resolve;
787
876
  });
788
877
  rewardPromise = current;
789
- rewardAd.show().catch(() => {
790
- rewardAd.load().then(() => rewardAd.show()).catch((err) => {
791
- console.error("激励视频广告显示失败", err);
878
+ ad.show().catch(() => {
879
+ ad.load().then(() => ad.show()).catch((err) => {
880
+ console.error("[HlwAd] Rewarded video show error:", err);
792
881
  finish({ ok: false, err });
793
882
  });
794
883
  });
@@ -858,12 +947,19 @@ function navigate(type = "navigateTo", url = "", options = {}) {
858
947
  }
859
948
  function useNavigate() {
860
949
  return {
950
+ /** 核心底层路由分发函数 */
861
951
  navigate,
952
+ /** 保留当前页面,跳转到应用内的某个页面 */
862
953
  to: (url, options) => navigate("navigateTo", url, options),
954
+ /** 关闭当前页面,跳转到应用内的某个页面 */
863
955
  redirect: (url, options) => navigate("redirectTo", url, options),
956
+ /** 跳转到 switchTab 页面,并关闭其他所有非 tabBar 页面 */
864
957
  tab: (url, options) => navigate("switchTab", url, options),
958
+ /** 关闭所有页面,打开到应用内的某个页面 */
865
959
  reLaunch: (url, options) => navigate("reLaunch", url, options),
960
+ /** 关闭当前页面,返回上一页面或多级页面 */
866
961
  back: (delta = 1, options = {}) => navigate("navigateBack", "", { ...options, delta }),
962
+ /** 打开另一个小程序 */
867
963
  miniProgram: (appId, options) => navigate("miniprogram", appId, options)
868
964
  };
869
965
  }
@@ -1268,6 +1364,7 @@ function copyText(data) {
1268
1364
  uni.setClipboardData({
1269
1365
  data,
1270
1366
  showToast: false,
1367
+ // 禁用系统默认 Toast 提示,使用自定义的无图标 Toast
1271
1368
  success: () => uni.showToast({ title: "复制成功", icon: "none", duration: 1500 })
1272
1369
  });
1273
1370
  }
@@ -1286,13 +1383,13 @@ function injectTap(vnode, binding) {
1286
1383
  }
1287
1384
  const vCopy = {
1288
1385
  /**
1289
- * 在指令创建时注入点击事件。
1386
+ * 在指令创建时注入点击事件拦截器。
1290
1387
  */
1291
1388
  created(el, binding, vnode) {
1292
1389
  injectTap(vnode, binding);
1293
1390
  },
1294
1391
  /**
1295
- * 在绑定值更新前重新注入点击事件。
1392
+ * 在绑定值更新前重新注入点击事件拦截器,以获取最新的绑定值。
1296
1393
  */
1297
1394
  beforeUpdate(el, binding, vnode) {
1298
1395
  injectTap(vnode, binding);
@@ -1306,6 +1403,7 @@ export {
1306
1403
  DEFAULT_THEMES,
1307
1404
  FONT_PRESETS,
1308
1405
  FONT_SCALE_KEY,
1406
+ PluginService,
1309
1407
  ServiceNamespace,
1310
1408
  ServicePrefix,
1311
1409
  THEME_CHANGE_EVENT,
@@ -1314,9 +1412,12 @@ export {
1314
1412
  TYPOGRAPHY_ROLES,
1315
1413
  adapters,
1316
1414
  alistAdapter,
1415
+ auth,
1317
1416
  buildThemeStyle,
1318
1417
  clearDeviceCache,
1418
+ copy,
1319
1419
  cosAdapter,
1420
+ download,
1320
1421
  getAdapter,
1321
1422
  getCurrentAppearance,
1322
1423
  getCurrentAppearanceMode,
@@ -1328,8 +1429,17 @@ export {
1328
1429
  getCurrentTypographyVars,
1329
1430
  hlw,
1330
1431
  ossAdapter,
1432
+ paste,
1331
1433
  qiniuAdapter,
1332
1434
  resolveAppearance,
1435
+ saveImage,
1436
+ saveImageUrl,
1437
+ saveVideoFile,
1438
+ saveVideoUrl,
1439
+ signText,
1440
+ toBoolean,
1441
+ toNumber,
1442
+ toQuery,
1333
1443
  useApp,
1334
1444
  useDevice,
1335
1445
  useHlwAd,
@@ -1342,5 +1452,6 @@ export {
1342
1452
  useThemeStore,
1343
1453
  useUpload,
1344
1454
  useUtils,
1345
- vCopy
1455
+ vCopy,
1456
+ withQuery
1346
1457
  };