@hlw-uni/mp-vue 1.2.26 → 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.
- package/dist/app.d.ts +33 -0
- package/dist/composables/ad/index.d.ts +134 -0
- package/dist/composables/color/index.d.ts +8 -0
- package/dist/composables/contact/index.d.ts +28 -0
- package/dist/composables/device/index.d.ts +129 -0
- package/dist/composables/format/index.d.ts +9 -0
- package/dist/composables/http/adapters/alist.d.ts +3 -0
- package/dist/composables/http/adapters/base.d.ts +19 -0
- package/dist/composables/http/adapters/cos.d.ts +3 -0
- package/dist/composables/http/adapters/index.d.ts +15 -0
- package/dist/composables/http/adapters/oss.d.ts +3 -0
- package/dist/composables/http/adapters/qiniu.d.ts +3 -0
- package/dist/composables/http/client.d.ts +66 -0
- package/dist/composables/http/index.d.ts +8 -0
- package/dist/composables/http/types.d.ts +51 -0
- package/dist/composables/index.d.ts +26 -0
- package/dist/composables/loading/index.d.ts +7 -0
- package/dist/composables/msg/index.d.ts +36 -0
- package/dist/composables/navigator/index.d.ts +47 -0
- package/dist/composables/page-meta/index.d.ts +18 -0
- package/dist/composables/refs/index.d.ts +8 -0
- package/dist/composables/share/index.d.ts +67 -0
- package/dist/composables/storage/index.d.ts +16 -0
- package/dist/composables/theme/font.d.ts +1 -1
- package/dist/composables/theme/index.d.ts +15 -2
- package/dist/composables/utils/index.d.ts +39 -0
- package/dist/composables/validate/index.d.ts +12 -0
- package/dist/directives/copy.d.ts +3 -0
- package/dist/directives/index.d.ts +1 -0
- package/dist/hlw.d.ts +14 -0
- package/dist/index.d.ts +10 -7
- package/dist/index.js +1722 -63
- package/dist/index.mjs +1721 -62
- package/package.json +5 -3
- package/src/app.ts +173 -0
- package/src/components/hlw-ad/index.vue +74 -30
- package/src/composables/ad/index.ts +386 -0
- package/src/composables/color/index.ts +44 -0
- package/src/composables/contact/index.ts +88 -0
- package/src/composables/device/index.ts +168 -0
- package/src/composables/format/index.ts +48 -0
- package/src/composables/http/adapters/alist.ts +19 -0
- package/src/composables/http/adapters/base.ts +21 -0
- package/src/composables/http/adapters/cos.ts +23 -0
- package/src/composables/http/adapters/index.ts +31 -0
- package/src/composables/http/adapters/oss.ts +22 -0
- package/src/composables/http/adapters/qiniu.ts +19 -0
- package/src/composables/http/client.ts +237 -0
- package/src/composables/http/index.ts +8 -0
- package/src/composables/http/types.ts +57 -0
- package/src/composables/http/useRequest.ts +107 -0
- package/src/composables/index.ts +82 -0
- package/src/composables/loading/index.ts +23 -0
- package/src/composables/msg/index.ts +132 -0
- package/src/composables/navigator/index.ts +104 -0
- package/src/composables/page-meta/index.ts +49 -0
- package/src/composables/refs/index.ts +30 -0
- package/src/composables/share/index.ts +185 -0
- package/src/composables/storage/index.ts +76 -0
- package/src/composables/theme/font.ts +26 -5
- package/src/composables/theme/index.ts +26 -11
- package/src/composables/theme/palette.ts +1 -1
- package/src/composables/utils/index.ts +160 -0
- package/src/composables/validate/index.ts +58 -0
- package/src/directives/copy.ts +50 -0
- package/src/directives/index.ts +1 -0
- package/src/hlw.ts +37 -0
- package/src/index.ts +21 -20
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { App, Component } from 'vue';
|
|
2
|
+
import { HlwInstance } from './hlw';
|
|
3
|
+
import { HttpClient } from './composables/http';
|
|
4
|
+
|
|
5
|
+
export interface InterceptorOptions {
|
|
6
|
+
/** API 基础地址 */
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
/** 自动注入 Token 的 header 键名 */
|
|
9
|
+
tokenHeader?: string;
|
|
10
|
+
/** Token 来源函数 */
|
|
11
|
+
getToken?: () => string;
|
|
12
|
+
/** 登录失效时的处理函数 */
|
|
13
|
+
onUnauthorized?: () => void;
|
|
14
|
+
/** 接口业务错误码是否自动 toast */
|
|
15
|
+
autoToastError?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 创建 uni-app 应用入口工具。
|
|
19
|
+
*/
|
|
20
|
+
export declare function useApp(): {
|
|
21
|
+
install: (AppComponent: Component) => () => {
|
|
22
|
+
app: App<Element>;
|
|
23
|
+
};
|
|
24
|
+
use: (pluginOrInstaller: any) => void;
|
|
25
|
+
hlw: HlwInstance;
|
|
26
|
+
http: HttpClient;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* 注册默认请求、响应和错误拦截器。
|
|
30
|
+
*/
|
|
31
|
+
export declare function setupDefaultInterceptors(options?: InterceptorOptions & {
|
|
32
|
+
sigSecret?: string;
|
|
33
|
+
}): void;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* useAd —— 完整的广告业务封装
|
|
4
|
+
*
|
|
5
|
+
* 内置了:
|
|
6
|
+
* - 6 个 unit_id 配置(store 缓存,调 getConfig 拉一次)
|
|
7
|
+
* - 激励视频:广告加载 loading → onShown 自动关闭 → 中途关闭挽留 modal → 看完调业务方的 claim 发奖
|
|
8
|
+
* - 插屏:一行调用
|
|
9
|
+
* - 底层 SDK 适配(onLoad / offClose / show 兜底 / 实例缓存)
|
|
10
|
+
*
|
|
11
|
+
* 业务侧使用方式:
|
|
12
|
+
*
|
|
13
|
+
* 1. 在 App.vue 注入「全局」回调(拿配置 + 校验登录):
|
|
14
|
+
*
|
|
15
|
+
* import { configAd } from "@hlw-uni/mp-vue";
|
|
16
|
+
* import { getAdConfig } from "@/api/ad";
|
|
17
|
+
* import { useUserStore } from "@/store";
|
|
18
|
+
*
|
|
19
|
+
* configAd({
|
|
20
|
+
* getConfig: async () => {
|
|
21
|
+
* const res = await getAdConfig();
|
|
22
|
+
* return res.code === 1 && res.data ? res.data : null;
|
|
23
|
+
* },
|
|
24
|
+
* isAuth: () => !!useUserStore().token,
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* 2. 任意页面拉配置 / 用 unit_id 渲染:
|
|
28
|
+
*
|
|
29
|
+
* const { config, loadConfig, showPopup } = useAd();
|
|
30
|
+
* await loadConfig();
|
|
31
|
+
* <hlw-ad type="banner" :unit-id="config.banner" />
|
|
32
|
+
*
|
|
33
|
+
* 3. 看广告领奖励(业务方按场景传不同的 claim 接口):
|
|
34
|
+
*
|
|
35
|
+
* const ok = await showReward(async () => {
|
|
36
|
+
* const res = await claimAdReward();
|
|
37
|
+
* return res.code === 1
|
|
38
|
+
* ? { ok: true, reward: res.data?.reward }
|
|
39
|
+
* : { ok: false, msg: res.info };
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // 不传 claim 就是纯展示,看完即返回 true
|
|
43
|
+
* const ok = await showReward();
|
|
44
|
+
*/
|
|
45
|
+
/** 6 种广告类型 */
|
|
46
|
+
export type AdType = "banner" | "grid" | "custom" | "video" | "reward" | "popup";
|
|
47
|
+
/** 广告配置 —— 字段名跟后端表列名对齐(plugin_qz_mp.{type}_unit_id) */
|
|
48
|
+
export interface AdConfig {
|
|
49
|
+
banner_unit_id: string;
|
|
50
|
+
grid_unit_id: string;
|
|
51
|
+
custom_unit_id: string;
|
|
52
|
+
video_unit_id: string;
|
|
53
|
+
reward_unit_id: string;
|
|
54
|
+
popup_unit_id: string;
|
|
55
|
+
}
|
|
56
|
+
/** 广告错误对象(onError 回调参数) */
|
|
57
|
+
export interface AdError {
|
|
58
|
+
errCode: number;
|
|
59
|
+
errMsg: string;
|
|
60
|
+
}
|
|
61
|
+
/** 业务回调注入接口 —— configAd 时由项目提供 */
|
|
62
|
+
export interface AdAdapter {
|
|
63
|
+
/** 拉取广告配置;返回 null 表示拉失败,store 不更新 */
|
|
64
|
+
getConfig: () => Promise<AdConfig | null>;
|
|
65
|
+
/** 是否已登录;不传 = 不校验(showReward 调用前会问一次) */
|
|
66
|
+
isAuth?: () => boolean;
|
|
67
|
+
}
|
|
68
|
+
/** 激励视频关闭回调返回 */
|
|
69
|
+
export interface AdCloseResult {
|
|
70
|
+
/** 用户是否完整观看 */
|
|
71
|
+
isEnded: boolean;
|
|
72
|
+
}
|
|
73
|
+
/** showReward 的 claim 回调返回契约 */
|
|
74
|
+
export interface AdClaimResult {
|
|
75
|
+
/** 本次结果:true=成功 / false=失败 */
|
|
76
|
+
ok: boolean;
|
|
77
|
+
/** 奖励数(用于 toast 显示 +N 积分;无则不 toast) */
|
|
78
|
+
reward?: number;
|
|
79
|
+
/** 失败提示语;不传不弹 toast */
|
|
80
|
+
msg?: string;
|
|
81
|
+
/** 仅 isEnded=false 时常用:true 让 mp-core 重新 show 一次(业务方挽留确认后用) */
|
|
82
|
+
retry?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* showReward 的 claim 回调签名 —— 业务方按场景实现(领积分、解锁、抽奖等)。
|
|
86
|
+
* 每次广告关闭后被调用一次(无论是否完整看完),业务方根据 closeRes.isEnded 决定怎么走:
|
|
87
|
+
* - isEnded=true → 调发奖接口 → return { ok: true, reward: N }
|
|
88
|
+
* - isEnded=false → 业务自己决定挽留:return { ok: false, retry: true } 让重新 show
|
|
89
|
+
*/
|
|
90
|
+
export type AdClaimFn = (closeRes: AdCloseResult) => Promise<AdClaimResult>;
|
|
91
|
+
/**
|
|
92
|
+
* 注入业务回调,应用启动时调用一次。
|
|
93
|
+
* 不调用也不会崩,但 loadConfig / showReward 会无效。
|
|
94
|
+
*/
|
|
95
|
+
export declare function configAd(a: AdAdapter): void;
|
|
96
|
+
export declare function useAd(): {
|
|
97
|
+
config: Ref<{
|
|
98
|
+
banner_unit_id: string;
|
|
99
|
+
grid_unit_id: string;
|
|
100
|
+
custom_unit_id: string;
|
|
101
|
+
video_unit_id: string;
|
|
102
|
+
reward_unit_id: string;
|
|
103
|
+
popup_unit_id: string;
|
|
104
|
+
}, AdConfig | {
|
|
105
|
+
banner_unit_id: string;
|
|
106
|
+
grid_unit_id: string;
|
|
107
|
+
custom_unit_id: string;
|
|
108
|
+
video_unit_id: string;
|
|
109
|
+
reward_unit_id: string;
|
|
110
|
+
popup_unit_id: string;
|
|
111
|
+
}>;
|
|
112
|
+
loaded: Ref<boolean, boolean>;
|
|
113
|
+
loadConfig: (force?: boolean) => Promise<void>;
|
|
114
|
+
getUnitId: (type: AdType) => string;
|
|
115
|
+
showReward: (claim?: AdClaimFn) => Promise<boolean>;
|
|
116
|
+
showPopup: () => Promise<boolean>;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* 激励视频中途关闭挽留弹窗 —— 业务方在 claim 回调里也可以复用:
|
|
120
|
+
*
|
|
121
|
+
* showReward(async (closeRes) => {
|
|
122
|
+
* if (!closeRes.isEnded) {
|
|
123
|
+
* const goon = await confirmReward();
|
|
124
|
+
* return { ok: false, retry: goon };
|
|
125
|
+
* }
|
|
126
|
+
* const r = await claimAdReward();
|
|
127
|
+
* return r.code === 1 ? { ok: true, reward: r.data?.reward } : { ok: false, msg: r.info };
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* @returns true=用户选「继续观看」 / false=放弃
|
|
131
|
+
*/
|
|
132
|
+
export declare function confirmReward(): Promise<boolean>;
|
|
133
|
+
/** 销毁全部广告实例并清空缓存(业务一般不用,hot reload 时调) */
|
|
134
|
+
export declare function destroyAds(): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
/** 后端返回的客服配置(按 button open-type=contact 标准属性命名) */
|
|
3
|
+
export interface ContactConfig {
|
|
4
|
+
send_message_title: string;
|
|
5
|
+
send_message_path: string;
|
|
6
|
+
send_message_img: string;
|
|
7
|
+
show_message_card: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Adapter 注入接口 */
|
|
10
|
+
export interface ContactAdapter {
|
|
11
|
+
/** 拉取客服配置;返回 null 表示拉失败,store 不更新 */
|
|
12
|
+
getConfig: () => Promise<ContactConfig | null>;
|
|
13
|
+
}
|
|
14
|
+
/** v-bind 到 button 的 camelCase props(微信原生属性约定) */
|
|
15
|
+
export interface ContactBindProps {
|
|
16
|
+
sendMessageTitle: string;
|
|
17
|
+
sendMessagePath: string;
|
|
18
|
+
sendMessageImg: string;
|
|
19
|
+
showMessageCard: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 注入业务回调(应用启动时调用一次;不调用则 useContact 始终返回空字段)。
|
|
23
|
+
*/
|
|
24
|
+
export declare function configContact(a: ContactAdapter): void;
|
|
25
|
+
/**
|
|
26
|
+
* 返回 v-bind 友好的客服配置 computed(首次调用会异步拉一次配置)。
|
|
27
|
+
*/
|
|
28
|
+
export declare function useContact(): ComputedRef<ContactBindProps>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
export interface DeviceInfo {
|
|
3
|
+
/** 小程序 appId */
|
|
4
|
+
appid: string;
|
|
5
|
+
/** 应用名称 */
|
|
6
|
+
app_name: string;
|
|
7
|
+
/** 小程序版本号(版本名称) */
|
|
8
|
+
app_version: string;
|
|
9
|
+
/** 小程序版本号(版本号) */
|
|
10
|
+
app_version_code: string;
|
|
11
|
+
/** 小程序来源渠道 */
|
|
12
|
+
app_channel: string;
|
|
13
|
+
/** 设备品牌。如:apple、huawei */
|
|
14
|
+
device_brand: string;
|
|
15
|
+
/** 设备型号 */
|
|
16
|
+
device_model: string;
|
|
17
|
+
/** 设备 ID */
|
|
18
|
+
device_id: string;
|
|
19
|
+
/** 设备类型:phone/pad/pc */
|
|
20
|
+
device_type: string;
|
|
21
|
+
/** 设备方向:portrait/landscape */
|
|
22
|
+
device_orientation: "portrait" | "landscape";
|
|
23
|
+
/** 手机品牌。H5 不支持 */
|
|
24
|
+
brand: string;
|
|
25
|
+
/** 手机型号 */
|
|
26
|
+
model: string;
|
|
27
|
+
/** 操作系统版本 */
|
|
28
|
+
system: string;
|
|
29
|
+
/** 操作系统版本(简写) */
|
|
30
|
+
os: string;
|
|
31
|
+
/** 设备像素比 */
|
|
32
|
+
pixel_ratio: number;
|
|
33
|
+
/** 屏幕宽度 (px) */
|
|
34
|
+
screen_width: number;
|
|
35
|
+
/** 屏幕高度 (px) */
|
|
36
|
+
screen_height: number;
|
|
37
|
+
/** 可用窗口宽度 (px) */
|
|
38
|
+
window_width: number;
|
|
39
|
+
/** 可用窗口高度 (px) */
|
|
40
|
+
window_height: number;
|
|
41
|
+
/** 状态栏高度 (px) */
|
|
42
|
+
status_bar_height: number;
|
|
43
|
+
/** 微信基础库版本 */
|
|
44
|
+
sdk_version: string;
|
|
45
|
+
/** 宿主名称。如:WeChat、alipay */
|
|
46
|
+
host_name: string;
|
|
47
|
+
/** 宿主版本。如:微信版本号 */
|
|
48
|
+
host_version: string;
|
|
49
|
+
/** 宿主语言 */
|
|
50
|
+
host_language: string;
|
|
51
|
+
/** 宿主主题:light/dark */
|
|
52
|
+
host_theme: string;
|
|
53
|
+
/** 平台类型 weapp/toutiao/h5 */
|
|
54
|
+
platform: string;
|
|
55
|
+
/** 客户端语言 */
|
|
56
|
+
language: string;
|
|
57
|
+
/** 客户端版本号 */
|
|
58
|
+
version: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 获取单例缓存的设备信息。
|
|
62
|
+
*/
|
|
63
|
+
export declare function useDevice(): Ref<{
|
|
64
|
+
appid: string;
|
|
65
|
+
app_name: string;
|
|
66
|
+
app_version: string;
|
|
67
|
+
app_version_code: string;
|
|
68
|
+
app_channel: string;
|
|
69
|
+
device_brand: string;
|
|
70
|
+
device_model: string;
|
|
71
|
+
device_id: string;
|
|
72
|
+
device_type: string;
|
|
73
|
+
device_orientation: "portrait" | "landscape";
|
|
74
|
+
brand: string;
|
|
75
|
+
model: string;
|
|
76
|
+
system: string;
|
|
77
|
+
os: string;
|
|
78
|
+
pixel_ratio: number;
|
|
79
|
+
screen_width: number;
|
|
80
|
+
screen_height: number;
|
|
81
|
+
window_width: number;
|
|
82
|
+
window_height: number;
|
|
83
|
+
status_bar_height: number;
|
|
84
|
+
sdk_version: string;
|
|
85
|
+
host_name: string;
|
|
86
|
+
host_version: string;
|
|
87
|
+
host_language: string;
|
|
88
|
+
host_theme: string;
|
|
89
|
+
platform: string;
|
|
90
|
+
language: string;
|
|
91
|
+
version: string;
|
|
92
|
+
} | null, DeviceInfo | {
|
|
93
|
+
appid: string;
|
|
94
|
+
app_name: string;
|
|
95
|
+
app_version: string;
|
|
96
|
+
app_version_code: string;
|
|
97
|
+
app_channel: string;
|
|
98
|
+
device_brand: string;
|
|
99
|
+
device_model: string;
|
|
100
|
+
device_id: string;
|
|
101
|
+
device_type: string;
|
|
102
|
+
device_orientation: "portrait" | "landscape";
|
|
103
|
+
brand: string;
|
|
104
|
+
model: string;
|
|
105
|
+
system: string;
|
|
106
|
+
os: string;
|
|
107
|
+
pixel_ratio: number;
|
|
108
|
+
screen_width: number;
|
|
109
|
+
screen_height: number;
|
|
110
|
+
window_width: number;
|
|
111
|
+
window_height: number;
|
|
112
|
+
status_bar_height: number;
|
|
113
|
+
sdk_version: string;
|
|
114
|
+
host_name: string;
|
|
115
|
+
host_version: string;
|
|
116
|
+
host_language: string;
|
|
117
|
+
host_theme: string;
|
|
118
|
+
platform: string;
|
|
119
|
+
language: string;
|
|
120
|
+
version: string;
|
|
121
|
+
} | null>;
|
|
122
|
+
/**
|
|
123
|
+
* 把 deviceInfo 对象转成 URL query string(不含前导 ?)
|
|
124
|
+
*/
|
|
125
|
+
export declare function deviceToQuery(): string;
|
|
126
|
+
/**
|
|
127
|
+
* 手动清除缓存(切换账号等场景可能需要)
|
|
128
|
+
*/
|
|
129
|
+
export declare function clearDeviceCache(): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 云存储上传适配器 - 上传上下文
|
|
3
|
+
*/
|
|
4
|
+
/** 上传上下文。 */
|
|
5
|
+
export interface UploadContext {
|
|
6
|
+
filePath: string;
|
|
7
|
+
fileName: string;
|
|
8
|
+
/** 云存储密钥凭证 */
|
|
9
|
+
credentials?: Record<string, string>;
|
|
10
|
+
/** 额外表单数据 */
|
|
11
|
+
extraData?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
/** 云存储适配器接口。 */
|
|
14
|
+
export interface UploadAdapter {
|
|
15
|
+
/** 适配器名称 */
|
|
16
|
+
name: string;
|
|
17
|
+
/** 根据上下文构建表单数据 */
|
|
18
|
+
buildFormData(ctx: UploadContext): Record<string, string | number>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { UploadAdapter } from './base';
|
|
2
|
+
/**
|
|
3
|
+
* 云存储上传适配器统一导出
|
|
4
|
+
*/
|
|
5
|
+
export { cosAdapter } from './cos';
|
|
6
|
+
export { ossAdapter } from './oss';
|
|
7
|
+
export { qiniuAdapter } from './qiniu';
|
|
8
|
+
export { alistAdapter } from './alist';
|
|
9
|
+
export type { UploadAdapter, UploadContext } from './base';
|
|
10
|
+
/** 所有已注册的上传适配器。 */
|
|
11
|
+
export declare const adapters: Record<string, UploadAdapter>;
|
|
12
|
+
/**
|
|
13
|
+
* 按名称获取上传适配器,不存在时抛错。
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAdapter(name: string): UploadAdapter;
|
|
@@ -0,0 +1,66 @@
|
|
|
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;
|
|
@@ -0,0 +1,8 @@
|
|
|
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';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP 类型定义
|
|
3
|
+
*/
|
|
4
|
+
/** API 统一响应格式 */
|
|
5
|
+
export interface ApiResponse<T = unknown> {
|
|
6
|
+
code: number;
|
|
7
|
+
data: T;
|
|
8
|
+
info: string;
|
|
9
|
+
}
|
|
10
|
+
/** 分页数据 */
|
|
11
|
+
export interface PageResult<T = unknown> {
|
|
12
|
+
list: T[];
|
|
13
|
+
total: number;
|
|
14
|
+
page: number;
|
|
15
|
+
pageSize: number;
|
|
16
|
+
}
|
|
17
|
+
/** 请求配置 */
|
|
18
|
+
export interface RequestConfig {
|
|
19
|
+
url: string;
|
|
20
|
+
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
21
|
+
data?: unknown;
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
timeout?: number;
|
|
24
|
+
}
|
|
25
|
+
/** 拦截器类型 */
|
|
26
|
+
export type RequestInterceptor = (config: RequestConfig) => RequestConfig | Promise<RequestConfig>;
|
|
27
|
+
export type ResponseInterceptor<T = unknown> = (res: ApiResponse<T>) => ApiResponse<T> | void | Promise<ApiResponse<T> | void>;
|
|
28
|
+
export type ErrorInterceptor = (err: Error) => void | Error | Promise<void | Error>;
|
|
29
|
+
/** 上传配置 */
|
|
30
|
+
export interface UploadConfig {
|
|
31
|
+
/** 上传接口地址 */
|
|
32
|
+
server: string;
|
|
33
|
+
/** 文件路径 */
|
|
34
|
+
filePath: string;
|
|
35
|
+
/** 文件名,可选,默认取 filePath */
|
|
36
|
+
fileName?: string;
|
|
37
|
+
/** 上传类型,支持 cos | oss | qiniu | alist | local */
|
|
38
|
+
type: string;
|
|
39
|
+
/** 云存储密钥凭证 */
|
|
40
|
+
credentials?: Record<string, string>;
|
|
41
|
+
/** 自定义请求头 */
|
|
42
|
+
header?: Record<string, string>;
|
|
43
|
+
/** 上传类型为 local 时,作为最终 server */
|
|
44
|
+
url?: string;
|
|
45
|
+
}
|
|
46
|
+
/** 上传结果 */
|
|
47
|
+
export interface UploadResult {
|
|
48
|
+
code: number;
|
|
49
|
+
msg: string;
|
|
50
|
+
data: string;
|
|
51
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composables 统一导出
|
|
3
|
+
*/
|
|
4
|
+
export * from './http';
|
|
5
|
+
export { useLoading } from './loading';
|
|
6
|
+
export { useMsg, type HlwMsg, type ToastOptions, type ModalOptions, type ToastIcon } from './msg';
|
|
7
|
+
export { useDevice, deviceToQuery, clearDeviceCache, type DeviceInfo } from './device';
|
|
8
|
+
export { useRefs } from './refs';
|
|
9
|
+
export { usePageMeta } from './page-meta';
|
|
10
|
+
export { useStorage, type StorageInstance } from './storage';
|
|
11
|
+
export { useValidate } from './validate';
|
|
12
|
+
export { useFormat } from './format';
|
|
13
|
+
export { useAd, configAd, destroyAds, confirmReward, type AdType, type AdConfig, type AdError, type AdAdapter, type AdCloseResult, type AdClaimResult, type AdClaimFn, } from './ad';
|
|
14
|
+
export { useShare, useShareConfig, configShare, type ShareConfig, type ShareConfigResolver, type ShareFrom, type ShareAppMessageContent, type ShareTimelineContent, type ShareConfigMap, type ShareConfigAdapter, type PageShareItem, type PageShareFallback, type SharePayload, } from './share';
|
|
15
|
+
export { useContact, configContact, type ContactConfig, type ContactAdapter, type ContactBindProps, } from './contact';
|
|
16
|
+
export { useUtils, type DownloadFileOptions, type DownloadFileResult, type TapEvent } from './utils';
|
|
17
|
+
export { useColor } from './color';
|
|
18
|
+
export { useRouter, type NavigateType, type NavigateOptions } from './navigator';
|
|
19
|
+
export type { FontScale, FontPreset } from './theme';
|
|
20
|
+
export { FONT_SCALE_KEY, FONT_PRESETS, getCurrentFontScale, getCurrentFontVars, THEME_CHANGE_EVENT, buildThemeStyle, useThemePageStyle, } from './theme';
|
|
21
|
+
export type { ThemeColor } from './theme';
|
|
22
|
+
export { THEME_COLOR_KEY, THEME_SEMANTIC_COLORS, DEFAULT_THEMES, getCurrentThemeColor, getCurrentThemeVars, } from './theme';
|
|
23
|
+
export type { Appearance, AppearanceMode, AppearancePreset } from './theme';
|
|
24
|
+
export { APPEARANCE_KEY, APPEARANCE_PRESETS, APPEARANCE_VAR_MAP, getCurrentAppearance, getCurrentAppearanceMode, getCurrentAppearanceVars, resolveAppearance, } from './theme';
|
|
25
|
+
export type { TypographyRole } from './theme';
|
|
26
|
+
export { TYPOGRAPHY_ROLES, getCurrentTypographyVars } from './theme';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useMsg - 消息提示 composable
|
|
3
|
+
*/
|
|
4
|
+
export type ToastIcon = "success" | "fail" | "exception" | "none";
|
|
5
|
+
export type ToastDuration = "short" | "long";
|
|
6
|
+
export interface ToastOptions {
|
|
7
|
+
message: string;
|
|
8
|
+
icon?: ToastIcon;
|
|
9
|
+
image?: string;
|
|
10
|
+
duration?: number;
|
|
11
|
+
mask?: boolean;
|
|
12
|
+
position?: "top" | "center" | "bottom";
|
|
13
|
+
}
|
|
14
|
+
export interface ModalOptions {
|
|
15
|
+
title?: string;
|
|
16
|
+
content: string;
|
|
17
|
+
confirmText?: string;
|
|
18
|
+
cancelText?: string;
|
|
19
|
+
confirmColor?: string;
|
|
20
|
+
cancelColor?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface HlwMsg {
|
|
23
|
+
toast(opts: ToastOptions | string): void;
|
|
24
|
+
success(message: string): void;
|
|
25
|
+
error(message: string): void;
|
|
26
|
+
fail(message: string): void;
|
|
27
|
+
showLoading(message?: string): void;
|
|
28
|
+
hideLoading(): void;
|
|
29
|
+
confirm(opts: ModalOptions): Promise<boolean>;
|
|
30
|
+
modal(opts: ModalOptions): Promise<boolean>;
|
|
31
|
+
setLoadingBar(progress: number): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 统一的消息提示与弹窗能力。
|
|
35
|
+
*/
|
|
36
|
+
export declare function useMsg(): HlwMsg;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 路由/跳转能力 —— 包装 uni-app 各类 jump API 为一个统一对象
|
|
3
|
+
*
|
|
4
|
+
* 使用:
|
|
5
|
+
* const { navigate } = useRouter();
|
|
6
|
+
* navigate(tool.jump_type, tool.jump_value);
|
|
7
|
+
*
|
|
8
|
+
* 未装 vue-router 也能用;命名风格对齐 Vue Router,熟悉的 push/replace/back
|
|
9
|
+
* 会在后续迭代中补齐。
|
|
10
|
+
*/
|
|
11
|
+
/** 已知的跳转类型;保留 `(string & {})` 允许任意自定义值向下兼容 */
|
|
12
|
+
export type NavigateType = "navigateTo" | "redirectTo" | "switchTab" | "reLaunch" | "webview" | "miniprogram" | (string & {});
|
|
13
|
+
export interface NavigateOptions {
|
|
14
|
+
/** 失败回调,收到 uni 返回的错误信息 */
|
|
15
|
+
onFail?: (errMsg: string) => void;
|
|
16
|
+
/** 是否禁用默认的 Toast 错误提示,默认 false */
|
|
17
|
+
silent?: boolean;
|
|
18
|
+
/** 仅 miniprogram:目标小程序的页面路径(如 pages/index/index?id=1),留空则打开首页 */
|
|
19
|
+
path?: string;
|
|
20
|
+
/** 仅 miniprogram:目标小程序版本,默认 release */
|
|
21
|
+
envVersion?: "develop" | "trial" | "release";
|
|
22
|
+
/** 仅 miniprogram:传给目标小程序的额外数据,对方从 onLaunch/onShow 读取 */
|
|
23
|
+
extraData?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 根据 type + value 调用对应的 uni API,屏蔽参数差异。
|
|
27
|
+
*
|
|
28
|
+
* 对应关系:
|
|
29
|
+
* - `navigateTo`(默认) → uni.navigateTo
|
|
30
|
+
* - `redirectTo` → uni.redirectTo
|
|
31
|
+
* - `switchTab` → uni.switchTab(value 必须是 tabBar 页)
|
|
32
|
+
* - `reLaunch` → uni.reLaunch
|
|
33
|
+
* - `webview` → 默认 Toast 提示,上层需接入 web-view 承载页
|
|
34
|
+
* - `miniprogram` → uni.navigateToMiniProgram,value 格式 `appid:path`
|
|
35
|
+
*/
|
|
36
|
+
declare function doNavigate(type: NavigateType, value: string, options?: NavigateOptions): void;
|
|
37
|
+
/**
|
|
38
|
+
* 路由 composable:返回跳转方法集合。
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const { navigate } = useRouter();
|
|
42
|
+
* navigate("switchTab", "/pages/index/index");
|
|
43
|
+
*/
|
|
44
|
+
export declare function useRouter(): {
|
|
45
|
+
navigate: typeof doNavigate;
|
|
46
|
+
};
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
};
|