@hlw-uni/mp-vue 1.2.28 → 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/index.js
CHANGED
|
@@ -1,11 +1,1188 @@
|
|
|
1
1
|
(function(global, factory) {
|
|
2
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue"), require("
|
|
3
|
-
})(this, function(exports2, vue,
|
|
4
|
-
"use strict";
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue"), require("pinia"), require("@dcloudio/uni-app")) : typeof define === "function" && define.amd ? define(["exports", "vue", "pinia", "@dcloudio/uni-app"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.HlwUniVue = {}, global.vue, global.pinia, global.uniApp));
|
|
3
|
+
})(this, function(exports2, vue, pinia, uniApp) {
|
|
4
|
+
"use strict";var __defProp = Object.defineProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __publicField = (obj, key, value) => {
|
|
7
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
+
return value;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const cosAdapter = {
|
|
12
|
+
name: "cos",
|
|
13
|
+
/**
|
|
14
|
+
* 生成 COS 直传所需的表单字段。
|
|
15
|
+
*/
|
|
16
|
+
buildFormData(ctx) {
|
|
17
|
+
const c = ctx.credentials ?? {};
|
|
18
|
+
return {
|
|
19
|
+
"q-ak": c["ak"] ?? "",
|
|
20
|
+
policy: c["policy"] ?? "",
|
|
21
|
+
"q-key-time": c["key-time"] ?? "",
|
|
22
|
+
"q-signature": c["signature"] ?? "",
|
|
23
|
+
"Content-Disposition": `inline;filename=${encodeURIComponent(ctx.fileName)}`,
|
|
24
|
+
success_action_status: 200,
|
|
25
|
+
...ctx.extraData ?? {}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const ossAdapter = {
|
|
30
|
+
name: "oss",
|
|
31
|
+
/**
|
|
32
|
+
* 生成 OSS 直传所需的表单字段。
|
|
33
|
+
*/
|
|
34
|
+
buildFormData(ctx) {
|
|
35
|
+
const c = ctx.credentials ?? {};
|
|
36
|
+
return {
|
|
37
|
+
policy: c["policy"] ?? "",
|
|
38
|
+
signature: c["signature"] ?? "",
|
|
39
|
+
OSSAccessKeyId: c["accessKeyId"] ?? "",
|
|
40
|
+
success_action_status: 200,
|
|
41
|
+
"Content-Disposition": `inline;filename=${encodeURIComponent(ctx.fileName)}`,
|
|
42
|
+
...ctx.extraData ?? {}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const qiniuAdapter = {
|
|
47
|
+
name: "qiniu",
|
|
48
|
+
/**
|
|
49
|
+
* 生成七牛直传所需的表单字段。
|
|
50
|
+
*/
|
|
51
|
+
buildFormData(ctx) {
|
|
52
|
+
const c = ctx.credentials ?? {};
|
|
53
|
+
return {
|
|
54
|
+
token: c["token"] ?? "",
|
|
55
|
+
key: c["key"] ?? ctx.fileName,
|
|
56
|
+
...ctx.extraData ?? {}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const alistAdapter = {
|
|
61
|
+
name: "alist",
|
|
62
|
+
/**
|
|
63
|
+
* 生成 Alist 所需的表单字段。
|
|
64
|
+
*/
|
|
65
|
+
buildFormData(ctx) {
|
|
66
|
+
const c = ctx.credentials ?? {};
|
|
67
|
+
return {
|
|
68
|
+
"file-path": c["file-path"] ?? ctx.fileName,
|
|
69
|
+
authorization: c["token"] ?? "",
|
|
70
|
+
...ctx.extraData ?? {}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const adapters = {
|
|
75
|
+
cos: cosAdapter,
|
|
76
|
+
oss: ossAdapter,
|
|
77
|
+
qiniu: qiniuAdapter,
|
|
78
|
+
alist: alistAdapter
|
|
79
|
+
};
|
|
80
|
+
function getAdapter(name) {
|
|
81
|
+
const adapter2 = adapters[name];
|
|
82
|
+
if (!adapter2)
|
|
83
|
+
throw new Error(`[hlw] Unknown upload adapter: ${name}`);
|
|
84
|
+
return adapter2;
|
|
85
|
+
}
|
|
86
|
+
class HttpClient {
|
|
87
|
+
/**
|
|
88
|
+
* 创建 HttpClient 实例并初始化默认配置。
|
|
89
|
+
*/
|
|
90
|
+
constructor(options = {}) {
|
|
91
|
+
__publicField(this, "_reqInterceptors", []);
|
|
92
|
+
__publicField(this, "_resInterceptors", []);
|
|
93
|
+
__publicField(this, "_errInterceptors", []);
|
|
94
|
+
__publicField(this, "_baseURL");
|
|
95
|
+
__publicField(this, "_defaultHeaders");
|
|
96
|
+
__publicField(this, "_noCache");
|
|
97
|
+
this._baseURL = options.baseURL ?? "";
|
|
98
|
+
this._noCache = options.noCache ?? true;
|
|
99
|
+
this._defaultHeaders = {
|
|
100
|
+
"Content-Type": "application/json",
|
|
101
|
+
...options.headers
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** 运行时设置 baseURL。 */
|
|
105
|
+
setBaseURL(url) {
|
|
106
|
+
this._baseURL = url;
|
|
107
|
+
}
|
|
108
|
+
/** 注册请求拦截器,并返回注销函数。 */
|
|
109
|
+
onRequest(fn) {
|
|
110
|
+
this._reqInterceptors.push(fn);
|
|
111
|
+
return () => {
|
|
112
|
+
const idx = this._reqInterceptors.indexOf(fn);
|
|
113
|
+
if (idx > -1)
|
|
114
|
+
this._reqInterceptors.splice(idx, 1);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** 注册响应拦截器,并返回注销函数。 */
|
|
118
|
+
onResponse(fn) {
|
|
119
|
+
this._resInterceptors.push(fn);
|
|
120
|
+
return () => {
|
|
121
|
+
const idx = this._resInterceptors.indexOf(fn);
|
|
122
|
+
if (idx > -1)
|
|
123
|
+
this._resInterceptors.splice(idx, 1);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** 注册错误拦截器,并返回注销函数。 */
|
|
127
|
+
onError(fn) {
|
|
128
|
+
this._errInterceptors.push(fn);
|
|
129
|
+
return () => {
|
|
130
|
+
const idx = this._errInterceptors.indexOf(fn);
|
|
131
|
+
if (idx > -1)
|
|
132
|
+
this._errInterceptors.splice(idx, 1);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 执行一次全局请求,自动串联请求与响应拦截器。
|
|
137
|
+
*/
|
|
138
|
+
async request(config2) {
|
|
139
|
+
let cfg = {
|
|
140
|
+
method: "GET",
|
|
141
|
+
...config2,
|
|
142
|
+
headers: { ...this._defaultHeaders, ...config2.headers }
|
|
143
|
+
};
|
|
144
|
+
for (const fn of this._reqInterceptors) {
|
|
145
|
+
cfg = await fn(cfg);
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const fullUrl = this._buildUrl(cfg.url);
|
|
149
|
+
const res = await this._doRequest(fullUrl, cfg);
|
|
150
|
+
for (const fn of this._resInterceptors) {
|
|
151
|
+
const modified = await fn(res);
|
|
152
|
+
if (modified !== void 0)
|
|
153
|
+
return modified;
|
|
154
|
+
}
|
|
155
|
+
return res;
|
|
156
|
+
} catch (e) {
|
|
157
|
+
const err = e;
|
|
158
|
+
await this._applyErrorInterceptors(err);
|
|
159
|
+
throw err;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 创建组件内可复用的请求状态对象。
|
|
164
|
+
*/
|
|
165
|
+
useRequest() {
|
|
166
|
+
const loading = vue.ref(false);
|
|
167
|
+
const data = vue.ref(null);
|
|
168
|
+
const error = vue.ref(null);
|
|
169
|
+
const run = async (cfg) => {
|
|
170
|
+
loading.value = true;
|
|
171
|
+
error.value = null;
|
|
172
|
+
try {
|
|
173
|
+
const res = await this.request(cfg);
|
|
174
|
+
data.value = res.data;
|
|
175
|
+
return res;
|
|
176
|
+
} catch (e) {
|
|
177
|
+
error.value = e;
|
|
178
|
+
throw e;
|
|
179
|
+
} finally {
|
|
180
|
+
loading.value = false;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const get = (url, d) => run({ url, method: "GET", data: d });
|
|
184
|
+
const post = (url, d) => run({ url, method: "POST", data: d });
|
|
185
|
+
const put = (url, d) => run({ url, method: "PUT", data: d });
|
|
186
|
+
const del = (url, d) => run({ url, method: "DELETE", data: d });
|
|
187
|
+
return { loading, data, error, run, get, post, put, del };
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 根据上传类型选择适配器并执行文件上传。
|
|
191
|
+
*/
|
|
192
|
+
upload(config2) {
|
|
193
|
+
const fileName = config2.fileName ?? config2.filePath.split("/").pop() ?? "file";
|
|
194
|
+
let server = config2.server;
|
|
195
|
+
if (config2.type === "local" && config2.url)
|
|
196
|
+
server = config2.url;
|
|
197
|
+
const formData = config2.type === "local" ? config2.credentials ?? {} : getAdapter(config2.type).buildFormData({
|
|
198
|
+
filePath: config2.filePath,
|
|
199
|
+
fileName,
|
|
200
|
+
credentials: config2.credentials
|
|
201
|
+
});
|
|
202
|
+
return new Promise((resolve, reject) => {
|
|
203
|
+
uni.uploadFile({
|
|
204
|
+
url: server,
|
|
205
|
+
filePath: config2.filePath,
|
|
206
|
+
name: "file",
|
|
207
|
+
formData,
|
|
208
|
+
header: config2.header,
|
|
209
|
+
success: (res) => {
|
|
210
|
+
if (res.statusCode === 200) {
|
|
211
|
+
try {
|
|
212
|
+
const body = JSON.parse(res.data);
|
|
213
|
+
resolve({ code: body.code ?? 1, msg: body.message ?? "上传成功", data: body.data ?? "" });
|
|
214
|
+
} catch {
|
|
215
|
+
resolve({ code: 1, msg: "上传成功", data: res.data });
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
reject(new Error("上传失败"));
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
fail: (err) => reject(new Error(err.errMsg || "上传失败"))
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 拼接 baseURL,并在开启防缓存时追加时间戳参数。
|
|
227
|
+
*/
|
|
228
|
+
_buildUrl(url) {
|
|
229
|
+
if (/^https?:\/\//.test(url))
|
|
230
|
+
return url;
|
|
231
|
+
const full = `${this._baseURL}${url}`;
|
|
232
|
+
if (!this._noCache)
|
|
233
|
+
return full;
|
|
234
|
+
const sep = full.includes("?") ? "&" : "?";
|
|
235
|
+
return `${full}${sep}_t=${Date.now()}`;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* 调用 uni.request 发起底层网络请求。
|
|
239
|
+
*/
|
|
240
|
+
async _doRequest(url, cfg) {
|
|
241
|
+
return new Promise((resolve, reject) => {
|
|
242
|
+
uni.request({
|
|
243
|
+
url,
|
|
244
|
+
method: cfg.method,
|
|
245
|
+
data: cfg.data,
|
|
246
|
+
header: cfg.headers,
|
|
247
|
+
success: (res) => {
|
|
248
|
+
var _a;
|
|
249
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
250
|
+
resolve(res.data);
|
|
251
|
+
} else {
|
|
252
|
+
const msg2 = ((_a = res.data) == null ? void 0 : _a.info) ?? `请求失败: ${res.statusCode}`;
|
|
253
|
+
reject(new Error(String(msg2)));
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
fail: (err) => reject(new Error(err.errMsg || "网络请求失败"))
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 顺序执行已注册的错误拦截器。
|
|
262
|
+
*/
|
|
263
|
+
async _applyErrorInterceptors(err) {
|
|
264
|
+
for (const fn of this._errInterceptors) {
|
|
265
|
+
await fn(err);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const http = new HttpClient();
|
|
270
|
+
function useRequest(options = {}) {
|
|
271
|
+
const { initialData = null, manual = false, onSuccess, onError } = options;
|
|
272
|
+
const loading = vue.ref(false);
|
|
273
|
+
const data = vue.ref(initialData);
|
|
274
|
+
const error = vue.ref(null);
|
|
275
|
+
async function run(config2) {
|
|
276
|
+
loading.value = true;
|
|
277
|
+
error.value = null;
|
|
278
|
+
try {
|
|
279
|
+
const res = await http.request(config2);
|
|
280
|
+
data.value = res.data;
|
|
281
|
+
onSuccess == null ? void 0 : onSuccess(res.data, res);
|
|
282
|
+
return res;
|
|
283
|
+
} catch (e) {
|
|
284
|
+
error.value = e;
|
|
285
|
+
onError == null ? void 0 : onError(e);
|
|
286
|
+
throw e;
|
|
287
|
+
} finally {
|
|
288
|
+
loading.value = false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function get(url, data2) {
|
|
292
|
+
return run({ url, method: "GET", data: data2 });
|
|
293
|
+
}
|
|
294
|
+
function post(url, data2) {
|
|
295
|
+
return run({ url, method: "POST", data: data2 });
|
|
296
|
+
}
|
|
297
|
+
function put(url, data2) {
|
|
298
|
+
return run({ url, method: "PUT", data: data2 });
|
|
299
|
+
}
|
|
300
|
+
function del(url, data2) {
|
|
301
|
+
return run({ url, method: "DELETE", data: data2 });
|
|
302
|
+
}
|
|
303
|
+
return { loading, data, error, run, get, post, put, del };
|
|
304
|
+
}
|
|
305
|
+
function useUpload() {
|
|
306
|
+
const uploading = vue.ref(false);
|
|
307
|
+
async function upload(options) {
|
|
308
|
+
uploading.value = true;
|
|
309
|
+
try {
|
|
310
|
+
return await http.upload(options);
|
|
311
|
+
} finally {
|
|
312
|
+
uploading.value = false;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return { uploading, upload };
|
|
316
|
+
}
|
|
317
|
+
function useLoading() {
|
|
318
|
+
function showLoading(message = "加载中...") {
|
|
319
|
+
uni.showLoading({ title: message, mask: true });
|
|
320
|
+
}
|
|
321
|
+
function hideLoading() {
|
|
322
|
+
uni.hideLoading();
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
showLoading,
|
|
326
|
+
hideLoading
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function useMsg() {
|
|
330
|
+
function toast(opts) {
|
|
331
|
+
const normalized = typeof opts === "string" ? { message: opts } : opts;
|
|
332
|
+
const { message, icon = "none", image, duration = 2e3, mask = false, position = "center" } = normalized;
|
|
333
|
+
uni.showToast({ title: message, icon, image, duration, mask, position });
|
|
334
|
+
}
|
|
335
|
+
function success(message) {
|
|
336
|
+
uni.showToast({ title: message, icon: "success", duration: 2e3 });
|
|
337
|
+
}
|
|
338
|
+
function error(message) {
|
|
339
|
+
uni.showToast({ title: message, icon: "fail", duration: 2e3 });
|
|
340
|
+
}
|
|
341
|
+
function showLoading(message = "加载中...") {
|
|
342
|
+
uni.showLoading({ title: message, mask: true });
|
|
343
|
+
}
|
|
344
|
+
function hideLoading() {
|
|
345
|
+
uni.hideLoading();
|
|
346
|
+
}
|
|
347
|
+
function confirm(opts) {
|
|
348
|
+
return new Promise((resolve) => {
|
|
349
|
+
const {
|
|
350
|
+
title = "提示",
|
|
351
|
+
content,
|
|
352
|
+
confirmText = "确定",
|
|
353
|
+
cancelText = "取消",
|
|
354
|
+
confirmColor = "#3b82f6",
|
|
355
|
+
cancelColor = "#999999"
|
|
356
|
+
} = opts;
|
|
357
|
+
uni.showModal({
|
|
358
|
+
title,
|
|
359
|
+
content,
|
|
360
|
+
confirmText,
|
|
361
|
+
cancelText,
|
|
362
|
+
confirmColor,
|
|
363
|
+
cancelColor,
|
|
364
|
+
success: (res) => resolve(res.confirm),
|
|
365
|
+
fail: () => resolve(false)
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
function modal(opts) {
|
|
370
|
+
return confirm(opts);
|
|
371
|
+
}
|
|
372
|
+
function setLoadingBar(progress) {
|
|
373
|
+
const clamped = Math.max(0, Math.min(100, progress));
|
|
374
|
+
uni.setNavigationBarTitle({
|
|
375
|
+
title: `${"■".repeat(Math.round(clamped / 2))}${"□".repeat(50 - Math.round(clamped / 2))} ${clamped}%`
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
toast,
|
|
380
|
+
success,
|
|
381
|
+
error,
|
|
382
|
+
fail: error,
|
|
383
|
+
showLoading,
|
|
384
|
+
hideLoading,
|
|
385
|
+
confirm,
|
|
386
|
+
modal,
|
|
387
|
+
setLoadingBar
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
const _info = vue.ref(null);
|
|
391
|
+
function tryCall(fn) {
|
|
392
|
+
try {
|
|
393
|
+
return (fn == null ? void 0 : fn()) ?? {};
|
|
394
|
+
} catch {
|
|
395
|
+
return {};
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
function collect() {
|
|
399
|
+
var _a;
|
|
400
|
+
let deviceInfo = tryCall(uni.getDeviceInfo);
|
|
401
|
+
let windowInfo = tryCall(uni.getWindowInfo);
|
|
402
|
+
let appBaseInfo = tryCall(uni.getAppBaseInfo);
|
|
403
|
+
if (!deviceInfo.brand && !deviceInfo.model) {
|
|
404
|
+
const sys = tryCall(() => uni.getSystemInfoSync());
|
|
405
|
+
deviceInfo = { ...sys };
|
|
406
|
+
windowInfo = { ...sys };
|
|
407
|
+
appBaseInfo = { ...sys };
|
|
408
|
+
}
|
|
409
|
+
let appid = "";
|
|
410
|
+
try {
|
|
411
|
+
const accountInfo = uni.getAccountInfoSync();
|
|
412
|
+
appid = ((_a = accountInfo == null ? void 0 : accountInfo.miniProgram) == null ? void 0 : _a.appId) || "";
|
|
413
|
+
} catch {
|
|
414
|
+
appid = deviceInfo.appId || "";
|
|
415
|
+
}
|
|
416
|
+
const system = deviceInfo.system || "";
|
|
417
|
+
return {
|
|
418
|
+
appid,
|
|
419
|
+
app_name: appBaseInfo.appName || "",
|
|
420
|
+
app_version: appBaseInfo.appVersion || "",
|
|
421
|
+
app_version_code: appBaseInfo.appVersionCode || "",
|
|
422
|
+
app_channel: appBaseInfo.appChannel || "",
|
|
423
|
+
device_brand: deviceInfo.brand || "",
|
|
424
|
+
device_model: deviceInfo.model || "",
|
|
425
|
+
device_id: deviceInfo.deviceId || "",
|
|
426
|
+
device_type: deviceInfo.deviceType || "",
|
|
427
|
+
device_orientation: windowInfo.deviceOrientation || "portrait",
|
|
428
|
+
brand: deviceInfo.brand || "",
|
|
429
|
+
model: deviceInfo.model || "",
|
|
430
|
+
system,
|
|
431
|
+
os: system.split(" ")[0] || "",
|
|
432
|
+
pixel_ratio: windowInfo.pixelRatio || 0,
|
|
433
|
+
screen_width: windowInfo.screenWidth || 0,
|
|
434
|
+
screen_height: windowInfo.screenHeight || 0,
|
|
435
|
+
window_width: windowInfo.windowWidth || 0,
|
|
436
|
+
window_height: windowInfo.windowHeight || 0,
|
|
437
|
+
status_bar_height: windowInfo.statusBarHeight || 0,
|
|
438
|
+
sdk_version: appBaseInfo.SDKVersion || "",
|
|
439
|
+
host_name: appBaseInfo.hostName || "",
|
|
440
|
+
host_version: appBaseInfo.hostVersion || "",
|
|
441
|
+
host_language: appBaseInfo.hostLanguage || "",
|
|
442
|
+
host_theme: appBaseInfo.hostTheme || "",
|
|
443
|
+
platform: deviceInfo.platform || "",
|
|
444
|
+
language: appBaseInfo.language || "",
|
|
445
|
+
version: appBaseInfo.version || ""
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
function ensure() {
|
|
449
|
+
if (!_info.value) {
|
|
450
|
+
_info.value = collect();
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function useDevice() {
|
|
454
|
+
ensure();
|
|
455
|
+
return _info;
|
|
456
|
+
}
|
|
457
|
+
function deviceToQuery() {
|
|
458
|
+
ensure();
|
|
459
|
+
if (!_info.value)
|
|
460
|
+
return "";
|
|
461
|
+
return Object.entries(_info.value).filter(([, v]) => v !== "" && v !== 0).map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`).join("&");
|
|
462
|
+
}
|
|
463
|
+
function clearDeviceCache() {
|
|
464
|
+
_info.value = null;
|
|
465
|
+
}
|
|
466
|
+
function useRefs() {
|
|
467
|
+
const refs = vue.ref({});
|
|
468
|
+
vue.onBeforeUpdate(() => {
|
|
469
|
+
refs.value = {};
|
|
470
|
+
});
|
|
471
|
+
vue.onUnmounted(() => {
|
|
472
|
+
refs.value = {};
|
|
473
|
+
});
|
|
474
|
+
const setRefs = (key) => (el) => {
|
|
475
|
+
if (el)
|
|
476
|
+
refs.value[key] = el;
|
|
477
|
+
};
|
|
478
|
+
return { refs, setRefs };
|
|
479
|
+
}
|
|
480
|
+
function usePageMeta() {
|
|
481
|
+
function setTitle(title) {
|
|
482
|
+
uni.setNavigationBarTitle({ title });
|
|
483
|
+
}
|
|
484
|
+
function setOptions(options) {
|
|
485
|
+
if (options.title || options.navigationBarTitleText) {
|
|
486
|
+
setTitle(options.title || options.navigationBarTitleText);
|
|
487
|
+
}
|
|
488
|
+
if (options.navigationBarBackgroundColor || options.navigationBarTextStyle) {
|
|
489
|
+
uni.setNavigationBarColor({
|
|
490
|
+
frontColor: options.navigationBarTextStyle === "white" ? "#ffffff" : "#000000",
|
|
491
|
+
backgroundColor: options.navigationBarBackgroundColor ?? "#ffffff"
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
if (options.backgroundColor) {
|
|
495
|
+
uni.setBackgroundColor({ backgroundColor: options.backgroundColor });
|
|
496
|
+
}
|
|
497
|
+
if (options.enablePullDownRefresh !== void 0) {
|
|
498
|
+
uni.setBackgroundTextStyle({ textStyle: "dark" });
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return {
|
|
502
|
+
setTitle,
|
|
503
|
+
setOptions
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function useStorage() {
|
|
507
|
+
function get(key) {
|
|
508
|
+
try {
|
|
509
|
+
const value = uni.getStorageSync(key);
|
|
510
|
+
return value ?? null;
|
|
511
|
+
} catch {
|
|
512
|
+
return null;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function set(key, value) {
|
|
516
|
+
try {
|
|
517
|
+
uni.setStorageSync(key, value);
|
|
518
|
+
return true;
|
|
519
|
+
} catch {
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function remove(key) {
|
|
524
|
+
try {
|
|
525
|
+
uni.removeStorageSync(key);
|
|
526
|
+
return true;
|
|
527
|
+
} catch {
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
function clear() {
|
|
532
|
+
try {
|
|
533
|
+
uni.clearStorageSync();
|
|
534
|
+
return true;
|
|
535
|
+
} catch {
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
function info() {
|
|
540
|
+
try {
|
|
541
|
+
return uni.getStorageInfoSync();
|
|
542
|
+
} catch {
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return { get, set, remove, clear, info };
|
|
547
|
+
}
|
|
548
|
+
function useValidate() {
|
|
549
|
+
function phone(value) {
|
|
550
|
+
return /^1[3-9]\d{9}$/.test(value);
|
|
551
|
+
}
|
|
552
|
+
function email(value) {
|
|
553
|
+
return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
|
|
554
|
+
}
|
|
555
|
+
function url(value) {
|
|
556
|
+
try {
|
|
557
|
+
new URL(value);
|
|
558
|
+
return true;
|
|
559
|
+
} catch {
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
function idCard(value) {
|
|
564
|
+
return /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/.test(value);
|
|
565
|
+
}
|
|
566
|
+
function carNumber(value) {
|
|
567
|
+
return /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-Z0-9]{5}$/.test(value);
|
|
568
|
+
}
|
|
569
|
+
function password(value) {
|
|
570
|
+
return /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/.test(value);
|
|
571
|
+
}
|
|
572
|
+
function empty(value) {
|
|
573
|
+
if (value == null)
|
|
574
|
+
return true;
|
|
575
|
+
if (typeof value === "string")
|
|
576
|
+
return value.trim() === "";
|
|
577
|
+
if (Array.isArray(value))
|
|
578
|
+
return value.length === 0;
|
|
579
|
+
if (typeof value === "object")
|
|
580
|
+
return Object.keys(value).length === 0;
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
return {
|
|
584
|
+
phone,
|
|
585
|
+
email,
|
|
586
|
+
url,
|
|
587
|
+
idCard,
|
|
588
|
+
carNumber,
|
|
589
|
+
password,
|
|
590
|
+
empty
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
function useFormat() {
|
|
594
|
+
function date(date2, format = "YYYY-MM-DD HH:mm:ss") {
|
|
595
|
+
const d = new Date(date2);
|
|
596
|
+
if (isNaN(d.getTime()))
|
|
597
|
+
return "";
|
|
598
|
+
const year = d.getFullYear();
|
|
599
|
+
const month = String(d.getMonth() + 1).padStart(2, "0");
|
|
600
|
+
const day = String(d.getDate()).padStart(2, "0");
|
|
601
|
+
const hours = String(d.getHours()).padStart(2, "0");
|
|
602
|
+
const minutes = String(d.getMinutes()).padStart(2, "0");
|
|
603
|
+
const seconds = String(d.getSeconds()).padStart(2, "0");
|
|
604
|
+
return format.replace("YYYY", String(year)).replace("MM", month).replace("DD", day).replace("HH", hours).replace("mm", minutes).replace("ss", seconds);
|
|
605
|
+
}
|
|
606
|
+
function fileSize(bytes) {
|
|
607
|
+
if (bytes === 0)
|
|
608
|
+
return "0 B";
|
|
609
|
+
const k = 1024;
|
|
610
|
+
const sizes = ["B", "KB", "MB", "GB", "TB"];
|
|
611
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
612
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
|
613
|
+
}
|
|
614
|
+
function phone(value) {
|
|
615
|
+
return value.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
|
|
616
|
+
}
|
|
617
|
+
function money(amount, decimals = 2, decPoint = ".", thousandsSep = ",") {
|
|
618
|
+
return amount.toFixed(decimals).replace(/\B(?=(\d{3})+(?!\d))/g, thousandsSep);
|
|
619
|
+
}
|
|
620
|
+
return { date, fileSize, phone, money };
|
|
621
|
+
}
|
|
622
|
+
const EMPTY = {
|
|
623
|
+
banner_unit_id: "",
|
|
624
|
+
grid_unit_id: "",
|
|
625
|
+
custom_unit_id: "",
|
|
626
|
+
video_unit_id: "",
|
|
627
|
+
reward_unit_id: "",
|
|
628
|
+
popup_unit_id: ""
|
|
629
|
+
};
|
|
630
|
+
let adapter$1 = null;
|
|
631
|
+
function configAd(a) {
|
|
632
|
+
adapter$1 = a;
|
|
633
|
+
}
|
|
634
|
+
const useAdStore = pinia.defineStore("hlw_ad", () => {
|
|
635
|
+
const config2 = vue.ref({ ...EMPTY });
|
|
636
|
+
const loaded = vue.ref(false);
|
|
637
|
+
return { config: config2, loaded };
|
|
638
|
+
});
|
|
639
|
+
let _msg$1 = null;
|
|
640
|
+
const msg = () => _msg$1 ?? (_msg$1 = useMsg());
|
|
641
|
+
const rewardedCache = /* @__PURE__ */ new Map();
|
|
642
|
+
const interstitialCache = /* @__PURE__ */ new Map();
|
|
643
|
+
function useAd() {
|
|
644
|
+
const store = useAdStore();
|
|
645
|
+
const { config: config2, loaded } = pinia.storeToRefs(store);
|
|
646
|
+
async function loadConfig2(force = false) {
|
|
647
|
+
if (loaded.value && !force)
|
|
648
|
+
return;
|
|
649
|
+
if (!(adapter$1 == null ? void 0 : adapter$1.getConfig)) {
|
|
650
|
+
console.warn("[useAd] adapter.getConfig 未注入;先调用 configAd()");
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
try {
|
|
654
|
+
const cfg = await adapter$1.getConfig();
|
|
655
|
+
if (cfg) {
|
|
656
|
+
store.config = cfg;
|
|
657
|
+
store.loaded = true;
|
|
658
|
+
}
|
|
659
|
+
} catch (e) {
|
|
660
|
+
console.warn("[useAd] load config failed", e);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
function getUnitId(type) {
|
|
664
|
+
return store.config[`${type}_unit_id`] || "";
|
|
665
|
+
}
|
|
666
|
+
async function showReward(claim) {
|
|
667
|
+
const unitId = getUnitId("reward");
|
|
668
|
+
if (!unitId) {
|
|
669
|
+
msg().toast("激励广告未配置");
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
if ((adapter$1 == null ? void 0 : adapter$1.isAuth) && !adapter$1.isAuth()) {
|
|
673
|
+
msg().toast("请先登录");
|
|
674
|
+
return false;
|
|
675
|
+
}
|
|
676
|
+
while (true) {
|
|
677
|
+
const closeRes = await playRewardedOnce(unitId);
|
|
678
|
+
if (!claim) {
|
|
679
|
+
if (closeRes.isEnded)
|
|
680
|
+
return true;
|
|
681
|
+
const goon = await confirmReward();
|
|
682
|
+
if (!goon)
|
|
683
|
+
return false;
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
try {
|
|
687
|
+
const r = await claim(closeRes);
|
|
688
|
+
if (r.retry)
|
|
689
|
+
continue;
|
|
690
|
+
if (!r.ok) {
|
|
691
|
+
if (r.msg)
|
|
692
|
+
msg().error(r.msg);
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
if (r.reward && r.reward > 0)
|
|
696
|
+
msg().success(`+${r.reward} 积分`);
|
|
697
|
+
return true;
|
|
698
|
+
} catch (e) {
|
|
699
|
+
console.warn("[useAd] claim failed", e);
|
|
700
|
+
msg().error("领取失败,请稍后再试");
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
async function showPopup() {
|
|
706
|
+
const unitId = getUnitId("popup");
|
|
707
|
+
if (!unitId)
|
|
708
|
+
return false;
|
|
709
|
+
return await showInterstitialAd(unitId);
|
|
710
|
+
}
|
|
711
|
+
return {
|
|
712
|
+
// 状态
|
|
713
|
+
config: config2,
|
|
714
|
+
loaded,
|
|
715
|
+
// 方法
|
|
716
|
+
loadConfig: loadConfig2,
|
|
717
|
+
getUnitId,
|
|
718
|
+
showReward,
|
|
719
|
+
showPopup
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
async function playRewardedOnce(unitId) {
|
|
723
|
+
msg().showLoading("广告加载中");
|
|
724
|
+
let hidden = false;
|
|
725
|
+
const hide = () => {
|
|
726
|
+
if (hidden)
|
|
727
|
+
return;
|
|
728
|
+
hidden = true;
|
|
729
|
+
msg().hideLoading();
|
|
730
|
+
};
|
|
731
|
+
try {
|
|
732
|
+
const isEnded = await showRewardedAd(unitId, { onShown: hide });
|
|
733
|
+
return { isEnded };
|
|
734
|
+
} finally {
|
|
735
|
+
hide();
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
function confirmReward() {
|
|
739
|
+
return new Promise((resolve) => {
|
|
740
|
+
uni.showModal({
|
|
741
|
+
title: "提示",
|
|
742
|
+
content: "看完广告才可以领取奖励哦,要继续观看吗?",
|
|
743
|
+
confirmText: "继续观看",
|
|
744
|
+
cancelText: "放弃",
|
|
745
|
+
success: (r) => resolve(!!r.confirm),
|
|
746
|
+
fail: () => resolve(false)
|
|
747
|
+
});
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
function showRewardedAd(unitId, hooks) {
|
|
751
|
+
return new Promise((resolve) => {
|
|
752
|
+
var _a;
|
|
753
|
+
let entry = rewardedCache.get(unitId);
|
|
754
|
+
if (!entry) {
|
|
755
|
+
const ad2 = uni.createRewardedVideoAd({ adUnitId: unitId });
|
|
756
|
+
if (!ad2) {
|
|
757
|
+
resolve(false);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
(_a = ad2.onError) == null ? void 0 : _a.call(ad2, (err) => {
|
|
761
|
+
console.warn(`[useAd] reward onError (${unitId})`, err);
|
|
762
|
+
});
|
|
763
|
+
entry = { ad: ad2, loading: false };
|
|
764
|
+
rewardedCache.set(unitId, entry);
|
|
765
|
+
}
|
|
766
|
+
const { ad } = entry;
|
|
767
|
+
let closeHandler = null;
|
|
768
|
+
let errorHandler = null;
|
|
769
|
+
const cleanup = () => {
|
|
770
|
+
var _a2, _b;
|
|
771
|
+
if (closeHandler) {
|
|
772
|
+
(_a2 = ad.offClose) == null ? void 0 : _a2.call(ad, closeHandler);
|
|
773
|
+
closeHandler = null;
|
|
774
|
+
}
|
|
775
|
+
if (errorHandler) {
|
|
776
|
+
(_b = ad.offError) == null ? void 0 : _b.call(ad, errorHandler);
|
|
777
|
+
errorHandler = null;
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
closeHandler = (res) => {
|
|
781
|
+
cleanup();
|
|
782
|
+
resolve(!!(res && res.isEnded));
|
|
783
|
+
};
|
|
784
|
+
errorHandler = (err) => {
|
|
785
|
+
console.warn(`[useAd] reward show error (${unitId})`, err);
|
|
786
|
+
cleanup();
|
|
787
|
+
resolve(false);
|
|
788
|
+
};
|
|
789
|
+
ad.onClose(closeHandler);
|
|
790
|
+
ad.onError(errorHandler);
|
|
791
|
+
const doShow = () => ad.show().then(() => {
|
|
792
|
+
var _a2;
|
|
793
|
+
try {
|
|
794
|
+
(_a2 = hooks == null ? void 0 : hooks.onShown) == null ? void 0 : _a2.call(hooks);
|
|
795
|
+
} catch (e) {
|
|
796
|
+
console.warn("[useAd] onShown error", e);
|
|
797
|
+
}
|
|
798
|
+
}).catch(() => {
|
|
799
|
+
cleanup();
|
|
800
|
+
resolve(false);
|
|
801
|
+
});
|
|
802
|
+
if (entry.loading) {
|
|
803
|
+
Promise.resolve().then(doShow);
|
|
804
|
+
} else {
|
|
805
|
+
entry.loading = true;
|
|
806
|
+
ad.load().then(doShow).catch(doShow).finally(() => {
|
|
807
|
+
if (entry)
|
|
808
|
+
entry.loading = false;
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
function showInterstitialAd(unitId) {
|
|
814
|
+
return new Promise((resolve) => {
|
|
815
|
+
var _a;
|
|
816
|
+
let ad = interstitialCache.get(unitId);
|
|
817
|
+
if (!ad) {
|
|
818
|
+
ad = uni.createInterstitialAd({ adUnitId: unitId });
|
|
819
|
+
if (!ad) {
|
|
820
|
+
resolve(false);
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
(_a = ad.onError) == null ? void 0 : _a.call(ad, (err) => {
|
|
824
|
+
console.warn(`[useAd] popup onError (${unitId})`, err);
|
|
825
|
+
});
|
|
826
|
+
interstitialCache.set(unitId, ad);
|
|
827
|
+
}
|
|
828
|
+
ad.show().then(() => resolve(true)).catch(() => {
|
|
829
|
+
if (typeof ad.load !== "function") {
|
|
830
|
+
resolve(false);
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
ad.load().then(() => ad.show()).then(() => resolve(true)).catch(() => resolve(false));
|
|
834
|
+
});
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
function destroyAds() {
|
|
838
|
+
rewardedCache.forEach((e) => {
|
|
839
|
+
var _a, _b;
|
|
840
|
+
return (_b = (_a = e.ad) == null ? void 0 : _a.destroy) == null ? void 0 : _b.call(_a);
|
|
841
|
+
});
|
|
842
|
+
rewardedCache.clear();
|
|
843
|
+
interstitialCache.forEach((ad) => {
|
|
844
|
+
var _a;
|
|
845
|
+
return (_a = ad == null ? void 0 : ad.destroy) == null ? void 0 : _a.call(ad);
|
|
846
|
+
});
|
|
847
|
+
interstitialCache.clear();
|
|
848
|
+
}
|
|
849
|
+
function useShare(config2) {
|
|
850
|
+
const resolve = (from) => typeof config2 === "function" ? config2(from) : config2;
|
|
851
|
+
uniApp.onShareAppMessage((options) => {
|
|
852
|
+
const resolved = resolve((options == null ? void 0 : options.from) ?? "menu");
|
|
853
|
+
const payload = {};
|
|
854
|
+
if (resolved.title !== void 0)
|
|
855
|
+
payload.title = resolved.title;
|
|
856
|
+
if (resolved.path !== void 0)
|
|
857
|
+
payload.path = resolved.path;
|
|
858
|
+
if (resolved.imageUrl !== void 0)
|
|
859
|
+
payload.imageUrl = resolved.imageUrl;
|
|
860
|
+
return payload;
|
|
861
|
+
});
|
|
862
|
+
uniApp.onShareTimeline(() => {
|
|
863
|
+
const resolved = resolve("menu");
|
|
864
|
+
const timeline = resolved.timeline ?? {};
|
|
865
|
+
const payload = {};
|
|
866
|
+
const title = timeline.title ?? resolved.title;
|
|
867
|
+
const imageUrl = timeline.imageUrl ?? resolved.imageUrl;
|
|
868
|
+
if (title !== void 0)
|
|
869
|
+
payload.title = title;
|
|
870
|
+
if (timeline.query !== void 0)
|
|
871
|
+
payload.query = timeline.query;
|
|
872
|
+
if (imageUrl !== void 0)
|
|
873
|
+
payload.imageUrl = imageUrl;
|
|
874
|
+
return payload;
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
let shareAdapter = null;
|
|
878
|
+
const shareCache = vue.ref(null);
|
|
879
|
+
let sharePending = null;
|
|
880
|
+
function configShare(a) {
|
|
881
|
+
shareAdapter = a;
|
|
882
|
+
}
|
|
883
|
+
function loadShareConfig() {
|
|
884
|
+
if (shareCache.value)
|
|
885
|
+
return Promise.resolve();
|
|
886
|
+
if (sharePending)
|
|
887
|
+
return sharePending;
|
|
888
|
+
if (!(shareAdapter == null ? void 0 : shareAdapter.getConfig)) {
|
|
889
|
+
console.warn("[useShareConfig] adapter.getConfig 未注入;先调用 configShare()");
|
|
890
|
+
return Promise.resolve();
|
|
891
|
+
}
|
|
892
|
+
sharePending = shareAdapter.getConfig().then((cfg) => {
|
|
893
|
+
if (cfg)
|
|
894
|
+
shareCache.value = cfg;
|
|
895
|
+
}).catch((e) => {
|
|
896
|
+
console.warn("[useShareConfig] load failed", e);
|
|
897
|
+
}).finally(() => {
|
|
898
|
+
sharePending = null;
|
|
899
|
+
});
|
|
900
|
+
return sharePending;
|
|
901
|
+
}
|
|
902
|
+
function useShareConfig(pageKey, fallback) {
|
|
903
|
+
void loadShareConfig();
|
|
904
|
+
return () => {
|
|
905
|
+
var _a;
|
|
906
|
+
const remote = (_a = shareCache.value) == null ? void 0 : _a[pageKey];
|
|
907
|
+
const title = (remote == null ? void 0 : remote.title) || fallback.title;
|
|
908
|
+
const image = (remote == null ? void 0 : remote.image) || fallback.image;
|
|
909
|
+
const payload = { title, path: fallback.path };
|
|
910
|
+
if (image)
|
|
911
|
+
payload.imageUrl = image;
|
|
912
|
+
return payload;
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
let adapter = null;
|
|
916
|
+
const config = vue.ref(null);
|
|
917
|
+
let pending = null;
|
|
918
|
+
function configContact(a) {
|
|
919
|
+
adapter = a;
|
|
920
|
+
}
|
|
921
|
+
function loadConfig() {
|
|
922
|
+
if (config.value)
|
|
923
|
+
return Promise.resolve();
|
|
924
|
+
if (pending)
|
|
925
|
+
return pending;
|
|
926
|
+
if (!(adapter == null ? void 0 : adapter.getConfig)) {
|
|
927
|
+
console.warn("[useContact] adapter.getConfig 未注入;先调用 configContact()");
|
|
928
|
+
return Promise.resolve();
|
|
929
|
+
}
|
|
930
|
+
pending = adapter.getConfig().then((cfg) => {
|
|
931
|
+
if (cfg)
|
|
932
|
+
config.value = cfg;
|
|
933
|
+
}).catch((e) => {
|
|
934
|
+
console.warn("[useContact] load config failed", e);
|
|
935
|
+
}).finally(() => {
|
|
936
|
+
pending = null;
|
|
937
|
+
});
|
|
938
|
+
return pending;
|
|
939
|
+
}
|
|
940
|
+
function useContact() {
|
|
941
|
+
void loadConfig();
|
|
942
|
+
return vue.computed(() => {
|
|
943
|
+
var _a, _b, _c, _d;
|
|
944
|
+
return {
|
|
945
|
+
sendMessageTitle: ((_a = config.value) == null ? void 0 : _a.send_message_title) || "",
|
|
946
|
+
sendMessagePath: ((_b = config.value) == null ? void 0 : _b.send_message_path) || "",
|
|
947
|
+
sendMessageImg: ((_c = config.value) == null ? void 0 : _c.send_message_img) || "",
|
|
948
|
+
showMessageCard: ((_d = config.value) == null ? void 0 : _d.show_message_card) ?? false
|
|
949
|
+
};
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
function useUtils() {
|
|
953
|
+
function copy(data, showToast = true) {
|
|
954
|
+
return new Promise((resolve) => {
|
|
955
|
+
uni.setClipboardData({
|
|
956
|
+
data,
|
|
957
|
+
showToast: false,
|
|
958
|
+
success: () => {
|
|
959
|
+
if (showToast) {
|
|
960
|
+
uni.showToast({ title: "复制成功", icon: "none", duration: 1500 });
|
|
961
|
+
}
|
|
962
|
+
resolve(true);
|
|
963
|
+
},
|
|
964
|
+
fail: () => resolve(false)
|
|
965
|
+
});
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
function copyFromEvent(event) {
|
|
969
|
+
var _a;
|
|
970
|
+
const dataset = (_a = event == null ? void 0 : event.currentTarget) == null ? void 0 : _a.dataset;
|
|
971
|
+
const text = dataset == null ? void 0 : dataset.copy;
|
|
972
|
+
if (text == null || text === "")
|
|
973
|
+
return;
|
|
974
|
+
const showToast = (dataset == null ? void 0 : dataset.copyToast) !== "false";
|
|
975
|
+
copy(String(text), showToast);
|
|
976
|
+
}
|
|
977
|
+
function paste() {
|
|
978
|
+
return new Promise((resolve) => {
|
|
979
|
+
uni.getClipboardData({
|
|
980
|
+
success: (res) => resolve(res.data),
|
|
981
|
+
fail: () => resolve("")
|
|
982
|
+
});
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
function saveImage(filePath) {
|
|
986
|
+
return new Promise((resolve) => {
|
|
987
|
+
uni.saveImageToPhotosAlbum({
|
|
988
|
+
filePath,
|
|
989
|
+
success: () => {
|
|
990
|
+
uni.showToast({ title: "保存成功", icon: "success" });
|
|
991
|
+
resolve(true);
|
|
992
|
+
},
|
|
993
|
+
fail: (err) => {
|
|
994
|
+
if (err.errMsg.includes("auth deny") || err.errMsg.includes("authorize")) {
|
|
995
|
+
uni.showModal({
|
|
996
|
+
title: "提示",
|
|
997
|
+
content: "需要授权相册权限",
|
|
998
|
+
confirmText: "去设置",
|
|
999
|
+
success: (res) => {
|
|
1000
|
+
if (res.confirm)
|
|
1001
|
+
uni.openSetting();
|
|
1002
|
+
}
|
|
1003
|
+
});
|
|
1004
|
+
} else {
|
|
1005
|
+
uni.showToast({ title: "保存失败", icon: "none" });
|
|
1006
|
+
}
|
|
1007
|
+
resolve(false);
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
function downloadFile(options) {
|
|
1013
|
+
return new Promise((resolve) => {
|
|
1014
|
+
const task = uni.downloadFile({
|
|
1015
|
+
url: options.url,
|
|
1016
|
+
filePath: options.filePath,
|
|
1017
|
+
header: options.header,
|
|
1018
|
+
success: (res) => {
|
|
1019
|
+
if (res.statusCode === 200) {
|
|
1020
|
+
resolve({ success: true, tempFilePath: res.tempFilePath, statusCode: res.statusCode });
|
|
1021
|
+
} else {
|
|
1022
|
+
resolve({ success: false, statusCode: res.statusCode, errMsg: `下载失败,状态码:${res.statusCode}` });
|
|
1023
|
+
}
|
|
1024
|
+
},
|
|
1025
|
+
fail: (err) => resolve({ success: false, errMsg: err.errMsg })
|
|
1026
|
+
});
|
|
1027
|
+
if (options.onProgress) {
|
|
1028
|
+
task.onProgressUpdate((res) => {
|
|
1029
|
+
options.onProgress(res.progress, res.totalBytesWritten, res.totalBytesExpectedToWrite);
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
async function downloadAndSaveImage(url, onProgress) {
|
|
1035
|
+
try {
|
|
1036
|
+
uni.showLoading({ title: "下载中...", mask: true });
|
|
1037
|
+
const result = await downloadFile({
|
|
1038
|
+
url,
|
|
1039
|
+
onProgress: onProgress ? (progress) => onProgress(progress) : void 0
|
|
1040
|
+
});
|
|
1041
|
+
uni.hideLoading();
|
|
1042
|
+
if (!result.success || !result.tempFilePath) {
|
|
1043
|
+
uni.showToast({ title: result.errMsg || "下载失败", icon: "none" });
|
|
1044
|
+
return false;
|
|
1045
|
+
}
|
|
1046
|
+
return await saveImage(result.tempFilePath);
|
|
1047
|
+
} catch {
|
|
1048
|
+
uni.hideLoading();
|
|
1049
|
+
uni.showToast({ title: "操作失败", icon: "none" });
|
|
1050
|
+
return false;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
return { copy, copyFromEvent, paste, saveImage, downloadFile, downloadAndSaveImage };
|
|
1054
|
+
}
|
|
1055
|
+
const HEX_RE = /^#[0-9a-fA-F]{6}$/;
|
|
1056
|
+
function parseHex(hex) {
|
|
1057
|
+
if (!HEX_RE.test(hex))
|
|
1058
|
+
throw new Error(`Invalid hex color: ${hex}`);
|
|
1059
|
+
return [
|
|
1060
|
+
parseInt(hex.slice(1, 3), 16),
|
|
1061
|
+
parseInt(hex.slice(3, 5), 16),
|
|
1062
|
+
parseInt(hex.slice(5, 7), 16)
|
|
1063
|
+
];
|
|
1064
|
+
}
|
|
1065
|
+
function useColor() {
|
|
1066
|
+
function varsToStyle2(vars) {
|
|
1067
|
+
return Object.entries(vars).map(([k, v]) => `${k}:${v}`).join(";") + ";";
|
|
1068
|
+
}
|
|
1069
|
+
function hexToRgba2(hex, alpha) {
|
|
1070
|
+
const [r, g, b] = parseHex(hex);
|
|
1071
|
+
return `rgba(${r},${g},${b},${alpha})`;
|
|
1072
|
+
}
|
|
1073
|
+
function darkenHex2(hex, amount = 0.15) {
|
|
1074
|
+
const [r, g, b] = parseHex(hex);
|
|
1075
|
+
const d = (c) => Math.max(0, Math.round(c * (1 - amount)));
|
|
1076
|
+
return `#${d(r).toString(16).padStart(2, "0")}${d(g).toString(16).padStart(2, "0")}${d(b).toString(16).padStart(2, "0")}`;
|
|
1077
|
+
}
|
|
1078
|
+
return { varsToStyle: varsToStyle2, hexToRgba: hexToRgba2, darkenHex: darkenHex2 };
|
|
1079
|
+
}
|
|
1080
|
+
function doNavigate(type, value, options = {}) {
|
|
1081
|
+
var _a;
|
|
1082
|
+
const { onFail, silent = false } = options;
|
|
1083
|
+
if (!value) {
|
|
1084
|
+
if (!silent)
|
|
1085
|
+
uni.showToast({ title: "跳转目标未配置", icon: "none" });
|
|
1086
|
+
onFail == null ? void 0 : onFail("跳转目标未配置");
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
const fail = (err) => {
|
|
1090
|
+
const msg2 = (err == null ? void 0 : err.errMsg) || `无法跳转:${value}`;
|
|
1091
|
+
if (!silent)
|
|
1092
|
+
uni.showToast({ title: msg2, icon: "none" });
|
|
1093
|
+
onFail == null ? void 0 : onFail(msg2);
|
|
1094
|
+
};
|
|
1095
|
+
switch (type) {
|
|
1096
|
+
case "switchTab":
|
|
1097
|
+
uni.switchTab({ url: value, fail });
|
|
1098
|
+
break;
|
|
1099
|
+
case "redirectTo":
|
|
1100
|
+
uni.redirectTo({ url: value, fail });
|
|
1101
|
+
break;
|
|
1102
|
+
case "reLaunch":
|
|
1103
|
+
uni.reLaunch({ url: value, fail });
|
|
1104
|
+
break;
|
|
1105
|
+
case "webview":
|
|
1106
|
+
if (!silent)
|
|
1107
|
+
uni.showToast({ title: `H5:${value}`, icon: "none" });
|
|
1108
|
+
break;
|
|
1109
|
+
case "miniprogram": {
|
|
1110
|
+
(_a = uni.navigateToMiniProgram) == null ? void 0 : _a.call(uni, {
|
|
1111
|
+
appId: value,
|
|
1112
|
+
path: options.path || "",
|
|
1113
|
+
envVersion: options.envVersion,
|
|
1114
|
+
extraData: options.extraData,
|
|
1115
|
+
fail
|
|
1116
|
+
});
|
|
1117
|
+
break;
|
|
1118
|
+
}
|
|
1119
|
+
case "navigateTo":
|
|
1120
|
+
default:
|
|
1121
|
+
uni.navigateTo({ url: value, fail });
|
|
1122
|
+
break;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
function useRouter() {
|
|
1126
|
+
return {
|
|
1127
|
+
navigate: doNavigate
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
const useThemeStore = pinia.defineStore(
|
|
1131
|
+
"theme",
|
|
1132
|
+
() => {
|
|
1133
|
+
const scale = vue.ref("normal");
|
|
1134
|
+
function setScale(s) {
|
|
1135
|
+
scale.value = s;
|
|
1136
|
+
uni.setStorageSync(FONT_SCALE_KEY, s);
|
|
1137
|
+
uni.$emit(THEME_CHANGE_EVENT);
|
|
1138
|
+
}
|
|
1139
|
+
const fontOptions = Object.keys(FONT_PRESETS).map((key) => ({
|
|
1140
|
+
value: key,
|
|
1141
|
+
label: FONT_PRESETS[key].label
|
|
1142
|
+
}));
|
|
1143
|
+
const primaryColor = vue.ref(DEFAULT_THEMES[0].value);
|
|
1144
|
+
const themes = DEFAULT_THEMES;
|
|
1145
|
+
const activeTheme = vue.computed(
|
|
1146
|
+
() => themes.find((t) => t.value === primaryColor.value) ?? { label: "自定义", value: primaryColor.value }
|
|
1147
|
+
);
|
|
1148
|
+
function setTheme(color) {
|
|
1149
|
+
primaryColor.value = color;
|
|
1150
|
+
uni.setStorageSync(THEME_COLOR_KEY, color);
|
|
1151
|
+
uni.$emit(THEME_CHANGE_EVENT);
|
|
1152
|
+
}
|
|
1153
|
+
const appearance = vue.ref("auto");
|
|
1154
|
+
const appearanceOptions = APPEARANCE_PRESETS;
|
|
1155
|
+
const appearanceMode = vue.computed(() => resolveAppearance(appearance.value));
|
|
1156
|
+
const isDark = vue.computed(() => appearanceMode.value === "dark");
|
|
1157
|
+
function setAppearance(a) {
|
|
1158
|
+
appearance.value = a;
|
|
1159
|
+
uni.setStorageSync(APPEARANCE_KEY, a);
|
|
1160
|
+
uni.$emit(THEME_CHANGE_EVENT);
|
|
1161
|
+
}
|
|
1162
|
+
return {
|
|
1163
|
+
// 字体
|
|
1164
|
+
scale,
|
|
1165
|
+
fontOptions,
|
|
1166
|
+
setScale,
|
|
1167
|
+
// 主题色
|
|
1168
|
+
primaryColor,
|
|
1169
|
+
themes,
|
|
1170
|
+
activeTheme,
|
|
1171
|
+
setTheme,
|
|
1172
|
+
// 外观模式
|
|
1173
|
+
appearance,
|
|
1174
|
+
appearanceOptions,
|
|
1175
|
+
appearanceMode,
|
|
1176
|
+
isDark,
|
|
1177
|
+
setAppearance
|
|
1178
|
+
};
|
|
1179
|
+
},
|
|
1180
|
+
{ unistorage: true }
|
|
1181
|
+
);
|
|
5
1182
|
const FONT_SCALE_KEY = "hlw_font_scale";
|
|
6
1183
|
const FONT_PRESETS = {
|
|
7
1184
|
small: {
|
|
8
|
-
label: "
|
|
1185
|
+
label: "较小",
|
|
9
1186
|
vars: {
|
|
10
1187
|
"--font-xs": "16rpx",
|
|
11
1188
|
"--font-sm": "20rpx",
|
|
@@ -15,6 +1192,17 @@
|
|
|
15
1192
|
"--font-xl": "36rpx"
|
|
16
1193
|
}
|
|
17
1194
|
},
|
|
1195
|
+
compact: {
|
|
1196
|
+
label: "略小",
|
|
1197
|
+
vars: {
|
|
1198
|
+
"--font-xs": "18rpx",
|
|
1199
|
+
"--font-sm": "22rpx",
|
|
1200
|
+
"--font-base": "26rpx",
|
|
1201
|
+
"--font-md": "30rpx",
|
|
1202
|
+
"--font-lg": "34rpx",
|
|
1203
|
+
"--font-xl": "38rpx"
|
|
1204
|
+
}
|
|
1205
|
+
},
|
|
18
1206
|
normal: {
|
|
19
1207
|
label: "标准",
|
|
20
1208
|
vars: {
|
|
@@ -26,8 +1214,19 @@
|
|
|
26
1214
|
"--font-xl": "40rpx"
|
|
27
1215
|
}
|
|
28
1216
|
},
|
|
1217
|
+
medium: {
|
|
1218
|
+
label: "适中",
|
|
1219
|
+
vars: {
|
|
1220
|
+
"--font-xs": "22rpx",
|
|
1221
|
+
"--font-sm": "28rpx",
|
|
1222
|
+
"--font-base": "32rpx",
|
|
1223
|
+
"--font-md": "36rpx",
|
|
1224
|
+
"--font-lg": "42rpx",
|
|
1225
|
+
"--font-xl": "46rpx"
|
|
1226
|
+
}
|
|
1227
|
+
},
|
|
29
1228
|
large: {
|
|
30
|
-
label: "
|
|
1229
|
+
label: "较大",
|
|
31
1230
|
vars: {
|
|
32
1231
|
"--font-xs": "24rpx",
|
|
33
1232
|
"--font-sm": "30rpx",
|
|
@@ -38,7 +1237,7 @@
|
|
|
38
1237
|
}
|
|
39
1238
|
},
|
|
40
1239
|
xlarge: {
|
|
41
|
-
label: "
|
|
1240
|
+
label: "超大",
|
|
42
1241
|
vars: {
|
|
43
1242
|
"--font-xs": "28rpx",
|
|
44
1243
|
"--font-sm": "36rpx",
|
|
@@ -47,12 +1246,23 @@
|
|
|
47
1246
|
"--font-lg": "56rpx",
|
|
48
1247
|
"--font-xl": "64rpx"
|
|
49
1248
|
}
|
|
1249
|
+
},
|
|
1250
|
+
xxlarge: {
|
|
1251
|
+
label: "特大",
|
|
1252
|
+
vars: {
|
|
1253
|
+
"--font-xs": "32rpx",
|
|
1254
|
+
"--font-sm": "42rpx",
|
|
1255
|
+
"--font-base": "48rpx",
|
|
1256
|
+
"--font-md": "56rpx",
|
|
1257
|
+
"--font-lg": "64rpx",
|
|
1258
|
+
"--font-xl": "72rpx"
|
|
1259
|
+
}
|
|
50
1260
|
}
|
|
51
1261
|
};
|
|
52
1262
|
function getCurrentFontScale() {
|
|
53
1263
|
try {
|
|
54
1264
|
const v = uni.getStorageSync(FONT_SCALE_KEY);
|
|
55
|
-
if (v === "small" || v === "large" || v === "xlarge")
|
|
1265
|
+
if (v === "small" || v === "compact" || v === "medium" || v === "large" || v === "xlarge" || v === "xxlarge")
|
|
56
1266
|
return v;
|
|
57
1267
|
} catch {
|
|
58
1268
|
}
|
|
@@ -61,7 +1271,7 @@
|
|
|
61
1271
|
function getCurrentFontVars() {
|
|
62
1272
|
return FONT_PRESETS[getCurrentFontScale()].vars;
|
|
63
1273
|
}
|
|
64
|
-
const { hexToRgba, darkenHex } =
|
|
1274
|
+
const { hexToRgba, darkenHex } = useColor();
|
|
65
1275
|
const THEME_COLOR_KEY = "hlw_theme_color";
|
|
66
1276
|
const THEME_SEMANTIC_COLORS = {
|
|
67
1277
|
success: "#10b981",
|
|
@@ -190,7 +1400,55 @@
|
|
|
190
1400
|
function getCurrentAppearanceVars() {
|
|
191
1401
|
return APPEARANCE_VAR_MAP[getCurrentAppearanceMode()];
|
|
192
1402
|
}
|
|
193
|
-
const
|
|
1403
|
+
const TYPOGRAPHY_ROLES = {
|
|
1404
|
+
"title-lg": {
|
|
1405
|
+
size: "var(--font-xl)",
|
|
1406
|
+
weight: "600",
|
|
1407
|
+
lineHeight: "1.2",
|
|
1408
|
+
color: "var(--text-primary)"
|
|
1409
|
+
},
|
|
1410
|
+
"title": {
|
|
1411
|
+
size: "var(--font-md)",
|
|
1412
|
+
weight: "500",
|
|
1413
|
+
lineHeight: "1.3",
|
|
1414
|
+
color: "var(--text-primary)"
|
|
1415
|
+
},
|
|
1416
|
+
"subtitle": {
|
|
1417
|
+
size: "var(--font-base)",
|
|
1418
|
+
weight: "500",
|
|
1419
|
+
lineHeight: "1.3",
|
|
1420
|
+
color: "var(--text-secondary)"
|
|
1421
|
+
},
|
|
1422
|
+
"body": {
|
|
1423
|
+
size: "var(--font-base)",
|
|
1424
|
+
weight: "400",
|
|
1425
|
+
lineHeight: "1.5",
|
|
1426
|
+
color: "var(--text-secondary)"
|
|
1427
|
+
},
|
|
1428
|
+
"desc": {
|
|
1429
|
+
size: "var(--font-sm)",
|
|
1430
|
+
weight: "400",
|
|
1431
|
+
lineHeight: "1.4",
|
|
1432
|
+
color: "var(--text-subtle)"
|
|
1433
|
+
},
|
|
1434
|
+
"caption": {
|
|
1435
|
+
size: "var(--font-xs)",
|
|
1436
|
+
weight: "500",
|
|
1437
|
+
lineHeight: "1.3",
|
|
1438
|
+
color: "var(--text-muted)"
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
function getCurrentTypographyVars() {
|
|
1442
|
+
const vars = {};
|
|
1443
|
+
for (const [role, cfg] of Object.entries(TYPOGRAPHY_ROLES)) {
|
|
1444
|
+
vars[`--text-${role}-size`] = cfg.size;
|
|
1445
|
+
vars[`--text-${role}-weight`] = cfg.weight;
|
|
1446
|
+
vars[`--text-${role}-line-height`] = cfg.lineHeight;
|
|
1447
|
+
vars[`--text-${role}-color`] = cfg.color;
|
|
1448
|
+
}
|
|
1449
|
+
return vars;
|
|
1450
|
+
}
|
|
1451
|
+
const { varsToStyle } = useColor();
|
|
194
1452
|
const THEME_CHANGE_EVENT = "hlw:theme-change";
|
|
195
1453
|
function buildThemeStyle() {
|
|
196
1454
|
return varsToStyle({
|
|
@@ -200,78 +1458,479 @@
|
|
|
200
1458
|
});
|
|
201
1459
|
}
|
|
202
1460
|
function useThemePageStyle() {
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
1461
|
+
const store = useThemeStore();
|
|
1462
|
+
const themePageStyle = vue.computed(() => {
|
|
1463
|
+
void store.scale;
|
|
1464
|
+
void store.primaryColor;
|
|
1465
|
+
void store.appearance;
|
|
1466
|
+
return buildThemeStyle();
|
|
1467
|
+
});
|
|
209
1468
|
return { themePageStyle };
|
|
210
1469
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
1470
|
+
let _msg = null;
|
|
1471
|
+
let _device = null;
|
|
1472
|
+
let _utils = null;
|
|
1473
|
+
let _color = null;
|
|
1474
|
+
const hlw = {
|
|
1475
|
+
/** 延迟创建消息提示实例。 */
|
|
1476
|
+
get $msg() {
|
|
1477
|
+
return _msg ?? (_msg = useMsg());
|
|
1478
|
+
},
|
|
1479
|
+
/** 延迟读取并缓存设备信息。 */
|
|
1480
|
+
get $device() {
|
|
1481
|
+
return (_device ?? (_device = useDevice())).value;
|
|
1482
|
+
},
|
|
1483
|
+
/** 复用全局 HTTP 实例。 */
|
|
1484
|
+
$http: http,
|
|
1485
|
+
/** 延迟创建通用工具实例。 */
|
|
1486
|
+
get $utils() {
|
|
1487
|
+
return _utils ?? (_utils = useUtils());
|
|
1488
|
+
},
|
|
1489
|
+
/** 延迟创建颜色工具实例。 */
|
|
1490
|
+
get $color() {
|
|
1491
|
+
return _color ?? (_color = useColor());
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
function getDefaultExportFromCjs(x) {
|
|
1495
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
1496
|
+
}
|
|
1497
|
+
var md5$1 = { exports: {} };
|
|
1498
|
+
var crypt = { exports: {} };
|
|
1499
|
+
(function() {
|
|
1500
|
+
var base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", crypt$1 = {
|
|
1501
|
+
// Bit-wise rotation left
|
|
1502
|
+
rotl: function(n, b) {
|
|
1503
|
+
return n << b | n >>> 32 - b;
|
|
1504
|
+
},
|
|
1505
|
+
// Bit-wise rotation right
|
|
1506
|
+
rotr: function(n, b) {
|
|
1507
|
+
return n << 32 - b | n >>> b;
|
|
1508
|
+
},
|
|
1509
|
+
// Swap big-endian to little-endian and vice versa
|
|
1510
|
+
endian: function(n) {
|
|
1511
|
+
if (n.constructor == Number) {
|
|
1512
|
+
return crypt$1.rotl(n, 8) & 16711935 | crypt$1.rotl(n, 24) & 4278255360;
|
|
1513
|
+
}
|
|
1514
|
+
for (var i = 0; i < n.length; i++)
|
|
1515
|
+
n[i] = crypt$1.endian(n[i]);
|
|
1516
|
+
return n;
|
|
1517
|
+
},
|
|
1518
|
+
// Generate an array of any length of random bytes
|
|
1519
|
+
randomBytes: function(n) {
|
|
1520
|
+
for (var bytes = []; n > 0; n--)
|
|
1521
|
+
bytes.push(Math.floor(Math.random() * 256));
|
|
1522
|
+
return bytes;
|
|
1523
|
+
},
|
|
1524
|
+
// Convert a byte array to big-endian 32-bit words
|
|
1525
|
+
bytesToWords: function(bytes) {
|
|
1526
|
+
for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)
|
|
1527
|
+
words[b >>> 5] |= bytes[i] << 24 - b % 32;
|
|
1528
|
+
return words;
|
|
1529
|
+
},
|
|
1530
|
+
// Convert big-endian 32-bit words to a byte array
|
|
1531
|
+
wordsToBytes: function(words) {
|
|
1532
|
+
for (var bytes = [], b = 0; b < words.length * 32; b += 8)
|
|
1533
|
+
bytes.push(words[b >>> 5] >>> 24 - b % 32 & 255);
|
|
1534
|
+
return bytes;
|
|
1535
|
+
},
|
|
1536
|
+
// Convert a byte array to a hex string
|
|
1537
|
+
bytesToHex: function(bytes) {
|
|
1538
|
+
for (var hex = [], i = 0; i < bytes.length; i++) {
|
|
1539
|
+
hex.push((bytes[i] >>> 4).toString(16));
|
|
1540
|
+
hex.push((bytes[i] & 15).toString(16));
|
|
1541
|
+
}
|
|
1542
|
+
return hex.join("");
|
|
1543
|
+
},
|
|
1544
|
+
// Convert a hex string to a byte array
|
|
1545
|
+
hexToBytes: function(hex) {
|
|
1546
|
+
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
|
1547
|
+
bytes.push(parseInt(hex.substr(c, 2), 16));
|
|
1548
|
+
return bytes;
|
|
1549
|
+
},
|
|
1550
|
+
// Convert a byte array to a base-64 string
|
|
1551
|
+
bytesToBase64: function(bytes) {
|
|
1552
|
+
for (var base64 = [], i = 0; i < bytes.length; i += 3) {
|
|
1553
|
+
var triplet = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
|
|
1554
|
+
for (var j = 0; j < 4; j++)
|
|
1555
|
+
if (i * 8 + j * 6 <= bytes.length * 8)
|
|
1556
|
+
base64.push(base64map.charAt(triplet >>> 6 * (3 - j) & 63));
|
|
1557
|
+
else
|
|
1558
|
+
base64.push("=");
|
|
1559
|
+
}
|
|
1560
|
+
return base64.join("");
|
|
1561
|
+
},
|
|
1562
|
+
// Convert a base-64 string to a byte array
|
|
1563
|
+
base64ToBytes: function(base64) {
|
|
1564
|
+
base64 = base64.replace(/[^A-Z0-9+\/]/ig, "");
|
|
1565
|
+
for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) {
|
|
1566
|
+
if (imod4 == 0)
|
|
1567
|
+
continue;
|
|
1568
|
+
bytes.push((base64map.indexOf(base64.charAt(i - 1)) & Math.pow(2, -2 * imod4 + 8) - 1) << imod4 * 2 | base64map.indexOf(base64.charAt(i)) >>> 6 - imod4 * 2);
|
|
1569
|
+
}
|
|
1570
|
+
return bytes;
|
|
219
1571
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
)
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
1572
|
+
};
|
|
1573
|
+
crypt.exports = crypt$1;
|
|
1574
|
+
})();
|
|
1575
|
+
var cryptExports = crypt.exports;
|
|
1576
|
+
var charenc = {
|
|
1577
|
+
// UTF-8 encoding
|
|
1578
|
+
utf8: {
|
|
1579
|
+
// Convert a string to a byte array
|
|
1580
|
+
stringToBytes: function(str) {
|
|
1581
|
+
return charenc.bin.stringToBytes(unescape(encodeURIComponent(str)));
|
|
1582
|
+
},
|
|
1583
|
+
// Convert a byte array to a string
|
|
1584
|
+
bytesToString: function(bytes) {
|
|
1585
|
+
return decodeURIComponent(escape(charenc.bin.bytesToString(bytes)));
|
|
233
1586
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
function
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
1587
|
+
},
|
|
1588
|
+
// Binary encoding
|
|
1589
|
+
bin: {
|
|
1590
|
+
// Convert a string to a byte array
|
|
1591
|
+
stringToBytes: function(str) {
|
|
1592
|
+
for (var bytes = [], i = 0; i < str.length; i++)
|
|
1593
|
+
bytes.push(str.charCodeAt(i) & 255);
|
|
1594
|
+
return bytes;
|
|
1595
|
+
},
|
|
1596
|
+
// Convert a byte array to a string
|
|
1597
|
+
bytesToString: function(bytes) {
|
|
1598
|
+
for (var str = [], i = 0; i < bytes.length; i++)
|
|
1599
|
+
str.push(String.fromCharCode(bytes[i]));
|
|
1600
|
+
return str.join("");
|
|
242
1601
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
var charenc_1 = charenc;
|
|
1605
|
+
/*!
|
|
1606
|
+
* Determine if an object is a Buffer
|
|
1607
|
+
*
|
|
1608
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
1609
|
+
* @license MIT
|
|
1610
|
+
*/
|
|
1611
|
+
var isBuffer_1 = function(obj) {
|
|
1612
|
+
return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer);
|
|
1613
|
+
};
|
|
1614
|
+
function isBuffer(obj) {
|
|
1615
|
+
return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
|
1616
|
+
}
|
|
1617
|
+
function isSlowBuffer(obj) {
|
|
1618
|
+
return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isBuffer(obj.slice(0, 0));
|
|
1619
|
+
}
|
|
1620
|
+
(function() {
|
|
1621
|
+
var crypt2 = cryptExports, utf8 = charenc_1.utf8, isBuffer2 = isBuffer_1, bin = charenc_1.bin, md52 = function(message, options) {
|
|
1622
|
+
if (message.constructor == String)
|
|
1623
|
+
if (options && options.encoding === "binary")
|
|
1624
|
+
message = bin.stringToBytes(message);
|
|
1625
|
+
else
|
|
1626
|
+
message = utf8.stringToBytes(message);
|
|
1627
|
+
else if (isBuffer2(message))
|
|
1628
|
+
message = Array.prototype.slice.call(message, 0);
|
|
1629
|
+
else if (!Array.isArray(message) && message.constructor !== Uint8Array)
|
|
1630
|
+
message = message.toString();
|
|
1631
|
+
var m = crypt2.bytesToWords(message), l = message.length * 8, a = 1732584193, b = -271733879, c = -1732584194, d = 271733878;
|
|
1632
|
+
for (var i = 0; i < m.length; i++) {
|
|
1633
|
+
m[i] = (m[i] << 8 | m[i] >>> 24) & 16711935 | (m[i] << 24 | m[i] >>> 8) & 4278255360;
|
|
1634
|
+
}
|
|
1635
|
+
m[l >>> 5] |= 128 << l % 32;
|
|
1636
|
+
m[(l + 64 >>> 9 << 4) + 14] = l;
|
|
1637
|
+
var FF = md52._ff, GG = md52._gg, HH = md52._hh, II = md52._ii;
|
|
1638
|
+
for (var i = 0; i < m.length; i += 16) {
|
|
1639
|
+
var aa = a, bb = b, cc = c, dd = d;
|
|
1640
|
+
a = FF(a, b, c, d, m[i + 0], 7, -680876936);
|
|
1641
|
+
d = FF(d, a, b, c, m[i + 1], 12, -389564586);
|
|
1642
|
+
c = FF(c, d, a, b, m[i + 2], 17, 606105819);
|
|
1643
|
+
b = FF(b, c, d, a, m[i + 3], 22, -1044525330);
|
|
1644
|
+
a = FF(a, b, c, d, m[i + 4], 7, -176418897);
|
|
1645
|
+
d = FF(d, a, b, c, m[i + 5], 12, 1200080426);
|
|
1646
|
+
c = FF(c, d, a, b, m[i + 6], 17, -1473231341);
|
|
1647
|
+
b = FF(b, c, d, a, m[i + 7], 22, -45705983);
|
|
1648
|
+
a = FF(a, b, c, d, m[i + 8], 7, 1770035416);
|
|
1649
|
+
d = FF(d, a, b, c, m[i + 9], 12, -1958414417);
|
|
1650
|
+
c = FF(c, d, a, b, m[i + 10], 17, -42063);
|
|
1651
|
+
b = FF(b, c, d, a, m[i + 11], 22, -1990404162);
|
|
1652
|
+
a = FF(a, b, c, d, m[i + 12], 7, 1804603682);
|
|
1653
|
+
d = FF(d, a, b, c, m[i + 13], 12, -40341101);
|
|
1654
|
+
c = FF(c, d, a, b, m[i + 14], 17, -1502002290);
|
|
1655
|
+
b = FF(b, c, d, a, m[i + 15], 22, 1236535329);
|
|
1656
|
+
a = GG(a, b, c, d, m[i + 1], 5, -165796510);
|
|
1657
|
+
d = GG(d, a, b, c, m[i + 6], 9, -1069501632);
|
|
1658
|
+
c = GG(c, d, a, b, m[i + 11], 14, 643717713);
|
|
1659
|
+
b = GG(b, c, d, a, m[i + 0], 20, -373897302);
|
|
1660
|
+
a = GG(a, b, c, d, m[i + 5], 5, -701558691);
|
|
1661
|
+
d = GG(d, a, b, c, m[i + 10], 9, 38016083);
|
|
1662
|
+
c = GG(c, d, a, b, m[i + 15], 14, -660478335);
|
|
1663
|
+
b = GG(b, c, d, a, m[i + 4], 20, -405537848);
|
|
1664
|
+
a = GG(a, b, c, d, m[i + 9], 5, 568446438);
|
|
1665
|
+
d = GG(d, a, b, c, m[i + 14], 9, -1019803690);
|
|
1666
|
+
c = GG(c, d, a, b, m[i + 3], 14, -187363961);
|
|
1667
|
+
b = GG(b, c, d, a, m[i + 8], 20, 1163531501);
|
|
1668
|
+
a = GG(a, b, c, d, m[i + 13], 5, -1444681467);
|
|
1669
|
+
d = GG(d, a, b, c, m[i + 2], 9, -51403784);
|
|
1670
|
+
c = GG(c, d, a, b, m[i + 7], 14, 1735328473);
|
|
1671
|
+
b = GG(b, c, d, a, m[i + 12], 20, -1926607734);
|
|
1672
|
+
a = HH(a, b, c, d, m[i + 5], 4, -378558);
|
|
1673
|
+
d = HH(d, a, b, c, m[i + 8], 11, -2022574463);
|
|
1674
|
+
c = HH(c, d, a, b, m[i + 11], 16, 1839030562);
|
|
1675
|
+
b = HH(b, c, d, a, m[i + 14], 23, -35309556);
|
|
1676
|
+
a = HH(a, b, c, d, m[i + 1], 4, -1530992060);
|
|
1677
|
+
d = HH(d, a, b, c, m[i + 4], 11, 1272893353);
|
|
1678
|
+
c = HH(c, d, a, b, m[i + 7], 16, -155497632);
|
|
1679
|
+
b = HH(b, c, d, a, m[i + 10], 23, -1094730640);
|
|
1680
|
+
a = HH(a, b, c, d, m[i + 13], 4, 681279174);
|
|
1681
|
+
d = HH(d, a, b, c, m[i + 0], 11, -358537222);
|
|
1682
|
+
c = HH(c, d, a, b, m[i + 3], 16, -722521979);
|
|
1683
|
+
b = HH(b, c, d, a, m[i + 6], 23, 76029189);
|
|
1684
|
+
a = HH(a, b, c, d, m[i + 9], 4, -640364487);
|
|
1685
|
+
d = HH(d, a, b, c, m[i + 12], 11, -421815835);
|
|
1686
|
+
c = HH(c, d, a, b, m[i + 15], 16, 530742520);
|
|
1687
|
+
b = HH(b, c, d, a, m[i + 2], 23, -995338651);
|
|
1688
|
+
a = II(a, b, c, d, m[i + 0], 6, -198630844);
|
|
1689
|
+
d = II(d, a, b, c, m[i + 7], 10, 1126891415);
|
|
1690
|
+
c = II(c, d, a, b, m[i + 14], 15, -1416354905);
|
|
1691
|
+
b = II(b, c, d, a, m[i + 5], 21, -57434055);
|
|
1692
|
+
a = II(a, b, c, d, m[i + 12], 6, 1700485571);
|
|
1693
|
+
d = II(d, a, b, c, m[i + 3], 10, -1894986606);
|
|
1694
|
+
c = II(c, d, a, b, m[i + 10], 15, -1051523);
|
|
1695
|
+
b = II(b, c, d, a, m[i + 1], 21, -2054922799);
|
|
1696
|
+
a = II(a, b, c, d, m[i + 8], 6, 1873313359);
|
|
1697
|
+
d = II(d, a, b, c, m[i + 15], 10, -30611744);
|
|
1698
|
+
c = II(c, d, a, b, m[i + 6], 15, -1560198380);
|
|
1699
|
+
b = II(b, c, d, a, m[i + 13], 21, 1309151649);
|
|
1700
|
+
a = II(a, b, c, d, m[i + 4], 6, -145523070);
|
|
1701
|
+
d = II(d, a, b, c, m[i + 11], 10, -1120210379);
|
|
1702
|
+
c = II(c, d, a, b, m[i + 2], 15, 718787259);
|
|
1703
|
+
b = II(b, c, d, a, m[i + 9], 21, -343485551);
|
|
1704
|
+
a = a + aa >>> 0;
|
|
1705
|
+
b = b + bb >>> 0;
|
|
1706
|
+
c = c + cc >>> 0;
|
|
1707
|
+
d = d + dd >>> 0;
|
|
1708
|
+
}
|
|
1709
|
+
return crypt2.endian([a, b, c, d]);
|
|
1710
|
+
};
|
|
1711
|
+
md52._ff = function(a, b, c, d, x, s, t) {
|
|
1712
|
+
var n = a + (b & c | ~b & d) + (x >>> 0) + t;
|
|
1713
|
+
return (n << s | n >>> 32 - s) + b;
|
|
1714
|
+
};
|
|
1715
|
+
md52._gg = function(a, b, c, d, x, s, t) {
|
|
1716
|
+
var n = a + (b & d | c & ~d) + (x >>> 0) + t;
|
|
1717
|
+
return (n << s | n >>> 32 - s) + b;
|
|
1718
|
+
};
|
|
1719
|
+
md52._hh = function(a, b, c, d, x, s, t) {
|
|
1720
|
+
var n = a + (b ^ c ^ d) + (x >>> 0) + t;
|
|
1721
|
+
return (n << s | n >>> 32 - s) + b;
|
|
1722
|
+
};
|
|
1723
|
+
md52._ii = function(a, b, c, d, x, s, t) {
|
|
1724
|
+
var n = a + (c ^ (b | ~d)) + (x >>> 0) + t;
|
|
1725
|
+
return (n << s | n >>> 32 - s) + b;
|
|
1726
|
+
};
|
|
1727
|
+
md52._blocksize = 16;
|
|
1728
|
+
md52._digestsize = 16;
|
|
1729
|
+
md5$1.exports = function(message, options) {
|
|
1730
|
+
if (message === void 0 || message === null)
|
|
1731
|
+
throw new Error("Illegal argument " + message);
|
|
1732
|
+
var digestbytes = crypt2.wordsToBytes(md52(message, options));
|
|
1733
|
+
return options && options.asBytes ? digestbytes : options && options.asString ? bin.bytesToString(digestbytes) : crypt2.bytesToHex(digestbytes);
|
|
1734
|
+
};
|
|
1735
|
+
})();
|
|
1736
|
+
var md5Exports = md5$1.exports;
|
|
1737
|
+
const md5 = /* @__PURE__ */ getDefaultExportFromCjs(md5Exports);
|
|
1738
|
+
let _installed = false;
|
|
1739
|
+
let _interceptorCleanup = [];
|
|
1740
|
+
const _defaultOpts = {
|
|
1741
|
+
tokenHeader: "x-token",
|
|
1742
|
+
autoToastError: true
|
|
1743
|
+
};
|
|
1744
|
+
function useApp() {
|
|
1745
|
+
const _plugins = [];
|
|
1746
|
+
function use(pluginOrInstaller) {
|
|
1747
|
+
_plugins.push((app) => app.use(pluginOrInstaller));
|
|
1748
|
+
}
|
|
1749
|
+
function install(AppComponent) {
|
|
1750
|
+
if (_installed) {
|
|
1751
|
+
console.warn("[hlw] useApp().install() 应只调用一次");
|
|
1752
|
+
}
|
|
1753
|
+
_installed = true;
|
|
1754
|
+
function createApp() {
|
|
1755
|
+
const app = vue.createSSRApp(AppComponent);
|
|
1756
|
+
app.config.globalProperties["hlw"] = hlw;
|
|
1757
|
+
_plugins.forEach((fn) => fn(app));
|
|
1758
|
+
return { app };
|
|
1759
|
+
}
|
|
1760
|
+
return createApp;
|
|
1761
|
+
}
|
|
1762
|
+
return { install, use, hlw, http };
|
|
1763
|
+
}
|
|
1764
|
+
function buildSignString(url) {
|
|
1765
|
+
try {
|
|
1766
|
+
const [path, query] = url.split("?");
|
|
1767
|
+
if (!query)
|
|
1768
|
+
return path + "&";
|
|
1769
|
+
const params = query.split("&").filter(Boolean);
|
|
1770
|
+
params.sort();
|
|
1771
|
+
return params.join("&") + "&";
|
|
1772
|
+
} catch {
|
|
1773
|
+
return url;
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
let _sigSecret = "";
|
|
1777
|
+
function setupDefaultInterceptors(options = {}) {
|
|
1778
|
+
const opts = { ..._defaultOpts, ...options };
|
|
1779
|
+
if (opts.sigSecret)
|
|
1780
|
+
_sigSecret = opts.sigSecret;
|
|
1781
|
+
if (opts.baseURL)
|
|
1782
|
+
http.setBaseURL(opts.baseURL);
|
|
1783
|
+
_interceptorCleanup.forEach((dispose) => dispose());
|
|
1784
|
+
_interceptorCleanup = [];
|
|
1785
|
+
const offRequest = http.onRequest((config2) => {
|
|
1786
|
+
const device = useDevice();
|
|
1787
|
+
if (device.value) {
|
|
1788
|
+
const d = device.value;
|
|
1789
|
+
const query = [
|
|
1790
|
+
["appid", d.appid],
|
|
1791
|
+
["device_brand", d.device_brand],
|
|
1792
|
+
["device_model", d.device_model],
|
|
1793
|
+
["device_id", d.device_id],
|
|
1794
|
+
["device_type", d.device_type],
|
|
1795
|
+
["device_orientation", d.device_orientation],
|
|
1796
|
+
["platform", d.platform],
|
|
1797
|
+
["system", d.system],
|
|
1798
|
+
["os", d.os],
|
|
1799
|
+
["version", d.version],
|
|
1800
|
+
["sdk_version", d.sdk_version],
|
|
1801
|
+
["host_name", d.host_name],
|
|
1802
|
+
["host_version", d.host_version],
|
|
1803
|
+
["host_language", d.host_language],
|
|
1804
|
+
["language", d.language],
|
|
1805
|
+
["app_version", d.app_version],
|
|
1806
|
+
["app_version_code", d.app_version_code],
|
|
1807
|
+
["screen_width", String(d.screen_width)],
|
|
1808
|
+
["screen_height", String(d.screen_height)]
|
|
1809
|
+
].map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v ?? "")}`).join("&");
|
|
1810
|
+
config2.url = config2.url + (config2.url.includes("?") ? "&" : "?") + query;
|
|
1811
|
+
config2.headers = { ...config2.headers, "X-Appid": d.appid };
|
|
1812
|
+
}
|
|
1813
|
+
if (_sigSecret) {
|
|
1814
|
+
const signStr = buildSignString(config2.url);
|
|
1815
|
+
const sig = md5(signStr + _sigSecret);
|
|
1816
|
+
config2.url = config2.url + "&sig=" + sig;
|
|
1817
|
+
}
|
|
1818
|
+
if (opts.getToken) {
|
|
1819
|
+
const token = opts.getToken();
|
|
1820
|
+
if (token) {
|
|
1821
|
+
config2.headers = {
|
|
1822
|
+
...config2.headers,
|
|
1823
|
+
[opts.tokenHeader]: token
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
return config2;
|
|
1828
|
+
});
|
|
1829
|
+
const offResponse = http.onResponse((res) => {
|
|
1830
|
+
if (opts.autoToastError && res.code !== 1) {
|
|
1831
|
+
uni.showToast({ title: res.info || "请求失败", icon: "none" });
|
|
1832
|
+
}
|
|
1833
|
+
return res;
|
|
1834
|
+
});
|
|
1835
|
+
const offError = http.onError((err) => {
|
|
1836
|
+
var _a;
|
|
1837
|
+
if (err.message.includes("401")) {
|
|
1838
|
+
(_a = opts.onUnauthorized) == null ? void 0 : _a.call(opts);
|
|
1839
|
+
}
|
|
1840
|
+
});
|
|
1841
|
+
_interceptorCleanup = [offRequest, offResponse, offError];
|
|
1842
|
+
}
|
|
1843
|
+
function copyText(data) {
|
|
1844
|
+
uni.setClipboardData({
|
|
1845
|
+
data,
|
|
1846
|
+
showToast: false,
|
|
1847
|
+
success: () => uni.showToast({ title: "复制成功", icon: "none", duration: 1500 })
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
function injectTap(vnode, binding) {
|
|
1851
|
+
if (!vnode.props)
|
|
1852
|
+
vnode.props = {};
|
|
1853
|
+
const props = vnode.props;
|
|
1854
|
+
const prev = props.onTap;
|
|
1855
|
+
props.onTap = (e) => {
|
|
1856
|
+
prev == null ? void 0 : prev(e);
|
|
1857
|
+
const value = binding.value;
|
|
1858
|
+
if (value == null || value === "")
|
|
1859
|
+
return;
|
|
1860
|
+
copyText(String(value));
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
const vCopy = {
|
|
1864
|
+
/**
|
|
1865
|
+
* 在指令创建时注入点击事件。
|
|
1866
|
+
*/
|
|
1867
|
+
created(el, binding, vnode) {
|
|
1868
|
+
injectTap(vnode, binding);
|
|
260
1869
|
},
|
|
261
|
-
|
|
262
|
-
|
|
1870
|
+
/**
|
|
1871
|
+
* 在绑定值更新前重新注入点击事件。
|
|
1872
|
+
*/
|
|
1873
|
+
beforeUpdate(el, binding, vnode) {
|
|
1874
|
+
injectTap(vnode, binding);
|
|
1875
|
+
}
|
|
1876
|
+
};
|
|
1877
|
+
exports2.APPEARANCE_KEY = APPEARANCE_KEY;
|
|
1878
|
+
exports2.APPEARANCE_PRESETS = APPEARANCE_PRESETS;
|
|
1879
|
+
exports2.APPEARANCE_VAR_MAP = APPEARANCE_VAR_MAP;
|
|
263
1880
|
exports2.DEFAULT_THEMES = DEFAULT_THEMES;
|
|
264
1881
|
exports2.FONT_PRESETS = FONT_PRESETS;
|
|
265
1882
|
exports2.FONT_SCALE_KEY = FONT_SCALE_KEY;
|
|
1883
|
+
exports2.HttpClient = HttpClient;
|
|
266
1884
|
exports2.THEME_CHANGE_EVENT = THEME_CHANGE_EVENT;
|
|
267
1885
|
exports2.THEME_COLOR_KEY = THEME_COLOR_KEY;
|
|
268
1886
|
exports2.THEME_SEMANTIC_COLORS = THEME_SEMANTIC_COLORS;
|
|
1887
|
+
exports2.TYPOGRAPHY_ROLES = TYPOGRAPHY_ROLES;
|
|
1888
|
+
exports2.adapters = adapters;
|
|
1889
|
+
exports2.alistAdapter = alistAdapter;
|
|
269
1890
|
exports2.buildThemeStyle = buildThemeStyle;
|
|
1891
|
+
exports2.clearDeviceCache = clearDeviceCache;
|
|
1892
|
+
exports2.configAd = configAd;
|
|
1893
|
+
exports2.configContact = configContact;
|
|
1894
|
+
exports2.configShare = configShare;
|
|
1895
|
+
exports2.confirmReward = confirmReward;
|
|
1896
|
+
exports2.cosAdapter = cosAdapter;
|
|
1897
|
+
exports2.destroyAds = destroyAds;
|
|
1898
|
+
exports2.deviceToQuery = deviceToQuery;
|
|
1899
|
+
exports2.getAdapter = getAdapter;
|
|
1900
|
+
exports2.getCurrentAppearance = getCurrentAppearance;
|
|
1901
|
+
exports2.getCurrentAppearanceMode = getCurrentAppearanceMode;
|
|
1902
|
+
exports2.getCurrentAppearanceVars = getCurrentAppearanceVars;
|
|
270
1903
|
exports2.getCurrentFontScale = getCurrentFontScale;
|
|
271
1904
|
exports2.getCurrentFontVars = getCurrentFontVars;
|
|
272
1905
|
exports2.getCurrentThemeColor = getCurrentThemeColor;
|
|
273
1906
|
exports2.getCurrentThemeVars = getCurrentThemeVars;
|
|
1907
|
+
exports2.getCurrentTypographyVars = getCurrentTypographyVars;
|
|
1908
|
+
exports2.hlw = hlw;
|
|
1909
|
+
exports2.http = http;
|
|
1910
|
+
exports2.ossAdapter = ossAdapter;
|
|
1911
|
+
exports2.qiniuAdapter = qiniuAdapter;
|
|
1912
|
+
exports2.resolveAppearance = resolveAppearance;
|
|
1913
|
+
exports2.setupDefaultInterceptors = setupDefaultInterceptors;
|
|
1914
|
+
exports2.useAd = useAd;
|
|
1915
|
+
exports2.useApp = useApp;
|
|
1916
|
+
exports2.useColor = useColor;
|
|
1917
|
+
exports2.useContact = useContact;
|
|
1918
|
+
exports2.useDevice = useDevice;
|
|
1919
|
+
exports2.useFormat = useFormat;
|
|
1920
|
+
exports2.useLoading = useLoading;
|
|
1921
|
+
exports2.useMsg = useMsg;
|
|
1922
|
+
exports2.usePageMeta = usePageMeta;
|
|
1923
|
+
exports2.useRefs = useRefs;
|
|
1924
|
+
exports2.useRequest = useRequest;
|
|
1925
|
+
exports2.useRouter = useRouter;
|
|
1926
|
+
exports2.useShare = useShare;
|
|
1927
|
+
exports2.useShareConfig = useShareConfig;
|
|
1928
|
+
exports2.useStorage = useStorage;
|
|
274
1929
|
exports2.useThemePageStyle = useThemePageStyle;
|
|
275
1930
|
exports2.useThemeStore = useThemeStore;
|
|
1931
|
+
exports2.useUpload = useUpload;
|
|
1932
|
+
exports2.useUtils = useUtils;
|
|
1933
|
+
exports2.useValidate = useValidate;
|
|
1934
|
+
exports2.vCopy = vCopy;
|
|
276
1935
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
277
1936
|
});
|