@hlw-uni/mp-vue 1.2.28 → 2.0.2

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 (70) hide show
  1. package/dist/app.d.ts +33 -0
  2. package/dist/composables/_internal/unwrap.d.ts +15 -0
  3. package/dist/composables/ad/index.d.ts +101 -0
  4. package/dist/composables/color/index.d.ts +8 -0
  5. package/dist/composables/contact/index.d.ts +32 -0
  6. package/dist/composables/device/index.d.ts +129 -0
  7. package/dist/composables/format/index.d.ts +9 -0
  8. package/dist/composables/http/adapters/alist.d.ts +3 -0
  9. package/dist/composables/http/adapters/base.d.ts +19 -0
  10. package/dist/composables/http/adapters/cos.d.ts +3 -0
  11. package/dist/composables/http/adapters/index.d.ts +15 -0
  12. package/dist/composables/http/adapters/oss.d.ts +3 -0
  13. package/dist/composables/http/adapters/qiniu.d.ts +3 -0
  14. package/dist/composables/http/client.d.ts +66 -0
  15. package/dist/composables/http/index.d.ts +8 -0
  16. package/dist/composables/http/types.d.ts +51 -0
  17. package/dist/composables/index.d.ts +26 -0
  18. package/dist/composables/loading/index.d.ts +7 -0
  19. package/dist/composables/msg/index.d.ts +36 -0
  20. package/dist/composables/navigator/index.d.ts +47 -0
  21. package/dist/composables/page-meta/index.d.ts +18 -0
  22. package/dist/composables/refs/index.d.ts +8 -0
  23. package/dist/composables/share/index.d.ts +71 -0
  24. package/dist/composables/storage/index.d.ts +16 -0
  25. package/dist/composables/theme/font.d.ts +1 -1
  26. package/dist/composables/theme/index.d.ts +15 -2
  27. package/dist/composables/utils/index.d.ts +39 -0
  28. package/dist/composables/validate/index.d.ts +12 -0
  29. package/dist/directives/copy.d.ts +3 -0
  30. package/dist/directives/index.d.ts +1 -0
  31. package/dist/hlw.d.ts +14 -0
  32. package/dist/index.d.ts +10 -7
  33. package/dist/index.js +1733 -63
  34. package/dist/index.mjs +1732 -62
  35. package/package.json +5 -3
  36. package/src/app.ts +173 -0
  37. package/src/components/hlw-ad/index.vue +74 -30
  38. package/src/composables/_internal/unwrap.ts +19 -0
  39. package/src/composables/ad/index.ts +395 -0
  40. package/src/composables/color/index.ts +44 -0
  41. package/src/composables/contact/index.ts +92 -0
  42. package/src/composables/device/index.ts +168 -0
  43. package/src/composables/format/index.ts +48 -0
  44. package/src/composables/http/adapters/alist.ts +19 -0
  45. package/src/composables/http/adapters/base.ts +21 -0
  46. package/src/composables/http/adapters/cos.ts +23 -0
  47. package/src/composables/http/adapters/index.ts +31 -0
  48. package/src/composables/http/adapters/oss.ts +22 -0
  49. package/src/composables/http/adapters/qiniu.ts +19 -0
  50. package/src/composables/http/client.ts +237 -0
  51. package/src/composables/http/index.ts +8 -0
  52. package/src/composables/http/types.ts +57 -0
  53. package/src/composables/http/useRequest.ts +107 -0
  54. package/src/composables/index.ts +82 -0
  55. package/src/composables/loading/index.ts +23 -0
  56. package/src/composables/msg/index.ts +132 -0
  57. package/src/composables/navigator/index.ts +104 -0
  58. package/src/composables/page-meta/index.ts +49 -0
  59. package/src/composables/refs/index.ts +30 -0
  60. package/src/composables/share/index.ts +189 -0
  61. package/src/composables/storage/index.ts +76 -0
  62. package/src/composables/theme/font.ts +26 -5
  63. package/src/composables/theme/index.ts +26 -11
  64. package/src/composables/theme/palette.ts +1 -1
  65. package/src/composables/utils/index.ts +160 -0
  66. package/src/composables/validate/index.ts +58 -0
  67. package/src/directives/copy.ts +50 -0
  68. package/src/directives/index.ts +1 -0
  69. package/src/hlw.ts +37 -0
  70. package/src/index.ts +21 -20
package/dist/index.js CHANGED
@@ -1,11 +1,1199 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue"), require("@hlw-uni/mp-core"), require("pinia")) : typeof define === "function" && define.amd ? define(["exports", "vue", "@hlw-uni/mp-core", "pinia"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.HlwUniVue = {}, global.vue, global.mpCore, global.pinia));
3
- })(this, function(exports2, vue, mpCore, pinia) {
4
- "use strict";
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue"), require("pinia"), require("@dcloudio/uni-app")) : typeof define === "function" && define.amd ? define(["exports", "vue", "pinia", "@dcloudio/uni-app"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.HlwUniVue = {}, global.vue, global.pinia, global.uniApp));
3
+ })(this, function(exports2, vue, pinia, uniApp) {
4
+ "use strict";var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => {
7
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ return value;
9
+ };
10
+
11
+ const cosAdapter = {
12
+ name: "cos",
13
+ /**
14
+ * 生成 COS 直传所需的表单字段。
15
+ */
16
+ buildFormData(ctx) {
17
+ const c = ctx.credentials ?? {};
18
+ return {
19
+ "q-ak": c["ak"] ?? "",
20
+ policy: c["policy"] ?? "",
21
+ "q-key-time": c["key-time"] ?? "",
22
+ "q-signature": c["signature"] ?? "",
23
+ "Content-Disposition": `inline;filename=${encodeURIComponent(ctx.fileName)}`,
24
+ success_action_status: 200,
25
+ ...ctx.extraData ?? {}
26
+ };
27
+ }
28
+ };
29
+ const ossAdapter = {
30
+ name: "oss",
31
+ /**
32
+ * 生成 OSS 直传所需的表单字段。
33
+ */
34
+ buildFormData(ctx) {
35
+ const c = ctx.credentials ?? {};
36
+ return {
37
+ policy: c["policy"] ?? "",
38
+ signature: c["signature"] ?? "",
39
+ OSSAccessKeyId: c["accessKeyId"] ?? "",
40
+ success_action_status: 200,
41
+ "Content-Disposition": `inline;filename=${encodeURIComponent(ctx.fileName)}`,
42
+ ...ctx.extraData ?? {}
43
+ };
44
+ }
45
+ };
46
+ const qiniuAdapter = {
47
+ name: "qiniu",
48
+ /**
49
+ * 生成七牛直传所需的表单字段。
50
+ */
51
+ buildFormData(ctx) {
52
+ const c = ctx.credentials ?? {};
53
+ return {
54
+ token: c["token"] ?? "",
55
+ key: c["key"] ?? ctx.fileName,
56
+ ...ctx.extraData ?? {}
57
+ };
58
+ }
59
+ };
60
+ const alistAdapter = {
61
+ name: "alist",
62
+ /**
63
+ * 生成 Alist 所需的表单字段。
64
+ */
65
+ buildFormData(ctx) {
66
+ const c = ctx.credentials ?? {};
67
+ return {
68
+ "file-path": c["file-path"] ?? ctx.fileName,
69
+ authorization: c["token"] ?? "",
70
+ ...ctx.extraData ?? {}
71
+ };
72
+ }
73
+ };
74
+ const adapters = {
75
+ cos: cosAdapter,
76
+ oss: ossAdapter,
77
+ qiniu: qiniuAdapter,
78
+ alist: alistAdapter
79
+ };
80
+ function getAdapter(name) {
81
+ const adapter2 = adapters[name];
82
+ if (!adapter2)
83
+ throw new Error(`[hlw] Unknown upload adapter: ${name}`);
84
+ return adapter2;
85
+ }
86
+ class HttpClient {
87
+ /**
88
+ * 创建 HttpClient 实例并初始化默认配置。
89
+ */
90
+ constructor(options = {}) {
91
+ __publicField(this, "_reqInterceptors", []);
92
+ __publicField(this, "_resInterceptors", []);
93
+ __publicField(this, "_errInterceptors", []);
94
+ __publicField(this, "_baseURL");
95
+ __publicField(this, "_defaultHeaders");
96
+ __publicField(this, "_noCache");
97
+ this._baseURL = options.baseURL ?? "";
98
+ this._noCache = options.noCache ?? true;
99
+ this._defaultHeaders = {
100
+ "Content-Type": "application/json",
101
+ ...options.headers
102
+ };
103
+ }
104
+ /** 运行时设置 baseURL。 */
105
+ setBaseURL(url) {
106
+ this._baseURL = url;
107
+ }
108
+ /** 注册请求拦截器,并返回注销函数。 */
109
+ onRequest(fn) {
110
+ this._reqInterceptors.push(fn);
111
+ return () => {
112
+ const idx = this._reqInterceptors.indexOf(fn);
113
+ if (idx > -1)
114
+ this._reqInterceptors.splice(idx, 1);
115
+ };
116
+ }
117
+ /** 注册响应拦截器,并返回注销函数。 */
118
+ onResponse(fn) {
119
+ this._resInterceptors.push(fn);
120
+ return () => {
121
+ const idx = this._resInterceptors.indexOf(fn);
122
+ if (idx > -1)
123
+ this._resInterceptors.splice(idx, 1);
124
+ };
125
+ }
126
+ /** 注册错误拦截器,并返回注销函数。 */
127
+ onError(fn) {
128
+ this._errInterceptors.push(fn);
129
+ return () => {
130
+ const idx = this._errInterceptors.indexOf(fn);
131
+ if (idx > -1)
132
+ this._errInterceptors.splice(idx, 1);
133
+ };
134
+ }
135
+ /**
136
+ * 执行一次全局请求,自动串联请求与响应拦截器。
137
+ */
138
+ async request(config2) {
139
+ let cfg = {
140
+ method: "GET",
141
+ ...config2,
142
+ headers: { ...this._defaultHeaders, ...config2.headers }
143
+ };
144
+ for (const fn of this._reqInterceptors) {
145
+ cfg = await fn(cfg);
146
+ }
147
+ try {
148
+ const fullUrl = this._buildUrl(cfg.url);
149
+ const res = await this._doRequest(fullUrl, cfg);
150
+ for (const fn of this._resInterceptors) {
151
+ const modified = await fn(res);
152
+ if (modified !== void 0)
153
+ return modified;
154
+ }
155
+ return res;
156
+ } catch (e) {
157
+ const err = e;
158
+ await this._applyErrorInterceptors(err);
159
+ throw err;
160
+ }
161
+ }
162
+ /**
163
+ * 创建组件内可复用的请求状态对象。
164
+ */
165
+ useRequest() {
166
+ const loading = vue.ref(false);
167
+ const data = vue.ref(null);
168
+ const error = vue.ref(null);
169
+ const run = async (cfg) => {
170
+ loading.value = true;
171
+ error.value = null;
172
+ try {
173
+ const res = await this.request(cfg);
174
+ data.value = res.data;
175
+ return res;
176
+ } catch (e) {
177
+ error.value = e;
178
+ throw e;
179
+ } finally {
180
+ loading.value = false;
181
+ }
182
+ };
183
+ const get = (url, d) => run({ url, method: "GET", data: d });
184
+ const post = (url, d) => run({ url, method: "POST", data: d });
185
+ const put = (url, d) => run({ url, method: "PUT", data: d });
186
+ const del = (url, d) => run({ url, method: "DELETE", data: d });
187
+ return { loading, data, error, run, get, post, put, del };
188
+ }
189
+ /**
190
+ * 根据上传类型选择适配器并执行文件上传。
191
+ */
192
+ upload(config2) {
193
+ const fileName = config2.fileName ?? config2.filePath.split("/").pop() ?? "file";
194
+ let server = config2.server;
195
+ if (config2.type === "local" && config2.url)
196
+ server = config2.url;
197
+ const formData = config2.type === "local" ? config2.credentials ?? {} : getAdapter(config2.type).buildFormData({
198
+ filePath: config2.filePath,
199
+ fileName,
200
+ credentials: config2.credentials
201
+ });
202
+ return new Promise((resolve, reject) => {
203
+ uni.uploadFile({
204
+ url: server,
205
+ filePath: config2.filePath,
206
+ name: "file",
207
+ formData,
208
+ header: config2.header,
209
+ success: (res) => {
210
+ if (res.statusCode === 200) {
211
+ try {
212
+ const body = JSON.parse(res.data);
213
+ resolve({ code: body.code ?? 1, msg: body.message ?? "上传成功", data: body.data ?? "" });
214
+ } catch {
215
+ resolve({ code: 1, msg: "上传成功", data: res.data });
216
+ }
217
+ } else {
218
+ reject(new Error("上传失败"));
219
+ }
220
+ },
221
+ fail: (err) => reject(new Error(err.errMsg || "上传失败"))
222
+ });
223
+ });
224
+ }
225
+ /**
226
+ * 拼接 baseURL,并在开启防缓存时追加时间戳参数。
227
+ */
228
+ _buildUrl(url) {
229
+ if (/^https?:\/\//.test(url))
230
+ return url;
231
+ const full = `${this._baseURL}${url}`;
232
+ if (!this._noCache)
233
+ return full;
234
+ const sep = full.includes("?") ? "&" : "?";
235
+ return `${full}${sep}_t=${Date.now()}`;
236
+ }
237
+ /**
238
+ * 调用 uni.request 发起底层网络请求。
239
+ */
240
+ async _doRequest(url, cfg) {
241
+ return new Promise((resolve, reject) => {
242
+ uni.request({
243
+ url,
244
+ method: cfg.method,
245
+ data: cfg.data,
246
+ header: cfg.headers,
247
+ success: (res) => {
248
+ var _a;
249
+ if (res.statusCode >= 200 && res.statusCode < 300) {
250
+ resolve(res.data);
251
+ } else {
252
+ const msg2 = ((_a = res.data) == null ? void 0 : _a.info) ?? `请求失败: ${res.statusCode}`;
253
+ reject(new Error(String(msg2)));
254
+ }
255
+ },
256
+ fail: (err) => reject(new Error(err.errMsg || "网络请求失败"))
257
+ });
258
+ });
259
+ }
260
+ /**
261
+ * 顺序执行已注册的错误拦截器。
262
+ */
263
+ async _applyErrorInterceptors(err) {
264
+ for (const fn of this._errInterceptors) {
265
+ await fn(err);
266
+ }
267
+ }
268
+ }
269
+ const http = new HttpClient();
270
+ function useRequest(options = {}) {
271
+ const { initialData = null, manual = false, onSuccess, onError } = options;
272
+ const loading = vue.ref(false);
273
+ const data = vue.ref(initialData);
274
+ const error = vue.ref(null);
275
+ async function run(config2) {
276
+ loading.value = true;
277
+ error.value = null;
278
+ try {
279
+ const res = await http.request(config2);
280
+ data.value = res.data;
281
+ onSuccess == null ? void 0 : onSuccess(res.data, res);
282
+ return res;
283
+ } catch (e) {
284
+ error.value = e;
285
+ onError == null ? void 0 : onError(e);
286
+ throw e;
287
+ } finally {
288
+ loading.value = false;
289
+ }
290
+ }
291
+ function get(url, data2) {
292
+ return run({ url, method: "GET", data: data2 });
293
+ }
294
+ function post(url, data2) {
295
+ return run({ url, method: "POST", data: data2 });
296
+ }
297
+ function put(url, data2) {
298
+ return run({ url, method: "PUT", data: data2 });
299
+ }
300
+ function del(url, data2) {
301
+ return run({ url, method: "DELETE", data: data2 });
302
+ }
303
+ return { loading, data, error, run, get, post, put, del };
304
+ }
305
+ function useUpload() {
306
+ const uploading = vue.ref(false);
307
+ async function upload(options) {
308
+ uploading.value = true;
309
+ try {
310
+ return await http.upload(options);
311
+ } finally {
312
+ uploading.value = false;
313
+ }
314
+ }
315
+ return { uploading, upload };
316
+ }
317
+ function useLoading() {
318
+ function showLoading(message = "加载中...") {
319
+ uni.showLoading({ title: message, mask: true });
320
+ }
321
+ function hideLoading() {
322
+ uni.hideLoading();
323
+ }
324
+ return {
325
+ showLoading,
326
+ hideLoading
327
+ };
328
+ }
329
+ function useMsg() {
330
+ function toast(opts) {
331
+ const normalized = typeof opts === "string" ? { message: opts } : opts;
332
+ const { message, icon = "none", image, duration = 2e3, mask = false, position = "center" } = normalized;
333
+ uni.showToast({ title: message, icon, image, duration, mask, position });
334
+ }
335
+ function success(message) {
336
+ uni.showToast({ title: message, icon: "success", duration: 2e3 });
337
+ }
338
+ function error(message) {
339
+ uni.showToast({ title: message, icon: "fail", duration: 2e3 });
340
+ }
341
+ function showLoading(message = "加载中...") {
342
+ uni.showLoading({ title: message, mask: true });
343
+ }
344
+ function hideLoading() {
345
+ uni.hideLoading();
346
+ }
347
+ function confirm(opts) {
348
+ return new Promise((resolve) => {
349
+ const {
350
+ title = "提示",
351
+ content,
352
+ confirmText = "确定",
353
+ cancelText = "取消",
354
+ confirmColor = "#3b82f6",
355
+ cancelColor = "#999999"
356
+ } = opts;
357
+ uni.showModal({
358
+ title,
359
+ content,
360
+ confirmText,
361
+ cancelText,
362
+ confirmColor,
363
+ cancelColor,
364
+ success: (res) => resolve(res.confirm),
365
+ fail: () => resolve(false)
366
+ });
367
+ });
368
+ }
369
+ function modal(opts) {
370
+ return confirm(opts);
371
+ }
372
+ function setLoadingBar(progress) {
373
+ const clamped = Math.max(0, Math.min(100, progress));
374
+ uni.setNavigationBarTitle({
375
+ title: `${"■".repeat(Math.round(clamped / 2))}${"□".repeat(50 - Math.round(clamped / 2))} ${clamped}%`
376
+ });
377
+ }
378
+ return {
379
+ toast,
380
+ success,
381
+ error,
382
+ fail: error,
383
+ showLoading,
384
+ hideLoading,
385
+ confirm,
386
+ modal,
387
+ setLoadingBar
388
+ };
389
+ }
390
+ const _info = vue.ref(null);
391
+ function tryCall(fn) {
392
+ try {
393
+ return (fn == null ? void 0 : fn()) ?? {};
394
+ } catch {
395
+ return {};
396
+ }
397
+ }
398
+ function collect() {
399
+ var _a;
400
+ let deviceInfo = tryCall(uni.getDeviceInfo);
401
+ let windowInfo = tryCall(uni.getWindowInfo);
402
+ let appBaseInfo = tryCall(uni.getAppBaseInfo);
403
+ if (!deviceInfo.brand && !deviceInfo.model) {
404
+ const sys = tryCall(() => uni.getSystemInfoSync());
405
+ deviceInfo = { ...sys };
406
+ windowInfo = { ...sys };
407
+ appBaseInfo = { ...sys };
408
+ }
409
+ let appid = "";
410
+ try {
411
+ const accountInfo = uni.getAccountInfoSync();
412
+ appid = ((_a = accountInfo == null ? void 0 : accountInfo.miniProgram) == null ? void 0 : _a.appId) || "";
413
+ } catch {
414
+ appid = deviceInfo.appId || "";
415
+ }
416
+ const system = deviceInfo.system || "";
417
+ return {
418
+ appid,
419
+ app_name: appBaseInfo.appName || "",
420
+ app_version: appBaseInfo.appVersion || "",
421
+ app_version_code: appBaseInfo.appVersionCode || "",
422
+ app_channel: appBaseInfo.appChannel || "",
423
+ device_brand: deviceInfo.brand || "",
424
+ device_model: deviceInfo.model || "",
425
+ device_id: deviceInfo.deviceId || "",
426
+ device_type: deviceInfo.deviceType || "",
427
+ device_orientation: windowInfo.deviceOrientation || "portrait",
428
+ brand: deviceInfo.brand || "",
429
+ model: deviceInfo.model || "",
430
+ system,
431
+ os: system.split(" ")[0] || "",
432
+ pixel_ratio: windowInfo.pixelRatio || 0,
433
+ screen_width: windowInfo.screenWidth || 0,
434
+ screen_height: windowInfo.screenHeight || 0,
435
+ window_width: windowInfo.windowWidth || 0,
436
+ window_height: windowInfo.windowHeight || 0,
437
+ status_bar_height: windowInfo.statusBarHeight || 0,
438
+ sdk_version: appBaseInfo.SDKVersion || "",
439
+ host_name: appBaseInfo.hostName || "",
440
+ host_version: appBaseInfo.hostVersion || "",
441
+ host_language: appBaseInfo.hostLanguage || "",
442
+ host_theme: appBaseInfo.hostTheme || "",
443
+ platform: deviceInfo.platform || "",
444
+ language: appBaseInfo.language || "",
445
+ version: appBaseInfo.version || ""
446
+ };
447
+ }
448
+ function ensure() {
449
+ if (!_info.value) {
450
+ _info.value = collect();
451
+ }
452
+ }
453
+ function useDevice() {
454
+ ensure();
455
+ return _info;
456
+ }
457
+ function deviceToQuery() {
458
+ ensure();
459
+ if (!_info.value)
460
+ return "";
461
+ return Object.entries(_info.value).filter(([, v]) => v !== "" && v !== 0).map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`).join("&");
462
+ }
463
+ function clearDeviceCache() {
464
+ _info.value = null;
465
+ }
466
+ function useRefs() {
467
+ const refs = vue.ref({});
468
+ vue.onBeforeUpdate(() => {
469
+ refs.value = {};
470
+ });
471
+ vue.onUnmounted(() => {
472
+ refs.value = {};
473
+ });
474
+ const setRefs = (key) => (el) => {
475
+ if (el)
476
+ refs.value[key] = el;
477
+ };
478
+ return { refs, setRefs };
479
+ }
480
+ function usePageMeta() {
481
+ function setTitle(title) {
482
+ uni.setNavigationBarTitle({ title });
483
+ }
484
+ function setOptions(options) {
485
+ if (options.title || options.navigationBarTitleText) {
486
+ setTitle(options.title || options.navigationBarTitleText);
487
+ }
488
+ if (options.navigationBarBackgroundColor || options.navigationBarTextStyle) {
489
+ uni.setNavigationBarColor({
490
+ frontColor: options.navigationBarTextStyle === "white" ? "#ffffff" : "#000000",
491
+ backgroundColor: options.navigationBarBackgroundColor ?? "#ffffff"
492
+ });
493
+ }
494
+ if (options.backgroundColor) {
495
+ uni.setBackgroundColor({ backgroundColor: options.backgroundColor });
496
+ }
497
+ if (options.enablePullDownRefresh !== void 0) {
498
+ uni.setBackgroundTextStyle({ textStyle: "dark" });
499
+ }
500
+ }
501
+ return {
502
+ setTitle,
503
+ setOptions
504
+ };
505
+ }
506
+ function useStorage() {
507
+ function get(key) {
508
+ try {
509
+ const value = uni.getStorageSync(key);
510
+ return value ?? null;
511
+ } catch {
512
+ return null;
513
+ }
514
+ }
515
+ function set(key, value) {
516
+ try {
517
+ uni.setStorageSync(key, value);
518
+ return true;
519
+ } catch {
520
+ return false;
521
+ }
522
+ }
523
+ function remove(key) {
524
+ try {
525
+ uni.removeStorageSync(key);
526
+ return true;
527
+ } catch {
528
+ return false;
529
+ }
530
+ }
531
+ function clear() {
532
+ try {
533
+ uni.clearStorageSync();
534
+ return true;
535
+ } catch {
536
+ return false;
537
+ }
538
+ }
539
+ function info() {
540
+ try {
541
+ return uni.getStorageInfoSync();
542
+ } catch {
543
+ return null;
544
+ }
545
+ }
546
+ return { get, set, remove, clear, info };
547
+ }
548
+ function useValidate() {
549
+ function phone(value) {
550
+ return /^1[3-9]\d{9}$/.test(value);
551
+ }
552
+ function email(value) {
553
+ return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
554
+ }
555
+ function url(value) {
556
+ try {
557
+ new URL(value);
558
+ return true;
559
+ } catch {
560
+ return false;
561
+ }
562
+ }
563
+ function idCard(value) {
564
+ return /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/.test(value);
565
+ }
566
+ function carNumber(value) {
567
+ return /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-Z0-9]{5}$/.test(value);
568
+ }
569
+ function password(value) {
570
+ return /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/.test(value);
571
+ }
572
+ function empty(value) {
573
+ if (value == null)
574
+ return true;
575
+ if (typeof value === "string")
576
+ return value.trim() === "";
577
+ if (Array.isArray(value))
578
+ return value.length === 0;
579
+ if (typeof value === "object")
580
+ return Object.keys(value).length === 0;
581
+ return false;
582
+ }
583
+ return {
584
+ phone,
585
+ email,
586
+ url,
587
+ idCard,
588
+ carNumber,
589
+ password,
590
+ empty
591
+ };
592
+ }
593
+ function useFormat() {
594
+ function date(date2, format = "YYYY-MM-DD HH:mm:ss") {
595
+ const d = new Date(date2);
596
+ if (isNaN(d.getTime()))
597
+ return "";
598
+ const year = d.getFullYear();
599
+ const month = String(d.getMonth() + 1).padStart(2, "0");
600
+ const day = String(d.getDate()).padStart(2, "0");
601
+ const hours = String(d.getHours()).padStart(2, "0");
602
+ const minutes = String(d.getMinutes()).padStart(2, "0");
603
+ const seconds = String(d.getSeconds()).padStart(2, "0");
604
+ return format.replace("YYYY", String(year)).replace("MM", month).replace("DD", day).replace("HH", hours).replace("mm", minutes).replace("ss", seconds);
605
+ }
606
+ function fileSize(bytes) {
607
+ if (bytes === 0)
608
+ return "0 B";
609
+ const k = 1024;
610
+ const sizes = ["B", "KB", "MB", "GB", "TB"];
611
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
612
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
613
+ }
614
+ function phone(value) {
615
+ return value.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
616
+ }
617
+ function money(amount, decimals = 2, decPoint = ".", thousandsSep = ",") {
618
+ return amount.toFixed(decimals).replace(/\B(?=(\d{3})+(?!\d))/g, thousandsSep);
619
+ }
620
+ return { date, fileSize, phone, money };
621
+ }
622
+ function unwrapPayload(raw) {
623
+ if (raw == null)
624
+ return null;
625
+ if (typeof raw === "object" && "code" in raw && typeof raw.code === "number") {
626
+ const env = raw;
627
+ return env.code === 1 && env.data ? env.data : null;
628
+ }
629
+ return raw;
630
+ }
631
+ const EMPTY = {
632
+ banner_unit_id: "",
633
+ grid_unit_id: "",
634
+ custom_unit_id: "",
635
+ video_unit_id: "",
636
+ reward_unit_id: "",
637
+ popup_unit_id: ""
638
+ };
639
+ let adapter$1 = null;
640
+ function setConfigAd(a) {
641
+ adapter$1 = a;
642
+ }
643
+ const useAdStore = pinia.defineStore("hlw_ad", () => {
644
+ const config2 = vue.ref({ ...EMPTY });
645
+ const loaded = vue.ref(false);
646
+ return { config: config2, loaded };
647
+ });
648
+ let _msg$1 = null;
649
+ const msg = () => _msg$1 ?? (_msg$1 = useMsg());
650
+ const rewardedCache = /* @__PURE__ */ new Map();
651
+ const interstitialCache = /* @__PURE__ */ new Map();
652
+ function useAd() {
653
+ const store = useAdStore();
654
+ const { config: config2, loaded } = pinia.storeToRefs(store);
655
+ async function loadConfig2(force = false) {
656
+ if (loaded.value && !force)
657
+ return;
658
+ if (!(adapter$1 == null ? void 0 : adapter$1.getConfig)) {
659
+ console.warn("[useAd] adapter.getConfig 未注入;先调用 setConfigAd()");
660
+ return;
661
+ }
662
+ try {
663
+ const cfg = unwrapPayload(await adapter$1.getConfig());
664
+ if (cfg) {
665
+ store.config = cfg;
666
+ store.loaded = true;
667
+ }
668
+ } catch (e) {
669
+ console.warn("[useAd] load config failed", e);
670
+ }
671
+ }
672
+ function getUnitId(type) {
673
+ return store.config[`${type}_unit_id`] || "";
674
+ }
675
+ async function showReward(claim) {
676
+ const unitId = getUnitId("reward");
677
+ if (!unitId) {
678
+ msg().toast("激励广告未配置");
679
+ return false;
680
+ }
681
+ if ((adapter$1 == null ? void 0 : adapter$1.isAuth) && !adapter$1.isAuth()) {
682
+ msg().toast("请先登录");
683
+ return false;
684
+ }
685
+ while (true) {
686
+ const closeRes = await playRewardedOnce(unitId);
687
+ if (!claim) {
688
+ if (closeRes.isEnded)
689
+ return true;
690
+ const goon = await confirmReward();
691
+ if (!goon)
692
+ return false;
693
+ continue;
694
+ }
695
+ try {
696
+ const r = await claim(closeRes);
697
+ if (r.retry)
698
+ continue;
699
+ if (!r.ok) {
700
+ if (r.msg)
701
+ msg().error(r.msg);
702
+ return false;
703
+ }
704
+ if (r.reward && r.reward > 0)
705
+ msg().success(`+${r.reward} 积分`);
706
+ return true;
707
+ } catch (e) {
708
+ console.warn("[useAd] claim failed", e);
709
+ msg().error("领取失败,请稍后再试");
710
+ return false;
711
+ }
712
+ }
713
+ }
714
+ async function showPopup() {
715
+ const unitId = getUnitId("popup");
716
+ if (!unitId)
717
+ return false;
718
+ return await showInterstitialAd(unitId);
719
+ }
720
+ return {
721
+ // 状态
722
+ config: config2,
723
+ loaded,
724
+ // 方法
725
+ loadConfig: loadConfig2,
726
+ getUnitId,
727
+ showReward,
728
+ showPopup
729
+ };
730
+ }
731
+ async function playRewardedOnce(unitId) {
732
+ msg().showLoading("广告加载中");
733
+ let hidden = false;
734
+ const hide = () => {
735
+ if (hidden)
736
+ return;
737
+ hidden = true;
738
+ msg().hideLoading();
739
+ };
740
+ try {
741
+ const isEnded = await showRewardedAd(unitId, { onShown: hide });
742
+ return { isEnded };
743
+ } finally {
744
+ hide();
745
+ }
746
+ }
747
+ function confirmReward() {
748
+ return new Promise((resolve) => {
749
+ uni.showModal({
750
+ title: "提示",
751
+ content: "看完广告才可以领取奖励哦,要继续观看吗?",
752
+ confirmText: "继续观看",
753
+ cancelText: "放弃",
754
+ success: (r) => resolve(!!r.confirm),
755
+ fail: () => resolve(false)
756
+ });
757
+ });
758
+ }
759
+ function showRewardedAd(unitId, hooks) {
760
+ return new Promise((resolve) => {
761
+ var _a;
762
+ let entry = rewardedCache.get(unitId);
763
+ if (!entry) {
764
+ const ad2 = uni.createRewardedVideoAd({ adUnitId: unitId });
765
+ if (!ad2) {
766
+ resolve(false);
767
+ return;
768
+ }
769
+ (_a = ad2.onError) == null ? void 0 : _a.call(ad2, (err) => {
770
+ console.warn(`[useAd] reward onError (${unitId})`, err);
771
+ });
772
+ entry = { ad: ad2, loading: false };
773
+ rewardedCache.set(unitId, entry);
774
+ }
775
+ const { ad } = entry;
776
+ let closeHandler = null;
777
+ let errorHandler = null;
778
+ const cleanup = () => {
779
+ var _a2, _b;
780
+ if (closeHandler) {
781
+ (_a2 = ad.offClose) == null ? void 0 : _a2.call(ad, closeHandler);
782
+ closeHandler = null;
783
+ }
784
+ if (errorHandler) {
785
+ (_b = ad.offError) == null ? void 0 : _b.call(ad, errorHandler);
786
+ errorHandler = null;
787
+ }
788
+ };
789
+ closeHandler = (res) => {
790
+ cleanup();
791
+ resolve(!!(res && res.isEnded));
792
+ };
793
+ errorHandler = (err) => {
794
+ console.warn(`[useAd] reward show error (${unitId})`, err);
795
+ cleanup();
796
+ resolve(false);
797
+ };
798
+ ad.onClose(closeHandler);
799
+ ad.onError(errorHandler);
800
+ const doShow = () => ad.show().then(() => {
801
+ var _a2;
802
+ try {
803
+ (_a2 = hooks == null ? void 0 : hooks.onShown) == null ? void 0 : _a2.call(hooks);
804
+ } catch (e) {
805
+ console.warn("[useAd] onShown error", e);
806
+ }
807
+ }).catch(() => {
808
+ cleanup();
809
+ resolve(false);
810
+ });
811
+ if (entry.loading) {
812
+ Promise.resolve().then(doShow);
813
+ } else {
814
+ entry.loading = true;
815
+ ad.load().then(doShow).catch(doShow).finally(() => {
816
+ if (entry)
817
+ entry.loading = false;
818
+ });
819
+ }
820
+ });
821
+ }
822
+ function showInterstitialAd(unitId) {
823
+ return new Promise((resolve) => {
824
+ var _a;
825
+ let ad = interstitialCache.get(unitId);
826
+ if (!ad) {
827
+ ad = uni.createInterstitialAd({ adUnitId: unitId });
828
+ if (!ad) {
829
+ resolve(false);
830
+ return;
831
+ }
832
+ (_a = ad.onError) == null ? void 0 : _a.call(ad, (err) => {
833
+ console.warn(`[useAd] popup onError (${unitId})`, err);
834
+ });
835
+ interstitialCache.set(unitId, ad);
836
+ }
837
+ ad.show().then(() => resolve(true)).catch(() => {
838
+ if (typeof ad.load !== "function") {
839
+ resolve(false);
840
+ return;
841
+ }
842
+ ad.load().then(() => ad.show()).then(() => resolve(true)).catch(() => resolve(false));
843
+ });
844
+ });
845
+ }
846
+ function destroyAds() {
847
+ rewardedCache.forEach((e) => {
848
+ var _a, _b;
849
+ return (_b = (_a = e.ad) == null ? void 0 : _a.destroy) == null ? void 0 : _b.call(_a);
850
+ });
851
+ rewardedCache.clear();
852
+ interstitialCache.forEach((ad) => {
853
+ var _a;
854
+ return (_a = ad == null ? void 0 : ad.destroy) == null ? void 0 : _a.call(ad);
855
+ });
856
+ interstitialCache.clear();
857
+ }
858
+ function useShare(config2) {
859
+ const resolve = (from) => typeof config2 === "function" ? config2(from) : config2;
860
+ uniApp.onShareAppMessage((options) => {
861
+ const resolved = resolve((options == null ? void 0 : options.from) ?? "menu");
862
+ const payload = {};
863
+ if (resolved.title !== void 0)
864
+ payload.title = resolved.title;
865
+ if (resolved.path !== void 0)
866
+ payload.path = resolved.path;
867
+ if (resolved.imageUrl !== void 0)
868
+ payload.imageUrl = resolved.imageUrl;
869
+ return payload;
870
+ });
871
+ uniApp.onShareTimeline(() => {
872
+ const resolved = resolve("menu");
873
+ const timeline = resolved.timeline ?? {};
874
+ const payload = {};
875
+ const title = timeline.title ?? resolved.title;
876
+ const imageUrl = timeline.imageUrl ?? resolved.imageUrl;
877
+ if (title !== void 0)
878
+ payload.title = title;
879
+ if (timeline.query !== void 0)
880
+ payload.query = timeline.query;
881
+ if (imageUrl !== void 0)
882
+ payload.imageUrl = imageUrl;
883
+ return payload;
884
+ });
885
+ }
886
+ let shareAdapter = null;
887
+ const shareCache = vue.ref(null);
888
+ let sharePending = null;
889
+ function setConfigShare(a) {
890
+ shareAdapter = a;
891
+ }
892
+ function loadShareConfig() {
893
+ if (shareCache.value)
894
+ return Promise.resolve();
895
+ if (sharePending)
896
+ return sharePending;
897
+ if (!(shareAdapter == null ? void 0 : shareAdapter.getConfig)) {
898
+ console.warn("[useShareConfig] adapter.getConfig 未注入;先调用 setConfigShare()");
899
+ return Promise.resolve();
900
+ }
901
+ sharePending = shareAdapter.getConfig().then((raw) => {
902
+ const cfg = unwrapPayload(raw);
903
+ if (cfg)
904
+ shareCache.value = cfg;
905
+ }).catch((e) => {
906
+ console.warn("[useShareConfig] load failed", e);
907
+ }).finally(() => {
908
+ sharePending = null;
909
+ });
910
+ return sharePending;
911
+ }
912
+ function useShareConfig(pageKey, fallback) {
913
+ void loadShareConfig();
914
+ return () => {
915
+ var _a;
916
+ const remote = (_a = shareCache.value) == null ? void 0 : _a[pageKey];
917
+ const title = (remote == null ? void 0 : remote.title) || fallback.title;
918
+ const image = (remote == null ? void 0 : remote.image) || fallback.image;
919
+ const payload = { title, path: fallback.path };
920
+ if (image)
921
+ payload.imageUrl = image;
922
+ return payload;
923
+ };
924
+ }
925
+ let adapter = null;
926
+ const config = vue.ref(null);
927
+ let pending = null;
928
+ function setConfigContact(a) {
929
+ adapter = a;
930
+ }
931
+ function loadConfig() {
932
+ if (config.value)
933
+ return Promise.resolve();
934
+ if (pending)
935
+ return pending;
936
+ if (!(adapter == null ? void 0 : adapter.getConfig)) {
937
+ console.warn("[useContact] adapter.getConfig 未注入;先调用 setConfigContact()");
938
+ return Promise.resolve();
939
+ }
940
+ pending = adapter.getConfig().then((raw) => {
941
+ const cfg = unwrapPayload(raw);
942
+ if (cfg)
943
+ config.value = cfg;
944
+ }).catch((e) => {
945
+ console.warn("[useContact] load config failed", e);
946
+ }).finally(() => {
947
+ pending = null;
948
+ });
949
+ return pending;
950
+ }
951
+ function useContact() {
952
+ void loadConfig();
953
+ return vue.computed(() => {
954
+ var _a, _b, _c, _d;
955
+ return {
956
+ sendMessageTitle: ((_a = config.value) == null ? void 0 : _a.send_message_title) || "",
957
+ sendMessagePath: ((_b = config.value) == null ? void 0 : _b.send_message_path) || "",
958
+ sendMessageImg: ((_c = config.value) == null ? void 0 : _c.send_message_img) || "",
959
+ showMessageCard: ((_d = config.value) == null ? void 0 : _d.show_message_card) ?? false
960
+ };
961
+ });
962
+ }
963
+ function useUtils() {
964
+ function copy(data, showToast = true) {
965
+ return new Promise((resolve) => {
966
+ uni.setClipboardData({
967
+ data,
968
+ showToast: false,
969
+ success: () => {
970
+ if (showToast) {
971
+ uni.showToast({ title: "复制成功", icon: "none", duration: 1500 });
972
+ }
973
+ resolve(true);
974
+ },
975
+ fail: () => resolve(false)
976
+ });
977
+ });
978
+ }
979
+ function copyFromEvent(event) {
980
+ var _a;
981
+ const dataset = (_a = event == null ? void 0 : event.currentTarget) == null ? void 0 : _a.dataset;
982
+ const text = dataset == null ? void 0 : dataset.copy;
983
+ if (text == null || text === "")
984
+ return;
985
+ const showToast = (dataset == null ? void 0 : dataset.copyToast) !== "false";
986
+ copy(String(text), showToast);
987
+ }
988
+ function paste() {
989
+ return new Promise((resolve) => {
990
+ uni.getClipboardData({
991
+ success: (res) => resolve(res.data),
992
+ fail: () => resolve("")
993
+ });
994
+ });
995
+ }
996
+ function saveImage(filePath) {
997
+ return new Promise((resolve) => {
998
+ uni.saveImageToPhotosAlbum({
999
+ filePath,
1000
+ success: () => {
1001
+ uni.showToast({ title: "保存成功", icon: "success" });
1002
+ resolve(true);
1003
+ },
1004
+ fail: (err) => {
1005
+ if (err.errMsg.includes("auth deny") || err.errMsg.includes("authorize")) {
1006
+ uni.showModal({
1007
+ title: "提示",
1008
+ content: "需要授权相册权限",
1009
+ confirmText: "去设置",
1010
+ success: (res) => {
1011
+ if (res.confirm)
1012
+ uni.openSetting();
1013
+ }
1014
+ });
1015
+ } else {
1016
+ uni.showToast({ title: "保存失败", icon: "none" });
1017
+ }
1018
+ resolve(false);
1019
+ }
1020
+ });
1021
+ });
1022
+ }
1023
+ function downloadFile(options) {
1024
+ return new Promise((resolve) => {
1025
+ const task = uni.downloadFile({
1026
+ url: options.url,
1027
+ filePath: options.filePath,
1028
+ header: options.header,
1029
+ success: (res) => {
1030
+ if (res.statusCode === 200) {
1031
+ resolve({ success: true, tempFilePath: res.tempFilePath, statusCode: res.statusCode });
1032
+ } else {
1033
+ resolve({ success: false, statusCode: res.statusCode, errMsg: `下载失败,状态码:${res.statusCode}` });
1034
+ }
1035
+ },
1036
+ fail: (err) => resolve({ success: false, errMsg: err.errMsg })
1037
+ });
1038
+ if (options.onProgress) {
1039
+ task.onProgressUpdate((res) => {
1040
+ options.onProgress(res.progress, res.totalBytesWritten, res.totalBytesExpectedToWrite);
1041
+ });
1042
+ }
1043
+ });
1044
+ }
1045
+ async function downloadAndSaveImage(url, onProgress) {
1046
+ try {
1047
+ uni.showLoading({ title: "下载中...", mask: true });
1048
+ const result = await downloadFile({
1049
+ url,
1050
+ onProgress: onProgress ? (progress) => onProgress(progress) : void 0
1051
+ });
1052
+ uni.hideLoading();
1053
+ if (!result.success || !result.tempFilePath) {
1054
+ uni.showToast({ title: result.errMsg || "下载失败", icon: "none" });
1055
+ return false;
1056
+ }
1057
+ return await saveImage(result.tempFilePath);
1058
+ } catch {
1059
+ uni.hideLoading();
1060
+ uni.showToast({ title: "操作失败", icon: "none" });
1061
+ return false;
1062
+ }
1063
+ }
1064
+ return { copy, copyFromEvent, paste, saveImage, downloadFile, downloadAndSaveImage };
1065
+ }
1066
+ const HEX_RE = /^#[0-9a-fA-F]{6}$/;
1067
+ function parseHex(hex) {
1068
+ if (!HEX_RE.test(hex))
1069
+ throw new Error(`Invalid hex color: ${hex}`);
1070
+ return [
1071
+ parseInt(hex.slice(1, 3), 16),
1072
+ parseInt(hex.slice(3, 5), 16),
1073
+ parseInt(hex.slice(5, 7), 16)
1074
+ ];
1075
+ }
1076
+ function useColor() {
1077
+ function varsToStyle2(vars) {
1078
+ return Object.entries(vars).map(([k, v]) => `${k}:${v}`).join(";") + ";";
1079
+ }
1080
+ function hexToRgba2(hex, alpha) {
1081
+ const [r, g, b] = parseHex(hex);
1082
+ return `rgba(${r},${g},${b},${alpha})`;
1083
+ }
1084
+ function darkenHex2(hex, amount = 0.15) {
1085
+ const [r, g, b] = parseHex(hex);
1086
+ const d = (c) => Math.max(0, Math.round(c * (1 - amount)));
1087
+ return `#${d(r).toString(16).padStart(2, "0")}${d(g).toString(16).padStart(2, "0")}${d(b).toString(16).padStart(2, "0")}`;
1088
+ }
1089
+ return { varsToStyle: varsToStyle2, hexToRgba: hexToRgba2, darkenHex: darkenHex2 };
1090
+ }
1091
+ function doNavigate(type, value, options = {}) {
1092
+ var _a;
1093
+ const { onFail, silent = false } = options;
1094
+ if (!value) {
1095
+ if (!silent)
1096
+ uni.showToast({ title: "跳转目标未配置", icon: "none" });
1097
+ onFail == null ? void 0 : onFail("跳转目标未配置");
1098
+ return;
1099
+ }
1100
+ const fail = (err) => {
1101
+ const msg2 = (err == null ? void 0 : err.errMsg) || `无法跳转:${value}`;
1102
+ if (!silent)
1103
+ uni.showToast({ title: msg2, icon: "none" });
1104
+ onFail == null ? void 0 : onFail(msg2);
1105
+ };
1106
+ switch (type) {
1107
+ case "switchTab":
1108
+ uni.switchTab({ url: value, fail });
1109
+ break;
1110
+ case "redirectTo":
1111
+ uni.redirectTo({ url: value, fail });
1112
+ break;
1113
+ case "reLaunch":
1114
+ uni.reLaunch({ url: value, fail });
1115
+ break;
1116
+ case "webview":
1117
+ if (!silent)
1118
+ uni.showToast({ title: `H5:${value}`, icon: "none" });
1119
+ break;
1120
+ case "miniprogram": {
1121
+ (_a = uni.navigateToMiniProgram) == null ? void 0 : _a.call(uni, {
1122
+ appId: value,
1123
+ path: options.path || "",
1124
+ envVersion: options.envVersion,
1125
+ extraData: options.extraData,
1126
+ fail
1127
+ });
1128
+ break;
1129
+ }
1130
+ case "navigateTo":
1131
+ default:
1132
+ uni.navigateTo({ url: value, fail });
1133
+ break;
1134
+ }
1135
+ }
1136
+ function useRouter() {
1137
+ return {
1138
+ navigate: doNavigate
1139
+ };
1140
+ }
1141
+ const useThemeStore = pinia.defineStore(
1142
+ "theme",
1143
+ () => {
1144
+ const scale = vue.ref("normal");
1145
+ function setScale(s) {
1146
+ scale.value = s;
1147
+ uni.setStorageSync(FONT_SCALE_KEY, s);
1148
+ uni.$emit(THEME_CHANGE_EVENT);
1149
+ }
1150
+ const fontOptions = Object.keys(FONT_PRESETS).map((key) => ({
1151
+ value: key,
1152
+ label: FONT_PRESETS[key].label
1153
+ }));
1154
+ const primaryColor = vue.ref(DEFAULT_THEMES[0].value);
1155
+ const themes = DEFAULT_THEMES;
1156
+ const activeTheme = vue.computed(
1157
+ () => themes.find((t) => t.value === primaryColor.value) ?? { label: "自定义", value: primaryColor.value }
1158
+ );
1159
+ function setTheme(color) {
1160
+ primaryColor.value = color;
1161
+ uni.setStorageSync(THEME_COLOR_KEY, color);
1162
+ uni.$emit(THEME_CHANGE_EVENT);
1163
+ }
1164
+ const appearance = vue.ref("auto");
1165
+ const appearanceOptions = APPEARANCE_PRESETS;
1166
+ const appearanceMode = vue.computed(() => resolveAppearance(appearance.value));
1167
+ const isDark = vue.computed(() => appearanceMode.value === "dark");
1168
+ function setAppearance(a) {
1169
+ appearance.value = a;
1170
+ uni.setStorageSync(APPEARANCE_KEY, a);
1171
+ uni.$emit(THEME_CHANGE_EVENT);
1172
+ }
1173
+ return {
1174
+ // 字体
1175
+ scale,
1176
+ fontOptions,
1177
+ setScale,
1178
+ // 主题色
1179
+ primaryColor,
1180
+ themes,
1181
+ activeTheme,
1182
+ setTheme,
1183
+ // 外观模式
1184
+ appearance,
1185
+ appearanceOptions,
1186
+ appearanceMode,
1187
+ isDark,
1188
+ setAppearance
1189
+ };
1190
+ },
1191
+ { unistorage: true }
1192
+ );
5
1193
  const FONT_SCALE_KEY = "hlw_font_scale";
6
1194
  const FONT_PRESETS = {
7
1195
  small: {
8
- label: "小字体",
1196
+ label: "较小",
9
1197
  vars: {
10
1198
  "--font-xs": "16rpx",
11
1199
  "--font-sm": "20rpx",
@@ -15,6 +1203,17 @@
15
1203
  "--font-xl": "36rpx"
16
1204
  }
17
1205
  },
1206
+ compact: {
1207
+ label: "略小",
1208
+ vars: {
1209
+ "--font-xs": "18rpx",
1210
+ "--font-sm": "22rpx",
1211
+ "--font-base": "26rpx",
1212
+ "--font-md": "30rpx",
1213
+ "--font-lg": "34rpx",
1214
+ "--font-xl": "38rpx"
1215
+ }
1216
+ },
18
1217
  normal: {
19
1218
  label: "标准",
20
1219
  vars: {
@@ -26,8 +1225,19 @@
26
1225
  "--font-xl": "40rpx"
27
1226
  }
28
1227
  },
1228
+ medium: {
1229
+ label: "适中",
1230
+ vars: {
1231
+ "--font-xs": "22rpx",
1232
+ "--font-sm": "28rpx",
1233
+ "--font-base": "32rpx",
1234
+ "--font-md": "36rpx",
1235
+ "--font-lg": "42rpx",
1236
+ "--font-xl": "46rpx"
1237
+ }
1238
+ },
29
1239
  large: {
30
- label: "大字体",
1240
+ label: "较大",
31
1241
  vars: {
32
1242
  "--font-xs": "24rpx",
33
1243
  "--font-sm": "30rpx",
@@ -38,7 +1248,7 @@
38
1248
  }
39
1249
  },
40
1250
  xlarge: {
41
- label: "超大字体",
1251
+ label: "超大",
42
1252
  vars: {
43
1253
  "--font-xs": "28rpx",
44
1254
  "--font-sm": "36rpx",
@@ -47,12 +1257,23 @@
47
1257
  "--font-lg": "56rpx",
48
1258
  "--font-xl": "64rpx"
49
1259
  }
1260
+ },
1261
+ xxlarge: {
1262
+ label: "特大",
1263
+ vars: {
1264
+ "--font-xs": "32rpx",
1265
+ "--font-sm": "42rpx",
1266
+ "--font-base": "48rpx",
1267
+ "--font-md": "56rpx",
1268
+ "--font-lg": "64rpx",
1269
+ "--font-xl": "72rpx"
1270
+ }
50
1271
  }
51
1272
  };
52
1273
  function getCurrentFontScale() {
53
1274
  try {
54
1275
  const v = uni.getStorageSync(FONT_SCALE_KEY);
55
- if (v === "small" || v === "large" || v === "xlarge")
1276
+ if (v === "small" || v === "compact" || v === "medium" || v === "large" || v === "xlarge" || v === "xxlarge")
56
1277
  return v;
57
1278
  } catch {
58
1279
  }
@@ -61,7 +1282,7 @@
61
1282
  function getCurrentFontVars() {
62
1283
  return FONT_PRESETS[getCurrentFontScale()].vars;
63
1284
  }
64
- const { hexToRgba, darkenHex } = mpCore.useColor();
1285
+ const { hexToRgba, darkenHex } = useColor();
65
1286
  const THEME_COLOR_KEY = "hlw_theme_color";
66
1287
  const THEME_SEMANTIC_COLORS = {
67
1288
  success: "#10b981",
@@ -190,7 +1411,55 @@
190
1411
  function getCurrentAppearanceVars() {
191
1412
  return APPEARANCE_VAR_MAP[getCurrentAppearanceMode()];
192
1413
  }
193
- const { varsToStyle } = mpCore.useColor();
1414
+ const TYPOGRAPHY_ROLES = {
1415
+ "title-lg": {
1416
+ size: "var(--font-xl)",
1417
+ weight: "600",
1418
+ lineHeight: "1.2",
1419
+ color: "var(--text-primary)"
1420
+ },
1421
+ "title": {
1422
+ size: "var(--font-md)",
1423
+ weight: "500",
1424
+ lineHeight: "1.3",
1425
+ color: "var(--text-primary)"
1426
+ },
1427
+ "subtitle": {
1428
+ size: "var(--font-base)",
1429
+ weight: "500",
1430
+ lineHeight: "1.3",
1431
+ color: "var(--text-secondary)"
1432
+ },
1433
+ "body": {
1434
+ size: "var(--font-base)",
1435
+ weight: "400",
1436
+ lineHeight: "1.5",
1437
+ color: "var(--text-secondary)"
1438
+ },
1439
+ "desc": {
1440
+ size: "var(--font-sm)",
1441
+ weight: "400",
1442
+ lineHeight: "1.4",
1443
+ color: "var(--text-subtle)"
1444
+ },
1445
+ "caption": {
1446
+ size: "var(--font-xs)",
1447
+ weight: "500",
1448
+ lineHeight: "1.3",
1449
+ color: "var(--text-muted)"
1450
+ }
1451
+ };
1452
+ function getCurrentTypographyVars() {
1453
+ const vars = {};
1454
+ for (const [role, cfg] of Object.entries(TYPOGRAPHY_ROLES)) {
1455
+ vars[`--text-${role}-size`] = cfg.size;
1456
+ vars[`--text-${role}-weight`] = cfg.weight;
1457
+ vars[`--text-${role}-line-height`] = cfg.lineHeight;
1458
+ vars[`--text-${role}-color`] = cfg.color;
1459
+ }
1460
+ return vars;
1461
+ }
1462
+ const { varsToStyle } = useColor();
194
1463
  const THEME_CHANGE_EVENT = "hlw:theme-change";
195
1464
  function buildThemeStyle() {
196
1465
  return varsToStyle({
@@ -200,78 +1469,479 @@
200
1469
  });
201
1470
  }
202
1471
  function useThemePageStyle() {
203
- const themePageStyle = vue.ref(buildThemeStyle());
204
- const onThemeChange = () => {
205
- themePageStyle.value = buildThemeStyle();
206
- };
207
- vue.onMounted(() => uni.$on(THEME_CHANGE_EVENT, onThemeChange));
208
- vue.onUnmounted(() => uni.$off(THEME_CHANGE_EVENT, onThemeChange));
1472
+ const store = useThemeStore();
1473
+ const themePageStyle = vue.computed(() => {
1474
+ void store.scale;
1475
+ void store.primaryColor;
1476
+ void store.appearance;
1477
+ return buildThemeStyle();
1478
+ });
209
1479
  return { themePageStyle };
210
1480
  }
211
- const useThemeStore = pinia.defineStore(
212
- "theme",
213
- () => {
214
- const scale = vue.ref("normal");
215
- function setScale(s) {
216
- scale.value = s;
217
- uni.setStorageSync(FONT_SCALE_KEY, s);
218
- uni.$emit(THEME_CHANGE_EVENT);
1481
+ let _msg = null;
1482
+ let _device = null;
1483
+ let _utils = null;
1484
+ let _color = null;
1485
+ const hlw = {
1486
+ /** 延迟创建消息提示实例。 */
1487
+ get $msg() {
1488
+ return _msg ?? (_msg = useMsg());
1489
+ },
1490
+ /** 延迟读取并缓存设备信息。 */
1491
+ get $device() {
1492
+ return (_device ?? (_device = useDevice())).value;
1493
+ },
1494
+ /** 复用全局 HTTP 实例。 */
1495
+ $http: http,
1496
+ /** 延迟创建通用工具实例。 */
1497
+ get $utils() {
1498
+ return _utils ?? (_utils = useUtils());
1499
+ },
1500
+ /** 延迟创建颜色工具实例。 */
1501
+ get $color() {
1502
+ return _color ?? (_color = useColor());
1503
+ }
1504
+ };
1505
+ function getDefaultExportFromCjs(x) {
1506
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
1507
+ }
1508
+ var md5$1 = { exports: {} };
1509
+ var crypt = { exports: {} };
1510
+ (function() {
1511
+ var base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", crypt$1 = {
1512
+ // Bit-wise rotation left
1513
+ rotl: function(n, b) {
1514
+ return n << b | n >>> 32 - b;
1515
+ },
1516
+ // Bit-wise rotation right
1517
+ rotr: function(n, b) {
1518
+ return n << 32 - b | n >>> b;
1519
+ },
1520
+ // Swap big-endian to little-endian and vice versa
1521
+ endian: function(n) {
1522
+ if (n.constructor == Number) {
1523
+ return crypt$1.rotl(n, 8) & 16711935 | crypt$1.rotl(n, 24) & 4278255360;
1524
+ }
1525
+ for (var i = 0; i < n.length; i++)
1526
+ n[i] = crypt$1.endian(n[i]);
1527
+ return n;
1528
+ },
1529
+ // Generate an array of any length of random bytes
1530
+ randomBytes: function(n) {
1531
+ for (var bytes = []; n > 0; n--)
1532
+ bytes.push(Math.floor(Math.random() * 256));
1533
+ return bytes;
1534
+ },
1535
+ // Convert a byte array to big-endian 32-bit words
1536
+ bytesToWords: function(bytes) {
1537
+ for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)
1538
+ words[b >>> 5] |= bytes[i] << 24 - b % 32;
1539
+ return words;
1540
+ },
1541
+ // Convert big-endian 32-bit words to a byte array
1542
+ wordsToBytes: function(words) {
1543
+ for (var bytes = [], b = 0; b < words.length * 32; b += 8)
1544
+ bytes.push(words[b >>> 5] >>> 24 - b % 32 & 255);
1545
+ return bytes;
1546
+ },
1547
+ // Convert a byte array to a hex string
1548
+ bytesToHex: function(bytes) {
1549
+ for (var hex = [], i = 0; i < bytes.length; i++) {
1550
+ hex.push((bytes[i] >>> 4).toString(16));
1551
+ hex.push((bytes[i] & 15).toString(16));
1552
+ }
1553
+ return hex.join("");
1554
+ },
1555
+ // Convert a hex string to a byte array
1556
+ hexToBytes: function(hex) {
1557
+ for (var bytes = [], c = 0; c < hex.length; c += 2)
1558
+ bytes.push(parseInt(hex.substr(c, 2), 16));
1559
+ return bytes;
1560
+ },
1561
+ // Convert a byte array to a base-64 string
1562
+ bytesToBase64: function(bytes) {
1563
+ for (var base64 = [], i = 0; i < bytes.length; i += 3) {
1564
+ var triplet = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
1565
+ for (var j = 0; j < 4; j++)
1566
+ if (i * 8 + j * 6 <= bytes.length * 8)
1567
+ base64.push(base64map.charAt(triplet >>> 6 * (3 - j) & 63));
1568
+ else
1569
+ base64.push("=");
1570
+ }
1571
+ return base64.join("");
1572
+ },
1573
+ // Convert a base-64 string to a byte array
1574
+ base64ToBytes: function(base64) {
1575
+ base64 = base64.replace(/[^A-Z0-9+\/]/ig, "");
1576
+ for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) {
1577
+ if (imod4 == 0)
1578
+ continue;
1579
+ bytes.push((base64map.indexOf(base64.charAt(i - 1)) & Math.pow(2, -2 * imod4 + 8) - 1) << imod4 * 2 | base64map.indexOf(base64.charAt(i)) >>> 6 - imod4 * 2);
1580
+ }
1581
+ return bytes;
219
1582
  }
220
- const fontOptions = Object.keys(FONT_PRESETS).map((key) => ({
221
- value: key,
222
- label: FONT_PRESETS[key].label
223
- }));
224
- const primaryColor = vue.ref(DEFAULT_THEMES[0].value);
225
- const themes = DEFAULT_THEMES;
226
- const activeTheme = vue.computed(
227
- () => themes.find((t) => t.value === primaryColor.value) ?? { label: "自定义", value: primaryColor.value }
228
- );
229
- function setTheme(color) {
230
- primaryColor.value = color;
231
- uni.setStorageSync(THEME_COLOR_KEY, color);
232
- uni.$emit(THEME_CHANGE_EVENT);
1583
+ };
1584
+ crypt.exports = crypt$1;
1585
+ })();
1586
+ var cryptExports = crypt.exports;
1587
+ var charenc = {
1588
+ // UTF-8 encoding
1589
+ utf8: {
1590
+ // Convert a string to a byte array
1591
+ stringToBytes: function(str) {
1592
+ return charenc.bin.stringToBytes(unescape(encodeURIComponent(str)));
1593
+ },
1594
+ // Convert a byte array to a string
1595
+ bytesToString: function(bytes) {
1596
+ return decodeURIComponent(escape(charenc.bin.bytesToString(bytes)));
233
1597
  }
234
- const appearance = vue.ref("auto");
235
- const appearanceOptions = APPEARANCE_PRESETS;
236
- const appearanceMode = vue.computed(() => resolveAppearance(appearance.value));
237
- const isDark = vue.computed(() => appearanceMode.value === "dark");
238
- function setAppearance(a) {
239
- appearance.value = a;
240
- uni.setStorageSync(APPEARANCE_KEY, a);
241
- uni.$emit(THEME_CHANGE_EVENT);
1598
+ },
1599
+ // Binary encoding
1600
+ bin: {
1601
+ // Convert a string to a byte array
1602
+ stringToBytes: function(str) {
1603
+ for (var bytes = [], i = 0; i < str.length; i++)
1604
+ bytes.push(str.charCodeAt(i) & 255);
1605
+ return bytes;
1606
+ },
1607
+ // Convert a byte array to a string
1608
+ bytesToString: function(bytes) {
1609
+ for (var str = [], i = 0; i < bytes.length; i++)
1610
+ str.push(String.fromCharCode(bytes[i]));
1611
+ return str.join("");
242
1612
  }
243
- return {
244
- // 字体
245
- scale,
246
- fontOptions,
247
- setScale,
248
- // 主题色
249
- primaryColor,
250
- themes,
251
- activeTheme,
252
- setTheme,
253
- // 外观模式
254
- appearance,
255
- appearanceOptions,
256
- appearanceMode,
257
- isDark,
258
- setAppearance
259
- };
1613
+ }
1614
+ };
1615
+ var charenc_1 = charenc;
1616
+ /*!
1617
+ * Determine if an object is a Buffer
1618
+ *
1619
+ * @author Feross Aboukhadijeh <https://feross.org>
1620
+ * @license MIT
1621
+ */
1622
+ var isBuffer_1 = function(obj) {
1623
+ return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer);
1624
+ };
1625
+ function isBuffer(obj) {
1626
+ return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
1627
+ }
1628
+ function isSlowBuffer(obj) {
1629
+ return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isBuffer(obj.slice(0, 0));
1630
+ }
1631
+ (function() {
1632
+ var crypt2 = cryptExports, utf8 = charenc_1.utf8, isBuffer2 = isBuffer_1, bin = charenc_1.bin, md52 = function(message, options) {
1633
+ if (message.constructor == String)
1634
+ if (options && options.encoding === "binary")
1635
+ message = bin.stringToBytes(message);
1636
+ else
1637
+ message = utf8.stringToBytes(message);
1638
+ else if (isBuffer2(message))
1639
+ message = Array.prototype.slice.call(message, 0);
1640
+ else if (!Array.isArray(message) && message.constructor !== Uint8Array)
1641
+ message = message.toString();
1642
+ var m = crypt2.bytesToWords(message), l = message.length * 8, a = 1732584193, b = -271733879, c = -1732584194, d = 271733878;
1643
+ for (var i = 0; i < m.length; i++) {
1644
+ m[i] = (m[i] << 8 | m[i] >>> 24) & 16711935 | (m[i] << 24 | m[i] >>> 8) & 4278255360;
1645
+ }
1646
+ m[l >>> 5] |= 128 << l % 32;
1647
+ m[(l + 64 >>> 9 << 4) + 14] = l;
1648
+ var FF = md52._ff, GG = md52._gg, HH = md52._hh, II = md52._ii;
1649
+ for (var i = 0; i < m.length; i += 16) {
1650
+ var aa = a, bb = b, cc = c, dd = d;
1651
+ a = FF(a, b, c, d, m[i + 0], 7, -680876936);
1652
+ d = FF(d, a, b, c, m[i + 1], 12, -389564586);
1653
+ c = FF(c, d, a, b, m[i + 2], 17, 606105819);
1654
+ b = FF(b, c, d, a, m[i + 3], 22, -1044525330);
1655
+ a = FF(a, b, c, d, m[i + 4], 7, -176418897);
1656
+ d = FF(d, a, b, c, m[i + 5], 12, 1200080426);
1657
+ c = FF(c, d, a, b, m[i + 6], 17, -1473231341);
1658
+ b = FF(b, c, d, a, m[i + 7], 22, -45705983);
1659
+ a = FF(a, b, c, d, m[i + 8], 7, 1770035416);
1660
+ d = FF(d, a, b, c, m[i + 9], 12, -1958414417);
1661
+ c = FF(c, d, a, b, m[i + 10], 17, -42063);
1662
+ b = FF(b, c, d, a, m[i + 11], 22, -1990404162);
1663
+ a = FF(a, b, c, d, m[i + 12], 7, 1804603682);
1664
+ d = FF(d, a, b, c, m[i + 13], 12, -40341101);
1665
+ c = FF(c, d, a, b, m[i + 14], 17, -1502002290);
1666
+ b = FF(b, c, d, a, m[i + 15], 22, 1236535329);
1667
+ a = GG(a, b, c, d, m[i + 1], 5, -165796510);
1668
+ d = GG(d, a, b, c, m[i + 6], 9, -1069501632);
1669
+ c = GG(c, d, a, b, m[i + 11], 14, 643717713);
1670
+ b = GG(b, c, d, a, m[i + 0], 20, -373897302);
1671
+ a = GG(a, b, c, d, m[i + 5], 5, -701558691);
1672
+ d = GG(d, a, b, c, m[i + 10], 9, 38016083);
1673
+ c = GG(c, d, a, b, m[i + 15], 14, -660478335);
1674
+ b = GG(b, c, d, a, m[i + 4], 20, -405537848);
1675
+ a = GG(a, b, c, d, m[i + 9], 5, 568446438);
1676
+ d = GG(d, a, b, c, m[i + 14], 9, -1019803690);
1677
+ c = GG(c, d, a, b, m[i + 3], 14, -187363961);
1678
+ b = GG(b, c, d, a, m[i + 8], 20, 1163531501);
1679
+ a = GG(a, b, c, d, m[i + 13], 5, -1444681467);
1680
+ d = GG(d, a, b, c, m[i + 2], 9, -51403784);
1681
+ c = GG(c, d, a, b, m[i + 7], 14, 1735328473);
1682
+ b = GG(b, c, d, a, m[i + 12], 20, -1926607734);
1683
+ a = HH(a, b, c, d, m[i + 5], 4, -378558);
1684
+ d = HH(d, a, b, c, m[i + 8], 11, -2022574463);
1685
+ c = HH(c, d, a, b, m[i + 11], 16, 1839030562);
1686
+ b = HH(b, c, d, a, m[i + 14], 23, -35309556);
1687
+ a = HH(a, b, c, d, m[i + 1], 4, -1530992060);
1688
+ d = HH(d, a, b, c, m[i + 4], 11, 1272893353);
1689
+ c = HH(c, d, a, b, m[i + 7], 16, -155497632);
1690
+ b = HH(b, c, d, a, m[i + 10], 23, -1094730640);
1691
+ a = HH(a, b, c, d, m[i + 13], 4, 681279174);
1692
+ d = HH(d, a, b, c, m[i + 0], 11, -358537222);
1693
+ c = HH(c, d, a, b, m[i + 3], 16, -722521979);
1694
+ b = HH(b, c, d, a, m[i + 6], 23, 76029189);
1695
+ a = HH(a, b, c, d, m[i + 9], 4, -640364487);
1696
+ d = HH(d, a, b, c, m[i + 12], 11, -421815835);
1697
+ c = HH(c, d, a, b, m[i + 15], 16, 530742520);
1698
+ b = HH(b, c, d, a, m[i + 2], 23, -995338651);
1699
+ a = II(a, b, c, d, m[i + 0], 6, -198630844);
1700
+ d = II(d, a, b, c, m[i + 7], 10, 1126891415);
1701
+ c = II(c, d, a, b, m[i + 14], 15, -1416354905);
1702
+ b = II(b, c, d, a, m[i + 5], 21, -57434055);
1703
+ a = II(a, b, c, d, m[i + 12], 6, 1700485571);
1704
+ d = II(d, a, b, c, m[i + 3], 10, -1894986606);
1705
+ c = II(c, d, a, b, m[i + 10], 15, -1051523);
1706
+ b = II(b, c, d, a, m[i + 1], 21, -2054922799);
1707
+ a = II(a, b, c, d, m[i + 8], 6, 1873313359);
1708
+ d = II(d, a, b, c, m[i + 15], 10, -30611744);
1709
+ c = II(c, d, a, b, m[i + 6], 15, -1560198380);
1710
+ b = II(b, c, d, a, m[i + 13], 21, 1309151649);
1711
+ a = II(a, b, c, d, m[i + 4], 6, -145523070);
1712
+ d = II(d, a, b, c, m[i + 11], 10, -1120210379);
1713
+ c = II(c, d, a, b, m[i + 2], 15, 718787259);
1714
+ b = II(b, c, d, a, m[i + 9], 21, -343485551);
1715
+ a = a + aa >>> 0;
1716
+ b = b + bb >>> 0;
1717
+ c = c + cc >>> 0;
1718
+ d = d + dd >>> 0;
1719
+ }
1720
+ return crypt2.endian([a, b, c, d]);
1721
+ };
1722
+ md52._ff = function(a, b, c, d, x, s, t) {
1723
+ var n = a + (b & c | ~b & d) + (x >>> 0) + t;
1724
+ return (n << s | n >>> 32 - s) + b;
1725
+ };
1726
+ md52._gg = function(a, b, c, d, x, s, t) {
1727
+ var n = a + (b & d | c & ~d) + (x >>> 0) + t;
1728
+ return (n << s | n >>> 32 - s) + b;
1729
+ };
1730
+ md52._hh = function(a, b, c, d, x, s, t) {
1731
+ var n = a + (b ^ c ^ d) + (x >>> 0) + t;
1732
+ return (n << s | n >>> 32 - s) + b;
1733
+ };
1734
+ md52._ii = function(a, b, c, d, x, s, t) {
1735
+ var n = a + (c ^ (b | ~d)) + (x >>> 0) + t;
1736
+ return (n << s | n >>> 32 - s) + b;
1737
+ };
1738
+ md52._blocksize = 16;
1739
+ md52._digestsize = 16;
1740
+ md5$1.exports = function(message, options) {
1741
+ if (message === void 0 || message === null)
1742
+ throw new Error("Illegal argument " + message);
1743
+ var digestbytes = crypt2.wordsToBytes(md52(message, options));
1744
+ return options && options.asBytes ? digestbytes : options && options.asString ? bin.bytesToString(digestbytes) : crypt2.bytesToHex(digestbytes);
1745
+ };
1746
+ })();
1747
+ var md5Exports = md5$1.exports;
1748
+ const md5 = /* @__PURE__ */ getDefaultExportFromCjs(md5Exports);
1749
+ let _installed = false;
1750
+ let _interceptorCleanup = [];
1751
+ const _defaultOpts = {
1752
+ tokenHeader: "x-token",
1753
+ autoToastError: true
1754
+ };
1755
+ function useApp() {
1756
+ const _plugins = [];
1757
+ function use(pluginOrInstaller) {
1758
+ _plugins.push((app) => app.use(pluginOrInstaller));
1759
+ }
1760
+ function install(AppComponent) {
1761
+ if (_installed) {
1762
+ console.warn("[hlw] useApp().install() 应只调用一次");
1763
+ }
1764
+ _installed = true;
1765
+ function createApp() {
1766
+ const app = vue.createSSRApp(AppComponent);
1767
+ app.config.globalProperties["hlw"] = hlw;
1768
+ _plugins.forEach((fn) => fn(app));
1769
+ return { app };
1770
+ }
1771
+ return createApp;
1772
+ }
1773
+ return { install, use, hlw, http };
1774
+ }
1775
+ function buildSignString(url) {
1776
+ try {
1777
+ const [path, query] = url.split("?");
1778
+ if (!query)
1779
+ return path + "&";
1780
+ const params = query.split("&").filter(Boolean);
1781
+ params.sort();
1782
+ return params.join("&") + "&";
1783
+ } catch {
1784
+ return url;
1785
+ }
1786
+ }
1787
+ let _sigSecret = "";
1788
+ function setupInterceptors(options = {}) {
1789
+ const opts = { ..._defaultOpts, ...options };
1790
+ if (opts.sigSecret)
1791
+ _sigSecret = opts.sigSecret;
1792
+ if (opts.baseURL)
1793
+ http.setBaseURL(opts.baseURL);
1794
+ _interceptorCleanup.forEach((dispose) => dispose());
1795
+ _interceptorCleanup = [];
1796
+ const offRequest = http.onRequest((config2) => {
1797
+ const device = useDevice();
1798
+ if (device.value) {
1799
+ const d = device.value;
1800
+ const query = [
1801
+ ["appid", d.appid],
1802
+ ["device_brand", d.device_brand],
1803
+ ["device_model", d.device_model],
1804
+ ["device_id", d.device_id],
1805
+ ["device_type", d.device_type],
1806
+ ["device_orientation", d.device_orientation],
1807
+ ["platform", d.platform],
1808
+ ["system", d.system],
1809
+ ["os", d.os],
1810
+ ["version", d.version],
1811
+ ["sdk_version", d.sdk_version],
1812
+ ["host_name", d.host_name],
1813
+ ["host_version", d.host_version],
1814
+ ["host_language", d.host_language],
1815
+ ["language", d.language],
1816
+ ["app_version", d.app_version],
1817
+ ["app_version_code", d.app_version_code],
1818
+ ["screen_width", String(d.screen_width)],
1819
+ ["screen_height", String(d.screen_height)]
1820
+ ].map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v ?? "")}`).join("&");
1821
+ config2.url = config2.url + (config2.url.includes("?") ? "&" : "?") + query;
1822
+ config2.headers = { ...config2.headers, "X-Appid": d.appid };
1823
+ }
1824
+ if (_sigSecret) {
1825
+ const signStr = buildSignString(config2.url);
1826
+ const sig = md5(signStr + _sigSecret);
1827
+ config2.url = config2.url + "&sig=" + sig;
1828
+ }
1829
+ if (opts.getToken) {
1830
+ const token = opts.getToken();
1831
+ if (token) {
1832
+ config2.headers = {
1833
+ ...config2.headers,
1834
+ [opts.tokenHeader]: token
1835
+ };
1836
+ }
1837
+ }
1838
+ return config2;
1839
+ });
1840
+ const offResponse = http.onResponse((res) => {
1841
+ if (opts.autoToastError && res.code !== 1) {
1842
+ uni.showToast({ title: res.info || "请求失败", icon: "none" });
1843
+ }
1844
+ return res;
1845
+ });
1846
+ const offError = http.onError((err) => {
1847
+ var _a;
1848
+ if (err.message.includes("401")) {
1849
+ (_a = opts.onUnauthorized) == null ? void 0 : _a.call(opts);
1850
+ }
1851
+ });
1852
+ _interceptorCleanup = [offRequest, offResponse, offError];
1853
+ }
1854
+ function copyText(data) {
1855
+ uni.setClipboardData({
1856
+ data,
1857
+ showToast: false,
1858
+ success: () => uni.showToast({ title: "复制成功", icon: "none", duration: 1500 })
1859
+ });
1860
+ }
1861
+ function injectTap(vnode, binding) {
1862
+ if (!vnode.props)
1863
+ vnode.props = {};
1864
+ const props = vnode.props;
1865
+ const prev = props.onTap;
1866
+ props.onTap = (e) => {
1867
+ prev == null ? void 0 : prev(e);
1868
+ const value = binding.value;
1869
+ if (value == null || value === "")
1870
+ return;
1871
+ copyText(String(value));
1872
+ };
1873
+ }
1874
+ const vCopy = {
1875
+ /**
1876
+ * 在指令创建时注入点击事件。
1877
+ */
1878
+ created(el, binding, vnode) {
1879
+ injectTap(vnode, binding);
260
1880
  },
261
- { unistorage: true }
262
- );
1881
+ /**
1882
+ * 在绑定值更新前重新注入点击事件。
1883
+ */
1884
+ beforeUpdate(el, binding, vnode) {
1885
+ injectTap(vnode, binding);
1886
+ }
1887
+ };
1888
+ exports2.APPEARANCE_KEY = APPEARANCE_KEY;
1889
+ exports2.APPEARANCE_PRESETS = APPEARANCE_PRESETS;
1890
+ exports2.APPEARANCE_VAR_MAP = APPEARANCE_VAR_MAP;
263
1891
  exports2.DEFAULT_THEMES = DEFAULT_THEMES;
264
1892
  exports2.FONT_PRESETS = FONT_PRESETS;
265
1893
  exports2.FONT_SCALE_KEY = FONT_SCALE_KEY;
1894
+ exports2.HttpClient = HttpClient;
266
1895
  exports2.THEME_CHANGE_EVENT = THEME_CHANGE_EVENT;
267
1896
  exports2.THEME_COLOR_KEY = THEME_COLOR_KEY;
268
1897
  exports2.THEME_SEMANTIC_COLORS = THEME_SEMANTIC_COLORS;
1898
+ exports2.TYPOGRAPHY_ROLES = TYPOGRAPHY_ROLES;
1899
+ exports2.adapters = adapters;
1900
+ exports2.alistAdapter = alistAdapter;
269
1901
  exports2.buildThemeStyle = buildThemeStyle;
1902
+ exports2.clearDeviceCache = clearDeviceCache;
1903
+ exports2.confirmReward = confirmReward;
1904
+ exports2.cosAdapter = cosAdapter;
1905
+ exports2.destroyAds = destroyAds;
1906
+ exports2.deviceToQuery = deviceToQuery;
1907
+ exports2.getAdapter = getAdapter;
1908
+ exports2.getCurrentAppearance = getCurrentAppearance;
1909
+ exports2.getCurrentAppearanceMode = getCurrentAppearanceMode;
1910
+ exports2.getCurrentAppearanceVars = getCurrentAppearanceVars;
270
1911
  exports2.getCurrentFontScale = getCurrentFontScale;
271
1912
  exports2.getCurrentFontVars = getCurrentFontVars;
272
1913
  exports2.getCurrentThemeColor = getCurrentThemeColor;
273
1914
  exports2.getCurrentThemeVars = getCurrentThemeVars;
1915
+ exports2.getCurrentTypographyVars = getCurrentTypographyVars;
1916
+ exports2.hlw = hlw;
1917
+ exports2.http = http;
1918
+ exports2.ossAdapter = ossAdapter;
1919
+ exports2.qiniuAdapter = qiniuAdapter;
1920
+ exports2.resolveAppearance = resolveAppearance;
1921
+ exports2.setConfigAd = setConfigAd;
1922
+ exports2.setConfigContact = setConfigContact;
1923
+ exports2.setConfigShare = setConfigShare;
1924
+ exports2.setupInterceptors = setupInterceptors;
1925
+ exports2.useAd = useAd;
1926
+ exports2.useApp = useApp;
1927
+ exports2.useColor = useColor;
1928
+ exports2.useContact = useContact;
1929
+ exports2.useDevice = useDevice;
1930
+ exports2.useFormat = useFormat;
1931
+ exports2.useLoading = useLoading;
1932
+ exports2.useMsg = useMsg;
1933
+ exports2.usePageMeta = usePageMeta;
1934
+ exports2.useRefs = useRefs;
1935
+ exports2.useRequest = useRequest;
1936
+ exports2.useRouter = useRouter;
1937
+ exports2.useShare = useShare;
1938
+ exports2.useShareConfig = useShareConfig;
1939
+ exports2.useStorage = useStorage;
274
1940
  exports2.useThemePageStyle = useThemePageStyle;
275
1941
  exports2.useThemeStore = useThemeStore;
1942
+ exports2.useUpload = useUpload;
1943
+ exports2.useUtils = useUtils;
1944
+ exports2.useValidate = useValidate;
1945
+ exports2.vCopy = vCopy;
276
1946
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
277
1947
  });