@hlw-uni/mp-vue 1.2.28 → 2.0.0

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 (68) hide show
  1. package/dist/app.d.ts +33 -0
  2. package/dist/composables/ad/index.d.ts +134 -0
  3. package/dist/composables/color/index.d.ts +8 -0
  4. package/dist/composables/contact/index.d.ts +28 -0
  5. package/dist/composables/device/index.d.ts +129 -0
  6. package/dist/composables/format/index.d.ts +9 -0
  7. package/dist/composables/http/adapters/alist.d.ts +3 -0
  8. package/dist/composables/http/adapters/base.d.ts +19 -0
  9. package/dist/composables/http/adapters/cos.d.ts +3 -0
  10. package/dist/composables/http/adapters/index.d.ts +15 -0
  11. package/dist/composables/http/adapters/oss.d.ts +3 -0
  12. package/dist/composables/http/adapters/qiniu.d.ts +3 -0
  13. package/dist/composables/http/client.d.ts +66 -0
  14. package/dist/composables/http/index.d.ts +8 -0
  15. package/dist/composables/http/types.d.ts +51 -0
  16. package/dist/composables/index.d.ts +26 -0
  17. package/dist/composables/loading/index.d.ts +7 -0
  18. package/dist/composables/msg/index.d.ts +36 -0
  19. package/dist/composables/navigator/index.d.ts +47 -0
  20. package/dist/composables/page-meta/index.d.ts +18 -0
  21. package/dist/composables/refs/index.d.ts +8 -0
  22. package/dist/composables/share/index.d.ts +67 -0
  23. package/dist/composables/storage/index.d.ts +16 -0
  24. package/dist/composables/theme/font.d.ts +1 -1
  25. package/dist/composables/theme/index.d.ts +15 -2
  26. package/dist/composables/utils/index.d.ts +39 -0
  27. package/dist/composables/validate/index.d.ts +12 -0
  28. package/dist/directives/copy.d.ts +3 -0
  29. package/dist/directives/index.d.ts +1 -0
  30. package/dist/hlw.d.ts +14 -0
  31. package/dist/index.d.ts +10 -7
  32. package/dist/index.js +1722 -63
  33. package/dist/index.mjs +1721 -62
  34. package/package.json +5 -3
  35. package/src/app.ts +173 -0
  36. package/src/components/hlw-ad/index.vue +74 -30
  37. package/src/composables/ad/index.ts +386 -0
  38. package/src/composables/color/index.ts +44 -0
  39. package/src/composables/contact/index.ts +88 -0
  40. package/src/composables/device/index.ts +168 -0
  41. package/src/composables/format/index.ts +48 -0
  42. package/src/composables/http/adapters/alist.ts +19 -0
  43. package/src/composables/http/adapters/base.ts +21 -0
  44. package/src/composables/http/adapters/cos.ts +23 -0
  45. package/src/composables/http/adapters/index.ts +31 -0
  46. package/src/composables/http/adapters/oss.ts +22 -0
  47. package/src/composables/http/adapters/qiniu.ts +19 -0
  48. package/src/composables/http/client.ts +237 -0
  49. package/src/composables/http/index.ts +8 -0
  50. package/src/composables/http/types.ts +57 -0
  51. package/src/composables/http/useRequest.ts +107 -0
  52. package/src/composables/index.ts +82 -0
  53. package/src/composables/loading/index.ts +23 -0
  54. package/src/composables/msg/index.ts +132 -0
  55. package/src/composables/navigator/index.ts +104 -0
  56. package/src/composables/page-meta/index.ts +49 -0
  57. package/src/composables/refs/index.ts +30 -0
  58. package/src/composables/share/index.ts +185 -0
  59. package/src/composables/storage/index.ts +76 -0
  60. package/src/composables/theme/font.ts +26 -5
  61. package/src/composables/theme/index.ts +26 -11
  62. package/src/composables/theme/palette.ts +1 -1
  63. package/src/composables/utils/index.ts +160 -0
  64. package/src/composables/validate/index.ts +58 -0
  65. package/src/directives/copy.ts +50 -0
  66. package/src/directives/index.ts +1 -0
  67. package/src/hlw.ts +37 -0
  68. package/src/index.ts +21 -20
@@ -0,0 +1,8 @@
1
+ import { Ref } from 'vue';
2
+ /**
3
+ * 管理动态 ref 集合,适合 v-for 场景。
4
+ */
5
+ export declare function useRefs(): {
6
+ refs: Ref<Record<string, any>, Record<string, any>>;
7
+ setRefs: (key: string) => (el: any) => void;
8
+ };
@@ -0,0 +1,67 @@
1
+ export interface ShareAppMessageContent {
2
+ /** 分享标题 */
3
+ title?: string;
4
+ /** 分享路径,必须是以 / 开头的完整路径 */
5
+ path?: string;
6
+ /** 自定义图片路径 */
7
+ imageUrl?: string;
8
+ }
9
+ export interface ShareTimelineContent {
10
+ /** 朋友圈分享标题 */
11
+ title?: string;
12
+ /** 页面携带的 query 参数 */
13
+ query?: string;
14
+ /** 自定义图片路径 */
15
+ imageUrl?: string;
16
+ }
17
+ export interface ShareConfig extends ShareAppMessageContent {
18
+ /** 朋友圈专属配置,不填则复用朋友分享配置 */
19
+ timeline?: ShareTimelineContent;
20
+ }
21
+ /**
22
+ * 分享来源。
23
+ * - `button` 页面内转发按钮
24
+ * - `menu` 右上角菜单
25
+ */
26
+ export type ShareFrom = 'button' | 'menu';
27
+ export type ShareConfigResolver = (from: ShareFrom) => ShareConfig;
28
+ /**
29
+ * 注册小程序分享钩子。
30
+ */
31
+ export declare function useShare(config: ShareConfig | ShareConfigResolver): void;
32
+ /** 单页分享配置 */
33
+ export interface PageShareItem {
34
+ title: string;
35
+ image: string;
36
+ }
37
+ /** 后端返回的页面 key → 配置映射 */
38
+ export type ShareConfigMap = Record<string, PageShareItem>;
39
+ /** Adapter 注入接口 */
40
+ export interface ShareConfigAdapter {
41
+ /** 拉取分享配置;返回 null 表示拉失败 */
42
+ getConfig: () => Promise<ShareConfigMap | null>;
43
+ }
44
+ /** 页面声明的兜底文案 / 跳转路径 */
45
+ export interface PageShareFallback {
46
+ /** 后端 title 为空时用 */
47
+ title: string;
48
+ /** 分享跳转路径(必须 / 开头);path 不走后端,由页面自定义 */
49
+ path: string;
50
+ /** 后端 image 为空时用;通常留空让微信自动截图 */
51
+ image?: string;
52
+ }
53
+ /** 分享 payload —— 同时喂给 onShareAppMessage / onShareTimeline */
54
+ export interface SharePayload {
55
+ title: string;
56
+ path: string;
57
+ imageUrl?: string;
58
+ }
59
+ /**
60
+ * 注入业务回调(应用启动时调用一次;不调用则始终用 fallback)。
61
+ */
62
+ export declare function configShare(a: ShareConfigAdapter): void;
63
+ /**
64
+ * 业务级分享配置 helper —— 返回 resolver,可直接喂 onShareAppMessage / onShareTimeline。
65
+ * 后端配置异步加载,加载完成前先用 fallback、加载完后自动切到后端值。
66
+ */
67
+ export declare function useShareConfig(pageKey: string, fallback: PageShareFallback): () => SharePayload;
@@ -0,0 +1,16 @@
1
+ /// <reference types="@dcloudio/types" />
2
+ /// <reference types="@dcloudio/types" />
3
+ /**
4
+ * useStorage - 本地存储 composable
5
+ */
6
+ export interface StorageInstance {
7
+ get: <T = unknown>(key: string) => T | null;
8
+ set: <T>(key: string, value: T) => boolean;
9
+ remove: (key: string) => boolean;
10
+ clear: () => boolean;
11
+ info: () => UniApp.GetStorageInfoSuccess | null;
12
+ }
13
+ /**
14
+ * 本地存储读写工具。
15
+ */
16
+ export declare function useStorage(): StorageInstance;
@@ -1,4 +1,4 @@
1
- export type FontScale = "small" | "normal" | "large" | "xlarge";
1
+ export type FontScale = "small" | "compact" | "normal" | "medium" | "large" | "xlarge" | "xxlarge";
2
2
  export interface FontPreset {
3
3
  label: string;
4
4
  vars: Record<string, string>;
@@ -1,4 +1,8 @@
1
- import { Ref } from 'vue';
1
+ import { ComputedRef } from 'vue';
2
+ /**
3
+ * @deprecated 历史事件名;现已改用 pinia store 响应式驱动,emit 不再有效。
4
+ * 保留 export 仅为不破坏外部 import(不影响功能)。
5
+ */
2
6
  export declare const THEME_CHANGE_EVENT = "hlw:theme-change";
3
7
  /**
4
8
  * 只注入会随主题变化的变量(字号档位、主题色、外观模式)。
@@ -8,8 +12,17 @@ export declare const THEME_CHANGE_EVENT = "hlw:theme-change";
8
12
  * 让业务侧可以自由 override,不被运行时注入覆盖。
9
13
  */
10
14
  export declare function buildThemeStyle(): string;
15
+ /**
16
+ * 获取主题样式字符串,用于注入 <page-meta :page-style>。
17
+ *
18
+ * 实现走 pinia store 响应式:store.scale / primaryColor / appearance 任一变化
19
+ * → computed 重算 → page-meta 自动 setData。
20
+ *
21
+ * 注:早期版本用 uni.$emit + onMounted+uni.$on 事件总线驱动,在 vue3 + 小程序部分
22
+ * 基础库下 emit 后 ref 不响应(导致字号 / 主题色 / 外观切换不生效)。已改成响应式驱动。
23
+ */
11
24
  export declare function useThemePageStyle(): {
12
- themePageStyle: Ref<string, string>;
25
+ themePageStyle: ComputedRef<string>;
13
26
  };
14
27
  export type { FontScale, FontPreset } from './font';
15
28
  export { FONT_SCALE_KEY, FONT_PRESETS, getCurrentFontScale, getCurrentFontVars } from './font';
@@ -0,0 +1,39 @@
1
+ /**
2
+ * 小程序通用工具。
3
+ */
4
+ export interface DownloadFileOptions {
5
+ /** 下载地址 */
6
+ url: string;
7
+ /** 文件保存路径,可选 */
8
+ filePath?: string;
9
+ /** HTTP 请求头,可选 */
10
+ header?: Record<string, string>;
11
+ /** 下载进度回调,可选 */
12
+ onProgress?: (progress: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => void;
13
+ }
14
+ export interface DownloadFileResult {
15
+ /** 是否成功 */
16
+ success: boolean;
17
+ /** 临时文件路径 */
18
+ tempFilePath?: string;
19
+ /** 状态码 */
20
+ statusCode?: number;
21
+ /** 错误信息 */
22
+ errMsg?: string;
23
+ }
24
+ export type TapEvent = {
25
+ currentTarget?: {
26
+ dataset?: Record<string, any>;
27
+ };
28
+ };
29
+ /**
30
+ * 剪贴板、下载与相册保存工具集合。
31
+ */
32
+ export declare function useUtils(): {
33
+ copy: (data: string, showToast?: boolean) => Promise<boolean>;
34
+ copyFromEvent: (event: TapEvent) => void;
35
+ paste: () => Promise<string>;
36
+ saveImage: (filePath: string) => Promise<boolean>;
37
+ downloadFile: (options: DownloadFileOptions) => Promise<DownloadFileResult>;
38
+ downloadAndSaveImage: (url: string, onProgress?: ((progress: number) => void) | undefined) => Promise<boolean>;
39
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * useValidate - 校验工具 composable
3
+ */
4
+ export declare function useValidate(): {
5
+ phone: (value: string) => boolean;
6
+ email: (value: string) => boolean;
7
+ url: (value: string) => boolean;
8
+ idCard: (value: string) => boolean;
9
+ carNumber: (value: string) => boolean;
10
+ password: (value: string) => boolean;
11
+ empty: (value: unknown) => boolean;
12
+ };
@@ -0,0 +1,3 @@
1
+ import { Directive } from 'vue';
2
+
3
+ export declare const vCopy: Directive;
@@ -0,0 +1 @@
1
+ export { vCopy } from './copy';
package/dist/hlw.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { useMsg } from './composables/msg';
2
+ import { DeviceInfo } from './composables/device';
3
+ import { http } from './composables/http';
4
+ import { useUtils } from './composables/utils';
5
+ import { useColor } from './composables/color';
6
+
7
+ export interface HlwInstance {
8
+ $msg: ReturnType<typeof useMsg>;
9
+ $device: DeviceInfo;
10
+ $http: typeof http;
11
+ $utils: ReturnType<typeof useUtils>;
12
+ $color: ReturnType<typeof useColor>;
13
+ }
14
+ export declare const hlw: HlwInstance;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,16 @@
1
1
  /**
2
- * @hlw-uni/mp-vue package root exports
2
+ * @hlw-uni/mp-vue 统一导出
3
3
  *
4
- * Note:
5
- * Components are resolved through easycom using `@hlw-uni/mp-vue/src/components/...`.
6
- * The package root only exports plain TS modules so uni-app does not try to bundle
7
- * compiled SFC runtime helpers from the library entry.
4
+ * 2.0 起合并了原 @hlw-uni/mp-core 全部内容。
5
+ * 业务方一处 import,无需再分包:
6
+ * import { useAd, useMsg, useColor, useThemePageStyle, ... } from "@hlw-uni/mp-vue";
7
+ *
8
+ * UI 组件(hlw-page / hlw-button / hlw-ad 等)走 easycom 自动注册,不在这里 export。
8
9
  */
9
- export type { FontScale, FontPreset, ThemeColor } from './composables/theme';
10
+ export * from './composables';
10
11
  export type { HlwMenuItem } from './components/hlw-menu/types';
11
12
  export type { HlwPagingRef, HlwPagingInstance } from './components/hlw-paging/types';
12
- export { FONT_PRESETS, FONT_SCALE_KEY, DEFAULT_THEMES, THEME_COLOR_KEY, THEME_SEMANTIC_COLORS, THEME_CHANGE_EVENT, getCurrentFontScale, getCurrentFontVars, getCurrentThemeColor, getCurrentThemeVars, buildThemeStyle, useThemePageStyle, } from './composables/theme';
13
13
  export { useThemeStore } from './stores/theme';
14
+ export { useApp, setupDefaultInterceptors } from './app';
15
+ export { hlw, type HlwInstance } from './hlw';
16
+ export { vCopy } from './directives';