@hlw-uni/mp-vue 2.1.52 → 2.1.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.d.ts +2 -20
- package/dist/composables/device/index.d.ts +5 -70
- package/dist/composables/index.d.ts +5 -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 +484 -1256
- package/dist/index.mjs +483 -1255
- package/package.json +2 -1
- package/src/app.ts +3 -143
- package/src/components/hlw-ad/index.vue +2 -2
- package/src/components/hlw-page/index.vue +1 -1
- package/src/composables/device/index.ts +110 -83
- package/src/composables/index.ts +9 -39
- package/src/composables/navigator/index.ts +77 -77
- 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/index.ts +64 -168
- package/src/composables/theme/index.ts +4 -2
- package/src/composables/theme/palette.ts +22 -4
- 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/ad/index.d.ts +0 -78
- 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/ad/index.ts +0 -412
- 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/oss.ts +0 -0
- /package/src/composables/{http → request}/adapters/qiniu.ts +0 -0
package/dist/index.mjs
CHANGED
|
@@ -5,8 +5,8 @@ var __publicField = (obj, key, value) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
import { ref, onBeforeUpdate, onUnmounted, computed, createSSRApp } from "vue";
|
|
8
|
-
import { defineStore, storeToRefs } from "pinia";
|
|
9
8
|
import { onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
|
|
9
|
+
import { defineStore } from "pinia";
|
|
10
10
|
const cosAdapter = {
|
|
11
11
|
name: "cos",
|
|
12
12
|
/**
|
|
@@ -77,252 +77,194 @@ const adapters = {
|
|
|
77
77
|
alist: alistAdapter
|
|
78
78
|
};
|
|
79
79
|
function getAdapter(name) {
|
|
80
|
-
const
|
|
81
|
-
if (!
|
|
80
|
+
const adapter = adapters[name];
|
|
81
|
+
if (!adapter)
|
|
82
82
|
throw new Error(`[hlw] Unknown upload adapter: ${name}`);
|
|
83
|
-
return
|
|
83
|
+
return adapter;
|
|
84
84
|
}
|
|
85
|
-
class
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
__publicField(this, "
|
|
91
|
-
__publicField(this, "
|
|
92
|
-
__publicField(this, "_errInterceptors", []);
|
|
93
|
-
__publicField(this, "_baseURL");
|
|
94
|
-
__publicField(this, "_defaultHeaders");
|
|
95
|
-
__publicField(this, "_noCache");
|
|
96
|
-
this._baseURL = options.baseURL ?? "";
|
|
97
|
-
this._noCache = options.noCache ?? true;
|
|
98
|
-
this._defaultHeaders = {
|
|
99
|
-
"Content-Type": "application/json",
|
|
100
|
-
...options.headers
|
|
101
|
-
};
|
|
85
|
+
class UniRequestClient {
|
|
86
|
+
constructor() {
|
|
87
|
+
__publicField(this, "reqInterceptors", []);
|
|
88
|
+
__publicField(this, "resInterceptors", []);
|
|
89
|
+
__publicField(this, "errInterceptors", []);
|
|
90
|
+
__publicField(this, "baseURL", "");
|
|
91
|
+
__publicField(this, "defaultHeaders", { "Content-Type": "application/json" });
|
|
102
92
|
}
|
|
103
|
-
/** 运行时设置 baseURL。 */
|
|
104
93
|
setBaseURL(url) {
|
|
105
|
-
this.
|
|
94
|
+
this.baseURL = url;
|
|
106
95
|
}
|
|
107
|
-
/** 注册请求拦截器,并返回注销函数。 */
|
|
108
96
|
onRequest(fn) {
|
|
109
|
-
this.
|
|
110
|
-
return () =>
|
|
111
|
-
const idx = this._reqInterceptors.indexOf(fn);
|
|
112
|
-
if (idx > -1)
|
|
113
|
-
this._reqInterceptors.splice(idx, 1);
|
|
114
|
-
};
|
|
97
|
+
this.reqInterceptors.push(fn);
|
|
98
|
+
return () => this.remove(this.reqInterceptors, fn);
|
|
115
99
|
}
|
|
116
|
-
/** 注册响应拦截器,并返回注销函数。 */
|
|
117
100
|
onResponse(fn) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (idx > -1)
|
|
122
|
-
this._resInterceptors.splice(idx, 1);
|
|
123
|
-
};
|
|
101
|
+
const item = fn;
|
|
102
|
+
this.resInterceptors.push(item);
|
|
103
|
+
return () => this.remove(this.resInterceptors, item);
|
|
124
104
|
}
|
|
125
|
-
/** 注册错误拦截器,并返回注销函数。 */
|
|
126
105
|
onError(fn) {
|
|
127
|
-
this.
|
|
128
|
-
return () =>
|
|
129
|
-
const idx = this._errInterceptors.indexOf(fn);
|
|
130
|
-
if (idx > -1)
|
|
131
|
-
this._errInterceptors.splice(idx, 1);
|
|
132
|
-
};
|
|
106
|
+
this.errInterceptors.push(fn);
|
|
107
|
+
return () => this.remove(this.errInterceptors, fn);
|
|
133
108
|
}
|
|
134
|
-
|
|
135
|
-
* 执行一次全局请求,自动串联请求与响应拦截器。
|
|
136
|
-
*/
|
|
137
|
-
async request(config2) {
|
|
109
|
+
async request(config) {
|
|
138
110
|
let cfg = {
|
|
139
111
|
method: "GET",
|
|
140
|
-
...
|
|
141
|
-
headers: { ...this.
|
|
112
|
+
...config,
|
|
113
|
+
headers: { ...this.defaultHeaders, ...config.headers }
|
|
142
114
|
};
|
|
143
|
-
for (const fn of this.
|
|
115
|
+
for (const fn of this.reqInterceptors) {
|
|
144
116
|
cfg = await fn(cfg);
|
|
145
117
|
}
|
|
146
118
|
try {
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return modified;
|
|
119
|
+
const res = await this.send(this.resolveUrl(cfg.url), cfg);
|
|
120
|
+
for (const fn of this.resInterceptors) {
|
|
121
|
+
const next = await fn(res);
|
|
122
|
+
if (next !== void 0)
|
|
123
|
+
return next;
|
|
153
124
|
}
|
|
154
125
|
return res;
|
|
155
126
|
} catch (e) {
|
|
156
127
|
const err = e;
|
|
157
|
-
|
|
128
|
+
for (const fn of this.errInterceptors) {
|
|
129
|
+
await fn(err);
|
|
130
|
+
}
|
|
158
131
|
throw err;
|
|
159
132
|
}
|
|
160
133
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
*/
|
|
164
|
-
useRequest() {
|
|
165
|
-
const loading = ref(false);
|
|
166
|
-
const data = ref(null);
|
|
167
|
-
const error = ref(null);
|
|
168
|
-
const run = async (cfg) => {
|
|
169
|
-
loading.value = true;
|
|
170
|
-
error.value = null;
|
|
171
|
-
try {
|
|
172
|
-
const res = await this.request(cfg);
|
|
173
|
-
data.value = res.data;
|
|
174
|
-
return res;
|
|
175
|
-
} catch (e) {
|
|
176
|
-
error.value = e;
|
|
177
|
-
throw e;
|
|
178
|
-
} finally {
|
|
179
|
-
loading.value = false;
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
const get = (url, d) => run({ url, method: "GET", data: d });
|
|
183
|
-
const post = (url, d) => run({ url, method: "POST", data: d });
|
|
184
|
-
const put = (url, d) => run({ url, method: "PUT", data: d });
|
|
185
|
-
const del = (url, d) => run({ url, method: "DELETE", data: d });
|
|
186
|
-
return { loading, data, error, run, get, post, put, del };
|
|
134
|
+
get(url, data) {
|
|
135
|
+
return this.request({ url, method: "GET", data });
|
|
187
136
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
137
|
+
post(url, data) {
|
|
138
|
+
return this.request({ url, method: "POST", data });
|
|
139
|
+
}
|
|
140
|
+
put(url, data) {
|
|
141
|
+
return this.request({ url, method: "PUT", data });
|
|
142
|
+
}
|
|
143
|
+
del(url, data) {
|
|
144
|
+
return this.request({ url, method: "DELETE", data });
|
|
145
|
+
}
|
|
146
|
+
upload(config) {
|
|
147
|
+
const fileName = config.fileName ?? config.filePath.split("/").pop() ?? "file";
|
|
148
|
+
const server = config.type === "local" && config.url ? config.url : config.server;
|
|
149
|
+
const formData = config.type === "local" ? config.credentials ?? {} : getAdapter(config.type).buildFormData({
|
|
150
|
+
filePath: config.filePath,
|
|
198
151
|
fileName,
|
|
199
|
-
credentials:
|
|
152
|
+
credentials: config.credentials
|
|
200
153
|
});
|
|
201
154
|
return new Promise((resolve, reject) => {
|
|
202
155
|
uni.uploadFile({
|
|
203
156
|
url: server,
|
|
204
|
-
filePath:
|
|
157
|
+
filePath: config.filePath,
|
|
205
158
|
name: "file",
|
|
206
159
|
formData,
|
|
207
|
-
header:
|
|
160
|
+
header: config.header,
|
|
208
161
|
success: (res) => {
|
|
209
|
-
if (res.statusCode
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
162
|
+
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
163
|
+
reject(new Error(`上传失败: ${res.statusCode}`));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
const body = JSON.parse(res.data);
|
|
168
|
+
resolve({
|
|
169
|
+
code: body.code ?? 1,
|
|
170
|
+
msg: body.msg ?? body.message ?? "上传成功",
|
|
171
|
+
data: body.data ?? ""
|
|
172
|
+
});
|
|
173
|
+
} catch {
|
|
174
|
+
resolve({ code: 1, msg: "上传成功", data: res.data });
|
|
218
175
|
}
|
|
219
176
|
},
|
|
220
177
|
fail: (err) => reject(new Error(err.errMsg || "上传失败"))
|
|
221
178
|
});
|
|
222
179
|
});
|
|
223
180
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
*/
|
|
227
|
-
_buildUrl(url) {
|
|
228
|
-
if (/^https?:\/\//.test(url))
|
|
181
|
+
resolveServiceUrl(namespace, url, servicePrefix = "") {
|
|
182
|
+
if (isAbsolute(url))
|
|
229
183
|
return url;
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
return
|
|
184
|
+
const ns = namespace.replace(/^\/+|\/+$/g, "").replace(/\//g, ".");
|
|
185
|
+
const prefixValue = servicePrefix.replace(/^\/+|\/+$/g, "");
|
|
186
|
+
const path = url.startsWith("/") ? url : `/${url}`;
|
|
187
|
+
const prefix = [prefixValue, ns].filter(Boolean).join("/");
|
|
188
|
+
return prefix ? `/${prefix}${path}` : path;
|
|
189
|
+
}
|
|
190
|
+
resolveUrl(url) {
|
|
191
|
+
if (isAbsolute(url))
|
|
192
|
+
return url;
|
|
193
|
+
return `${this.baseURL}${url}`;
|
|
235
194
|
}
|
|
236
|
-
|
|
237
|
-
* 调用 uni.request 发起底层网络请求。
|
|
238
|
-
*/
|
|
239
|
-
async _doRequest(url, cfg) {
|
|
195
|
+
send(url, cfg) {
|
|
240
196
|
return new Promise((resolve, reject) => {
|
|
241
197
|
uni.request({
|
|
242
198
|
url,
|
|
243
199
|
method: cfg.method,
|
|
244
200
|
data: cfg.data,
|
|
245
201
|
header: cfg.headers,
|
|
202
|
+
timeout: cfg.timeout,
|
|
246
203
|
success: (res) => {
|
|
247
|
-
var _a;
|
|
248
204
|
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
249
205
|
resolve(res.data);
|
|
250
|
-
|
|
251
|
-
const msg2 = ((_a = res.data) == null ? void 0 : _a.info) ?? `请求失败: ${res.statusCode}`;
|
|
252
|
-
reject(new Error(String(msg2)));
|
|
206
|
+
return;
|
|
253
207
|
}
|
|
208
|
+
const body = res.data;
|
|
209
|
+
reject(new Error(String((body == null ? void 0 : body.info) ?? (body == null ? void 0 : body.message) ?? `请求失败: ${res.statusCode}`)));
|
|
254
210
|
},
|
|
255
211
|
fail: (err) => reject(new Error(err.errMsg || "网络请求失败"))
|
|
256
212
|
});
|
|
257
213
|
});
|
|
258
214
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
for (const fn of this._errInterceptors) {
|
|
264
|
-
await fn(err);
|
|
265
|
-
}
|
|
215
|
+
remove(items, item) {
|
|
216
|
+
const index = items.indexOf(item);
|
|
217
|
+
if (index > -1)
|
|
218
|
+
items.splice(index, 1);
|
|
266
219
|
}
|
|
267
220
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
async function run(config2) {
|
|
275
|
-
loading.value = true;
|
|
276
|
-
error.value = null;
|
|
277
|
-
try {
|
|
278
|
-
const res = await http.request(config2);
|
|
279
|
-
data.value = res.data;
|
|
280
|
-
onSuccess == null ? void 0 : onSuccess(res.data, res);
|
|
281
|
-
return res;
|
|
282
|
-
} catch (e) {
|
|
283
|
-
error.value = e;
|
|
284
|
-
onError == null ? void 0 : onError(e);
|
|
285
|
-
throw e;
|
|
286
|
-
} finally {
|
|
287
|
-
loading.value = false;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
function get(url, data2) {
|
|
291
|
-
return run({ url, method: "GET", data: data2 });
|
|
292
|
-
}
|
|
293
|
-
function post(url, data2) {
|
|
294
|
-
return run({ url, method: "POST", data: data2 });
|
|
295
|
-
}
|
|
296
|
-
function put(url, data2) {
|
|
297
|
-
return run({ url, method: "PUT", data: data2 });
|
|
298
|
-
}
|
|
299
|
-
function del(url, data2) {
|
|
300
|
-
return run({ url, method: "DELETE", data: data2 });
|
|
301
|
-
}
|
|
302
|
-
return { loading, data, error, run, get, post, put, del };
|
|
221
|
+
function isAbsolute(url) {
|
|
222
|
+
return /^(https?:)?\/\//.test(url) || url.startsWith("file://");
|
|
223
|
+
}
|
|
224
|
+
const requestClient = new UniRequestClient();
|
|
225
|
+
function useRequest() {
|
|
226
|
+
return requestClient;
|
|
303
227
|
}
|
|
304
228
|
function useUpload() {
|
|
305
229
|
const uploading = ref(false);
|
|
306
230
|
async function upload(options) {
|
|
307
231
|
uploading.value = true;
|
|
308
232
|
try {
|
|
309
|
-
return await
|
|
233
|
+
return await requestClient.upload(options);
|
|
310
234
|
} finally {
|
|
311
235
|
uploading.value = false;
|
|
312
236
|
}
|
|
313
237
|
}
|
|
314
238
|
return { uploading, upload };
|
|
315
239
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
240
|
+
class BaseService {
|
|
241
|
+
request(options) {
|
|
242
|
+
return useRequest().request({
|
|
243
|
+
...options,
|
|
244
|
+
url: useRequest().resolveServiceUrl(this.namespace ?? "", options.url, this.servicePrefix ?? "")
|
|
245
|
+
});
|
|
319
246
|
}
|
|
320
|
-
|
|
321
|
-
|
|
247
|
+
get(url, data) {
|
|
248
|
+
return this.request({ url, method: "GET", data });
|
|
322
249
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
250
|
+
post(url, data) {
|
|
251
|
+
return this.request({ url, method: "POST", data });
|
|
252
|
+
}
|
|
253
|
+
put(url, data) {
|
|
254
|
+
return this.request({ url, method: "PUT", data });
|
|
255
|
+
}
|
|
256
|
+
del(url, data) {
|
|
257
|
+
return this.request({ url, method: "DELETE", data });
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function ServiceNamespace(value) {
|
|
261
|
+
return function(target) {
|
|
262
|
+
target.prototype.namespace = typeof value === "string" ? value : value.namespace;
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function ServicePrefix(value) {
|
|
266
|
+
return function(target) {
|
|
267
|
+
target.prototype.servicePrefix = typeof value === "string" ? value : value.prefix;
|
|
326
268
|
};
|
|
327
269
|
}
|
|
328
270
|
function useMsg() {
|
|
@@ -388,779 +330,410 @@ function useMsg() {
|
|
|
388
330
|
setLoadingBar
|
|
389
331
|
};
|
|
390
332
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
} catch {
|
|
396
|
-
return {};
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
function collect() {
|
|
400
|
-
var _a;
|
|
401
|
-
let deviceInfo = tryCall(uni.getDeviceInfo);
|
|
402
|
-
let windowInfo = tryCall(uni.getWindowInfo);
|
|
403
|
-
let appBaseInfo = tryCall(uni.getAppBaseInfo);
|
|
404
|
-
if (!deviceInfo.brand && !deviceInfo.model) {
|
|
405
|
-
const sys = tryCall(() => uni.getSystemInfoSync());
|
|
406
|
-
deviceInfo = { ...sys };
|
|
407
|
-
windowInfo = { ...sys };
|
|
408
|
-
appBaseInfo = { ...sys };
|
|
409
|
-
}
|
|
410
|
-
let appid = "";
|
|
411
|
-
try {
|
|
412
|
-
const accountInfo = uni.getAccountInfoSync();
|
|
413
|
-
appid = ((_a = accountInfo == null ? void 0 : accountInfo.miniProgram) == null ? void 0 : _a.appId) || "";
|
|
414
|
-
} catch {
|
|
415
|
-
appid = deviceInfo.appId || "";
|
|
416
|
-
}
|
|
417
|
-
const system = deviceInfo.system || "";
|
|
418
|
-
return {
|
|
419
|
-
appid,
|
|
420
|
-
app_name: appBaseInfo.appName || "",
|
|
421
|
-
app_version: appBaseInfo.appVersion || "",
|
|
422
|
-
app_version_code: appBaseInfo.appVersionCode || "",
|
|
423
|
-
app_channel: appBaseInfo.appChannel || "",
|
|
424
|
-
device_brand: deviceInfo.brand || "",
|
|
425
|
-
device_model: deviceInfo.model || "",
|
|
426
|
-
device_id: deviceInfo.deviceId || "",
|
|
427
|
-
device_type: deviceInfo.deviceType || "",
|
|
428
|
-
device_orientation: windowInfo.deviceOrientation || "portrait",
|
|
429
|
-
brand: deviceInfo.brand || "",
|
|
430
|
-
model: deviceInfo.model || "",
|
|
431
|
-
system,
|
|
432
|
-
os: system.split(" ")[0] || "",
|
|
433
|
-
pixel_ratio: windowInfo.pixelRatio || 0,
|
|
434
|
-
screen_width: windowInfo.screenWidth || 0,
|
|
435
|
-
screen_height: windowInfo.screenHeight || 0,
|
|
436
|
-
window_width: windowInfo.windowWidth || 0,
|
|
437
|
-
window_height: windowInfo.windowHeight || 0,
|
|
438
|
-
status_bar_height: windowInfo.statusBarHeight || 0,
|
|
439
|
-
sdk_version: appBaseInfo.SDKVersion || "",
|
|
440
|
-
host_name: appBaseInfo.hostName || "",
|
|
441
|
-
host_version: appBaseInfo.hostVersion || "",
|
|
442
|
-
host_language: appBaseInfo.hostLanguage || "",
|
|
443
|
-
host_theme: appBaseInfo.hostTheme || "",
|
|
444
|
-
platform: deviceInfo.platform || "",
|
|
445
|
-
language: appBaseInfo.language || "",
|
|
446
|
-
version: appBaseInfo.version || ""
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
function ensure() {
|
|
450
|
-
if (!_info.value) {
|
|
451
|
-
_info.value = collect();
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
function useDevice() {
|
|
455
|
-
ensure();
|
|
456
|
-
return _info;
|
|
457
|
-
}
|
|
458
|
-
function deviceToQuery() {
|
|
459
|
-
ensure();
|
|
460
|
-
if (!_info.value)
|
|
461
|
-
return "";
|
|
462
|
-
return Object.entries(_info.value).filter(([, v]) => v !== "" && v !== 0).map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`).join("&");
|
|
333
|
+
function withQuery(url, qs) {
|
|
334
|
+
if (!qs)
|
|
335
|
+
return url;
|
|
336
|
+
return `${url}${url.includes("?") ? "&" : "?"}${qs}`;
|
|
463
337
|
}
|
|
464
|
-
function
|
|
465
|
-
|
|
338
|
+
function toQuery(data) {
|
|
339
|
+
return Object.entries(data).filter(([, val]) => val !== void 0 && val !== null).map(([key, val]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(val))}`).join("&");
|
|
466
340
|
}
|
|
467
|
-
function
|
|
468
|
-
const
|
|
469
|
-
|
|
470
|
-
refs.value = {};
|
|
471
|
-
});
|
|
472
|
-
onUnmounted(() => {
|
|
473
|
-
refs.value = {};
|
|
474
|
-
});
|
|
475
|
-
const setRefs = (key) => (el) => {
|
|
476
|
-
if (el)
|
|
477
|
-
refs.value[key] = el;
|
|
478
|
-
};
|
|
479
|
-
return { refs, setRefs };
|
|
480
|
-
}
|
|
481
|
-
function usePageMeta() {
|
|
482
|
-
function setTitle(title) {
|
|
483
|
-
uni.setNavigationBarTitle({ title });
|
|
484
|
-
}
|
|
485
|
-
function setOptions(options) {
|
|
486
|
-
if (options.title || options.navigationBarTitleText) {
|
|
487
|
-
setTitle(options.title || options.navigationBarTitleText);
|
|
488
|
-
}
|
|
489
|
-
if (options.navigationBarBackgroundColor || options.navigationBarTextStyle) {
|
|
490
|
-
uni.setNavigationBarColor({
|
|
491
|
-
frontColor: options.navigationBarTextStyle === "white" ? "#ffffff" : "#000000",
|
|
492
|
-
backgroundColor: options.navigationBarBackgroundColor ?? "#ffffff"
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
if (options.backgroundColor) {
|
|
496
|
-
uni.setBackgroundColor({ backgroundColor: options.backgroundColor });
|
|
497
|
-
}
|
|
498
|
-
if (options.enablePullDownRefresh !== void 0) {
|
|
499
|
-
uni.setBackgroundTextStyle({ textStyle: "dark" });
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
return {
|
|
503
|
-
setTitle,
|
|
504
|
-
setOptions
|
|
505
|
-
};
|
|
341
|
+
function signText(url) {
|
|
342
|
+
const [path, qs] = url.split("?");
|
|
343
|
+
return qs ? `${qs.split("&").filter(Boolean).sort().join("&")}&` : `${path}&`;
|
|
506
344
|
}
|
|
507
|
-
function
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
const value = uni.getStorageSync(key);
|
|
511
|
-
return value ?? null;
|
|
512
|
-
} catch {
|
|
513
|
-
return null;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
function set(key, value) {
|
|
517
|
-
try {
|
|
518
|
-
uni.setStorageSync(key, value);
|
|
519
|
-
return true;
|
|
520
|
-
} catch {
|
|
521
|
-
return false;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
function remove(key) {
|
|
525
|
-
try {
|
|
526
|
-
uni.removeStorageSync(key);
|
|
527
|
-
return true;
|
|
528
|
-
} catch {
|
|
529
|
-
return false;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
function clear() {
|
|
533
|
-
try {
|
|
534
|
-
uni.clearStorageSync();
|
|
535
|
-
return true;
|
|
536
|
-
} catch {
|
|
537
|
-
return false;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
function info() {
|
|
541
|
-
try {
|
|
542
|
-
return uni.getStorageInfoSync();
|
|
543
|
-
} catch {
|
|
544
|
-
return null;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
return { get, set, remove, clear, info };
|
|
345
|
+
function toNumber(val, def) {
|
|
346
|
+
const next = Number(val);
|
|
347
|
+
return Number.isFinite(next) ? next : def;
|
|
548
348
|
}
|
|
549
|
-
function
|
|
550
|
-
|
|
551
|
-
return
|
|
552
|
-
|
|
553
|
-
function email(value) {
|
|
554
|
-
return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
|
|
555
|
-
}
|
|
556
|
-
function url(value) {
|
|
557
|
-
try {
|
|
558
|
-
new URL(value);
|
|
559
|
-
return true;
|
|
560
|
-
} catch {
|
|
561
|
-
return false;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
function idCard(value) {
|
|
565
|
-
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);
|
|
566
|
-
}
|
|
567
|
-
function carNumber(value) {
|
|
568
|
-
return /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-Z0-9]{5}$/.test(value);
|
|
569
|
-
}
|
|
570
|
-
function password(value) {
|
|
571
|
-
return /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/.test(value);
|
|
572
|
-
}
|
|
573
|
-
function empty(value) {
|
|
574
|
-
if (value == null)
|
|
575
|
-
return true;
|
|
576
|
-
if (typeof value === "string")
|
|
577
|
-
return value.trim() === "";
|
|
578
|
-
if (Array.isArray(value))
|
|
579
|
-
return value.length === 0;
|
|
580
|
-
if (typeof value === "object")
|
|
581
|
-
return Object.keys(value).length === 0;
|
|
349
|
+
function toBoolean(val, def) {
|
|
350
|
+
if (typeof val === "boolean")
|
|
351
|
+
return val;
|
|
352
|
+
if (val === 0 || val === "0")
|
|
582
353
|
return false;
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
email,
|
|
587
|
-
url,
|
|
588
|
-
idCard,
|
|
589
|
-
carNumber,
|
|
590
|
-
password,
|
|
591
|
-
empty
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
function useFormat() {
|
|
595
|
-
function date(date2, format = "YYYY-MM-DD HH:mm:ss") {
|
|
596
|
-
const d = new Date(date2);
|
|
597
|
-
if (isNaN(d.getTime()))
|
|
598
|
-
return "";
|
|
599
|
-
const year = d.getFullYear();
|
|
600
|
-
const month = String(d.getMonth() + 1).padStart(2, "0");
|
|
601
|
-
const day = String(d.getDate()).padStart(2, "0");
|
|
602
|
-
const hours = String(d.getHours()).padStart(2, "0");
|
|
603
|
-
const minutes = String(d.getMinutes()).padStart(2, "0");
|
|
604
|
-
const seconds = String(d.getSeconds()).padStart(2, "0");
|
|
605
|
-
return format.replace("YYYY", String(year)).replace("MM", month).replace("DD", day).replace("HH", hours).replace("mm", minutes).replace("ss", seconds);
|
|
606
|
-
}
|
|
607
|
-
function fileSize(bytes) {
|
|
608
|
-
if (bytes === 0)
|
|
609
|
-
return "0 B";
|
|
610
|
-
const k = 1024;
|
|
611
|
-
const sizes = ["B", "KB", "MB", "GB", "TB"];
|
|
612
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
613
|
-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
|
614
|
-
}
|
|
615
|
-
function phone(value) {
|
|
616
|
-
return value.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
|
|
617
|
-
}
|
|
618
|
-
function money(amount, decimals = 2, decPoint = ".", thousandsSep = ",") {
|
|
619
|
-
return amount.toFixed(decimals).replace(/\B(?=(\d{3})+(?!\d))/g, thousandsSep);
|
|
620
|
-
}
|
|
621
|
-
return { date, fileSize, phone, money };
|
|
622
|
-
}
|
|
623
|
-
function unwrapPayload(raw) {
|
|
624
|
-
if (raw == null)
|
|
625
|
-
return null;
|
|
626
|
-
if (typeof raw === "object" && "code" in raw && typeof raw.code === "number") {
|
|
627
|
-
const env = raw;
|
|
628
|
-
return env.code === 1 && env.data ? env.data : null;
|
|
629
|
-
}
|
|
630
|
-
return raw;
|
|
631
|
-
}
|
|
632
|
-
const DEFAULT_POPUP_DELAY_MS = 3e3;
|
|
633
|
-
const EMPTY = {
|
|
634
|
-
banner_unit_id: "",
|
|
635
|
-
grid_unit_id: "",
|
|
636
|
-
custom_unit_id: "",
|
|
637
|
-
video_unit_id: "",
|
|
638
|
-
reward_unit_id: "",
|
|
639
|
-
popup_unit_id: "",
|
|
640
|
-
vip_no_ad: 0
|
|
641
|
-
};
|
|
642
|
-
let adapter$1 = null;
|
|
643
|
-
let pending$1 = null;
|
|
644
|
-
function setConfigAd(a) {
|
|
645
|
-
adapter$1 = a;
|
|
646
|
-
}
|
|
647
|
-
const useAdStore = defineStore("hlw_ad", () => {
|
|
648
|
-
const config2 = ref({ ...EMPTY });
|
|
649
|
-
const loaded = ref(false);
|
|
650
|
-
return { config: config2, loaded };
|
|
651
|
-
});
|
|
652
|
-
let _msg$1 = null;
|
|
653
|
-
const msg = () => _msg$1 ?? (_msg$1 = useMsg());
|
|
654
|
-
const rewardedCache = /* @__PURE__ */ new Map();
|
|
655
|
-
const interstitialCache = /* @__PURE__ */ new Map();
|
|
656
|
-
function useAd() {
|
|
657
|
-
const store = useAdStore();
|
|
658
|
-
const { loaded } = storeToRefs(store);
|
|
659
|
-
const config2 = computed(() => {
|
|
660
|
-
var _a, _b;
|
|
661
|
-
const raw = store.config;
|
|
662
|
-
const userForce = ((_a = adapter$1 == null ? void 0 : adapter$1.userNoAd) == null ? void 0 : _a.call(adapter$1)) === true;
|
|
663
|
-
const vipHide = raw.vip_no_ad === 1 && ((_b = adapter$1 == null ? void 0 : adapter$1.isVip) == null ? void 0 : _b.call(adapter$1)) === true;
|
|
664
|
-
if (userForce || vipHide) {
|
|
665
|
-
return { ...EMPTY, reward_unit_id: raw.reward_unit_id, vip_no_ad: 1 };
|
|
666
|
-
}
|
|
667
|
-
return raw;
|
|
668
|
-
});
|
|
669
|
-
async function loadConfig2(force = false) {
|
|
670
|
-
if (loaded.value && !force)
|
|
671
|
-
return;
|
|
672
|
-
if (pending$1 && !force)
|
|
673
|
-
return pending$1;
|
|
674
|
-
if (!(adapter$1 == null ? void 0 : adapter$1.getConfig)) {
|
|
675
|
-
console.warn("[useAd] adapter.getConfig 未注入;先调用 setConfigAd()");
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
const fn = adapter$1.getConfig;
|
|
679
|
-
const flight = (async () => {
|
|
680
|
-
try {
|
|
681
|
-
const cfg = unwrapPayload(await fn());
|
|
682
|
-
if (cfg) {
|
|
683
|
-
store.config = cfg;
|
|
684
|
-
store.loaded = true;
|
|
685
|
-
}
|
|
686
|
-
} catch (e) {
|
|
687
|
-
console.warn("[useAd] load config failed", e);
|
|
688
|
-
} finally {
|
|
689
|
-
if (pending$1 === flight)
|
|
690
|
-
pending$1 = null;
|
|
691
|
-
}
|
|
692
|
-
})();
|
|
693
|
-
pending$1 = flight;
|
|
694
|
-
return flight;
|
|
695
|
-
}
|
|
696
|
-
function getUnitId(type) {
|
|
697
|
-
return config2.value[`${type}_unit_id`] || "";
|
|
698
|
-
}
|
|
699
|
-
async function showReward(onClose) {
|
|
700
|
-
const unitId = getUnitId("reward");
|
|
701
|
-
if (!unitId) {
|
|
702
|
-
msg().toast("激励广告未配置");
|
|
703
|
-
return;
|
|
704
|
-
}
|
|
705
|
-
if ((adapter$1 == null ? void 0 : adapter$1.isAuth) && !adapter$1.isAuth()) {
|
|
706
|
-
msg().toast("请先登录");
|
|
707
|
-
return;
|
|
708
|
-
}
|
|
709
|
-
const closeRes = await playRewardedOnce(unitId);
|
|
710
|
-
if (onClose)
|
|
711
|
-
await onClose(closeRes);
|
|
712
|
-
}
|
|
713
|
-
function showPopup(delayMs = DEFAULT_POPUP_DELAY_MS) {
|
|
714
|
-
return new Promise((resolve) => {
|
|
715
|
-
setTimeout(() => {
|
|
716
|
-
loadConfig2().then(() => {
|
|
717
|
-
const unitId = getUnitId("popup");
|
|
718
|
-
if (!unitId) {
|
|
719
|
-
resolve(false);
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
showInterstitialAd(unitId).then(resolve);
|
|
723
|
-
});
|
|
724
|
-
}, delayMs);
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
return {
|
|
728
|
-
// 状态
|
|
729
|
-
config: config2,
|
|
730
|
-
loaded,
|
|
731
|
-
// 方法
|
|
732
|
-
loadConfig: loadConfig2,
|
|
733
|
-
getUnitId,
|
|
734
|
-
showReward,
|
|
735
|
-
showPopup,
|
|
736
|
-
confirm: confirmModal
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
async function playRewardedOnce(unitId) {
|
|
740
|
-
msg().showLoading("广告加载中");
|
|
741
|
-
let hidden = false;
|
|
742
|
-
const hide = () => {
|
|
743
|
-
if (hidden)
|
|
744
|
-
return;
|
|
745
|
-
hidden = true;
|
|
746
|
-
msg().hideLoading();
|
|
747
|
-
};
|
|
748
|
-
try {
|
|
749
|
-
const isEnded = await showRewardedAd(unitId, { onShown: hide });
|
|
750
|
-
return { isEnded };
|
|
751
|
-
} finally {
|
|
752
|
-
hide();
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
function confirmModal() {
|
|
756
|
-
return new Promise((resolve) => {
|
|
757
|
-
uni.showModal({
|
|
758
|
-
title: "提示",
|
|
759
|
-
content: "看完广告才可以领取奖励哦,要继续观看吗?",
|
|
760
|
-
confirmText: "继续观看",
|
|
761
|
-
cancelText: "放弃",
|
|
762
|
-
success: (r) => resolve(!!r.confirm),
|
|
763
|
-
fail: () => resolve(false)
|
|
764
|
-
});
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
function showRewardedAd(unitId, hooks) {
|
|
768
|
-
return new Promise((resolve) => {
|
|
769
|
-
var _a;
|
|
770
|
-
let entry = rewardedCache.get(unitId);
|
|
771
|
-
if (!entry) {
|
|
772
|
-
const ad2 = uni.createRewardedVideoAd({ adUnitId: unitId });
|
|
773
|
-
if (!ad2) {
|
|
774
|
-
resolve(false);
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
(_a = ad2.onError) == null ? void 0 : _a.call(ad2, (err) => {
|
|
778
|
-
console.warn(`[useAd] reward onError (${unitId})`, err);
|
|
779
|
-
});
|
|
780
|
-
entry = { ad: ad2, loading: false };
|
|
781
|
-
rewardedCache.set(unitId, entry);
|
|
782
|
-
}
|
|
783
|
-
const { ad } = entry;
|
|
784
|
-
let closeHandler = null;
|
|
785
|
-
let errorHandler = null;
|
|
786
|
-
const cleanup = () => {
|
|
787
|
-
var _a2, _b;
|
|
788
|
-
if (closeHandler) {
|
|
789
|
-
(_a2 = ad.offClose) == null ? void 0 : _a2.call(ad, closeHandler);
|
|
790
|
-
closeHandler = null;
|
|
791
|
-
}
|
|
792
|
-
if (errorHandler) {
|
|
793
|
-
(_b = ad.offError) == null ? void 0 : _b.call(ad, errorHandler);
|
|
794
|
-
errorHandler = null;
|
|
795
|
-
}
|
|
796
|
-
};
|
|
797
|
-
closeHandler = (res) => {
|
|
798
|
-
cleanup();
|
|
799
|
-
resolve(!!(res && res.isEnded));
|
|
800
|
-
};
|
|
801
|
-
errorHandler = (err) => {
|
|
802
|
-
console.warn(`[useAd] reward show error (${unitId})`, err);
|
|
803
|
-
cleanup();
|
|
804
|
-
resolve(false);
|
|
805
|
-
};
|
|
806
|
-
ad.onClose(closeHandler);
|
|
807
|
-
ad.onError(errorHandler);
|
|
808
|
-
const doShow = () => ad.show().then(() => {
|
|
809
|
-
var _a2;
|
|
810
|
-
try {
|
|
811
|
-
(_a2 = hooks == null ? void 0 : hooks.onShown) == null ? void 0 : _a2.call(hooks);
|
|
812
|
-
} catch (e) {
|
|
813
|
-
console.warn("[useAd] onShown error", e);
|
|
814
|
-
}
|
|
815
|
-
}).catch(() => {
|
|
816
|
-
cleanup();
|
|
817
|
-
resolve(false);
|
|
818
|
-
});
|
|
819
|
-
if (entry.loading) {
|
|
820
|
-
Promise.resolve().then(doShow);
|
|
821
|
-
} else {
|
|
822
|
-
entry.loading = true;
|
|
823
|
-
ad.load().then(doShow).catch(doShow).finally(() => {
|
|
824
|
-
if (entry)
|
|
825
|
-
entry.loading = false;
|
|
826
|
-
});
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
function showInterstitialAd(unitId) {
|
|
831
|
-
return new Promise((resolve) => {
|
|
832
|
-
var _a;
|
|
833
|
-
let ad = interstitialCache.get(unitId);
|
|
834
|
-
if (!ad) {
|
|
835
|
-
if (typeof uni.createInterstitialAd !== "function") {
|
|
836
|
-
console.warn("[useAd] 当前基础库不支持插屏广告");
|
|
837
|
-
resolve(false);
|
|
838
|
-
return;
|
|
839
|
-
}
|
|
840
|
-
ad = uni.createInterstitialAd({ adUnitId: unitId });
|
|
841
|
-
if (!ad) {
|
|
842
|
-
resolve(false);
|
|
843
|
-
return;
|
|
844
|
-
}
|
|
845
|
-
(_a = ad.onError) == null ? void 0 : _a.call(ad, (err) => {
|
|
846
|
-
console.warn(`[useAd] popup onError (${unitId})`, err);
|
|
847
|
-
});
|
|
848
|
-
interstitialCache.set(unitId, ad);
|
|
849
|
-
}
|
|
850
|
-
ad.show().then(() => resolve(true)).catch((err) => {
|
|
851
|
-
console.warn(`[useAd] popup show error (${unitId})`, err);
|
|
852
|
-
resolve(false);
|
|
853
|
-
});
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
|
-
function destroyAds() {
|
|
857
|
-
rewardedCache.forEach((e) => {
|
|
858
|
-
var _a, _b;
|
|
859
|
-
return (_b = (_a = e.ad) == null ? void 0 : _a.destroy) == null ? void 0 : _b.call(_a);
|
|
860
|
-
});
|
|
861
|
-
rewardedCache.clear();
|
|
862
|
-
interstitialCache.forEach((ad) => {
|
|
863
|
-
var _a;
|
|
864
|
-
return (_a = ad == null ? void 0 : ad.destroy) == null ? void 0 : _a.call(ad);
|
|
865
|
-
});
|
|
866
|
-
interstitialCache.clear();
|
|
867
|
-
}
|
|
868
|
-
function useShare(config2) {
|
|
869
|
-
const resolve = (from) => typeof config2 === "function" ? config2(from) : config2;
|
|
870
|
-
onShareAppMessage((options) => {
|
|
871
|
-
const resolved = resolve((options == null ? void 0 : options.from) ?? "menu");
|
|
872
|
-
const payload = {};
|
|
873
|
-
if (resolved.title !== void 0)
|
|
874
|
-
payload.title = resolved.title;
|
|
875
|
-
if (resolved.path !== void 0)
|
|
876
|
-
payload.path = resolved.path;
|
|
877
|
-
if (resolved.imageUrl !== void 0)
|
|
878
|
-
payload.imageUrl = resolved.imageUrl;
|
|
879
|
-
return payload;
|
|
880
|
-
});
|
|
881
|
-
onShareTimeline(() => {
|
|
882
|
-
const resolved = resolve("menu");
|
|
883
|
-
const timeline = resolved.timeline ?? {};
|
|
884
|
-
const payload = {};
|
|
885
|
-
const title = timeline.title ?? resolved.title;
|
|
886
|
-
const imageUrl = timeline.imageUrl ?? resolved.imageUrl;
|
|
887
|
-
if (title !== void 0)
|
|
888
|
-
payload.title = title;
|
|
889
|
-
if (timeline.query !== void 0)
|
|
890
|
-
payload.query = timeline.query;
|
|
891
|
-
if (imageUrl !== void 0)
|
|
892
|
-
payload.imageUrl = imageUrl;
|
|
893
|
-
return payload;
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
let shareAdapter = null;
|
|
897
|
-
const shareCache = ref(null);
|
|
898
|
-
let sharePending = null;
|
|
899
|
-
function setConfigShare(a) {
|
|
900
|
-
shareAdapter = a;
|
|
901
|
-
}
|
|
902
|
-
function loadShareConfig() {
|
|
903
|
-
if (shareCache.value)
|
|
904
|
-
return Promise.resolve();
|
|
905
|
-
if (sharePending)
|
|
906
|
-
return sharePending;
|
|
907
|
-
if (!(shareAdapter == null ? void 0 : shareAdapter.getConfig)) {
|
|
908
|
-
console.warn("[useShareConfig] adapter.getConfig 未注入;先调用 setConfigShare()");
|
|
909
|
-
return Promise.resolve();
|
|
910
|
-
}
|
|
911
|
-
sharePending = shareAdapter.getConfig().then((raw) => {
|
|
912
|
-
const cfg = unwrapPayload(raw);
|
|
913
|
-
if (cfg)
|
|
914
|
-
shareCache.value = cfg;
|
|
915
|
-
}).catch((e) => {
|
|
916
|
-
console.warn("[useShareConfig] load failed", e);
|
|
917
|
-
}).finally(() => {
|
|
918
|
-
sharePending = null;
|
|
919
|
-
});
|
|
920
|
-
return sharePending;
|
|
921
|
-
}
|
|
922
|
-
function useShareConfig(pageKey, fallback) {
|
|
923
|
-
void loadShareConfig();
|
|
924
|
-
return () => {
|
|
925
|
-
var _a;
|
|
926
|
-
const remote = (_a = shareCache.value) == null ? void 0 : _a[pageKey];
|
|
927
|
-
const title = (remote == null ? void 0 : remote.title) || fallback.title;
|
|
928
|
-
const image = (remote == null ? void 0 : remote.image) || fallback.image;
|
|
929
|
-
const payload = { title, path: fallback.path };
|
|
930
|
-
if (image)
|
|
931
|
-
payload.imageUrl = image;
|
|
932
|
-
return payload;
|
|
933
|
-
};
|
|
934
|
-
}
|
|
935
|
-
let adapter = null;
|
|
936
|
-
const config = ref(null);
|
|
937
|
-
let pending = null;
|
|
938
|
-
function setConfigContact(a) {
|
|
939
|
-
adapter = a;
|
|
940
|
-
}
|
|
941
|
-
function loadConfig() {
|
|
942
|
-
if (config.value)
|
|
943
|
-
return Promise.resolve();
|
|
944
|
-
if (pending)
|
|
945
|
-
return pending;
|
|
946
|
-
if (!(adapter == null ? void 0 : adapter.getConfig)) {
|
|
947
|
-
console.warn("[useContact] adapter.getConfig 未注入;先调用 setConfigContact()");
|
|
948
|
-
return Promise.resolve();
|
|
949
|
-
}
|
|
950
|
-
pending = adapter.getConfig().then((raw) => {
|
|
951
|
-
const cfg = unwrapPayload(raw);
|
|
952
|
-
if (cfg)
|
|
953
|
-
config.value = cfg;
|
|
954
|
-
}).catch((e) => {
|
|
955
|
-
console.warn("[useContact] load config failed", e);
|
|
956
|
-
}).finally(() => {
|
|
957
|
-
pending = null;
|
|
958
|
-
});
|
|
959
|
-
return pending;
|
|
960
|
-
}
|
|
961
|
-
function useContact() {
|
|
962
|
-
void loadConfig();
|
|
963
|
-
return computed(() => {
|
|
964
|
-
var _a, _b, _c, _d;
|
|
965
|
-
return {
|
|
966
|
-
sendMessageTitle: ((_a = config.value) == null ? void 0 : _a.send_message_title) || "",
|
|
967
|
-
sendMessagePath: ((_b = config.value) == null ? void 0 : _b.send_message_path) || "",
|
|
968
|
-
sendMessageImg: ((_c = config.value) == null ? void 0 : _c.send_message_img) || "",
|
|
969
|
-
showMessageCard: ((_d = config.value) == null ? void 0 : _d.show_message_card) ?? false
|
|
970
|
-
};
|
|
971
|
-
});
|
|
354
|
+
if (val === 1 || val === "1")
|
|
355
|
+
return true;
|
|
356
|
+
return def;
|
|
972
357
|
}
|
|
973
358
|
function useUtils() {
|
|
974
|
-
function copy(
|
|
975
|
-
|
|
976
|
-
if (typeof data !== "string") {
|
|
977
|
-
const dataset = ((_a = data == null ? void 0 : data.currentTarget) == null ? void 0 : _a.dataset) || ((_b = data == null ? void 0 : data.target) == null ? void 0 : _b.dataset);
|
|
978
|
-
const text = dataset == null ? void 0 : dataset.copy;
|
|
979
|
-
if (text == null || text === "")
|
|
980
|
-
return Promise.resolve(false);
|
|
981
|
-
return copy(String(text), (dataset == null ? void 0 : dataset.copyToast) !== "false");
|
|
982
|
-
}
|
|
983
|
-
return new Promise((resolve) => {
|
|
359
|
+
function copy(text, tip = true) {
|
|
360
|
+
return new Promise((ok) => {
|
|
984
361
|
uni.setClipboardData({
|
|
985
|
-
data,
|
|
362
|
+
data: text,
|
|
986
363
|
showToast: false,
|
|
987
364
|
success: () => {
|
|
988
|
-
if (
|
|
365
|
+
if (tip) {
|
|
989
366
|
uni.showToast({ title: "复制成功", icon: "none", duration: 1500 });
|
|
990
367
|
}
|
|
991
|
-
|
|
368
|
+
ok(true);
|
|
992
369
|
},
|
|
993
|
-
fail: () =>
|
|
370
|
+
fail: () => ok(false)
|
|
994
371
|
});
|
|
995
372
|
});
|
|
996
373
|
}
|
|
997
|
-
function copyFromEvent(event) {
|
|
998
|
-
return copy(event);
|
|
999
|
-
}
|
|
1000
374
|
function paste() {
|
|
1001
|
-
return new Promise((
|
|
375
|
+
return new Promise((ok) => {
|
|
1002
376
|
uni.getClipboardData({
|
|
1003
|
-
success: (res) =>
|
|
1004
|
-
fail: () =>
|
|
377
|
+
success: (res) => ok(res.data),
|
|
378
|
+
fail: () => ok("")
|
|
1005
379
|
});
|
|
1006
380
|
});
|
|
1007
381
|
}
|
|
1008
|
-
function
|
|
1009
|
-
|
|
382
|
+
function auth() {
|
|
383
|
+
uni.showModal({
|
|
384
|
+
title: "提示",
|
|
385
|
+
content: "需要授权相册权限",
|
|
386
|
+
confirmText: "去设置",
|
|
387
|
+
success: (res) => {
|
|
388
|
+
if (res.confirm)
|
|
389
|
+
uni.openSetting();
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function saveImage(path) {
|
|
394
|
+
return new Promise((ok) => {
|
|
1010
395
|
uni.saveImageToPhotosAlbum({
|
|
1011
|
-
filePath,
|
|
396
|
+
filePath: path,
|
|
1012
397
|
success: () => {
|
|
1013
398
|
uni.showToast({ title: "保存成功", icon: "success" });
|
|
1014
|
-
|
|
399
|
+
ok(true);
|
|
1015
400
|
},
|
|
1016
401
|
fail: (err) => {
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
content: "需要授权相册权限",
|
|
1021
|
-
confirmText: "去设置",
|
|
1022
|
-
success: (res) => {
|
|
1023
|
-
if (res.confirm)
|
|
1024
|
-
uni.openSetting();
|
|
1025
|
-
}
|
|
1026
|
-
});
|
|
402
|
+
const msg = String(err.errMsg || "");
|
|
403
|
+
if (msg.includes("auth deny") || msg.includes("authorize")) {
|
|
404
|
+
auth();
|
|
1027
405
|
} else {
|
|
1028
406
|
uni.showToast({ title: "保存失败", icon: "none" });
|
|
1029
407
|
}
|
|
1030
|
-
|
|
408
|
+
ok(false);
|
|
1031
409
|
}
|
|
1032
410
|
});
|
|
1033
411
|
});
|
|
1034
412
|
}
|
|
1035
|
-
function
|
|
1036
|
-
return new Promise((
|
|
413
|
+
function saveVideo(path) {
|
|
414
|
+
return new Promise((ok) => {
|
|
415
|
+
uni.saveVideoToPhotosAlbum({
|
|
416
|
+
filePath: path,
|
|
417
|
+
success: () => {
|
|
418
|
+
uni.showToast({ title: "保存成功", icon: "success" });
|
|
419
|
+
ok(true);
|
|
420
|
+
},
|
|
421
|
+
fail: (err) => {
|
|
422
|
+
const msg = String(err.errMsg || "");
|
|
423
|
+
if (msg.includes("auth deny") || msg.includes("authorize")) {
|
|
424
|
+
auth();
|
|
425
|
+
} else {
|
|
426
|
+
uni.showToast({ title: "保存失败", icon: "none" });
|
|
427
|
+
}
|
|
428
|
+
ok(false);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
function download(opt) {
|
|
434
|
+
return new Promise((ok) => {
|
|
1037
435
|
const task = uni.downloadFile({
|
|
1038
|
-
url:
|
|
1039
|
-
filePath:
|
|
1040
|
-
header:
|
|
436
|
+
url: opt.url,
|
|
437
|
+
filePath: opt.path,
|
|
438
|
+
header: opt.header,
|
|
1041
439
|
success: (res) => {
|
|
1042
440
|
if (res.statusCode === 200) {
|
|
1043
|
-
|
|
441
|
+
ok({ ok: true, path: res.tempFilePath, code: res.statusCode });
|
|
1044
442
|
} else {
|
|
1045
|
-
|
|
443
|
+
ok({ ok: false, code: res.statusCode, msg: `下载失败,状态码:${res.statusCode}` });
|
|
1046
444
|
}
|
|
1047
445
|
},
|
|
1048
|
-
fail: (err) =>
|
|
446
|
+
fail: (err) => ok({ ok: false, msg: err.errMsg })
|
|
1049
447
|
});
|
|
1050
|
-
if (
|
|
448
|
+
if (opt.progress) {
|
|
1051
449
|
task.onProgressUpdate((res) => {
|
|
1052
|
-
|
|
450
|
+
opt.progress(res.progress, res.totalBytesWritten, res.totalBytesExpectedToWrite);
|
|
1053
451
|
});
|
|
1054
452
|
}
|
|
1055
453
|
});
|
|
1056
454
|
}
|
|
1057
|
-
async function
|
|
455
|
+
async function saveImageUrl(url, progress) {
|
|
1058
456
|
try {
|
|
1059
457
|
uni.showLoading({ title: "下载中...", mask: true });
|
|
1060
|
-
const
|
|
1061
|
-
url,
|
|
1062
|
-
onProgress: onProgress ? (progress) => onProgress(progress) : void 0
|
|
1063
|
-
});
|
|
458
|
+
const res = await download({ url, progress: progress ? (value) => progress(value) : void 0 });
|
|
1064
459
|
uni.hideLoading();
|
|
1065
|
-
if (!
|
|
1066
|
-
uni.showToast({ title:
|
|
460
|
+
if (!res.ok || !res.path) {
|
|
461
|
+
uni.showToast({ title: res.msg || "下载失败", icon: "none" });
|
|
1067
462
|
return false;
|
|
1068
463
|
}
|
|
1069
|
-
return await saveImage(
|
|
464
|
+
return await saveImage(res.path);
|
|
1070
465
|
} catch {
|
|
1071
466
|
uni.hideLoading();
|
|
1072
467
|
uni.showToast({ title: "操作失败", icon: "none" });
|
|
1073
468
|
return false;
|
|
1074
469
|
}
|
|
1075
470
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
}
|
|
1092
|
-
function hexToRgba2(hex, alpha) {
|
|
1093
|
-
const [r, g, b] = parseHex(hex);
|
|
1094
|
-
return `rgba(${r},${g},${b},${alpha})`;
|
|
471
|
+
async function saveVideoUrl(url, progress) {
|
|
472
|
+
try {
|
|
473
|
+
uni.showLoading({ title: "下载中...", mask: true });
|
|
474
|
+
const res = await download({ url, progress: progress ? (value) => progress(value) : void 0 });
|
|
475
|
+
uni.hideLoading();
|
|
476
|
+
if (!res.ok || !res.path) {
|
|
477
|
+
uni.showToast({ title: res.msg || "下载失败", icon: "none" });
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
return await saveVideo(res.path);
|
|
481
|
+
} catch {
|
|
482
|
+
uni.hideLoading();
|
|
483
|
+
uni.showToast({ title: "操作失败", icon: "none" });
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
1095
486
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
487
|
+
return {
|
|
488
|
+
withQuery,
|
|
489
|
+
toQuery,
|
|
490
|
+
signText,
|
|
491
|
+
toNumber,
|
|
492
|
+
toBoolean,
|
|
493
|
+
copy,
|
|
494
|
+
paste,
|
|
495
|
+
saveImage,
|
|
496
|
+
saveVideo,
|
|
497
|
+
download,
|
|
498
|
+
saveImageUrl,
|
|
499
|
+
saveVideoUrl
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
let deviceCache = null;
|
|
503
|
+
function readSafe(fn) {
|
|
504
|
+
try {
|
|
505
|
+
return (fn == null ? void 0 : fn()) ?? {};
|
|
506
|
+
} catch {
|
|
507
|
+
return {};
|
|
1100
508
|
}
|
|
1101
|
-
return { varsToStyle: varsToStyle2, hexToRgba: hexToRgba2, darkenHex: darkenHex2 };
|
|
1102
509
|
}
|
|
1103
|
-
function
|
|
510
|
+
function collectDevice() {
|
|
511
|
+
let device = readSafe(uni.getDeviceInfo);
|
|
512
|
+
let window = readSafe(uni.getWindowInfo);
|
|
513
|
+
let app = readSafe(uni.getAppBaseInfo);
|
|
514
|
+
if (!device.brand && !device.model) {
|
|
515
|
+
const system2 = readSafe(() => uni.getSystemInfoSync());
|
|
516
|
+
device = { ...system2 };
|
|
517
|
+
window = { ...system2 };
|
|
518
|
+
app = { ...system2 };
|
|
519
|
+
}
|
|
520
|
+
const system = device.system || "";
|
|
521
|
+
return {
|
|
522
|
+
appid: getAppid(device),
|
|
523
|
+
app_name: app.appName || "",
|
|
524
|
+
app_version: app.appVersion || "",
|
|
525
|
+
app_version_code: app.appVersionCode || "",
|
|
526
|
+
app_channel: app.appChannel || "",
|
|
527
|
+
device_brand: device.brand || "",
|
|
528
|
+
device_model: device.model || "",
|
|
529
|
+
device_id: device.deviceId || "",
|
|
530
|
+
device_type: device.deviceType || "",
|
|
531
|
+
device_orientation: window.deviceOrientation || "portrait",
|
|
532
|
+
brand: device.brand || "",
|
|
533
|
+
model: device.model || "",
|
|
534
|
+
system,
|
|
535
|
+
os: system.split(" ")[0] || "",
|
|
536
|
+
pixel_ratio: window.pixelRatio || 0,
|
|
537
|
+
screen_width: window.screenWidth || 0,
|
|
538
|
+
screen_height: window.screenHeight || 0,
|
|
539
|
+
window_width: window.windowWidth || 0,
|
|
540
|
+
window_height: window.windowHeight || 0,
|
|
541
|
+
status_bar_height: window.statusBarHeight || 0,
|
|
542
|
+
sdk_version: app.SDKVersion || "",
|
|
543
|
+
host_name: app.hostName || "",
|
|
544
|
+
host_version: app.hostVersion || "",
|
|
545
|
+
host_language: app.hostLanguage || "",
|
|
546
|
+
host_theme: app.hostTheme || "",
|
|
547
|
+
platform: device.platform || "",
|
|
548
|
+
language: app.language || "",
|
|
549
|
+
version: app.version || ""
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function getAppid(device) {
|
|
1104
553
|
var _a;
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
return;
|
|
554
|
+
try {
|
|
555
|
+
const account = uni.getAccountInfoSync();
|
|
556
|
+
return ((_a = account == null ? void 0 : account.miniProgram) == null ? void 0 : _a.appId) || "";
|
|
557
|
+
} catch {
|
|
558
|
+
return device.appId || "";
|
|
1111
559
|
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
560
|
+
}
|
|
561
|
+
function getDevice() {
|
|
562
|
+
deviceCache ?? (deviceCache = collectDevice());
|
|
563
|
+
return deviceCache;
|
|
564
|
+
}
|
|
565
|
+
function getQueryInfo(info) {
|
|
566
|
+
return {
|
|
567
|
+
appid: info.appid,
|
|
568
|
+
device_brand: info.device_brand,
|
|
569
|
+
device_model: info.device_model,
|
|
570
|
+
device_id: info.device_id,
|
|
571
|
+
device_type: info.device_type,
|
|
572
|
+
device_orientation: info.device_orientation,
|
|
573
|
+
platform: info.platform,
|
|
574
|
+
system: info.system,
|
|
575
|
+
os: info.os,
|
|
576
|
+
version: info.version,
|
|
577
|
+
sdk_version: info.sdk_version,
|
|
578
|
+
host_name: info.host_name,
|
|
579
|
+
host_version: info.host_version,
|
|
580
|
+
host_language: info.host_language,
|
|
581
|
+
language: info.language,
|
|
582
|
+
app_version: info.app_version,
|
|
583
|
+
app_version_code: info.app_version_code,
|
|
584
|
+
screen_width: info.screen_width,
|
|
585
|
+
screen_height: info.screen_height
|
|
1117
586
|
};
|
|
1118
|
-
switch (type) {
|
|
1119
|
-
case "switchTab":
|
|
1120
|
-
uni.switchTab({ url: value, fail });
|
|
1121
|
-
break;
|
|
1122
|
-
case "redirectTo":
|
|
1123
|
-
uni.redirectTo({ url: value, fail });
|
|
1124
|
-
break;
|
|
1125
|
-
case "reLaunch":
|
|
1126
|
-
uni.reLaunch({ url: value, fail });
|
|
1127
|
-
break;
|
|
1128
|
-
case "webview":
|
|
1129
|
-
if (!silent)
|
|
1130
|
-
uni.showToast({ title: `H5:${value}`, icon: "none" });
|
|
1131
|
-
break;
|
|
1132
|
-
case "miniprogram": {
|
|
1133
|
-
(_a = uni.navigateToMiniProgram) == null ? void 0 : _a.call(uni, {
|
|
1134
|
-
appId: value,
|
|
1135
|
-
path: options.path || "",
|
|
1136
|
-
envVersion: options.envVersion,
|
|
1137
|
-
extraData: options.extraData ?? void 0,
|
|
1138
|
-
fail
|
|
1139
|
-
});
|
|
1140
|
-
break;
|
|
1141
|
-
}
|
|
1142
|
-
case "navigateTo":
|
|
1143
|
-
default:
|
|
1144
|
-
uni.navigateTo({ url: value, fail });
|
|
1145
|
-
break;
|
|
1146
|
-
}
|
|
1147
587
|
}
|
|
1148
|
-
function
|
|
588
|
+
function useDevice() {
|
|
589
|
+
const info = getDevice();
|
|
590
|
+
const { toQuery: toQuery2 } = useUtils();
|
|
591
|
+
return {
|
|
592
|
+
info,
|
|
593
|
+
query: toQuery2(getQueryInfo(info))
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function clearDeviceCache() {
|
|
597
|
+
deviceCache = null;
|
|
598
|
+
}
|
|
599
|
+
function useRefs() {
|
|
600
|
+
const refs = ref({});
|
|
601
|
+
onBeforeUpdate(() => {
|
|
602
|
+
refs.value = {};
|
|
603
|
+
});
|
|
604
|
+
onUnmounted(() => {
|
|
605
|
+
refs.value = {};
|
|
606
|
+
});
|
|
607
|
+
const setRefs = (key) => (el) => {
|
|
608
|
+
if (el)
|
|
609
|
+
refs.value[key] = el;
|
|
610
|
+
};
|
|
611
|
+
return { refs, setRefs };
|
|
612
|
+
}
|
|
613
|
+
function resolveConfig(config) {
|
|
614
|
+
return typeof config === "function" ? config() : config ?? {};
|
|
615
|
+
}
|
|
616
|
+
function buildPayload(base, extra) {
|
|
617
|
+
const current = {
|
|
618
|
+
...resolveConfig(base),
|
|
619
|
+
...resolveConfig(extra)
|
|
620
|
+
};
|
|
621
|
+
const payload = {};
|
|
622
|
+
if (current.title)
|
|
623
|
+
payload.title = current.title;
|
|
624
|
+
if (current.path)
|
|
625
|
+
payload.path = current.path;
|
|
626
|
+
if (current.imageUrl)
|
|
627
|
+
payload.imageUrl = current.imageUrl;
|
|
628
|
+
return payload;
|
|
629
|
+
}
|
|
630
|
+
function showShareMenu() {
|
|
631
|
+
var _a;
|
|
632
|
+
const api = typeof uni !== "undefined" ? uni : void 0;
|
|
633
|
+
(_a = api == null ? void 0 : api.showShareMenu) == null ? void 0 : _a.call(api, {
|
|
634
|
+
withShareTicket: true,
|
|
635
|
+
menus: ["shareAppMessage", "shareTimeline"],
|
|
636
|
+
fail: () => void 0
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
function useShare(config = {}) {
|
|
640
|
+
let appMessageRegistered = false;
|
|
641
|
+
let timelineRegistered = false;
|
|
642
|
+
const onShareAppMessage$1 = (extra) => {
|
|
643
|
+
if (appMessageRegistered)
|
|
644
|
+
return;
|
|
645
|
+
appMessageRegistered = true;
|
|
646
|
+
showShareMenu();
|
|
647
|
+
onShareAppMessage(() => buildPayload(config, extra));
|
|
648
|
+
};
|
|
649
|
+
const onShareTimeline$1 = (extra) => {
|
|
650
|
+
if (timelineRegistered)
|
|
651
|
+
return;
|
|
652
|
+
timelineRegistered = true;
|
|
653
|
+
showShareMenu();
|
|
654
|
+
onShareTimeline(() => {
|
|
655
|
+
var _a;
|
|
656
|
+
const payload = buildPayload(config, extra);
|
|
657
|
+
return {
|
|
658
|
+
title: payload.title,
|
|
659
|
+
query: (_a = payload.path) == null ? void 0 : _a.split("?")[1],
|
|
660
|
+
imageUrl: payload.imageUrl
|
|
661
|
+
};
|
|
662
|
+
});
|
|
663
|
+
};
|
|
664
|
+
onShareAppMessage$1();
|
|
665
|
+
onShareTimeline$1();
|
|
1149
666
|
return {
|
|
1150
|
-
|
|
667
|
+
onShareAppMessage: onShareAppMessage$1,
|
|
668
|
+
onShareTimeline: onShareTimeline$1,
|
|
669
|
+
showShareMenu
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
function fail(message, options = {}) {
|
|
673
|
+
var _a;
|
|
674
|
+
if (!options.silent) {
|
|
675
|
+
uni.showToast({ title: message, icon: "none" });
|
|
676
|
+
}
|
|
677
|
+
(_a = options.onFail) == null ? void 0 : _a.call(options, message);
|
|
678
|
+
}
|
|
679
|
+
function failHandler(target, options = {}) {
|
|
680
|
+
return (error) => {
|
|
681
|
+
fail((error == null ? void 0 : error.errMsg) || `无法跳转:${target}`, options);
|
|
1151
682
|
};
|
|
1152
683
|
}
|
|
1153
|
-
function
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
684
|
+
function navigate(type = "navigateTo", url = "", options = {}) {
|
|
685
|
+
if (type === "navigateBack") {
|
|
686
|
+
uni.navigateBack({ delta: options.delta || 1, fail: failHandler("返回上一页", options) });
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
if (!url) {
|
|
690
|
+
fail("跳转目标未配置", options);
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const onFail = failHandler(url, options);
|
|
694
|
+
if (type === "redirectTo") {
|
|
695
|
+
uni.redirectTo({ url, fail: onFail });
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
if (type === "switchTab") {
|
|
699
|
+
uni.switchTab({ url, fail: onFail });
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (type === "reLaunch") {
|
|
703
|
+
uni.reLaunch({ url, fail: onFail });
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
if (type === "miniprogram") {
|
|
707
|
+
const openMiniProgram = uni.navigateToMiniProgram;
|
|
708
|
+
if (!openMiniProgram) {
|
|
709
|
+
fail("当前平台不支持打开小程序", options);
|
|
710
|
+
return;
|
|
1158
711
|
}
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
712
|
+
openMiniProgram({
|
|
713
|
+
appId: url,
|
|
714
|
+
path: options.path || "",
|
|
715
|
+
envVersion: options.envVersion || "release",
|
|
716
|
+
extraData: options.extraData,
|
|
717
|
+
fail: onFail
|
|
718
|
+
});
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
if (type === "webview") {
|
|
722
|
+
fail(`H5:${url}`, options);
|
|
723
|
+
return;
|
|
1162
724
|
}
|
|
1163
|
-
|
|
725
|
+
uni.navigateTo({ url, fail: onFail });
|
|
726
|
+
}
|
|
727
|
+
function useNavigate() {
|
|
728
|
+
return {
|
|
729
|
+
navigate,
|
|
730
|
+
to: (url, options) => navigate("navigateTo", url, options),
|
|
731
|
+
redirect: (url, options) => navigate("redirectTo", url, options),
|
|
732
|
+
tab: (url, options) => navigate("switchTab", url, options),
|
|
733
|
+
reLaunch: (url, options) => navigate("reLaunch", url, options),
|
|
734
|
+
back: (delta = 1, options = {}) => navigate("navigateBack", "", { ...options, delta }),
|
|
735
|
+
miniProgram: (appId, options) => navigate("miniprogram", appId, options)
|
|
736
|
+
};
|
|
1164
737
|
}
|
|
1165
738
|
const useThemeStore = defineStore(
|
|
1166
739
|
"theme",
|
|
@@ -1306,7 +879,6 @@ function getCurrentFontScale() {
|
|
|
1306
879
|
function getCurrentFontVars() {
|
|
1307
880
|
return FONT_PRESETS[getCurrentFontScale()].vars;
|
|
1308
881
|
}
|
|
1309
|
-
const { hexToRgba, darkenHex } = useColor();
|
|
1310
882
|
const THEME_COLOR_KEY = "hlw_theme_color";
|
|
1311
883
|
const THEME_SEMANTIC_COLORS = {
|
|
1312
884
|
success: "#10b981",
|
|
@@ -1363,6 +935,25 @@ function getCurrentThemeVars() {
|
|
|
1363
935
|
"--info-dark": darkenHex(THEME_SEMANTIC_COLORS.info)
|
|
1364
936
|
};
|
|
1365
937
|
}
|
|
938
|
+
const HEX_RE = /^#[0-9a-fA-F]{6}$/;
|
|
939
|
+
function parseHex(hex) {
|
|
940
|
+
if (!HEX_RE.test(hex))
|
|
941
|
+
throw new Error(`Invalid hex color: ${hex}`);
|
|
942
|
+
return [
|
|
943
|
+
parseInt(hex.slice(1, 3), 16),
|
|
944
|
+
parseInt(hex.slice(3, 5), 16),
|
|
945
|
+
parseInt(hex.slice(5, 7), 16)
|
|
946
|
+
];
|
|
947
|
+
}
|
|
948
|
+
function hexToRgba(hex, alpha) {
|
|
949
|
+
const [r, g, b] = parseHex(hex);
|
|
950
|
+
return `rgba(${r},${g},${b},${alpha})`;
|
|
951
|
+
}
|
|
952
|
+
function darkenHex(hex, amount = 0.15) {
|
|
953
|
+
const [r, g, b] = parseHex(hex);
|
|
954
|
+
const darken = (value) => Math.max(0, Math.round(value * (1 - amount)));
|
|
955
|
+
return `#${darken(r).toString(16).padStart(2, "0")}${darken(g).toString(16).padStart(2, "0")}${darken(b).toString(16).padStart(2, "0")}`;
|
|
956
|
+
}
|
|
1366
957
|
const APPEARANCE_KEY = "hlw_appearance";
|
|
1367
958
|
const APPEARANCE_PRESETS = [
|
|
1368
959
|
{ value: "light", label: "浅色模式" },
|
|
@@ -1483,7 +1074,6 @@ function getCurrentTypographyVars() {
|
|
|
1483
1074
|
}
|
|
1484
1075
|
return vars;
|
|
1485
1076
|
}
|
|
1486
|
-
const { varsToStyle } = useColor();
|
|
1487
1077
|
const THEME_CHANGE_EVENT = "hlw:theme-change";
|
|
1488
1078
|
function buildThemeStyle() {
|
|
1489
1079
|
return varsToStyle({
|
|
@@ -1491,6 +1081,9 @@ function buildThemeStyle() {
|
|
|
1491
1081
|
...getCurrentThemeVars()
|
|
1492
1082
|
});
|
|
1493
1083
|
}
|
|
1084
|
+
function varsToStyle(vars) {
|
|
1085
|
+
return Object.entries(vars).map(([key, value]) => `${key}:${value}`).join(";") + ";";
|
|
1086
|
+
}
|
|
1494
1087
|
function useThemePageStyle() {
|
|
1495
1088
|
const store = useThemeStore();
|
|
1496
1089
|
const themePageStyle = computed(() => {
|
|
@@ -1500,17 +1093,8 @@ function useThemePageStyle() {
|
|
|
1500
1093
|
});
|
|
1501
1094
|
return { themePageStyle };
|
|
1502
1095
|
}
|
|
1503
|
-
function getErrorMessage(error) {
|
|
1504
|
-
if (error instanceof Error && error.message)
|
|
1505
|
-
return error.message;
|
|
1506
|
-
if (typeof error === "string" && error)
|
|
1507
|
-
return error;
|
|
1508
|
-
return "查询失败,请稍后重试";
|
|
1509
|
-
}
|
|
1510
1096
|
let _msg = null;
|
|
1511
|
-
let _device = null;
|
|
1512
1097
|
let _utils = null;
|
|
1513
|
-
let _color = null;
|
|
1514
1098
|
const hlw = {
|
|
1515
1099
|
/** 延迟创建消息提示实例。 */
|
|
1516
1100
|
get $msg() {
|
|
@@ -1518,269 +1102,16 @@ const hlw = {
|
|
|
1518
1102
|
},
|
|
1519
1103
|
/** 延迟读取并缓存设备信息。 */
|
|
1520
1104
|
get $device() {
|
|
1521
|
-
return
|
|
1105
|
+
return useDevice().info;
|
|
1522
1106
|
},
|
|
1523
|
-
/**
|
|
1524
|
-
$
|
|
1107
|
+
/** 复用全局请求实例。 */
|
|
1108
|
+
$request: useRequest(),
|
|
1525
1109
|
/** 延迟创建通用工具实例。 */
|
|
1526
1110
|
get $utils() {
|
|
1527
1111
|
return _utils ?? (_utils = useUtils());
|
|
1528
|
-
},
|
|
1529
|
-
/** 延迟创建颜色工具实例。 */
|
|
1530
|
-
get $color() {
|
|
1531
|
-
return _color ?? (_color = useColor());
|
|
1532
1112
|
}
|
|
1533
1113
|
};
|
|
1534
|
-
function getDefaultExportFromCjs(x) {
|
|
1535
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
1536
|
-
}
|
|
1537
|
-
var md5$1 = { exports: {} };
|
|
1538
|
-
var crypt = { exports: {} };
|
|
1539
|
-
(function() {
|
|
1540
|
-
var base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", crypt$1 = {
|
|
1541
|
-
// Bit-wise rotation left
|
|
1542
|
-
rotl: function(n, b) {
|
|
1543
|
-
return n << b | n >>> 32 - b;
|
|
1544
|
-
},
|
|
1545
|
-
// Bit-wise rotation right
|
|
1546
|
-
rotr: function(n, b) {
|
|
1547
|
-
return n << 32 - b | n >>> b;
|
|
1548
|
-
},
|
|
1549
|
-
// Swap big-endian to little-endian and vice versa
|
|
1550
|
-
endian: function(n) {
|
|
1551
|
-
if (n.constructor == Number) {
|
|
1552
|
-
return crypt$1.rotl(n, 8) & 16711935 | crypt$1.rotl(n, 24) & 4278255360;
|
|
1553
|
-
}
|
|
1554
|
-
for (var i = 0; i < n.length; i++)
|
|
1555
|
-
n[i] = crypt$1.endian(n[i]);
|
|
1556
|
-
return n;
|
|
1557
|
-
},
|
|
1558
|
-
// Generate an array of any length of random bytes
|
|
1559
|
-
randomBytes: function(n) {
|
|
1560
|
-
for (var bytes = []; n > 0; n--)
|
|
1561
|
-
bytes.push(Math.floor(Math.random() * 256));
|
|
1562
|
-
return bytes;
|
|
1563
|
-
},
|
|
1564
|
-
// Convert a byte array to big-endian 32-bit words
|
|
1565
|
-
bytesToWords: function(bytes) {
|
|
1566
|
-
for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)
|
|
1567
|
-
words[b >>> 5] |= bytes[i] << 24 - b % 32;
|
|
1568
|
-
return words;
|
|
1569
|
-
},
|
|
1570
|
-
// Convert big-endian 32-bit words to a byte array
|
|
1571
|
-
wordsToBytes: function(words) {
|
|
1572
|
-
for (var bytes = [], b = 0; b < words.length * 32; b += 8)
|
|
1573
|
-
bytes.push(words[b >>> 5] >>> 24 - b % 32 & 255);
|
|
1574
|
-
return bytes;
|
|
1575
|
-
},
|
|
1576
|
-
// Convert a byte array to a hex string
|
|
1577
|
-
bytesToHex: function(bytes) {
|
|
1578
|
-
for (var hex = [], i = 0; i < bytes.length; i++) {
|
|
1579
|
-
hex.push((bytes[i] >>> 4).toString(16));
|
|
1580
|
-
hex.push((bytes[i] & 15).toString(16));
|
|
1581
|
-
}
|
|
1582
|
-
return hex.join("");
|
|
1583
|
-
},
|
|
1584
|
-
// Convert a hex string to a byte array
|
|
1585
|
-
hexToBytes: function(hex) {
|
|
1586
|
-
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
|
1587
|
-
bytes.push(parseInt(hex.substr(c, 2), 16));
|
|
1588
|
-
return bytes;
|
|
1589
|
-
},
|
|
1590
|
-
// Convert a byte array to a base-64 string
|
|
1591
|
-
bytesToBase64: function(bytes) {
|
|
1592
|
-
for (var base64 = [], i = 0; i < bytes.length; i += 3) {
|
|
1593
|
-
var triplet = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
|
|
1594
|
-
for (var j = 0; j < 4; j++)
|
|
1595
|
-
if (i * 8 + j * 6 <= bytes.length * 8)
|
|
1596
|
-
base64.push(base64map.charAt(triplet >>> 6 * (3 - j) & 63));
|
|
1597
|
-
else
|
|
1598
|
-
base64.push("=");
|
|
1599
|
-
}
|
|
1600
|
-
return base64.join("");
|
|
1601
|
-
},
|
|
1602
|
-
// Convert a base-64 string to a byte array
|
|
1603
|
-
base64ToBytes: function(base64) {
|
|
1604
|
-
base64 = base64.replace(/[^A-Z0-9+\/]/ig, "");
|
|
1605
|
-
for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) {
|
|
1606
|
-
if (imod4 == 0)
|
|
1607
|
-
continue;
|
|
1608
|
-
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);
|
|
1609
|
-
}
|
|
1610
|
-
return bytes;
|
|
1611
|
-
}
|
|
1612
|
-
};
|
|
1613
|
-
crypt.exports = crypt$1;
|
|
1614
|
-
})();
|
|
1615
|
-
var cryptExports = crypt.exports;
|
|
1616
|
-
var charenc = {
|
|
1617
|
-
// UTF-8 encoding
|
|
1618
|
-
utf8: {
|
|
1619
|
-
// Convert a string to a byte array
|
|
1620
|
-
stringToBytes: function(str) {
|
|
1621
|
-
return charenc.bin.stringToBytes(unescape(encodeURIComponent(str)));
|
|
1622
|
-
},
|
|
1623
|
-
// Convert a byte array to a string
|
|
1624
|
-
bytesToString: function(bytes) {
|
|
1625
|
-
return decodeURIComponent(escape(charenc.bin.bytesToString(bytes)));
|
|
1626
|
-
}
|
|
1627
|
-
},
|
|
1628
|
-
// Binary encoding
|
|
1629
|
-
bin: {
|
|
1630
|
-
// Convert a string to a byte array
|
|
1631
|
-
stringToBytes: function(str) {
|
|
1632
|
-
for (var bytes = [], i = 0; i < str.length; i++)
|
|
1633
|
-
bytes.push(str.charCodeAt(i) & 255);
|
|
1634
|
-
return bytes;
|
|
1635
|
-
},
|
|
1636
|
-
// Convert a byte array to a string
|
|
1637
|
-
bytesToString: function(bytes) {
|
|
1638
|
-
for (var str = [], i = 0; i < bytes.length; i++)
|
|
1639
|
-
str.push(String.fromCharCode(bytes[i]));
|
|
1640
|
-
return str.join("");
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
};
|
|
1644
|
-
var charenc_1 = charenc;
|
|
1645
|
-
/*!
|
|
1646
|
-
* Determine if an object is a Buffer
|
|
1647
|
-
*
|
|
1648
|
-
* @author Feross Aboukhadijeh <https://feross.org>
|
|
1649
|
-
* @license MIT
|
|
1650
|
-
*/
|
|
1651
|
-
var isBuffer_1 = function(obj) {
|
|
1652
|
-
return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer);
|
|
1653
|
-
};
|
|
1654
|
-
function isBuffer(obj) {
|
|
1655
|
-
return !!obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
|
1656
|
-
}
|
|
1657
|
-
function isSlowBuffer(obj) {
|
|
1658
|
-
return typeof obj.readFloatLE === "function" && typeof obj.slice === "function" && isBuffer(obj.slice(0, 0));
|
|
1659
|
-
}
|
|
1660
|
-
(function() {
|
|
1661
|
-
var crypt2 = cryptExports, utf8 = charenc_1.utf8, isBuffer2 = isBuffer_1, bin = charenc_1.bin, md52 = function(message, options) {
|
|
1662
|
-
if (message.constructor == String)
|
|
1663
|
-
if (options && options.encoding === "binary")
|
|
1664
|
-
message = bin.stringToBytes(message);
|
|
1665
|
-
else
|
|
1666
|
-
message = utf8.stringToBytes(message);
|
|
1667
|
-
else if (isBuffer2(message))
|
|
1668
|
-
message = Array.prototype.slice.call(message, 0);
|
|
1669
|
-
else if (!Array.isArray(message) && message.constructor !== Uint8Array)
|
|
1670
|
-
message = message.toString();
|
|
1671
|
-
var m = crypt2.bytesToWords(message), l = message.length * 8, a = 1732584193, b = -271733879, c = -1732584194, d = 271733878;
|
|
1672
|
-
for (var i = 0; i < m.length; i++) {
|
|
1673
|
-
m[i] = (m[i] << 8 | m[i] >>> 24) & 16711935 | (m[i] << 24 | m[i] >>> 8) & 4278255360;
|
|
1674
|
-
}
|
|
1675
|
-
m[l >>> 5] |= 128 << l % 32;
|
|
1676
|
-
m[(l + 64 >>> 9 << 4) + 14] = l;
|
|
1677
|
-
var FF = md52._ff, GG = md52._gg, HH = md52._hh, II = md52._ii;
|
|
1678
|
-
for (var i = 0; i < m.length; i += 16) {
|
|
1679
|
-
var aa = a, bb = b, cc = c, dd = d;
|
|
1680
|
-
a = FF(a, b, c, d, m[i + 0], 7, -680876936);
|
|
1681
|
-
d = FF(d, a, b, c, m[i + 1], 12, -389564586);
|
|
1682
|
-
c = FF(c, d, a, b, m[i + 2], 17, 606105819);
|
|
1683
|
-
b = FF(b, c, d, a, m[i + 3], 22, -1044525330);
|
|
1684
|
-
a = FF(a, b, c, d, m[i + 4], 7, -176418897);
|
|
1685
|
-
d = FF(d, a, b, c, m[i + 5], 12, 1200080426);
|
|
1686
|
-
c = FF(c, d, a, b, m[i + 6], 17, -1473231341);
|
|
1687
|
-
b = FF(b, c, d, a, m[i + 7], 22, -45705983);
|
|
1688
|
-
a = FF(a, b, c, d, m[i + 8], 7, 1770035416);
|
|
1689
|
-
d = FF(d, a, b, c, m[i + 9], 12, -1958414417);
|
|
1690
|
-
c = FF(c, d, a, b, m[i + 10], 17, -42063);
|
|
1691
|
-
b = FF(b, c, d, a, m[i + 11], 22, -1990404162);
|
|
1692
|
-
a = FF(a, b, c, d, m[i + 12], 7, 1804603682);
|
|
1693
|
-
d = FF(d, a, b, c, m[i + 13], 12, -40341101);
|
|
1694
|
-
c = FF(c, d, a, b, m[i + 14], 17, -1502002290);
|
|
1695
|
-
b = FF(b, c, d, a, m[i + 15], 22, 1236535329);
|
|
1696
|
-
a = GG(a, b, c, d, m[i + 1], 5, -165796510);
|
|
1697
|
-
d = GG(d, a, b, c, m[i + 6], 9, -1069501632);
|
|
1698
|
-
c = GG(c, d, a, b, m[i + 11], 14, 643717713);
|
|
1699
|
-
b = GG(b, c, d, a, m[i + 0], 20, -373897302);
|
|
1700
|
-
a = GG(a, b, c, d, m[i + 5], 5, -701558691);
|
|
1701
|
-
d = GG(d, a, b, c, m[i + 10], 9, 38016083);
|
|
1702
|
-
c = GG(c, d, a, b, m[i + 15], 14, -660478335);
|
|
1703
|
-
b = GG(b, c, d, a, m[i + 4], 20, -405537848);
|
|
1704
|
-
a = GG(a, b, c, d, m[i + 9], 5, 568446438);
|
|
1705
|
-
d = GG(d, a, b, c, m[i + 14], 9, -1019803690);
|
|
1706
|
-
c = GG(c, d, a, b, m[i + 3], 14, -187363961);
|
|
1707
|
-
b = GG(b, c, d, a, m[i + 8], 20, 1163531501);
|
|
1708
|
-
a = GG(a, b, c, d, m[i + 13], 5, -1444681467);
|
|
1709
|
-
d = GG(d, a, b, c, m[i + 2], 9, -51403784);
|
|
1710
|
-
c = GG(c, d, a, b, m[i + 7], 14, 1735328473);
|
|
1711
|
-
b = GG(b, c, d, a, m[i + 12], 20, -1926607734);
|
|
1712
|
-
a = HH(a, b, c, d, m[i + 5], 4, -378558);
|
|
1713
|
-
d = HH(d, a, b, c, m[i + 8], 11, -2022574463);
|
|
1714
|
-
c = HH(c, d, a, b, m[i + 11], 16, 1839030562);
|
|
1715
|
-
b = HH(b, c, d, a, m[i + 14], 23, -35309556);
|
|
1716
|
-
a = HH(a, b, c, d, m[i + 1], 4, -1530992060);
|
|
1717
|
-
d = HH(d, a, b, c, m[i + 4], 11, 1272893353);
|
|
1718
|
-
c = HH(c, d, a, b, m[i + 7], 16, -155497632);
|
|
1719
|
-
b = HH(b, c, d, a, m[i + 10], 23, -1094730640);
|
|
1720
|
-
a = HH(a, b, c, d, m[i + 13], 4, 681279174);
|
|
1721
|
-
d = HH(d, a, b, c, m[i + 0], 11, -358537222);
|
|
1722
|
-
c = HH(c, d, a, b, m[i + 3], 16, -722521979);
|
|
1723
|
-
b = HH(b, c, d, a, m[i + 6], 23, 76029189);
|
|
1724
|
-
a = HH(a, b, c, d, m[i + 9], 4, -640364487);
|
|
1725
|
-
d = HH(d, a, b, c, m[i + 12], 11, -421815835);
|
|
1726
|
-
c = HH(c, d, a, b, m[i + 15], 16, 530742520);
|
|
1727
|
-
b = HH(b, c, d, a, m[i + 2], 23, -995338651);
|
|
1728
|
-
a = II(a, b, c, d, m[i + 0], 6, -198630844);
|
|
1729
|
-
d = II(d, a, b, c, m[i + 7], 10, 1126891415);
|
|
1730
|
-
c = II(c, d, a, b, m[i + 14], 15, -1416354905);
|
|
1731
|
-
b = II(b, c, d, a, m[i + 5], 21, -57434055);
|
|
1732
|
-
a = II(a, b, c, d, m[i + 12], 6, 1700485571);
|
|
1733
|
-
d = II(d, a, b, c, m[i + 3], 10, -1894986606);
|
|
1734
|
-
c = II(c, d, a, b, m[i + 10], 15, -1051523);
|
|
1735
|
-
b = II(b, c, d, a, m[i + 1], 21, -2054922799);
|
|
1736
|
-
a = II(a, b, c, d, m[i + 8], 6, 1873313359);
|
|
1737
|
-
d = II(d, a, b, c, m[i + 15], 10, -30611744);
|
|
1738
|
-
c = II(c, d, a, b, m[i + 6], 15, -1560198380);
|
|
1739
|
-
b = II(b, c, d, a, m[i + 13], 21, 1309151649);
|
|
1740
|
-
a = II(a, b, c, d, m[i + 4], 6, -145523070);
|
|
1741
|
-
d = II(d, a, b, c, m[i + 11], 10, -1120210379);
|
|
1742
|
-
c = II(c, d, a, b, m[i + 2], 15, 718787259);
|
|
1743
|
-
b = II(b, c, d, a, m[i + 9], 21, -343485551);
|
|
1744
|
-
a = a + aa >>> 0;
|
|
1745
|
-
b = b + bb >>> 0;
|
|
1746
|
-
c = c + cc >>> 0;
|
|
1747
|
-
d = d + dd >>> 0;
|
|
1748
|
-
}
|
|
1749
|
-
return crypt2.endian([a, b, c, d]);
|
|
1750
|
-
};
|
|
1751
|
-
md52._ff = function(a, b, c, d, x, s, t) {
|
|
1752
|
-
var n = a + (b & c | ~b & d) + (x >>> 0) + t;
|
|
1753
|
-
return (n << s | n >>> 32 - s) + b;
|
|
1754
|
-
};
|
|
1755
|
-
md52._gg = function(a, b, c, d, x, s, t) {
|
|
1756
|
-
var n = a + (b & d | c & ~d) + (x >>> 0) + t;
|
|
1757
|
-
return (n << s | n >>> 32 - s) + b;
|
|
1758
|
-
};
|
|
1759
|
-
md52._hh = function(a, b, c, d, x, s, t) {
|
|
1760
|
-
var n = a + (b ^ c ^ d) + (x >>> 0) + t;
|
|
1761
|
-
return (n << s | n >>> 32 - s) + b;
|
|
1762
|
-
};
|
|
1763
|
-
md52._ii = function(a, b, c, d, x, s, t) {
|
|
1764
|
-
var n = a + (c ^ (b | ~d)) + (x >>> 0) + t;
|
|
1765
|
-
return (n << s | n >>> 32 - s) + b;
|
|
1766
|
-
};
|
|
1767
|
-
md52._blocksize = 16;
|
|
1768
|
-
md52._digestsize = 16;
|
|
1769
|
-
md5$1.exports = function(message, options) {
|
|
1770
|
-
if (message === void 0 || message === null)
|
|
1771
|
-
throw new Error("Illegal argument " + message);
|
|
1772
|
-
var digestbytes = crypt2.wordsToBytes(md52(message, options));
|
|
1773
|
-
return options && options.asBytes ? digestbytes : options && options.asString ? bin.bytesToString(digestbytes) : crypt2.bytesToHex(digestbytes);
|
|
1774
|
-
};
|
|
1775
|
-
})();
|
|
1776
|
-
var md5Exports = md5$1.exports;
|
|
1777
|
-
const md5 = /* @__PURE__ */ getDefaultExportFromCjs(md5Exports);
|
|
1778
1114
|
let _installed = false;
|
|
1779
|
-
let _interceptorCleanup = [];
|
|
1780
|
-
const _defaultOpts = {
|
|
1781
|
-
tokenHeader: "x-token",
|
|
1782
|
-
autoToastError: true
|
|
1783
|
-
};
|
|
1784
1115
|
function useApp() {
|
|
1785
1116
|
const _plugins = [];
|
|
1786
1117
|
function use(pluginOrInstaller) {
|
|
@@ -1799,94 +1130,7 @@ function useApp() {
|
|
|
1799
1130
|
}
|
|
1800
1131
|
return createApp;
|
|
1801
1132
|
}
|
|
1802
|
-
return { install, use, hlw,
|
|
1803
|
-
}
|
|
1804
|
-
function buildSignString(url) {
|
|
1805
|
-
try {
|
|
1806
|
-
const [path, query] = url.split("?");
|
|
1807
|
-
if (!query)
|
|
1808
|
-
return path + "&";
|
|
1809
|
-
const params = query.split("&").filter(Boolean);
|
|
1810
|
-
params.sort();
|
|
1811
|
-
return params.join("&") + "&";
|
|
1812
|
-
} catch {
|
|
1813
|
-
return url;
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
let _sigSecret = "";
|
|
1817
|
-
function setupInterceptors(options = {}) {
|
|
1818
|
-
const opts = { ..._defaultOpts, ...options };
|
|
1819
|
-
if (opts.sigSecret)
|
|
1820
|
-
_sigSecret = opts.sigSecret;
|
|
1821
|
-
if (opts.baseURL)
|
|
1822
|
-
http.setBaseURL(opts.baseURL);
|
|
1823
|
-
_interceptorCleanup.forEach((dispose) => dispose());
|
|
1824
|
-
_interceptorCleanup = [];
|
|
1825
|
-
const offRequest = http.onRequest((config2) => {
|
|
1826
|
-
const method = (config2.method ?? "GET").toUpperCase();
|
|
1827
|
-
if (method === "GET" && config2.data && typeof config2.data === "object") {
|
|
1828
|
-
const qs = Object.entries(config2.data).filter(([, v]) => v !== void 0 && v !== null).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`).join("&");
|
|
1829
|
-
if (qs) {
|
|
1830
|
-
config2.url = config2.url + (config2.url.includes("?") ? "&" : "?") + qs;
|
|
1831
|
-
}
|
|
1832
|
-
config2.data = void 0;
|
|
1833
|
-
}
|
|
1834
|
-
const device = useDevice();
|
|
1835
|
-
if (device.value) {
|
|
1836
|
-
const d = device.value;
|
|
1837
|
-
const query = [
|
|
1838
|
-
["appid", d.appid],
|
|
1839
|
-
["device_brand", d.device_brand],
|
|
1840
|
-
["device_model", d.device_model],
|
|
1841
|
-
["device_id", d.device_id],
|
|
1842
|
-
["device_type", d.device_type],
|
|
1843
|
-
["device_orientation", d.device_orientation],
|
|
1844
|
-
["platform", d.platform],
|
|
1845
|
-
["system", d.system],
|
|
1846
|
-
["os", d.os],
|
|
1847
|
-
["version", d.version],
|
|
1848
|
-
["sdk_version", d.sdk_version],
|
|
1849
|
-
["host_name", d.host_name],
|
|
1850
|
-
["host_version", d.host_version],
|
|
1851
|
-
["host_language", d.host_language],
|
|
1852
|
-
["language", d.language],
|
|
1853
|
-
["app_version", d.app_version],
|
|
1854
|
-
["app_version_code", d.app_version_code],
|
|
1855
|
-
["screen_width", String(d.screen_width)],
|
|
1856
|
-
["screen_height", String(d.screen_height)]
|
|
1857
|
-
].map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v ?? "")}`).join("&");
|
|
1858
|
-
config2.url = config2.url + (config2.url.includes("?") ? "&" : "?") + query;
|
|
1859
|
-
config2.headers = { ...config2.headers, "X-Appid": d.appid };
|
|
1860
|
-
}
|
|
1861
|
-
if (_sigSecret) {
|
|
1862
|
-
const signStr = buildSignString(config2.url);
|
|
1863
|
-
const sig = md5(signStr + _sigSecret);
|
|
1864
|
-
config2.url = config2.url + "&sig=" + sig;
|
|
1865
|
-
}
|
|
1866
|
-
if (opts.getToken) {
|
|
1867
|
-
const token = opts.getToken();
|
|
1868
|
-
if (token) {
|
|
1869
|
-
config2.headers = {
|
|
1870
|
-
...config2.headers,
|
|
1871
|
-
[opts.tokenHeader]: token
|
|
1872
|
-
};
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
return config2;
|
|
1876
|
-
});
|
|
1877
|
-
const offResponse = http.onResponse((res) => {
|
|
1878
|
-
if (opts.autoToastError && res.code !== 1) {
|
|
1879
|
-
uni.showToast({ title: res.info || "请求失败", icon: "none" });
|
|
1880
|
-
}
|
|
1881
|
-
return res;
|
|
1882
|
-
});
|
|
1883
|
-
const offError = http.onError((err) => {
|
|
1884
|
-
var _a;
|
|
1885
|
-
if (err.message.includes("401")) {
|
|
1886
|
-
(_a = opts.onLogout) == null ? void 0 : _a.call(opts);
|
|
1887
|
-
}
|
|
1888
|
-
});
|
|
1889
|
-
_interceptorCleanup = [offRequest, offResponse, offError];
|
|
1133
|
+
return { install, use, hlw, request: useRequest() };
|
|
1890
1134
|
}
|
|
1891
1135
|
function copyText(data) {
|
|
1892
1136
|
uni.setClipboardData({
|
|
@@ -1926,10 +1170,12 @@ export {
|
|
|
1926
1170
|
APPEARANCE_KEY,
|
|
1927
1171
|
APPEARANCE_PRESETS,
|
|
1928
1172
|
APPEARANCE_VAR_MAP,
|
|
1173
|
+
BaseService,
|
|
1929
1174
|
DEFAULT_THEMES,
|
|
1930
1175
|
FONT_PRESETS,
|
|
1931
1176
|
FONT_SCALE_KEY,
|
|
1932
|
-
|
|
1177
|
+
ServiceNamespace,
|
|
1178
|
+
ServicePrefix,
|
|
1933
1179
|
THEME_CHANGE_EVENT,
|
|
1934
1180
|
THEME_COLOR_KEY,
|
|
1935
1181
|
THEME_SEMANTIC_COLORS,
|
|
@@ -1939,8 +1185,6 @@ export {
|
|
|
1939
1185
|
buildThemeStyle,
|
|
1940
1186
|
clearDeviceCache,
|
|
1941
1187
|
cosAdapter,
|
|
1942
|
-
destroyAds,
|
|
1943
|
-
deviceToQuery,
|
|
1944
1188
|
getAdapter,
|
|
1945
1189
|
getCurrentAppearance,
|
|
1946
1190
|
getCurrentAppearanceMode,
|
|
@@ -1950,36 +1194,20 @@ export {
|
|
|
1950
1194
|
getCurrentThemeColor,
|
|
1951
1195
|
getCurrentThemeVars,
|
|
1952
1196
|
getCurrentTypographyVars,
|
|
1953
|
-
getErrorMessage,
|
|
1954
1197
|
hlw,
|
|
1955
|
-
http,
|
|
1956
1198
|
ossAdapter,
|
|
1957
1199
|
qiniuAdapter,
|
|
1958
1200
|
resolveAppearance,
|
|
1959
|
-
setConfigAd,
|
|
1960
|
-
setConfigContact,
|
|
1961
|
-
setConfigShare,
|
|
1962
|
-
setupInterceptors,
|
|
1963
|
-
useAd,
|
|
1964
1201
|
useApp,
|
|
1965
|
-
useColor,
|
|
1966
|
-
useContact,
|
|
1967
1202
|
useDevice,
|
|
1968
|
-
useFormat,
|
|
1969
|
-
useLoading,
|
|
1970
1203
|
useMsg,
|
|
1971
|
-
|
|
1204
|
+
useNavigate,
|
|
1972
1205
|
useRefs,
|
|
1973
1206
|
useRequest,
|
|
1974
|
-
useRouter,
|
|
1975
1207
|
useShare,
|
|
1976
|
-
useShareConfig,
|
|
1977
|
-
useStorage,
|
|
1978
1208
|
useThemePageStyle,
|
|
1979
1209
|
useThemeStore,
|
|
1980
1210
|
useUpload,
|
|
1981
1211
|
useUtils,
|
|
1982
|
-
useUuid,
|
|
1983
|
-
useValidate,
|
|
1984
1212
|
vCopy
|
|
1985
1213
|
};
|