@hlw-uni/mp-vue 2.1.56 → 2.1.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/app.d.ts +12 -1
  2. package/dist/composables/ad/index.d.ts +26 -0
  3. package/dist/composables/device/index.d.ts +14 -0
  4. package/dist/composables/index.d.ts +1 -1
  5. package/dist/composables/msg/index.d.ts +44 -3
  6. package/dist/composables/navigator/index.d.ts +37 -1
  7. package/dist/composables/refs/index.d.ts +15 -1
  8. package/dist/composables/request/client.d.ts +87 -0
  9. package/dist/composables/request/service.d.ts +64 -0
  10. package/dist/composables/request/types.d.ts +50 -13
  11. package/dist/composables/share/index.d.ts +38 -0
  12. package/dist/composables/theme/appearance.d.ts +30 -4
  13. package/dist/composables/theme/font.d.ts +23 -0
  14. package/dist/composables/theme/index.d.ts +19 -6
  15. package/dist/composables/theme/palette.d.ts +23 -0
  16. package/dist/composables/theme/typography.d.ts +9 -1
  17. package/dist/composables/utils/index.d.ts +120 -13
  18. package/dist/directives/copy.d.ts +5 -0
  19. package/dist/hlw.d.ts +10 -0
  20. package/dist/index.js +305 -199
  21. package/dist/index.mjs +306 -200
  22. package/dist/stores/theme.d.ts +3 -0
  23. package/package.json +1 -1
  24. package/src/app.ts +20 -3
  25. package/src/components/hlw-ad/index.vue +58 -12
  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/composables/ad/index.ts +136 -62
  30. package/src/composables/device/index.ts +32 -2
  31. package/src/composables/index.ts +18 -1
  32. package/src/composables/msg/index.ts +70 -16
  33. package/src/composables/navigator/index.ts +45 -1
  34. package/src/composables/refs/index.ts +27 -4
  35. package/src/composables/request/client.ts +149 -0
  36. package/src/composables/request/service.ts +64 -0
  37. package/src/composables/request/types.ts +53 -13
  38. package/src/composables/share/index.ts +48 -0
  39. package/src/composables/theme/appearance.ts +31 -4
  40. package/src/composables/theme/font.ts +23 -0
  41. package/src/composables/theme/index.ts +23 -7
  42. package/src/composables/theme/palette.ts +32 -0
  43. package/src/composables/theme/typography.ts +9 -1
  44. package/src/composables/utils/index.ts +227 -127
  45. package/src/directives/copy.ts +31 -19
  46. package/src/hlw.ts +11 -0
  47. package/src/stores/theme.ts +28 -5
package/dist/app.d.ts CHANGED
@@ -3,7 +3,18 @@ import { HlwInstance } from './hlw';
3
3
  import { RequestClient } from './composables/request';
4
4
 
5
5
  /**
6
- * 创建 uni-app 应用入口工具。
6
+ * 创建 uni-app 应用入口与全局插件配置工具。
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { useApp } from '@hlw-uni/mp-vue';
11
+ * import App from './App.vue';
12
+ * import { createPinia } from 'pinia';
13
+ *
14
+ * const app = useApp();
15
+ * app.use(createPinia());
16
+ * export const createApp = app.install(App);
17
+ * ```
7
18
  */
8
19
  export declare function useApp(): {
9
20
  install: (AppComponent: Component) => () => {
@@ -1,12 +1,38 @@
1
1
  /**
2
2
  * 小程序广告工具。
3
+ * 提供插屏广告 (Interstitial Ad) 与激励视频广告 (Rewarded Video Ad) 的注册、缓存与展示能力。
4
+ */
5
+ /**
6
+ * 广告播放/加载结果数据结构。
3
7
  */
4
8
  export interface AdRes {
9
+ /** 广告是否正常加载或成功展示完成 */
5
10
  ok: boolean;
11
+ /** 激励视频是否完全播放完毕 (仅激励视频有此属性) */
6
12
  isEnded?: boolean;
13
+ /** 加载或展示失败时的错误对象 */
7
14
  err?: unknown;
8
15
  }
9
16
  type AdDone = (res: AdRes) => void;
17
+ /**
18
+ * 小程序广告 Composables。
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const { setAdPopup, showAdPopup, setAdReward, showAdReward } = useHlwAd();
23
+ *
24
+ * // 1. 插屏广告
25
+ * setAdPopup('ad-unit-id');
26
+ * await showAdPopup();
27
+ *
28
+ * // 2. 激励视频
29
+ * await setAdReward('ad-unit-id');
30
+ * const res = await showAdReward();
31
+ * if (res.ok && res.isEnded) {
32
+ * // 发放奖励
33
+ * }
34
+ * ```
35
+ */
10
36
  export declare function useHlwAd(): {
11
37
  setAdPopup: (adId: string, done?: ((ok: boolean) => void) | undefined) => boolean;
12
38
  showAdPopup: (delay?: number) => Promise<boolean>;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * 完整设备系统信息接口,包含小程序环境与宿主系统的关键元数据。
3
+ */
1
4
  export interface DeviceInfo {
2
5
  /** 小程序 appId */
3
6
  appid: string;
@@ -56,9 +59,20 @@ export interface DeviceInfo {
56
59
  /** 客户端版本号 */
57
60
  version: string;
58
61
  }
62
+ /**
63
+ * 过滤后常用于接口公共请求 Query 的设备字段子集。
64
+ */
59
65
  export type DeviceQueryInfo = Pick<DeviceInfo, "appid" | "device_brand" | "device_model" | "device_id" | "device_type" | "device_orientation" | "platform" | "system" | "os" | "version" | "sdk_version" | "host_name" | "host_version" | "host_language" | "language" | "app_version" | "app_version_code" | "screen_width" | "screen_height">;
66
+ /**
67
+ * 访问当前设备配置信息的 hooks。
68
+ *
69
+ * @returns 包含 `info` (原始数据) 和 `query` (用于 HTTP 报头/URL query 的 urlencoded 字符串)
70
+ */
60
71
  export declare function useDevice(): {
61
72
  info: DeviceInfo;
62
73
  query: string;
63
74
  };
75
+ /**
76
+ * 清除本地设备信息缓存,使下一次读取重新走系统调用收集。
77
+ */
64
78
  export declare function clearDeviceCache(): void;
@@ -7,7 +7,7 @@ export { useDevice, clearDeviceCache, type DeviceInfo, type DeviceQueryInfo, } f
7
7
  export { useRefs } from './refs';
8
8
  export { useShare, type ShareConfig, } from './share';
9
9
  export { useHlwAd, type AdRes } from './ad';
10
- export { useUtils, type DownloadOpt, type DownloadRes } from './utils';
10
+ export { useUtils, withQuery, toQuery, signText, toNumber, toBoolean, copy, paste, auth, saveImage, saveVideoFile, download, saveImageUrl, saveVideoUrl, type DownloadOpt, type DownloadRes, } from './utils';
11
11
  export { useNavigate, type NavigateType, type NavigateOptions } from './navigator';
12
12
  export type { FontScale, FontPreset } from './theme';
13
13
  export { FONT_SCALE_KEY, FONT_PRESETS, getCurrentFontScale, getCurrentFontVars, THEME_CHANGE_EVENT, buildThemeStyle, useThemePageStyle, } from './theme';
@@ -1,38 +1,79 @@
1
1
  /**
2
2
  * useMsg - 消息提示 composable
3
+ * 封装并统一小程序原生的 Toast、Loading 与模态弹窗 API。
3
4
  */
4
- export type ToastIcon = "success" | "fail" | "exception" | "none";
5
+ /** Toast 支持的图标类型 */
6
+ export type ToastIcon = "success" | "loading" | "error" | "none" | "fail" | "exception";
7
+ /** Toast 持续时间的预设档位 */
5
8
  export type ToastDuration = "short" | "long";
9
+ /**
10
+ * Toast 轻提示配置项。
11
+ */
6
12
  export interface ToastOptions {
13
+ /** 提示的消息内容 */
7
14
  message: string;
15
+ /** 显示的图标类型,默认为 'none' */
8
16
  icon?: ToastIcon;
17
+ /** 自定义图标的本地/网络图片路径(如传入,将忽略 icon 属性) */
9
18
  image?: string;
19
+ /** 持续时间,单位毫秒,默认 2000ms */
10
20
  duration?: number;
21
+ /** 是否显示透明蒙层防止穿透点击,默认 false */
11
22
  mask?: boolean;
23
+ /** 提示框的悬浮位置,仅在某些平台下生效 */
12
24
  position?: "top" | "center" | "bottom";
13
25
  }
26
+ /**
27
+ * 模态确认对话框配置项。
28
+ */
14
29
  export interface ModalOptions {
30
+ /** 弹窗标题,默认 '提示' */
15
31
  title?: string;
32
+ /** 弹窗内容 */
16
33
  content: string;
34
+ /** 确认按钮的文字,默认 '确定' */
17
35
  confirmText?: string;
36
+ /** 取消按钮的文字,默认 '取消' */
18
37
  cancelText?: string;
38
+ /** 确认按钮的文字颜色,默认使用主题蓝色 */
19
39
  confirmColor?: string;
40
+ /** 取消按钮的文字颜色,默认灰色 */
20
41
  cancelColor?: string;
21
- /** false=隐藏取消按钮(纯提示弹窗用) */
42
+ /** 是否显示取消按钮,若为 false 则只有确认按钮,默认 true */
22
43
  showCancel?: boolean;
23
44
  }
45
+ /**
46
+ * useMsg 返回的方法与接口实例。
47
+ */
24
48
  export interface HlwMsg {
49
+ /** 显示普通 Toast 轻提示,支持配置对象或纯文本 */
25
50
  toast(opts: ToastOptions | string): void;
51
+ /** 显示成功提示 (含成功图标) */
26
52
  success(message: string): void;
53
+ /** 显示失败提示 (含错误图标) */
27
54
  error(message: string): void;
55
+ /** 显示失败提示 (含错误图标) —— error 方法的别名 */
28
56
  fail(message: string): void;
57
+ /** 显示全局模态 Loading 状态,默认显示 "加载中..." */
29
58
  showLoading(message?: string): void;
59
+ /** 关闭全局 Loading 状态 */
30
60
  hideLoading(): void;
61
+ /** 弹出确认模态框,返回 Promise<boolean> 代表用户是否点击了“确认” */
31
62
  confirm(opts: ModalOptions): Promise<boolean>;
63
+ /** 弹出确认模态框 —— confirm 方法的别名 */
32
64
  modal(opts: ModalOptions): Promise<boolean>;
65
+ /** 利用手机端导航栏标题动态展现一个文本模拟的进度条 */
33
66
  setLoadingBar(progress: number): void;
34
67
  }
35
68
  /**
36
- * 统一的消息提示与弹窗能力。
69
+ * 统一的消息提示与弹窗能力 hook。
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * const msg = useMsg();
74
+ * msg.toast('操作成功');
75
+ * msg.showLoading('保存中...');
76
+ * const ok = await msg.confirm({ content: '确定删除吗?' });
77
+ * ```
37
78
  */
38
79
  export declare function useMsg(): HlwMsg;
@@ -1,23 +1,59 @@
1
1
  /**
2
- * useNavigate - uni-app 跳转工具
2
+ * useNavigate - uni-app 路由跳转工具
3
+ * 封装并统一原生的页面跳转、重定向、Switch Tab、返回、以及打开外部小程序或 WebView 等方法。
3
4
  */
5
+ /** 页面跳转类型,支持微信小程序的各类路由动作与 WebView/小程序跳转 */
4
6
  export type NavigateType = "navigateTo" | "redirectTo" | "switchTab" | "reLaunch" | "navigateBack" | "miniprogram" | "webview" | (string & {});
7
+ /**
8
+ * 路由跳转的额外配置选项。
9
+ */
5
10
  export interface NavigateOptions {
11
+ /** 发生失败时是否静默不抛出/显示 Toast 提示,默认 false */
6
12
  silent?: boolean;
13
+ /** 页面跳转失败时的回调 */
7
14
  onFail?: (message: string) => void;
15
+ /** 返回上级页面的层数,仅在 type="navigateBack" 时生效,默认 1 */
8
16
  delta?: number;
17
+ /** 打开外部小程序时的页面路径,仅在 type="miniprogram" 时生效 */
9
18
  path?: string;
19
+ /** 打开外部小程序的环境版本 (开发/体验/正式),仅在 type="miniprogram" 时生效 */
10
20
  envVersion?: "develop" | "trial" | "release";
21
+ /** 传递给目标小程序的额外数据 */
11
22
  extraData?: Record<string, unknown>;
12
23
  }
24
+ /**
25
+ * 核心的底层页面路由分发方法。
26
+ *
27
+ * @param type 跳转动作类型
28
+ * @param url 跳转目标路径或小程序 AppId
29
+ * @param options 额外的控制参数
30
+ */
13
31
  declare function navigate(type?: NavigateType, url?: string, options?: NavigateOptions): void;
32
+ /**
33
+ * 路由跳转工具 hooks。
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const router = useNavigate();
38
+ * router.to('/pages/index/index');
39
+ * router.back();
40
+ * router.miniProgram('app-id');
41
+ * ```
42
+ */
14
43
  export declare function useNavigate(): {
44
+ /** 核心底层路由分发函数 */
15
45
  navigate: typeof navigate;
46
+ /** 保留当前页面,跳转到应用内的某个页面 */
16
47
  to: (url: string, options?: NavigateOptions) => void;
48
+ /** 关闭当前页面,跳转到应用内的某个页面 */
17
49
  redirect: (url: string, options?: NavigateOptions) => void;
50
+ /** 跳转到 switchTab 页面,并关闭其他所有非 tabBar 页面 */
18
51
  tab: (url: string, options?: NavigateOptions) => void;
52
+ /** 关闭所有页面,打开到应用内的某个页面 */
19
53
  reLaunch: (url: string, options?: NavigateOptions) => void;
54
+ /** 关闭当前页面,返回上一页面或多级页面 */
20
55
  back: (delta?: number, options?: NavigateOptions) => void;
56
+ /** 打开另一个小程序 */
21
57
  miniProgram: (appId: string, options?: NavigateOptions) => void;
22
58
  };
23
59
  export {};
@@ -1,6 +1,20 @@
1
1
  import { Ref } from 'vue';
2
2
  /**
3
- * 管理动态 ref 集合,适合 v-for 场景。
3
+ * 管理动态 ref 集合的 hook,尤其适合 v-for 列表场景。
4
+ *
5
+ * @example
6
+ * ```vue
7
+ * <template>
8
+ * <view v-for="item in list" :key="item.id" :ref="setRefs(item.id)">
9
+ * {{ item.name }}
10
+ * </view>
11
+ * </template>
12
+ *
13
+ * <script setup>
14
+ * const { refs, setRefs } = useRefs();
15
+ * // 访问特定子项的 DOM/实例: refs.value[itemId]
16
+ * </script>
17
+ * ```
4
18
  */
5
19
  export declare function useRefs(): {
6
20
  refs: Ref<Record<string, any>, Record<string, any>>;
@@ -1,20 +1,107 @@
1
1
  import { ApiResponse, ErrorInterceptor, RequestConfig, RequestInterceptor, ResponseInterceptor, UploadConfig, UploadResult } from './types';
2
2
  import { Ref } from 'vue';
3
3
 
4
+ /**
5
+ * HTTP 请求客户端接口定义。
6
+ * 提供基础的 HTTP 请求方法、文件直传服务配置以及拦截器管理。
7
+ */
4
8
  export interface RequestClient {
9
+ /**
10
+ * 发送网络请求。
11
+ * @param config 请求配置项
12
+ * @returns 封装后的响应结果 Promise
13
+ */
5
14
  request<T = unknown>(config: RequestConfig): Promise<ApiResponse<T>>;
15
+ /**
16
+ * 发送 GET 请求的快捷方法。
17
+ * @param url 请求的目标 URL
18
+ * @param data 请求携带的 query 参数
19
+ * @returns 封装后的响应结果 Promise
20
+ */
6
21
  get<T = unknown>(url: string, data?: unknown): Promise<ApiResponse<T>>;
22
+ /**
23
+ * 发送 POST 请求的快捷方法。
24
+ * @param url 请求的目标 URL
25
+ * @param data 请求携带的 body 数据
26
+ * @returns 封装后的响应结果 Promise
27
+ */
7
28
  post<T = unknown>(url: string, data?: unknown): Promise<ApiResponse<T>>;
29
+ /**
30
+ * 发送 PUT 请求的快捷方法。
31
+ * @param url 请求的目标 URL
32
+ * @param data 请求携带的 body 数据
33
+ * @returns 封装后的响应结果 Promise
34
+ */
8
35
  put<T = unknown>(url: string, data?: unknown): Promise<ApiResponse<T>>;
36
+ /**
37
+ * 发送 DELETE 请求的快捷方法。
38
+ * @param url 请求的目标 URL
39
+ * @param data 请求携带的 query 或 body 数据
40
+ * @returns 封装后的响应结果 Promise
41
+ */
9
42
  del<T = unknown>(url: string, data?: unknown): Promise<ApiResponse<T>>;
43
+ /**
44
+ * 上传本地文件到服务器或第三方云存储。
45
+ * @param config 文件上传配置项
46
+ * @returns 上传解析结果 Promise
47
+ */
10
48
  upload(config: UploadConfig): Promise<UploadResult>;
49
+ /**
50
+ * 设置基础请求域名或前缀。
51
+ * @param url 域名字符串(如 'https://api.example.com')
52
+ */
11
53
  setBaseURL(url: string): void;
54
+ /**
55
+ * 拼接并解析微服务模块或命名空间下的请求 URL。
56
+ * @param namespace 命名空间/模块名称
57
+ * @param url 具体的接口路径
58
+ * @param servicePrefix 服务的前缀,可选
59
+ * @returns 拼接完成的完整路径
60
+ */
12
61
  resolveServiceUrl(namespace: string, url: string, servicePrefix?: string): string;
62
+ /**
63
+ * 注册请求拦截器,在请求发出前触发。
64
+ * @param fn 拦截器处理函数
65
+ * @returns 用于注销该拦截器的注销函数
66
+ */
13
67
  onRequest(fn: RequestInterceptor): () => void;
68
+ /**
69
+ * 注册响应拦截器,在成功接收响应后触发。
70
+ * @param fn 拦截器处理函数
71
+ * @returns 用于注销该拦截器的注销函数
72
+ */
14
73
  onResponse<T = unknown>(fn: ResponseInterceptor<T>): () => void;
74
+ /**
75
+ * 注册错误拦截器,在请求或响应阶段发生异常时触发。
76
+ * @param fn 错误拦截处理器
77
+ * @returns 用于注销该拦截器的注销函数
78
+ */
15
79
  onError(fn: ErrorInterceptor): () => void;
16
80
  }
81
+ /**
82
+ * 获取全局请求客户端单例。
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const http = useRequest();
87
+ * http.setBaseURL('https://api.example.com');
88
+ * ```
89
+ */
17
90
  export declare function useRequest(): RequestClient;
91
+ /**
92
+ * 文件上传 composable。
93
+ * 提供 `uploading` 状态与上传方法。
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * const { uploading, upload } = useUpload();
98
+ * const res = await upload({
99
+ * type: 'oss',
100
+ * filePath: 'temp-path',
101
+ * server: 'https://oss-endpoint.com'
102
+ * });
103
+ * ```
104
+ */
18
105
  export declare function useUpload(): {
19
106
  uploading: Ref<boolean, boolean>;
20
107
  upload: (options: UploadConfig) => Promise<UploadResult>;
@@ -1,28 +1,92 @@
1
1
  import { ApiResponse, RequestConfig } from './types';
2
2
 
3
+ /**
4
+ * 带有具体必填 URL 的服务请求配置。
5
+ */
3
6
  export type ServiceRequestConfig = Omit<RequestConfig, "url"> & {
4
7
  url: string;
5
8
  };
9
+ /**
10
+ * 命名空间装饰器配置项。
11
+ */
6
12
  export interface ServiceNamespaceOptions {
13
+ /** 微服务或模块命名空间 */
7
14
  namespace: string;
8
15
  }
16
+ /**
17
+ * 服务前缀装饰器配置项。
18
+ */
9
19
  export interface ServicePrefixOptions {
20
+ /** 基础路径前缀 */
10
21
  prefix: string;
11
22
  }
23
+ /**
24
+ * 基础服务抽象类。
25
+ * 业务 Service 类继承此类后,可通过 decorators 注入前缀与命名空间,
26
+ * 并通过便捷方法发起网络请求。
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * @ServicePrefix('/api')
31
+ * @ServiceNamespace('user')
32
+ * class UserService extends BaseService {
33
+ * getUserInfo(id: string) {
34
+ * return this.get(`/info?id=${id}`);
35
+ * }
36
+ * }
37
+ * ```
38
+ */
12
39
  export declare class BaseService {
40
+ /** 当前服务的命名空间(一般由 @ServiceNamespace 注入) */
13
41
  namespace: string;
42
+ /** 当前服务的基础路径前缀(一般由 @ServicePrefix 注入) */
14
43
  servicePrefix: string;
44
+ /**
45
+ * 发送服务请求。会自动拼接前缀与命名空间。
46
+ * @param options 请求配置项
47
+ * @returns 响应结果 Promise
48
+ */
15
49
  request<T = unknown>(options: ServiceRequestConfig): Promise<ApiResponse<T>>;
50
+ /**
51
+ * 快捷发送 GET 请求。
52
+ * @param url 请求相对路径
53
+ * @param data 请求参数
54
+ */
16
55
  get<T = unknown>(url: string, data?: unknown): Promise<ApiResponse<T>>;
56
+ /**
57
+ * 快捷发送 POST 请求。
58
+ * @param url 请求相对路径
59
+ * @param data 请求携带的 body
60
+ */
17
61
  post<T = unknown>(url: string, data?: unknown): Promise<ApiResponse<T>>;
62
+ /**
63
+ * 快捷发送 PUT 请求。
64
+ * @param url 请求相对路径
65
+ * @param data 请求携带的 body
66
+ */
18
67
  put<T = unknown>(url: string, data?: unknown): Promise<ApiResponse<T>>;
68
+ /**
69
+ * 快捷发送 DELETE 请求。
70
+ * @param url 请求相对路径
71
+ * @param data 请求参数
72
+ */
19
73
  del<T = unknown>(url: string, data?: unknown): Promise<ApiResponse<T>>;
20
74
  }
75
+ /**
76
+ * 服务命名空间类装饰器。
77
+ * 注入 `namespace` 到服务类中。
78
+ * @param value 命名空间名称或配置对象
79
+ */
21
80
  export declare function ServiceNamespace(value: string | ServiceNamespaceOptions): (target: {
22
81
  prototype: {
23
82
  namespace?: string;
24
83
  };
25
84
  }) => void;
85
+ /**
86
+ * 服务前缀类装饰器。
87
+ * 注入 `servicePrefix` 到服务类中。
88
+ * @param value 前缀值或配置对象
89
+ */
26
90
  export declare function ServicePrefix(value: string | ServicePrefixOptions): (target: {
27
91
  prototype: {
28
92
  servicePrefix?: string;
@@ -1,48 +1,85 @@
1
- /** API 统一响应格式 */
1
+ /**
2
+ * API 统一响应格式
3
+ * 定义服务端接口的标准数据返回格式。
4
+ */
2
5
  export interface ApiResponse<T = unknown> {
6
+ /** 业务状态码 (例如: 1 代表成功,非 1 代表不同类型的失败) */
3
7
  code: number;
8
+ /** 响应的主体数据 */
4
9
  data: T;
10
+ /** 响应的文本提示信息(如:操作成功、系统繁忙) */
5
11
  info: string;
6
12
  }
7
- /** 分页数据 */
13
+ /**
14
+ * 分页请求的标准数据包装格式。
15
+ */
8
16
  export interface PageResult<T = unknown> {
17
+ /** 分页列表数据 */
9
18
  list: T[];
19
+ /** 总记录数 */
10
20
  total: number;
21
+ /** 当前页码 */
11
22
  page: number;
23
+ /** 每页记录条数 */
12
24
  pageSize: number;
13
25
  }
14
- /** 请求配置 */
26
+ /**
27
+ * HTTP 请求参数配置项。
28
+ */
15
29
  export interface RequestConfig {
30
+ /** 请求的目标 URL,支持绝对路径或相对 BaseURL 的相对路径 */
16
31
  url: string;
32
+ /** 请求的 HTTP 方法,默认 "GET" */
17
33
  method?: "GET" | "POST" | "PUT" | "DELETE";
34
+ /** 请求携带的数据载体,GET/DELETE 对应 Query 传参,POST/PUT 对应 Body 传参 */
18
35
  data?: unknown;
36
+ /** 自定义请求头 */
19
37
  headers?: Record<string, string>;
38
+ /** 请求超时时间,单位毫秒 */
20
39
  timeout?: number;
21
40
  }
22
- /** 拦截器类型 */
41
+ /**
42
+ * 请求拦截器函数定义。
43
+ * 允许在请求被发出前修改请求配置,支持异步处理。
44
+ */
23
45
  export type RequestInterceptor = (config: RequestConfig) => RequestConfig | Promise<RequestConfig>;
46
+ /**
47
+ * 响应拦截器函数定义。
48
+ * 允许在响应被接收并传递给业务逻辑前对响应数据做预处理,支持异步处理。
49
+ */
24
50
  export type ResponseInterceptor<T = unknown> = (res: ApiResponse<T>) => ApiResponse<T> | void | Promise<ApiResponse<T> | void>;
51
+ /**
52
+ * 错误拦截器函数定义。
53
+ * 用于统一捕获和处理网络层或业务层抛出的异常。
54
+ */
25
55
  export type ErrorInterceptor = (err: Error) => void | Error | Promise<void | Error>;
26
- /** 上传配置 */
56
+ /**
57
+ * 云存储或文件直传服务配置项。
58
+ */
27
59
  export interface UploadConfig {
28
- /** 上传接口地址 */
60
+ /** 上传的服务器网关 URL */
29
61
  server: string;
30
- /** 文件路径 */
62
+ /** 本地待上传的文件路径 (tempFilePath) */
31
63
  filePath: string;
32
- /** 文件名,可选,默认取 filePath */
64
+ /** 直传服务器接收的文件参数名称,默认自动从 filePath 中截取 */
33
65
  fileName?: string;
34
- /** 上传类型,支持 cos | oss | qiniu | alist | local */
66
+ /** 云直传供应商类型,支持 'cos' | 'oss' | 'qiniu' | 'alist' | 'local' */
35
67
  type: string;
36
- /** 云存储密钥凭证 */
68
+ /** 直传签名凭证所需的一组敏感密钥对(AK、Signature、Token 等) */
37
69
  credentials?: Record<string, string>;
38
- /** 自定义请求头 */
70
+ /** 直传时的自定义 HTTP 请求头 */
39
71
  header?: Record<string, string>;
40
- /** 上传类型为 local 时,作为最终 server */
72
+ /** type="local" 时,可以通过此属性覆盖 server 参数作为最终上传端点 */
41
73
  url?: string;
42
74
  }
43
- /** 上传结果 */
75
+ /**
76
+ * 文件上传完成后标准接口解析出的结果。
77
+ */
44
78
  export interface UploadResult {
79
+ /** 业务状态码 */
45
80
  code: number;
81
+ /** 上传提示信息 */
46
82
  msg: string;
83
+ /** 上传成功后云端资源的可访问 URL 或文件路径 */
47
84
  data: string;
48
85
  }
@@ -1,12 +1,50 @@
1
+ /**
2
+ * 分享卡片配置项。
3
+ */
1
4
  export interface ShareConfig {
5
+ /** 分享的标题,默认使用小程序名称 */
2
6
  title?: string;
7
+ /** 分享的页面路径,支持携带 query 参数,如 '/pages/index/index?id=123' */
3
8
  path?: string;
9
+ /** 分享卡片的展示图 URL 或本地路径 */
4
10
  imageUrl?: string;
5
11
  }
12
+ /**
13
+ * 支持静态配置或动态解析器函数。
14
+ */
6
15
  export type ShareConfigResolver = ShareConfig | (() => ShareConfig);
16
+ /**
17
+ * 分享操作句柄接口。
18
+ */
7
19
  export interface ShareHandlers {
20
+ /**
21
+ * 手动触发分享好友设置。
22
+ * @param config 可选的额外覆盖分享配置
23
+ */
8
24
  onShareAppMessage: (config?: ShareConfigResolver) => void;
25
+ /**
26
+ * 手动触发分享朋友圈设置。
27
+ * @param config 可选的额外覆盖分享配置
28
+ */
9
29
  onShareTimeline: (config?: ShareConfigResolver) => void;
30
+ /**
31
+ * 显示分享菜单项,启用小程序右上角分享。
32
+ */
10
33
  showShareMenu: () => void;
11
34
  }
35
+ /**
36
+ * 小程序页面分享 Hook。
37
+ * 自动调用并监听当前页面的 `onShareAppMessage` 与 `onShareTimeline` 原生事件。
38
+ *
39
+ * @param config 默认的分享配置或配置函数
40
+ * @returns 包含手动触发或配置的方法句柄
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * useShare({
45
+ * title: '欢迎体验我的小程序',
46
+ * path: '/pages/index/index'
47
+ * });
48
+ * ```
49
+ */
12
50
  export declare function useShare(config?: ShareConfigResolver): ShareHandlers;
@@ -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>;