@hlw-uni/mp-vue 2.1.52 → 2.1.55
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 +2 -20
- package/dist/composables/ad/index.d.ts +11 -73
- package/dist/composables/device/index.d.ts +5 -70
- package/dist/composables/index.d.ts +6 -14
- package/dist/composables/navigator/index.d.ts +15 -39
- package/dist/composables/request/client.d.ts +21 -0
- package/dist/composables/request/index.d.ts +6 -0
- package/dist/composables/request/service.d.ts +30 -0
- package/dist/composables/{http → request}/types.d.ts +0 -3
- package/dist/composables/share/index.d.ts +7 -66
- package/dist/composables/utils/index.d.ts +25 -32
- package/dist/hlw.d.ts +2 -4
- package/dist/index.d.ts +2 -3
- package/dist/index.js +614 -1253
- package/dist/index.mjs +613 -1252
- package/package.json +2 -1
- package/src/app.ts +3 -143
- package/src/components/hlw-ad/index.vue +6 -5
- package/src/components/hlw-page/index.vue +1 -1
- package/src/composables/ad/README.md +58 -0
- package/src/composables/ad/index.ts +117 -376
- package/src/composables/device/README.md +50 -0
- package/src/composables/device/index.ts +110 -83
- package/src/composables/index.ts +10 -39
- package/src/composables/msg/README.md +79 -0
- package/src/composables/navigator/README.md +71 -0
- package/src/composables/navigator/index.ts +77 -77
- package/src/composables/refs/README.md +40 -0
- package/src/composables/request/README.md +124 -0
- package/src/composables/{http → request}/adapters/oss.ts +1 -0
- package/src/composables/request/client.ts +204 -0
- package/src/composables/request/index.ts +15 -0
- package/src/composables/request/service.ts +54 -0
- package/src/composables/{http → request}/types.ts +0 -4
- package/src/composables/share/README.md +53 -0
- package/src/composables/share/index.ts +64 -168
- package/src/composables/theme/README.md +131 -0
- package/src/composables/theme/index.ts +4 -2
- package/src/composables/theme/palette.ts +22 -4
- package/src/composables/utils/README.md +81 -0
- package/src/composables/utils/index.ts +131 -95
- package/src/hlw.ts +6 -14
- package/src/index.ts +2 -3
- package/dist/composables/_internal/unwrap.d.ts +0 -15
- package/dist/composables/algo/index.d.ts +0 -7
- package/dist/composables/algo/uuid.d.ts +0 -17
- package/dist/composables/color/index.d.ts +0 -8
- package/dist/composables/contact/index.d.ts +0 -32
- package/dist/composables/format/index.d.ts +0 -9
- package/dist/composables/http/client.d.ts +0 -66
- package/dist/composables/http/index.d.ts +0 -8
- package/dist/composables/loading/index.d.ts +0 -7
- package/dist/composables/page-meta/index.d.ts +0 -18
- package/dist/composables/storage/index.d.ts +0 -16
- package/dist/composables/validate/index.d.ts +0 -12
- package/dist/error.d.ts +0 -1
- package/src/composables/_internal/unwrap.ts +0 -19
- package/src/composables/algo/index.ts +0 -7
- package/src/composables/algo/uuid.ts +0 -27
- package/src/composables/color/index.ts +0 -44
- package/src/composables/contact/index.ts +0 -92
- package/src/composables/format/index.ts +0 -48
- package/src/composables/http/client.ts +0 -237
- package/src/composables/http/index.ts +0 -8
- package/src/composables/http/useRequest.ts +0 -107
- package/src/composables/loading/index.ts +0 -23
- package/src/composables/page-meta/index.ts +0 -49
- package/src/composables/storage/index.ts +0 -76
- package/src/composables/validate/index.ts +0 -58
- package/src/error.ts +0 -5
- /package/dist/composables/{http → request}/adapters/alist.d.ts +0 -0
- /package/dist/composables/{http → request}/adapters/base.d.ts +0 -0
- /package/dist/composables/{http → request}/adapters/cos.d.ts +0 -0
- /package/dist/composables/{http → request}/adapters/index.d.ts +0 -0
- /package/dist/composables/{http → request}/adapters/oss.d.ts +0 -0
- /package/dist/composables/{http → request}/adapters/qiniu.d.ts +0 -0
- /package/src/composables/{http → request}/adapters/alist.ts +0 -0
- /package/src/composables/{http → request}/adapters/base.ts +0 -0
- /package/src/composables/{http → request}/adapters/cos.ts +0 -0
- /package/src/composables/{http → request}/adapters/index.ts +0 -0
- /package/src/composables/{http → request}/adapters/qiniu.ts +0 -0
|
@@ -2,160 +2,183 @@
|
|
|
2
2
|
* 小程序通用工具。
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export interface
|
|
6
|
-
/** 下载地址 */
|
|
5
|
+
export interface DownloadOpt {
|
|
7
6
|
url: string;
|
|
8
|
-
|
|
9
|
-
filePath?: string;
|
|
10
|
-
/** HTTP 请求头,可选 */
|
|
7
|
+
path?: string;
|
|
11
8
|
header?: Record<string, string>;
|
|
12
|
-
|
|
13
|
-
onProgress?: (progress: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => void;
|
|
9
|
+
progress?: (value: number, done: number, total: number) => void;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
export interface
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/** 状态码 */
|
|
22
|
-
statusCode?: number;
|
|
23
|
-
/** 错误信息 */
|
|
24
|
-
errMsg?: string;
|
|
12
|
+
export interface DownloadRes {
|
|
13
|
+
ok: boolean;
|
|
14
|
+
path?: string;
|
|
15
|
+
code?: number;
|
|
16
|
+
msg?: string;
|
|
25
17
|
}
|
|
26
18
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
19
|
+
function withQuery(url: string, qs: string) {
|
|
20
|
+
if (!qs) return url;
|
|
21
|
+
return `${url}${url.includes("?") ? "&" : "?"}${qs}`;
|
|
22
|
+
}
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
24
|
+
function toQuery(data: Record<string, unknown>) {
|
|
25
|
+
return Object.entries(data)
|
|
26
|
+
.filter(([, val]) => val !== undefined && val !== null)
|
|
27
|
+
.map(([key, val]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(val))}`)
|
|
28
|
+
.join("&");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function signText(url: string) {
|
|
32
|
+
const [path, qs] = url.split("?");
|
|
33
|
+
return qs ? `${qs.split("&").filter(Boolean).sort().join("&")}&` : `${path}&`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function toNumber(val: unknown, def: number): number {
|
|
37
|
+
const next = Number(val);
|
|
38
|
+
return Number.isFinite(next) ? next : def;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function toBoolean(val: unknown, def: boolean): boolean {
|
|
42
|
+
if (typeof val === "boolean") return val;
|
|
43
|
+
if (val === 0 || val === "0") return false;
|
|
44
|
+
if (val === 1 || val === "1") return true;
|
|
45
|
+
return def;
|
|
46
|
+
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
export function useUtils() {
|
|
49
|
+
function copy(text: string, tip = true): Promise<boolean> {
|
|
50
|
+
return new Promise((ok) => {
|
|
49
51
|
uni.setClipboardData({
|
|
50
|
-
data,
|
|
52
|
+
data: text,
|
|
51
53
|
showToast: false,
|
|
52
54
|
success: () => {
|
|
53
|
-
if (
|
|
55
|
+
if (tip) {
|
|
54
56
|
uni.showToast({ title: "复制成功", icon: "none", duration: 1500 });
|
|
55
57
|
}
|
|
56
|
-
|
|
58
|
+
ok(true);
|
|
57
59
|
},
|
|
58
|
-
fail: () =>
|
|
60
|
+
fail: () => ok(false),
|
|
59
61
|
});
|
|
60
62
|
});
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
/**
|
|
64
|
-
* 从事件 dataset 的 data-copy 字段读取文本并复制。
|
|
65
|
-
*/
|
|
66
|
-
function copyFromEvent(event: TapEvent) {
|
|
67
|
-
return copy(event);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 读取当前剪贴板文本内容。
|
|
72
|
-
*/
|
|
73
65
|
function paste(): Promise<string> {
|
|
74
|
-
return new Promise((
|
|
66
|
+
return new Promise((ok) => {
|
|
75
67
|
uni.getClipboardData({
|
|
76
|
-
success: (res) =>
|
|
77
|
-
fail: () =>
|
|
68
|
+
success: (res) => ok(res.data),
|
|
69
|
+
fail: () => ok(""),
|
|
78
70
|
});
|
|
79
71
|
});
|
|
80
72
|
}
|
|
81
73
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
74
|
+
function auth() {
|
|
75
|
+
uni.showModal({
|
|
76
|
+
title: "提示",
|
|
77
|
+
content: "需要授权相册权限",
|
|
78
|
+
confirmText: "去设置",
|
|
79
|
+
success: (res) => {
|
|
80
|
+
if (res.confirm) uni.openSetting();
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function saveImage(path: string): Promise<boolean> {
|
|
86
|
+
return new Promise((ok) => {
|
|
87
87
|
uni.saveImageToPhotosAlbum({
|
|
88
|
-
filePath,
|
|
88
|
+
filePath: path,
|
|
89
89
|
success: () => {
|
|
90
90
|
uni.showToast({ title: "保存成功", icon: "success" });
|
|
91
|
-
|
|
91
|
+
ok(true);
|
|
92
92
|
},
|
|
93
93
|
fail: (err) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
content: "需要授权相册权限",
|
|
98
|
-
confirmText: "去设置",
|
|
99
|
-
success: (res) => {
|
|
100
|
-
if (res.confirm) uni.openSetting();
|
|
101
|
-
},
|
|
102
|
-
});
|
|
94
|
+
const msg = String(err.errMsg || "");
|
|
95
|
+
if (msg.includes("auth deny") || msg.includes("authorize")) {
|
|
96
|
+
auth();
|
|
103
97
|
} else {
|
|
104
98
|
uni.showToast({ title: "保存失败", icon: "none" });
|
|
105
99
|
}
|
|
106
|
-
|
|
100
|
+
ok(false);
|
|
107
101
|
},
|
|
108
102
|
});
|
|
109
103
|
});
|
|
110
104
|
}
|
|
111
105
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
106
|
+
function saveVideo(path: string): Promise<boolean> {
|
|
107
|
+
return new Promise((ok) => {
|
|
108
|
+
uni.saveVideoToPhotosAlbum({
|
|
109
|
+
filePath: path,
|
|
110
|
+
success: () => {
|
|
111
|
+
uni.showToast({ title: "保存成功", icon: "success" });
|
|
112
|
+
ok(true);
|
|
113
|
+
},
|
|
114
|
+
fail: (err) => {
|
|
115
|
+
const msg = String(err.errMsg || "");
|
|
116
|
+
if (msg.includes("auth deny") || msg.includes("authorize")) {
|
|
117
|
+
auth();
|
|
118
|
+
} else {
|
|
119
|
+
uni.showToast({ title: "保存失败", icon: "none" });
|
|
120
|
+
}
|
|
121
|
+
ok(false);
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function download(opt: DownloadOpt): Promise<DownloadRes> {
|
|
128
|
+
return new Promise((ok) => {
|
|
117
129
|
const task = uni.downloadFile({
|
|
118
|
-
url:
|
|
119
|
-
filePath:
|
|
120
|
-
header:
|
|
130
|
+
url: opt.url,
|
|
131
|
+
filePath: opt.path,
|
|
132
|
+
header: opt.header,
|
|
121
133
|
success: (res) => {
|
|
122
134
|
if (res.statusCode === 200) {
|
|
123
|
-
|
|
135
|
+
ok({ ok: true, path: res.tempFilePath, code: res.statusCode });
|
|
124
136
|
} else {
|
|
125
|
-
|
|
137
|
+
ok({ ok: false, code: res.statusCode, msg: `下载失败,状态码:${res.statusCode}` });
|
|
126
138
|
}
|
|
127
139
|
},
|
|
128
|
-
fail: (err) =>
|
|
140
|
+
fail: (err) => ok({ ok: false, msg: err.errMsg }),
|
|
129
141
|
});
|
|
130
142
|
|
|
131
|
-
if (
|
|
143
|
+
if (opt.progress) {
|
|
132
144
|
task.onProgressUpdate((res) => {
|
|
133
|
-
|
|
145
|
+
opt.progress!(res.progress, res.totalBytesWritten, res.totalBytesExpectedToWrite);
|
|
134
146
|
});
|
|
135
147
|
}
|
|
136
148
|
});
|
|
137
149
|
}
|
|
138
150
|
|
|
139
|
-
|
|
140
|
-
* 下载远程图片并直接保存到相册。
|
|
141
|
-
*/
|
|
142
|
-
async function downloadAndSaveImage(url: string, onProgress?: (progress: number) => void): Promise<boolean> {
|
|
151
|
+
async function saveImageUrl(url: string, progress?: (value: number) => void): Promise<boolean> {
|
|
143
152
|
try {
|
|
144
153
|
uni.showLoading({ title: "下载中...", mask: true });
|
|
154
|
+
const res = await download({ url, progress: progress ? (value) => progress(value) : undefined });
|
|
155
|
+
uni.hideLoading();
|
|
145
156
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
157
|
+
if (!res.ok || !res.path) {
|
|
158
|
+
uni.showToast({ title: res.msg || "下载失败", icon: "none" });
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return await saveImage(res.path);
|
|
163
|
+
} catch {
|
|
164
|
+
uni.hideLoading();
|
|
165
|
+
uni.showToast({ title: "操作失败", icon: "none" });
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
150
169
|
|
|
170
|
+
async function saveVideoUrl(url: string, progress?: (value: number) => void): Promise<boolean> {
|
|
171
|
+
try {
|
|
172
|
+
uni.showLoading({ title: "下载中...", mask: true });
|
|
173
|
+
const res = await download({ url, progress: progress ? (value) => progress(value) : undefined });
|
|
151
174
|
uni.hideLoading();
|
|
152
175
|
|
|
153
|
-
if (!
|
|
154
|
-
uni.showToast({ title:
|
|
176
|
+
if (!res.ok || !res.path) {
|
|
177
|
+
uni.showToast({ title: res.msg || "下载失败", icon: "none" });
|
|
155
178
|
return false;
|
|
156
179
|
}
|
|
157
180
|
|
|
158
|
-
return await
|
|
181
|
+
return await saveVideo(res.path);
|
|
159
182
|
} catch {
|
|
160
183
|
uni.hideLoading();
|
|
161
184
|
uni.showToast({ title: "操作失败", icon: "none" });
|
|
@@ -163,5 +186,18 @@ export function useUtils() {
|
|
|
163
186
|
}
|
|
164
187
|
}
|
|
165
188
|
|
|
166
|
-
return {
|
|
189
|
+
return {
|
|
190
|
+
withQuery,
|
|
191
|
+
toQuery,
|
|
192
|
+
signText,
|
|
193
|
+
toNumber,
|
|
194
|
+
toBoolean,
|
|
195
|
+
copy,
|
|
196
|
+
paste,
|
|
197
|
+
saveImage,
|
|
198
|
+
saveVideo,
|
|
199
|
+
download,
|
|
200
|
+
saveImageUrl,
|
|
201
|
+
saveVideoUrl,
|
|
202
|
+
};
|
|
167
203
|
}
|
package/src/hlw.ts
CHANGED
|
@@ -1,37 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* hlw - 全局命名空间工厂
|
|
3
|
-
* 提供 $msg、$device、$
|
|
4
|
-
*
|
|
5
|
-
* 注意:广告能力请直接 `import { useAd } from "@hlw-uni/mp-vue"`,不再通过 hlw.$ad 暴露。
|
|
3
|
+
* 提供 $msg、$device、$request、$utils 的统一访问入口。
|
|
6
4
|
*/
|
|
7
5
|
import { useMsg } from '@/composables/msg';
|
|
8
6
|
import { useDevice, type DeviceInfo } from '@/composables/device';
|
|
9
|
-
import {
|
|
7
|
+
import { useRequest } from '@/composables/request';
|
|
10
8
|
import { useUtils } from '@/composables/utils';
|
|
11
|
-
import { useColor } from '@/composables/color';
|
|
12
9
|
|
|
13
10
|
export interface HlwInstance {
|
|
14
11
|
$msg: ReturnType<typeof useMsg>;
|
|
15
12
|
$device: DeviceInfo;
|
|
16
|
-
$
|
|
13
|
+
$request: ReturnType<typeof useRequest>;
|
|
17
14
|
$utils: ReturnType<typeof useUtils>;
|
|
18
|
-
$color: ReturnType<typeof useColor>;
|
|
19
15
|
}
|
|
20
16
|
|
|
21
17
|
let _msg: ReturnType<typeof useMsg> | null = null;
|
|
22
|
-
let _device: ReturnType<typeof useDevice> | null = null;
|
|
23
18
|
let _utils: ReturnType<typeof useUtils> | null = null;
|
|
24
|
-
let _color: ReturnType<typeof useColor> | null = null;
|
|
25
19
|
|
|
26
20
|
export const hlw: HlwInstance = {
|
|
27
21
|
/** 延迟创建消息提示实例。 */
|
|
28
22
|
get $msg() { return (_msg ??= useMsg()); },
|
|
29
23
|
/** 延迟读取并缓存设备信息。 */
|
|
30
|
-
get $device() { return
|
|
31
|
-
/**
|
|
32
|
-
$
|
|
24
|
+
get $device() { return useDevice().info; },
|
|
25
|
+
/** 复用全局请求实例。 */
|
|
26
|
+
$request: useRequest(),
|
|
33
27
|
/** 延迟创建通用工具实例。 */
|
|
34
28
|
get $utils() { return (_utils ??= useUtils()); },
|
|
35
|
-
/** 延迟创建颜色工具实例。 */
|
|
36
|
-
get $color() { return (_color ??= useColor()); },
|
|
37
29
|
};
|
package/src/index.ts
CHANGED
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 2.0 起合并了原 @hlw-uni/mp-core 全部内容。
|
|
5
5
|
* 业务方一处 import,无需再分包:
|
|
6
|
-
* import {
|
|
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
|
|
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,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,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,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
|
-
}
|
|
@@ -1,27 +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 function useUuid() {
|
|
16
|
-
function v4(): string {
|
|
17
|
-
const bytes: number[] = [];
|
|
18
|
-
for (let i = 0; i < 16; i++) {
|
|
19
|
-
bytes.push(Math.floor(Math.random() * 256));
|
|
20
|
-
}
|
|
21
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
22
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
23
|
-
return bytes.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return { v4 };
|
|
27
|
-
}
|