nvue3 1.1.27 → 1.1.29
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/package.json +1 -1
- package/src/http.js +89 -77
- package/src/soft.js +15 -20
package/package.json
CHANGED
package/src/http.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tstShow = 350;
|
|
1
|
+
const tstShow = 350; //如果请求太快,toast会一闪而过,这里限制为至少350ms后执行hideLoading
|
|
2
|
+
const nextPost = []; //页面不紧急的消息暂存在这里,下一次请求时顺带捎上_append
|
|
3
|
+
const failBox = []; //保存错误消息,若服务器不可达,则临时存在这里
|
|
5
4
|
const isDebug = (process.env.NODE_ENV === 'development');
|
|
6
|
-
const nextPost = [];
|
|
7
|
-
const failBox = [];
|
|
8
5
|
|
|
9
6
|
const baseResp = {
|
|
10
7
|
success: 1,
|
|
@@ -14,15 +11,32 @@ const baseResp = {
|
|
|
14
11
|
};
|
|
15
12
|
|
|
16
13
|
const toastConf = {
|
|
17
|
-
'l': '
|
|
18
|
-
'r': '
|
|
19
|
-
'f': '
|
|
20
|
-
's': '
|
|
21
|
-
'd': '
|
|
22
|
-
'm': '
|
|
23
|
-
'p': '
|
|
14
|
+
'l': 'Loading...',
|
|
15
|
+
'r': 'Reading ...',
|
|
16
|
+
'f': 'Refreshing...',
|
|
17
|
+
's': 'Saving...',
|
|
18
|
+
'd': 'Deletion...',
|
|
19
|
+
'm': 'Sending...',
|
|
20
|
+
'p': 'Paying...',
|
|
24
21
|
};
|
|
25
22
|
|
|
23
|
+
const dimMsg = {
|
|
24
|
+
apierr: 'The API request target must be a string type address and must be mandatory',
|
|
25
|
+
cert: 'Network error or certificate error',
|
|
26
|
+
failed: 'Data request failed',
|
|
27
|
+
system: 'System exception',
|
|
28
|
+
server: 'Server connection failed',
|
|
29
|
+
timeout: 'Connection timeout, please check the network',
|
|
30
|
+
resolve: 'Unable to resolve host',
|
|
31
|
+
network: 'Network request failed',
|
|
32
|
+
bakin: 'Currently using a backup line, should we switch to the main line?',
|
|
33
|
+
bakout: 'Should we switch to the backup line?',
|
|
34
|
+
valid: 'The server did not respond with valid data',
|
|
35
|
+
upload: 'Upload failed',
|
|
36
|
+
frequent: 'Operation too frequent',
|
|
37
|
+
notexist: 'File does not exist',
|
|
38
|
+
}
|
|
39
|
+
|
|
26
40
|
const aliasConf = {};
|
|
27
41
|
|
|
28
42
|
const config = {
|
|
@@ -38,25 +52,28 @@ let justModalTime = 0;
|
|
|
38
52
|
let justPostTime = 0;
|
|
39
53
|
let justPostApi = '';
|
|
40
54
|
|
|
41
|
-
|
|
42
|
-
|
|
43
55
|
const _request = class {
|
|
44
56
|
|
|
45
57
|
constructor(uri, data, method) {
|
|
46
58
|
this.method = method.toUpperCase();
|
|
59
|
+
|
|
47
60
|
if (!data || data === undefined) data = {};
|
|
48
61
|
if (typeof data !== 'object') data = { value: data };
|
|
49
|
-
if ((typeof uri !== 'string') || (!uri)) {
|
|
50
|
-
console.error('error', uri)
|
|
51
|
-
throw new Error('api 请求目标必须是string类型地址,且必填');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
62
|
if ((nextPost.length > 0) && (this.method === 'POST')) {
|
|
55
63
|
data._append = JSON.parse(JSON.stringify(nextPost));
|
|
56
64
|
nextPost.length = 0;
|
|
57
65
|
}
|
|
66
|
+
this.request = data;
|
|
58
67
|
|
|
59
|
-
|
|
68
|
+
if ((typeof uri !== 'string') || (!uri)) {
|
|
69
|
+
if (isDebug) console.error('error', uri)
|
|
70
|
+
throw new Error(dimMsg.apierr);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (uri.slice(0, 4) === 'http') {
|
|
74
|
+
this.api = uri;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
60
77
|
|
|
61
78
|
if (uri[0] === '!') { //uri第1个字符为!,静默处理
|
|
62
79
|
this.silent = true;
|
|
@@ -67,20 +84,12 @@ const _request = class {
|
|
|
67
84
|
uri = uri.slice(1);
|
|
68
85
|
}
|
|
69
86
|
|
|
70
|
-
if (uri.slice(0, 4) === 'http') {
|
|
71
|
-
//https://domain.com/cont/action
|
|
72
|
-
let tmp = uri.split('/');
|
|
73
|
-
uri = '/' + tmp.slice(3).join('/'); //提取URL中的uri部分
|
|
74
|
-
host = `${tmp[0]}//${tmp[2]}`; //提取URL中的host部分
|
|
75
|
-
}
|
|
76
|
-
|
|
77
87
|
if (uri[0] !== '/') { //uri第1个字符为toast,提取出来
|
|
78
88
|
this.toast = toastConf[uri[0]] || '';
|
|
79
89
|
uri = uri.slice(1);
|
|
80
90
|
}
|
|
81
91
|
|
|
82
|
-
this.api =
|
|
83
|
-
this.request = data;
|
|
92
|
+
this.api = config.path + apiAlias(uri);
|
|
84
93
|
}
|
|
85
94
|
|
|
86
95
|
api = '';
|
|
@@ -109,7 +118,6 @@ const _request = class {
|
|
|
109
118
|
response = {};
|
|
110
119
|
}
|
|
111
120
|
|
|
112
|
-
|
|
113
121
|
function apiAlias(api) {
|
|
114
122
|
let uri = api.split('/');
|
|
115
123
|
if (!uri[1]) uri[1] = 'index';
|
|
@@ -132,6 +140,8 @@ function apiAlias(api) {
|
|
|
132
140
|
|
|
133
141
|
/**
|
|
134
142
|
* 请求后台数据出错时,统一弹窗
|
|
143
|
+
*
|
|
144
|
+
*
|
|
135
145
|
*/
|
|
136
146
|
function failMessage(RFM, resolve, reject) {
|
|
137
147
|
|
|
@@ -141,10 +151,10 @@ function failMessage(RFM, resolve, reject) {
|
|
|
141
151
|
RFM.loading = false;
|
|
142
152
|
uni.hideLoading();
|
|
143
153
|
uni.showToast({
|
|
144
|
-
title:
|
|
154
|
+
title: dim.dimMsg,
|
|
145
155
|
icon: 'none'
|
|
146
156
|
});
|
|
147
|
-
reject({ error: 1, message:
|
|
157
|
+
reject({ error: 1, message: dim.dimMsg });
|
|
148
158
|
return;
|
|
149
159
|
}
|
|
150
160
|
if (typeof reject !== 'function') reject = () => {};
|
|
@@ -168,7 +178,7 @@ function failMessage(RFM, resolve, reject) {
|
|
|
168
178
|
const { title, message, cancel } = RFM.response.modal;
|
|
169
179
|
uni.showModal({
|
|
170
180
|
showCancel: Boolean(cancel || false),
|
|
171
|
-
title: title ||
|
|
181
|
+
title: title || dimMsg.failed,
|
|
172
182
|
content: message || RFM.message,
|
|
173
183
|
success(res) {
|
|
174
184
|
RFM.response.confirm = res.confirm;
|
|
@@ -264,7 +274,7 @@ function doSuccess(REQ, res, resolve, reject) {
|
|
|
264
274
|
else {
|
|
265
275
|
//PHP框架级错误,得到的是一个json格式错误信息,基本为php直接返回非200的状态
|
|
266
276
|
REQ.error = REQ.response.error || 502;
|
|
267
|
-
REQ.message = REQ.response.message ||
|
|
277
|
+
REQ.message = REQ.response.message || dimMsg.system;
|
|
268
278
|
Object.assign(REQ.response, baseResp, {
|
|
269
279
|
success: 0,
|
|
270
280
|
error: REQ.error,
|
|
@@ -276,9 +286,9 @@ function doSuccess(REQ, res, resolve, reject) {
|
|
|
276
286
|
}
|
|
277
287
|
catch (err) {
|
|
278
288
|
//上面try里自身出错
|
|
279
|
-
console.error(err)
|
|
289
|
+
if (isDebug) console.error(err)
|
|
280
290
|
REQ.error = 9;
|
|
281
|
-
REQ.message = err.description || err.message ||
|
|
291
|
+
REQ.message = err.description || err.message || dimMsg.system;
|
|
282
292
|
Object.assign(REQ.response, baseResp, {
|
|
283
293
|
success: 0,
|
|
284
294
|
error: 9
|
|
@@ -298,25 +308,51 @@ function doFail(REF, res, resolve, reject) {
|
|
|
298
308
|
host: info[2],
|
|
299
309
|
port: info[3]
|
|
300
310
|
}
|
|
301
|
-
res.
|
|
311
|
+
res.message = dimMsg.server + info[2];
|
|
302
312
|
}
|
|
303
313
|
else if (res.errMsg.includes('timeout')) {
|
|
304
|
-
res.
|
|
314
|
+
res.message = dimMsg.timeout;
|
|
305
315
|
}
|
|
306
|
-
else if (res.errMsg.includes('Unable to resolve host')) {
|
|
307
|
-
res.
|
|
316
|
+
else if (res.errMsg.includes('Unable to resolve host') || res.errMsg.includes('NAME_NOT_RESOLVED')) {
|
|
317
|
+
res.message = dimMsg.resolve;
|
|
318
|
+
|
|
319
|
+
if (import.meta.env.VITE_API_BACKUP) {
|
|
320
|
+
if (config.path === import.meta.env.VITE_API_BACKUP) {
|
|
321
|
+
uni.showModal({
|
|
322
|
+
title: dimMsg.network,
|
|
323
|
+
content: dimMsg.bakin,
|
|
324
|
+
showCancel: true,
|
|
325
|
+
success(cnf) {
|
|
326
|
+
if (cnf.confirm) {
|
|
327
|
+
config.path = import.meta.env.VITE_API;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
uni.showModal({
|
|
334
|
+
title: dimMsg.network,
|
|
335
|
+
content: dimMsg.bakout,
|
|
336
|
+
showCancel: true,
|
|
337
|
+
success(cnf) {
|
|
338
|
+
if (cnf.confirm) {
|
|
339
|
+
config.path = import.meta.env.VITE_API_BACKUP;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
}
|
|
346
|
+
|
|
308
347
|
}
|
|
309
|
-
else
|
|
310
|
-
res.errMsg
|
|
348
|
+
else {
|
|
349
|
+
let mer = res.errMsg.match(/<title>(.+)<\/title>/);
|
|
350
|
+
if (mer) res.message = mer[1];
|
|
311
351
|
}
|
|
312
352
|
|
|
313
|
-
let mer = res.errMsg.match(/<title>(.+)<\/title>/);
|
|
314
|
-
if (mer) res.errMsg = mer[1];
|
|
315
|
-
|
|
316
|
-
res.message = res.errMsg;
|
|
317
353
|
REF.response = res;
|
|
318
354
|
REF.header.get = res.header;
|
|
319
|
-
REF.message = res.
|
|
355
|
+
REF.message = res.message;
|
|
320
356
|
REF.code = res.statusCode || -1;
|
|
321
357
|
REF.error = 1;
|
|
322
358
|
failMessage(REF, resolve, reject);
|
|
@@ -343,15 +379,11 @@ function doComplete(request, res, resolve, reject) {
|
|
|
343
379
|
console.log(request)
|
|
344
380
|
}
|
|
345
381
|
|
|
346
|
-
|
|
347
382
|
function postFailBox() {
|
|
348
383
|
if (failBox.length === 0) return;
|
|
349
384
|
return doRequest(new _request(`!${api}`, failBox, 'post'));
|
|
350
385
|
}
|
|
351
386
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
387
|
async function doRequest(request) {
|
|
356
388
|
|
|
357
389
|
if (request.toast) {
|
|
@@ -362,7 +394,6 @@ async function doRequest(request) {
|
|
|
362
394
|
});
|
|
363
395
|
}
|
|
364
396
|
|
|
365
|
-
|
|
366
397
|
return new Promise(async (resolve, reject) => {
|
|
367
398
|
request.timer.ready = Date.now();
|
|
368
399
|
request.header.put = await processor.header(request.api, request.request, request.method);
|
|
@@ -394,14 +425,10 @@ async function doRequest(request) {
|
|
|
394
425
|
});
|
|
395
426
|
}
|
|
396
427
|
|
|
397
|
-
|
|
398
428
|
function thisPost(api, data = {}) {
|
|
399
429
|
return doRequest(new _request(api, data, 'post'));
|
|
400
430
|
}
|
|
401
431
|
|
|
402
|
-
/**
|
|
403
|
-
* @param {Object} option
|
|
404
|
-
*/
|
|
405
432
|
/**
|
|
406
433
|
* @param {Object} uri
|
|
407
434
|
* @param {Object} option
|
|
@@ -426,7 +453,7 @@ async function doUploadAliYun(uri, option) {
|
|
|
426
453
|
const { url, formData, name, save } = resConf.data;
|
|
427
454
|
// console.log({ url, formData, name });
|
|
428
455
|
if (!url) {
|
|
429
|
-
return reject({ success: false, error: 505, message:
|
|
456
|
+
return reject({ success: false, error: 505, message: dimMsg.valid });
|
|
430
457
|
}
|
|
431
458
|
|
|
432
459
|
uni.uploadFile({
|
|
@@ -462,10 +489,9 @@ async function doUploadAliYun(uri, option) {
|
|
|
462
489
|
}
|
|
463
490
|
|
|
464
491
|
else {
|
|
465
|
-
reject({ success: false, error: resUp.statusCode, message:
|
|
492
|
+
reject({ success: false, error: resUp.statusCode, message: dimMsg.upload });
|
|
466
493
|
}
|
|
467
494
|
|
|
468
|
-
|
|
469
495
|
},
|
|
470
496
|
fail: errUp => {
|
|
471
497
|
// console.log({ errUp });
|
|
@@ -480,15 +506,9 @@ async function doUploadAliYun(uri, option) {
|
|
|
480
506
|
}
|
|
481
507
|
);
|
|
482
508
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
509
|
})
|
|
489
510
|
}
|
|
490
511
|
|
|
491
|
-
|
|
492
512
|
/**
|
|
493
513
|
* 操作频率检查
|
|
494
514
|
* @param {Object} api
|
|
@@ -503,7 +523,7 @@ async function FrequencyDetection(api) {
|
|
|
503
523
|
// console.log({ nowTime, justPostTime, just: nowTime - justPostTime, detection: config.detection });
|
|
504
524
|
|
|
505
525
|
return new Promise((resolve, reject) => {
|
|
506
|
-
reject({ error: 1, success: 0, message:
|
|
526
|
+
reject({ error: 1, success: 0, message: dimMsg.frequent })
|
|
507
527
|
});
|
|
508
528
|
|
|
509
529
|
}
|
|
@@ -514,8 +534,6 @@ async function FrequencyDetection(api) {
|
|
|
514
534
|
return null; //操作正常,可以继续
|
|
515
535
|
}
|
|
516
536
|
|
|
517
|
-
|
|
518
|
-
|
|
519
537
|
async function downloadFile(url, callback) {
|
|
520
538
|
|
|
521
539
|
const key = url.md5();
|
|
@@ -549,7 +567,7 @@ async function downloadFile(url, callback) {
|
|
|
549
567
|
}
|
|
550
568
|
else {
|
|
551
569
|
console.log('download null', { res })
|
|
552
|
-
resolve({ success: false, message:
|
|
570
|
+
resolve({ success: false, message: dimMsg.notexist })
|
|
553
571
|
}
|
|
554
572
|
},
|
|
555
573
|
fail: err => {
|
|
@@ -569,13 +587,10 @@ async function downloadFile(url, callback) {
|
|
|
569
587
|
|
|
570
588
|
});
|
|
571
589
|
|
|
572
|
-
|
|
573
|
-
|
|
574
590
|
});
|
|
575
591
|
|
|
576
592
|
}
|
|
577
593
|
|
|
578
|
-
|
|
579
594
|
return new Promise(async (resolve, reject) => {
|
|
580
595
|
|
|
581
596
|
let cache = uni.getStorageSync(key);
|
|
@@ -602,8 +617,6 @@ async function downloadFile(url, callback) {
|
|
|
602
617
|
|
|
603
618
|
}
|
|
604
619
|
|
|
605
|
-
|
|
606
|
-
|
|
607
620
|
export default class {
|
|
608
621
|
processor = null;
|
|
609
622
|
|
|
@@ -612,6 +625,7 @@ export default class {
|
|
|
612
625
|
for (let k in config) config[k] = conf[k];
|
|
613
626
|
if (conf.toast) Object.assign(toastConf, conf.toast);
|
|
614
627
|
if (conf.alias) Object.assign(aliasConf, conf.alias);
|
|
628
|
+
if (conf.locale) Object.assign(dimMsg, conf.locale);
|
|
615
629
|
if (isDebug) console.log(config);
|
|
616
630
|
}
|
|
617
631
|
|
|
@@ -658,6 +672,4 @@ export default class {
|
|
|
658
672
|
return await downloadFile(uri, callback);
|
|
659
673
|
}
|
|
660
674
|
|
|
661
|
-
|
|
662
|
-
|
|
663
675
|
};
|
package/src/soft.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default class {
|
|
2
2
|
system = ''; //操作系统及版本
|
|
3
|
-
platform = process.env.VUE_APP_PLATFORM; //mp-weixin,h5,app
|
|
3
|
+
platform = process.env.VUE_APP_PLATFORM; //mp-weixin,h5,app等
|
|
4
4
|
mode = process.env.NODE_ENV; //运行环境
|
|
5
5
|
|
|
6
6
|
brand = ''; //手机品牌,huawei,xiaomi,vivo,oppo
|
|
@@ -9,7 +9,7 @@ export default class {
|
|
|
9
9
|
|
|
10
10
|
singlePage = false; //是否从朋友圈进入的单页模式
|
|
11
11
|
|
|
12
|
-
// #ifdef APP
|
|
12
|
+
// #ifdef APP
|
|
13
13
|
os = '';
|
|
14
14
|
ua = '';
|
|
15
15
|
packName = ''; //APP包名
|
|
@@ -96,10 +96,10 @@ export default class {
|
|
|
96
96
|
const system = uni.getSystemInfoSync();
|
|
97
97
|
|
|
98
98
|
this.brand = (system.brand || 'unknow').toLowerCase(); //手机品牌
|
|
99
|
-
this.name = system.name || 'unknow'; //应用名称
|
|
99
|
+
this.name = system.appName || system.name || 'unknow'; //应用名称
|
|
100
100
|
this.model = system.model || 'unknow'; //手机品牌下的型号
|
|
101
101
|
this.devid = system.deviceId || 'unknow'; //设备唯一编码
|
|
102
|
-
this.sdk = system.SDKVersion || '0.0.0'; //小程序主版本号
|
|
102
|
+
this.sdk = system.SDKVersion || system.hostSDKVersion || '0.0.0'; //小程序主版本号
|
|
103
103
|
this.appid = system.appId;
|
|
104
104
|
this.os = system.osName;
|
|
105
105
|
this.osver = system.osVersion;
|
|
@@ -141,7 +141,6 @@ export default class {
|
|
|
141
141
|
if (!this.version) this.version = accountTou.microapp.envType;
|
|
142
142
|
// #endif
|
|
143
143
|
|
|
144
|
-
|
|
145
144
|
//胶囊按钮
|
|
146
145
|
// #ifdef MP-WEIXIN||MP-ALIPAY||MP-BAIDU||MP-TOUTIAO||MP-QQ
|
|
147
146
|
this.size.button = uni.getMenuButtonBoundingClientRect();
|
|
@@ -152,7 +151,7 @@ export default class {
|
|
|
152
151
|
this.size.button = { bottom: 56, height: 32, left: (width - 94), right: (width - 7), top: 24, width: 87 };
|
|
153
152
|
// #endif
|
|
154
153
|
|
|
155
|
-
// #ifdef APP
|
|
154
|
+
// #ifdef APP
|
|
156
155
|
this.os = plus.os.name.toLowerCase(); //操作系统,android或ios
|
|
157
156
|
this.osver = plus.os.version; //操作系统版本号
|
|
158
157
|
this.version = import.meta.env.VITE_VERSION; //热更包版本号
|
|
@@ -184,7 +183,6 @@ export default class {
|
|
|
184
183
|
});
|
|
185
184
|
}
|
|
186
185
|
|
|
187
|
-
|
|
188
186
|
plus.device.getInfo({
|
|
189
187
|
success: (res) => {
|
|
190
188
|
// console.log('plus.device.getInfo', res)
|
|
@@ -206,8 +204,6 @@ export default class {
|
|
|
206
204
|
|
|
207
205
|
}
|
|
208
206
|
|
|
209
|
-
|
|
210
|
-
|
|
211
207
|
/**
|
|
212
208
|
* 设置屏幕常亮
|
|
213
209
|
*
|
|
@@ -220,7 +216,7 @@ export default class {
|
|
|
220
216
|
keepScreenOn: keep
|
|
221
217
|
});
|
|
222
218
|
//#endif
|
|
223
|
-
//#ifdef APP
|
|
219
|
+
//#ifdef APP
|
|
224
220
|
plus.device.setWakelock(keep);
|
|
225
221
|
//#endif
|
|
226
222
|
}
|
|
@@ -235,7 +231,7 @@ export default class {
|
|
|
235
231
|
version: this.version,
|
|
236
232
|
theme: this.theme,
|
|
237
233
|
|
|
238
|
-
//#ifdef APP
|
|
234
|
+
//#ifdef APP
|
|
239
235
|
os: this.os,
|
|
240
236
|
packName: this.packName,
|
|
241
237
|
simulator: this.simulator, //模拟器可能性判断,oaid,aaid,uuid其中任一个读取出错各加1
|
|
@@ -248,7 +244,6 @@ export default class {
|
|
|
248
244
|
}
|
|
249
245
|
}
|
|
250
246
|
|
|
251
|
-
|
|
252
247
|
/**
|
|
253
248
|
* 为了防止快速点按返回键导致程序退出重写quit方法改为隐藏至后台
|
|
254
249
|
* 重写toast方法如果内容为 ‘再次返回退出应用’ 就隐藏应用,其他正常toast
|
|
@@ -264,18 +259,18 @@ export default class {
|
|
|
264
259
|
/**
|
|
265
260
|
* 再次返回退出应用
|
|
266
261
|
*/
|
|
267
|
-
|
|
262
|
+
const title = 'Press again to exit the application';
|
|
263
|
+
if (str === title) {
|
|
268
264
|
plus.runtime.quit();
|
|
265
|
+
return;
|
|
269
266
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
267
|
+
|
|
268
|
+
uni.showToast({
|
|
269
|
+
title,
|
|
270
|
+
icon: 'none'
|
|
271
|
+
})
|
|
276
272
|
});
|
|
277
273
|
|
|
278
274
|
}
|
|
279
275
|
|
|
280
|
-
|
|
281
276
|
}
|