@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
@@ -10,20 +10,46 @@
10
10
  * - 用 `var(--surface-card)` 代替硬编码 `#ffffff`
11
11
  * - 用 `var(--border-color-light)` 代替硬编码 `#f1f5f9`
12
12
  */
13
+ /** 外观模式选项类型:浅色模式、深色模式、跟随系统 */
13
14
  export type Appearance = "light" | "dark" | "auto";
15
+ /** 实际生效的外观模式:仅浅色或深色 */
14
16
  export type AppearanceMode = "light" | "dark";
17
+ /**
18
+ * 外观预设配置接口。
19
+ */
15
20
  export interface AppearancePreset {
21
+ /** 选项值 */
16
22
  value: Appearance;
23
+ /** 选项展示名称 */
17
24
  label: string;
18
25
  }
26
+ /** 存储外观设置的 LocalStorage 键名 */
19
27
  export declare const APPEARANCE_KEY = "hlw_appearance";
28
+ /** 预设外观模式列表,常供设置页渲染选择器使用 */
20
29
  export declare const APPEARANCE_PRESETS: AppearancePreset[];
30
+ /** 不同外观模式的 CSS 变量映射 */
21
31
  export declare const APPEARANCE_VAR_MAP: Record<AppearanceMode, Record<string, string>>;
22
- /** 读取用户设置的外观(light/dark/auto),默认 auto */
32
+ /**
33
+ * 读取用户设置的外观配置(light / dark / auto)。
34
+ * 默认返回 'auto'。
35
+ * @returns 设定的外观模式类型
36
+ */
23
37
  export declare function getCurrentAppearance(): Appearance;
24
- /** 将 auto 解析为具体的 light/dark,依据系统主题 */
38
+ /**
39
+ * 将 auto 设置或用户选择解析为具体的 light/dark 实际模式。
40
+ * 当为 auto 时,将读取系统当前的配色偏好。
41
+ * @param appearance 输入的外观配置
42
+ * @returns 解析后最终生效的外观模式 (light 或 dark)
43
+ */
25
44
  export declare function resolveAppearance(appearance: Appearance): AppearanceMode;
26
- /** 当前实际生效的模式(light 或 dark) */
45
+ /**
46
+ * 获取当前实际生效的外观模式 (light 或 dark)。
47
+ * 自动根据用户偏好及系统主题进行判定。
48
+ * @returns 实际生效的外观模式
49
+ */
27
50
  export declare function getCurrentAppearanceMode(): AppearanceMode;
28
- /** 当前外观对应的 CSS 变量 */
51
+ /**
52
+ * 获取当前外观对应的 CSS 变量映射表。
53
+ * @returns 包含各 CSS 变量名与对应颜色值键值对
54
+ */
29
55
  export declare function getCurrentAppearanceVars(): Record<string, string>;
@@ -1,9 +1,32 @@
1
+ /**
2
+ * 字体大小缩放档位类型。
3
+ * 从较小到特大,共 7 个档位。
4
+ */
1
5
  export type FontScale = "small" | "compact" | "normal" | "medium" | "large" | "xlarge" | "xxlarge";
6
+ /**
7
+ * 字体大小配置预设接口。
8
+ */
2
9
  export interface FontPreset {
10
+ /** 档位名称 */
3
11
  label: string;
12
+ /** 该档位对应的全部 CSS 字号变量及对应尺寸 */
4
13
  vars: Record<string, string>;
5
14
  }
15
+ /** 存储字体字号档位设置的 LocalStorage 键名 */
6
16
  export declare const FONT_SCALE_KEY = "hlw_font_scale";
17
+ /**
18
+ * 字体档位对应的尺寸变量预设表。
19
+ * 每个档位定义了从超小 (--font-xs) 到超大 (--font-xl) 的响应式字号。
20
+ */
7
21
  export declare const FONT_PRESETS: Record<FontScale, FontPreset>;
22
+ /**
23
+ * 获取当前用户配置的字体字号缩放档位。
24
+ * 默认返回 'normal'。
25
+ * @returns 字体档位
26
+ */
8
27
  export declare function getCurrentFontScale(): FontScale;
28
+ /**
29
+ * 获取当前字体字号档位所映射的 CSS 变量表。
30
+ * @returns CSS 变量名与具体字号的键值对
31
+ */
9
32
  export declare function getCurrentFontVars(): Record<string, string>;
@@ -5,20 +5,33 @@ import { ComputedRef } from 'vue';
5
5
  */
6
6
  export declare const THEME_CHANGE_EVENT = "hlw:theme-change";
7
7
  /**
8
- * 只注入运行时配置变量(字号档位、主题色)。
8
+ * 构建仅注入运行时配置变量(字号档位、主题色)的行内样式字符串。
9
9
  *
10
10
  * 页面背景、卡片色、文字色、边框色等业务视觉变量统一由项目全局 CSS
11
11
  * (static/css/style.scss)控制,避免 page-meta 运行时样式覆盖业务侧配置。
12
+ *
13
+ * @returns 扁平化后的 CSS 变量样式属性字符串
12
14
  */
13
15
  export declare function buildThemeStyle(): string;
14
16
  /**
15
- * 获取主题样式字符串,用于注入 <page-meta :page-style>。
17
+ * 获取及监听主题与字号变化,返回可注入到 `<page-meta :page-style="themePageStyle">` 的计算属性。
18
+ *
19
+ * 实现基于 pinia store 响应式:当 store 中的字号档位或主题色发生改变时,
20
+ * 触发计算属性重算并由 Vue 自动更新至 `<page-meta>` 的 setData 接口。
21
+ *
22
+ * @returns 包含 `themePageStyle` 计算属性的对象
16
23
  *
17
- * 实现走 pinia store 响应式:store.scale / primaryColor 任一变化
18
- * → computed 重算 → page-meta 自动 setData。
24
+ * @example
25
+ * ```vue
26
+ * <template>
27
+ * <page-meta :page-style="themePageStyle" />
28
+ * <view class="container">...</view>
29
+ * </template>
19
30
  *
20
- * 注:早期版本用 uni.$emit + onMounted+uni.$on 事件总线驱动,在 vue3 + 小程序部分
21
- * 基础库下 emit ref 不响应(导致字号 / 主题色切换不生效)。已改成响应式驱动。
31
+ * <script setup>
32
+ * const { themePageStyle } = useThemePageStyle();
33
+ * </script>
34
+ * ```
22
35
  */
23
36
  export declare function useThemePageStyle(): {
24
37
  themePageStyle: ComputedRef<string>;
@@ -1,14 +1,37 @@
1
+ /**
2
+ * 主题颜色配置项接口。
3
+ */
1
4
  export interface ThemeColor {
5
+ /** 颜色名称描述 */
2
6
  label: string;
7
+ /** 主题色十六进制值 (Hex Color) */
3
8
  value: string;
4
9
  }
10
+ /** 存储当前主题色设置的 LocalStorage 键名 */
5
11
  export declare const THEME_COLOR_KEY = "hlw_theme_color";
12
+ /**
13
+ * 预设的语义化颜色。
14
+ * 包含成功、警告、错误和提示的默认色彩配置。
15
+ */
6
16
  export declare const THEME_SEMANTIC_COLORS: {
7
17
  readonly success: "#10b981";
8
18
  readonly warning: "#f59e0b";
9
19
  readonly error: "#ef4444";
10
20
  readonly info: "#64748b";
11
21
  };
22
+ /**
23
+ * 系统预设的默认主题色列表。
24
+ */
12
25
  export declare const DEFAULT_THEMES: ThemeColor[];
26
+ /**
27
+ * 读取当前配置的主题色 Hex 字符串。
28
+ * 默认使用 `DEFAULT_THEMES` 数组中首位颜色的值。
29
+ * @returns 十六进制颜色字符串
30
+ */
13
31
  export declare function getCurrentThemeColor(): string;
32
+ /**
33
+ * 获取当前主题色所对应的完整 CSS 颜色语义变量映射表。
34
+ * 会基于当前主题色,自动计算衍生出对应的亮色调、暗色调以及各状态色语义变量。
35
+ * @returns 包含各 CSS 变量名与对应颜色值键值对
36
+ */
14
37
  export declare function getCurrentThemeVars(): Record<string, string>;
@@ -13,6 +13,9 @@
13
13
  * - desc: 卡片描述 / 副文
14
14
  * - caption: 角标 / 底部小字 / 时间戳
15
15
  */
16
+ /**
17
+ * 语义排版角色配置项接口。
18
+ */
16
19
  export interface TypographyRole {
17
20
  /** 对应 `--text-{role}-size` 的值(通常引用字号档位 token) */
18
21
  size: string;
@@ -23,11 +26,16 @@ export interface TypographyRole {
23
26
  /** 对应 `--text-{role}-color`(通常引用文字色 token) */
24
27
  color: string;
25
28
  }
29
+ /**
30
+ * 全局预设排版角色的参数配置表。
31
+ */
26
32
  export declare const TYPOGRAPHY_ROLES: Record<string, TypographyRole>;
27
33
  /**
28
34
  * 展开成 CSS 变量平铺 map,用于 buildThemeStyle 注入 page 元素。
29
35
  *
30
36
  * 每个角色产出 4 个变量:
31
- * --text-{role}-size / -weight / -line-height / -color
37
+ * --text-${role}-size / -weight / -line-height / -color
38
+ *
39
+ * @returns 包含全部排版 CSS 变量键值对的对象
32
40
  */
33
41
  export declare function getCurrentTypographyVars(): Record<string, string>;
@@ -1,35 +1,142 @@
1
1
  /**
2
2
  * 小程序通用工具。
3
+ * 包含查询字符串参数拼接、数据转换、剪贴板交互、授权及图片/视频等多媒体资源下载保存。
4
+ */
5
+ /**
6
+ * 文件下载选项配置接口。
3
7
  */
4
8
  export interface DownloadOpt {
9
+ /** 文件的网络下载链接 */
5
10
  url: string;
11
+ /** 指定文件保存的本地目标路径,可选 */
6
12
  path?: string;
13
+ /** 请求的自定义 HTTP 请求头 */
7
14
  header?: Record<string, string>;
15
+ /** 下载进度更新的回调函数 */
8
16
  progress?: (value: number, done: number, total: number) => void;
9
17
  }
18
+ /**
19
+ * 文件下载结果接口。
20
+ */
10
21
  export interface DownloadRes {
22
+ /** 是否成功下载 */
11
23
  ok: boolean;
24
+ /** 临时或保存后的本地文件路径 */
12
25
  path?: string;
26
+ /** 服务器返回的 HTTP 状态码 */
13
27
  code?: number;
28
+ /** 错误或提示信息 */
14
29
  msg?: string;
15
30
  }
16
- declare function withQuery(url: string, qs: string): string;
17
- declare function toQuery(data: Record<string, unknown>): string;
18
- declare function signText(url: string): string;
19
- declare function toNumber(val: unknown, def: number): number;
20
- declare function toBoolean(val: unknown, def: boolean): boolean;
31
+ /**
32
+ * 拼接 URL Query String。
33
+ * 会根据原 URL 中是否包含问号,自动拼接 `?` 或 `&`。
34
+ * @param url URL
35
+ * @param qs 格式化后的 query 字符串(如 'a=1&b=2')
36
+ * @returns 拼接后的完整 URL
37
+ */
38
+ export declare function withQuery(url: string, qs: string): string;
39
+ /**
40
+ * 将键值对对象转换为 URL 编码的 Query String。
41
+ * 会自动过滤值为 `undefined` 或 `null` 的键。
42
+ * @param data 需要转换的键值对数据对象
43
+ * @returns 格式化后的 Query String 字符串
44
+ */
45
+ export declare function toQuery(data: Record<string, unknown>): string;
46
+ /**
47
+ * 按照特定规则对 URL 或者是 Query 参数进行排序并构造签名文本。
48
+ * 常用于 API 请求签名的加密前置数据处理。
49
+ * @param url 需要签名的完整 URL 或路径
50
+ * @returns 排序拼接后的签名基准字符串
51
+ */
52
+ export declare function signText(url: string): string;
53
+ /**
54
+ * 安全转换未知值到数字类型,若转换失败则返回默认值。
55
+ * @param val 待转换的值
56
+ * @param def 默认数字
57
+ * @returns 转换后的数字或默认值
58
+ */
59
+ export declare function toNumber(val: unknown, def: number): number;
60
+ /**
61
+ * 安全转换未知值到布尔值类型,若转换失败则返回默认值。
62
+ * 兼容特殊数值(如 0, "0", "false" 视为 false;1, "1", "true" 视为 true)。
63
+ * @param val 待转换的值
64
+ * @param def 默认布尔值
65
+ * @returns 转换后的布尔值或默认值
66
+ */
67
+ export declare function toBoolean(val: unknown, def: boolean): boolean;
68
+ /**
69
+ * 复制文本内容至剪贴板。
70
+ * @param text 需要复制的文本
71
+ * @param tip 是否在成功时显示 "复制成功" 的 Toast 提示,默认 true
72
+ * @returns 是否复制成功
73
+ */
74
+ export declare function copy(text: string, tip?: boolean): Promise<boolean>;
75
+ /**
76
+ * 从系统剪贴板中读取文本内容。
77
+ * @returns 剪贴板文本,若读取失败或无内容返回空字符串
78
+ */
79
+ export declare function paste(): Promise<string>;
80
+ /**
81
+ * 引导用户进行系统相册权限授权提示弹窗。
82
+ */
83
+ export declare function auth(): void;
84
+ /**
85
+ * 保存本地临时图片文件到系统相册中。
86
+ * 若无权限会自动调起 `auth()` 引导用户去设置页开启权限。
87
+ * @param path 本地临时图片路径 (如 wxfile://xxx, http://tmp/xxx)
88
+ * @returns 保存是否成功
89
+ */
90
+ export declare function saveImage(path: string): Promise<boolean>;
91
+ /**
92
+ * 保存本地临时视频文件到系统相册中。
93
+ * 若无权限会自动引导授权。
94
+ * @param path 本地临时视频路径
95
+ * @returns 保存是否成功
96
+ */
97
+ export declare function saveVideoFile(path: string): Promise<boolean>;
98
+ /**
99
+ * 基于 UniApp 下载网络资源至本地临时目录中。
100
+ * @param opt 下载参数配置项
101
+ * @returns 下载结果 Promise
102
+ */
103
+ export declare function download(opt: DownloadOpt): Promise<DownloadRes>;
104
+ /**
105
+ * 下载并保存网络图片至系统相册。
106
+ * 过程中包含 Loading 提示以及权限处理。
107
+ * @param url 网络图片地址
108
+ * @param progress 可选的下载进度更新回调
109
+ * @returns 操作是否成功
110
+ */
111
+ export declare function saveImageUrl(url: string, progress?: (value: number) => void): Promise<boolean>;
112
+ /**
113
+ * 下载并保存网络视频至系统相册。
114
+ * 过程中包含 Loading 提示以及权限处理。
115
+ * @param url 网络视频地址
116
+ * @param progress 可选的下载进度更新回调
117
+ * @returns 操作是否成功
118
+ */
119
+ export declare function saveVideoUrl(url: string, progress?: (value: number) => void): Promise<boolean>;
120
+ /**
121
+ * 获取系统通用工具方法的 hook。
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * const { copy, saveImageUrl } = useUtils();
126
+ * copy('hello');
127
+ * ```
128
+ */
21
129
  export declare function useUtils(): {
22
130
  withQuery: typeof withQuery;
23
131
  toQuery: typeof toQuery;
24
132
  signText: typeof signText;
25
133
  toNumber: typeof toNumber;
26
134
  toBoolean: typeof toBoolean;
27
- copy: (text: string, tip?: boolean) => Promise<boolean>;
28
- paste: () => Promise<string>;
29
- saveImage: (path: string) => Promise<boolean>;
30
- saveVideo: (path: string) => Promise<boolean>;
31
- download: (opt: DownloadOpt) => Promise<DownloadRes>;
32
- saveImageUrl: (url: string, progress?: ((value: number) => void) | undefined) => Promise<boolean>;
33
- saveVideoUrl: (url: string, progress?: ((value: number) => void) | undefined) => Promise<boolean>;
135
+ copy: typeof copy;
136
+ paste: typeof paste;
137
+ saveImage: typeof saveImage;
138
+ saveVideoFile: typeof saveVideoFile;
139
+ download: typeof download;
140
+ saveImageUrl: typeof saveImageUrl;
141
+ saveVideoUrl: typeof saveVideoUrl;
34
142
  };
35
- export {};
@@ -1,3 +1,8 @@
1
1
  import { Directive } from 'vue';
2
2
 
3
+ /**
4
+ * 自定义 Vue 指令 `v-copy`
5
+ *
6
+ * 在元素/组件被创建或更新前,拦截其点击事件并注入复制剪贴板逻辑。
7
+ */
3
8
  export declare const vCopy: Directive;
package/dist/hlw.d.ts CHANGED
@@ -3,10 +3,20 @@ import { DeviceInfo } from './composables/device';
3
3
  import { useRequest } from './composables/request';
4
4
  import { useUtils } from './composables/utils';
5
5
 
6
+ /**
7
+ * 全局 hlw 实例接口定义,聚合了框架的核心能力。
8
+ */
6
9
  export interface HlwInstance {
10
+ /** 统一的消息提示与模态弹窗管理模块 */
7
11
  $msg: ReturnType<typeof useMsg>;
12
+ /** 当前运行设备的详细系统信息 */
8
13
  $device: DeviceInfo;
14
+ /** 全局配置的统一 HTTP 请求实例 */
9
15
  $request: ReturnType<typeof useRequest>;
16
+ /** 聚合的常用小程序公共工具函数 */
10
17
  $utils: ReturnType<typeof useUtils>;
11
18
  }
19
+ /**
20
+ * 全局单例 `hlw` 实例,各核心模块在首次读取时延迟初始化并缓存。
21
+ */
12
22
  export declare const hlw: HlwInstance;