@hlw-uni/mp-vue 2.1.52 → 2.1.54

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 (72) hide show
  1. package/dist/app.d.ts +2 -20
  2. package/dist/composables/device/index.d.ts +5 -70
  3. package/dist/composables/index.d.ts +5 -14
  4. package/dist/composables/navigator/index.d.ts +15 -39
  5. package/dist/composables/request/client.d.ts +21 -0
  6. package/dist/composables/request/index.d.ts +6 -0
  7. package/dist/composables/request/service.d.ts +30 -0
  8. package/dist/composables/{http → request}/types.d.ts +0 -3
  9. package/dist/composables/share/index.d.ts +7 -66
  10. package/dist/composables/utils/index.d.ts +25 -32
  11. package/dist/hlw.d.ts +2 -4
  12. package/dist/index.d.ts +2 -3
  13. package/dist/index.js +484 -1256
  14. package/dist/index.mjs +483 -1255
  15. package/package.json +2 -1
  16. package/src/app.ts +3 -143
  17. package/src/components/hlw-ad/index.vue +2 -2
  18. package/src/components/hlw-page/index.vue +1 -1
  19. package/src/composables/device/index.ts +110 -83
  20. package/src/composables/index.ts +9 -39
  21. package/src/composables/navigator/index.ts +77 -77
  22. package/src/composables/request/client.ts +204 -0
  23. package/src/composables/request/index.ts +15 -0
  24. package/src/composables/request/service.ts +54 -0
  25. package/src/composables/{http → request}/types.ts +0 -4
  26. package/src/composables/share/index.ts +64 -168
  27. package/src/composables/theme/index.ts +4 -2
  28. package/src/composables/theme/palette.ts +22 -4
  29. package/src/composables/utils/index.ts +131 -95
  30. package/src/hlw.ts +6 -14
  31. package/src/index.ts +2 -3
  32. package/dist/composables/_internal/unwrap.d.ts +0 -15
  33. package/dist/composables/ad/index.d.ts +0 -78
  34. package/dist/composables/algo/index.d.ts +0 -7
  35. package/dist/composables/algo/uuid.d.ts +0 -17
  36. package/dist/composables/color/index.d.ts +0 -8
  37. package/dist/composables/contact/index.d.ts +0 -32
  38. package/dist/composables/format/index.d.ts +0 -9
  39. package/dist/composables/http/client.d.ts +0 -66
  40. package/dist/composables/http/index.d.ts +0 -8
  41. package/dist/composables/loading/index.d.ts +0 -7
  42. package/dist/composables/page-meta/index.d.ts +0 -18
  43. package/dist/composables/storage/index.d.ts +0 -16
  44. package/dist/composables/validate/index.d.ts +0 -12
  45. package/dist/error.d.ts +0 -1
  46. package/src/composables/_internal/unwrap.ts +0 -19
  47. package/src/composables/ad/index.ts +0 -412
  48. package/src/composables/algo/index.ts +0 -7
  49. package/src/composables/algo/uuid.ts +0 -27
  50. package/src/composables/color/index.ts +0 -44
  51. package/src/composables/contact/index.ts +0 -92
  52. package/src/composables/format/index.ts +0 -48
  53. package/src/composables/http/client.ts +0 -237
  54. package/src/composables/http/index.ts +0 -8
  55. package/src/composables/http/useRequest.ts +0 -107
  56. package/src/composables/loading/index.ts +0 -23
  57. package/src/composables/page-meta/index.ts +0 -49
  58. package/src/composables/storage/index.ts +0 -76
  59. package/src/composables/validate/index.ts +0 -58
  60. package/src/error.ts +0 -5
  61. /package/dist/composables/{http → request}/adapters/alist.d.ts +0 -0
  62. /package/dist/composables/{http → request}/adapters/base.d.ts +0 -0
  63. /package/dist/composables/{http → request}/adapters/cos.d.ts +0 -0
  64. /package/dist/composables/{http → request}/adapters/index.d.ts +0 -0
  65. /package/dist/composables/{http → request}/adapters/oss.d.ts +0 -0
  66. /package/dist/composables/{http → request}/adapters/qiniu.d.ts +0 -0
  67. /package/src/composables/{http → request}/adapters/alist.ts +0 -0
  68. /package/src/composables/{http → request}/adapters/base.ts +0 -0
  69. /package/src/composables/{http → request}/adapters/cos.ts +0 -0
  70. /package/src/composables/{http → request}/adapters/index.ts +0 -0
  71. /package/src/composables/{http → request}/adapters/oss.ts +0 -0
  72. /package/src/composables/{http → request}/adapters/qiniu.ts +0 -0
package/src/index.ts CHANGED
@@ -3,14 +3,13 @@
3
3
  *
4
4
  * 2.0 起合并了原 @hlw-uni/mp-core 全部内容。
5
5
  * 业务方一处 import,无需再分包:
6
- * import { useAd, useMsg, useColor, useThemePageStyle, ... } from "@hlw-uni/mp-vue";
6
+ * import { useMsg, useThemePageStyle, ... } from "@hlw-uni/mp-vue";
7
7
  *
8
8
  * UI 组件(hlw-page / hlw-button / hlw-ad 等)走 easycom 自动注册,不在这里 export。
9
9
  */
10
10
 
11
11
  // Composables / 工具 / Theme
12
12
  export * from "./composables";
13
- export { getErrorMessage } from "./error";
14
13
 
15
14
  // 类型
16
15
  export type { HlwMenuItem } from "./components/hlw-menu/types";
@@ -20,7 +19,7 @@ export type { HlwPagingRef, HlwPagingInstance } from "./components/hlw-paging/ty
20
19
  export { useThemeStore } from "./stores/theme";
21
20
 
22
21
  // App 根上下文
23
- export { useApp, setupInterceptors } from "./app";
22
+ export { useApp } from "./app";
24
23
 
25
24
  // hlw 全局命名空间
26
25
  export { hlw, type HlwInstance } from "./hlw";
@@ -1,15 +0,0 @@
1
- /**
2
- * Adapter 返回值解包:兼容业务方传「已解包 T」或「ThinkAdmin envelope { code, data }」。
3
- *
4
- * 业务方写法:
5
- * setConfigAd({ getConfig: getAdConfig }) // 直接传 envelope-returning 函数
6
- * setConfigAd({ getConfig: async () => myUnwrapped }) // 也支持已解包
7
- *
8
- * 鸭子类型识别:raw 是对象且有 number 类型的 code 字段 → 当 envelope 处理。
9
- */
10
- export type AdapterPayload<T> = T | null | {
11
- code: number;
12
- data?: T;
13
- info?: string;
14
- };
15
- export declare function unwrapPayload<T>(raw: AdapterPayload<T>): T | null;
@@ -1,78 +0,0 @@
1
- import { AdapterPayload } from '../_internal/unwrap';
2
- import { ComputedRef, Ref } from 'vue';
3
-
4
- /** 6 种广告类型 */
5
- export type AdType = "banner" | "grid" | "custom" | "video" | "reward" | "popup";
6
- /** 广告配置 —— 字段名跟后端表列名对齐(plugin_qz_mp.{type}_unit_id) */
7
- export interface AdConfig {
8
- banner_unit_id: string;
9
- grid_unit_id: string;
10
- custom_unit_id: string;
11
- video_unit_id: string;
12
- reward_unit_id: string;
13
- popup_unit_id: string;
14
- /** VIP 屏蔽展示型广告(reward 除外):0=否,1=屏蔽 banner/grid/custom/video/popup */
15
- vip_no_ad?: 0 | 1;
16
- }
17
- /** 广告错误对象(onError 回调参数) */
18
- export interface AdError {
19
- errCode: number;
20
- errMsg: string;
21
- }
22
- /**
23
- * 业务回调注入接口 —— setConfigAd 时由项目提供。
24
- *
25
- * getConfig 支持两种返回:
26
- * - 已解包:直接返回 AdConfig 或 null
27
- * - ThinkAdmin envelope:返回 { code, data } 对象,库自动按 code===1 解包
28
- *
29
- * 业务方可以直接传 envelope-returning 的接口函数引用:
30
- * setConfigAd({ getConfig: getAdConfig })
31
- */
32
- export interface AdAdapter {
33
- getConfig: () => Promise<AdapterPayload<AdConfig>>;
34
- /** 是否已登录;不传 = 不校验(showReward 调用前会问一次) */
35
- isAuth?: () => boolean;
36
- /** 是否 VIP;配合 config.vip_no_ad=1 时屏蔽展示型广告(reward 不受影响) */
37
- isVip?: () => boolean;
38
- /**
39
- * 用户级强制屏蔽:返回 true 直接屏蔽展示型广告(reward 不受影响),
40
- * 优先级高于 mp.vip_no_ad + isVip 的联合判断;不传 = 不强制。
41
- */
42
- userNoAd?: () => boolean;
43
- }
44
- /** 激励视频关闭回调返回 */
45
- export interface AdCloseResult {
46
- /** 用户是否完整观看 */
47
- isEnded: boolean;
48
- }
49
- /**
50
- * 注入业务回调,应用启动时调用一次。
51
- * 不调用也不会崩,但 loadConfig / showReward 会无效。
52
- */
53
- export declare function setConfigAd(a: AdAdapter): void;
54
- export declare function useAd(): {
55
- config: ComputedRef<AdConfig>;
56
- loaded: Ref<boolean, boolean>;
57
- loadConfig: (force?: boolean) => Promise<void>;
58
- getUnitId: (type: AdType) => string;
59
- showReward: (onClose?: ((res: AdCloseResult) => void | Promise<void>) | undefined) => Promise<void>;
60
- showPopup: (delayMs?: number) => Promise<boolean>;
61
- confirm: typeof confirmModal;
62
- };
63
- /**
64
- * 激励视频中途关闭挽留弹窗 —— 通过 useAd().confirm 暴露给业务方:
65
- *
66
- * const { showReward, confirm } = useAd();
67
- * showReward(async ({ isEnded }) => {
68
- * if (!isEnded) return { ok: false, retry: await confirm() };
69
- * const r = await claimAdReward();
70
- * return r.code === 1 ? { ok: true, reward: r.data?.reward } : { ok: false, msg: r.info };
71
- * });
72
- *
73
- * @returns true=用户选「继续观看」 / false=放弃
74
- */
75
- declare function confirmModal(): Promise<boolean>;
76
- /** 销毁全部广告实例并清空缓存(业务一般不用,hot reload 时调) */
77
- export declare function destroyAds(): void;
78
- export {};
@@ -1,7 +0,0 @@
1
- /**
2
- * 算法集:把通用算法包成 useXxx composable,业务侧统一从这里取。
3
- *
4
- * 已有:
5
- * - useUuid RFC 4122 v4,32 字符 hex
6
- */
7
- export { useUuid } from './uuid';
@@ -1,17 +0,0 @@
1
- /**
2
- * UUID v4 生成器(RFC 4122 v4 算法),返回 32 字符 hex(无连字符)。
3
- *
4
- * 用途:当 nonce、idempotency key、临时唯一标识用。
5
- *
6
- * 算法:
7
- * 1. 生成 16 字节随机源
8
- * 2. byte 6 高 4 位置成 0100 标版本号 v4
9
- * 3. byte 8 高 2 位置成 10 标变体(RFC 4122)
10
- * 4. 16 字节转 hex 拼成 32 字符串
11
- *
12
- * 注意:随机源用 Math.random(小程序兼容兜底),加密强度有限,
13
- * 不能用于密钥派生 / token 签发,只能挡重放。
14
- */
15
- export declare function useUuid(): {
16
- v4: () => string;
17
- };
@@ -1,8 +0,0 @@
1
- /**
2
- * 颜色处理工具。
3
- */
4
- export declare function useColor(): {
5
- varsToStyle: (vars: Record<string, string>) => string;
6
- hexToRgba: (hex: string, alpha: number) => string;
7
- darkenHex: (hex: string, amount?: number) => string;
8
- };
@@ -1,32 +0,0 @@
1
- import { AdapterPayload } from '../_internal/unwrap';
2
- import { ComputedRef } from 'vue';
3
-
4
- /** 后端返回的客服配置(按 button open-type=contact 标准属性命名) */
5
- export interface ContactConfig {
6
- send_message_title: string;
7
- send_message_path: string;
8
- send_message_img: string;
9
- show_message_card: boolean;
10
- }
11
- /**
12
- * Adapter 注入接口 —— getConfig 支持「已解包」或「ThinkAdmin envelope」两种返回。
13
- * 业务方可以直接传 envelope-returning 接口:setConfigContact({ getConfig: getContactConfig })
14
- */
15
- export interface ContactAdapter {
16
- getConfig: () => Promise<AdapterPayload<ContactConfig>>;
17
- }
18
- /** v-bind 到 button 的 camelCase props(微信原生属性约定) */
19
- export interface ContactBindProps {
20
- sendMessageTitle: string;
21
- sendMessagePath: string;
22
- sendMessageImg: string;
23
- showMessageCard: boolean;
24
- }
25
- /**
26
- * 注入业务回调(应用启动时调用一次;不调用则 useContact 始终返回空字段)。
27
- */
28
- export declare function setConfigContact(a: ContactAdapter): void;
29
- /**
30
- * 返回 v-bind 友好的客服配置 computed(首次调用会异步拉一次配置)。
31
- */
32
- export declare function useContact(): ComputedRef<ContactBindProps>;
@@ -1,9 +0,0 @@
1
- /**
2
- * useFormat — 格式化工具 composable
3
- */
4
- export declare function useFormat(): {
5
- date: (date: Date | number | string, format?: string) => string;
6
- fileSize: (bytes: number) => string;
7
- phone: (value: string) => string;
8
- money: (amount: number, decimals?: number, decPoint?: string, thousandsSep?: string) => string;
9
- };
@@ -1,66 +0,0 @@
1
- import { ref } from 'vue';
2
- import { ApiResponse, RequestConfig, RequestInterceptor, ResponseInterceptor, ErrorInterceptor, UploadConfig, UploadResult } from './types';
3
-
4
- /** 组件内请求返回的状态对象。 */
5
- export interface UseRequestReturn<T = unknown> {
6
- loading: ReturnType<typeof ref<boolean>>;
7
- data: ReturnType<typeof ref<T | null>>;
8
- error: ReturnType<typeof ref<Error | null>>;
9
- run: (config: RequestConfig) => Promise<ApiResponse<T>>;
10
- get: (url: string, data?: unknown) => Promise<ApiResponse<T>>;
11
- post: (url: string, data?: unknown) => Promise<ApiResponse<T>>;
12
- put: (url: string, data?: unknown) => Promise<ApiResponse<T>>;
13
- del: (url: string, data?: unknown) => Promise<ApiResponse<T>>;
14
- }
15
- export declare class HttpClient {
16
- private _reqInterceptors;
17
- private _resInterceptors;
18
- private _errInterceptors;
19
- private _baseURL;
20
- private _defaultHeaders;
21
- private _noCache;
22
- /**
23
- * 创建 HttpClient 实例并初始化默认配置。
24
- */
25
- constructor(options?: {
26
- baseURL?: string;
27
- headers?: Record<string, string>;
28
- noCache?: boolean;
29
- });
30
- /** 运行时设置 baseURL。 */
31
- setBaseURL(url: string): void;
32
- /** 注册请求拦截器,并返回注销函数。 */
33
- onRequest(fn: RequestInterceptor): () => void;
34
- /** 注册响应拦截器,并返回注销函数。 */
35
- onResponse<T = unknown>(fn: ResponseInterceptor<T>): () => void;
36
- /** 注册错误拦截器,并返回注销函数。 */
37
- onError(fn: ErrorInterceptor): () => void;
38
- /**
39
- * 执行一次全局请求,自动串联请求与响应拦截器。
40
- */
41
- request<T = unknown>(config: RequestConfig): Promise<ApiResponse<T>>;
42
- /**
43
- * 创建组件内可复用的请求状态对象。
44
- */
45
- useRequest<T = unknown>(): UseRequestReturn<T>;
46
- /**
47
- * 根据上传类型选择适配器并执行文件上传。
48
- */
49
- upload(config: UploadConfig): Promise<UploadResult>;
50
- /**
51
- * 拼接 baseURL,并在开启防缓存时追加时间戳参数。
52
- */
53
- private _buildUrl;
54
- /**
55
- * 调用 uni.request 发起底层网络请求。
56
- */
57
- private _doRequest;
58
- /**
59
- * 顺序执行已注册的错误拦截器。
60
- */
61
- private _applyErrorInterceptors;
62
- }
63
- /**
64
- * 全局 HTTP 实例。
65
- */
66
- export declare const http: HttpClient;
@@ -1,8 +0,0 @@
1
- /**
2
- * HTTP 模块统一导出
3
- */
4
- export { http, HttpClient } from './client';
5
- export { useRequest, useUpload } from './useRequest';
6
- export type { ApiResponse, PageResult, RequestConfig, RequestInterceptor, ResponseInterceptor, ErrorInterceptor, UploadConfig, UploadResult } from './types';
7
- export type { UseRequestReturn } from './client';
8
- export * from './adapters';
@@ -1,7 +0,0 @@
1
- /**
2
- * useLoading - 全局 Loading 状态
3
- */
4
- export declare function useLoading(): {
5
- showLoading: (message?: string) => void;
6
- hideLoading: () => void;
7
- };
@@ -1,18 +0,0 @@
1
- /**
2
- * usePageMeta - 页面元信息 composable
3
- */
4
- export interface PageMeta {
5
- title?: string;
6
- navigationBarTitleText?: string;
7
- navigationBarBackgroundColor?: string;
8
- navigationBarTextStyle?: "white" | "black";
9
- backgroundColor?: string;
10
- enablePullDownRefresh?: boolean;
11
- }
12
- /**
13
- * 页面导航栏与背景元信息工具。
14
- */
15
- export declare function usePageMeta(): {
16
- setTitle: (title: string) => void;
17
- setOptions: (options: PageMeta) => void;
18
- };
@@ -1,16 +0,0 @@
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,12 +0,0 @@
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
- };
package/dist/error.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function getErrorMessage(error: unknown): string;
@@ -1,19 +0,0 @@
1
- /**
2
- * Adapter 返回值解包:兼容业务方传「已解包 T」或「ThinkAdmin envelope { code, data }」。
3
- *
4
- * 业务方写法:
5
- * setConfigAd({ getConfig: getAdConfig }) // 直接传 envelope-returning 函数
6
- * setConfigAd({ getConfig: async () => myUnwrapped }) // 也支持已解包
7
- *
8
- * 鸭子类型识别:raw 是对象且有 number 类型的 code 字段 → 当 envelope 处理。
9
- */
10
- export type AdapterPayload<T> = T | null | { code: number; data?: T; info?: string };
11
-
12
- export function unwrapPayload<T>(raw: AdapterPayload<T>): T | null {
13
- if (raw == null) return null;
14
- if (typeof raw === "object" && "code" in raw && typeof (raw as { code: unknown }).code === "number") {
15
- const env = raw as { code: number; data?: T };
16
- return env.code === 1 && env.data ? env.data : null;
17
- }
18
- return raw as T;
19
- }