@10yun/cv-mobile-ui 0.5.35 → 0.5.36

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.
@@ -0,0 +1,570 @@
1
+ let log = console.log; // 如果在项目的APP.vue文件中的onlaunch中设置 console.log = ()=> {} 则在此也不会有打印信息
2
+ log = () => {}; // 打开注释则该插件不会打印任何信息
3
+ let _app = {
4
+ //交互控制
5
+ log(t) {
6
+ log(t);
7
+ }, // 打印控制,
8
+ showLoading(msg, ifmask) {
9
+ uni.showLoading({
10
+ title: msg,
11
+ mask: ifmask || false
12
+ });
13
+ },
14
+ hideLoading() {
15
+ uni.hideLoading();
16
+ },
17
+ showToast(msg, icon) {
18
+ uni.showToast({
19
+ title: msg,
20
+ icon: icon || 'none'
21
+ });
22
+ },
23
+ getPosterUrl(objs) {
24
+ // 后端获取背景图的url路径方法
25
+ let { backgroundImage, type, formData } = objs;
26
+ return new Promise((rs, rj) => {
27
+ let image;
28
+ if (backgroundImage) {
29
+ image = backgroundImage;
30
+ } else {
31
+ //根据type获取背景图, 一般要改成request获取
32
+ switch (type) {
33
+ case 1:
34
+ image = '';
35
+ break;
36
+ default:
37
+ image = '';
38
+ break;
39
+ }
40
+ }
41
+ if (image) {
42
+ rs(image); // resolve图片的路径
43
+ } else {
44
+ rj('背景图片路径不存在');
45
+ }
46
+ });
47
+ },
48
+
49
+ //下面一般不用动他
50
+ shareTypeListSheetArray: {
51
+ array: [0, 1, 2, 3, 4, 5]
52
+ }, // 分享类型 0-图文链接 1-纯文字 2-纯图片 3-音乐 4-视频 5-小程序
53
+ isArray(arg) {
54
+ return Object.prototype.toString.call(arg) === '[object Array]';
55
+ },
56
+ isObject(arg) {
57
+ return Object.prototype.toString.call(arg) === '[object Object]';
58
+ },
59
+ isPromise(obj) {
60
+ return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
61
+ },
62
+ isNull(arg) {
63
+ return arg === null;
64
+ },
65
+ isUndefined(arg) {
66
+ return arg === undefined;
67
+ },
68
+ isUndef(arg) {
69
+ return arg === undefined;
70
+ },
71
+ isNotNull_string(arg) {
72
+ return arg !== null && arg !== undefined && arg !== '';
73
+ },
74
+ isFn(fn) {
75
+ return fn && typeof fn === 'function';
76
+ },
77
+ getStorage(key, scb, fcb) {
78
+ uni.getStorage({
79
+ key,
80
+ success: function (res) {
81
+ if (res.data && res.data != '') {
82
+ if (scb) scb(res.data);
83
+ } else {
84
+ if (fcb) fcb();
85
+ }
86
+ },
87
+ fail: function () {
88
+ if (fcb) fcb();
89
+ }
90
+ });
91
+ },
92
+ setStorage(key, data) {
93
+ log('设置缓存');
94
+ log('key:' + key);
95
+ log('data:' + JSON.stringify(data));
96
+ uni.setStorage({
97
+ key,
98
+ data
99
+ });
100
+ },
101
+ setStorageSync(key, data) {
102
+ uni.setStorageSync(key, data);
103
+ },
104
+ getStorageSync(key) {
105
+ return uni.getStorageSync(key);
106
+ },
107
+ clearStorageSync() {
108
+ uni.clearStorageSync();
109
+ },
110
+ removeStorageSync(key) {
111
+ uni.removeStorageSync(key);
112
+ },
113
+ getImageInfo(url, cb, fcb) {
114
+ url = checkMPUrl(url);
115
+ uni.getImageInfo({
116
+ src: url,
117
+ success(res) {
118
+ if (cb && typeof cb == 'function') cb(res);
119
+ },
120
+ fail(err) {
121
+ if (fcb && typeof fcb == 'function') fcb(err);
122
+ }
123
+ });
124
+ },
125
+ downloadFile(url, cb) {
126
+ url = checkMPUrl(url);
127
+ uni.downloadFile({
128
+ url,
129
+ success(res) {
130
+ if (cb && typeof cb == 'function') cb(res);
131
+ }
132
+ });
133
+ },
134
+ downloadFile_PromiseFc(url) {
135
+ return new Promise((rs, rj) => {
136
+ if (url.substring(0, 4) !== 'http') {
137
+ rs(url);
138
+ } else {
139
+ url = checkMPUrl(url);
140
+ log('url:' + url);
141
+ uni.downloadFile({
142
+ url,
143
+ success(res) {
144
+ if (res && res.tempFilePath) rs(res.tempFilePath);
145
+ else rj('not find tempFilePath');
146
+ },
147
+ fail(err) {
148
+ rj(err);
149
+ }
150
+ });
151
+ }
152
+ });
153
+ },
154
+ saveFile(url) {
155
+ uni.saveFile({
156
+ tempFilePath: url,
157
+ success(res) {
158
+ log('保存成功:' + JSON.stringify(res));
159
+ }
160
+ });
161
+ },
162
+ downLoadAndSaveFile_PromiseFc(url) {
163
+ return new Promise((rs, rj) => {
164
+ log('准备下载并保存图片:' + url);
165
+ if (url.substring(0, 4) === 'http') {
166
+ url = checkMPUrl(url);
167
+ uni.downloadFile({
168
+ url,
169
+ success(d_res) {
170
+ log('下载背景图成功:' + JSON.stringify(d_res));
171
+ if (d_res && d_res.tempFilePath) {
172
+ // #ifdef H5
173
+ rs(d_res.tempFilePath);
174
+ // #endif
175
+
176
+ // #ifndef H5
177
+ uni.saveFile({
178
+ tempFilePath: d_res.tempFilePath,
179
+ success(s_res) {
180
+ log('保存背景图成功:' + JSON.stringify(s_res));
181
+ if (s_res && s_res.savedFilePath) rs(s_res.savedFilePath);
182
+ else rs(d_res.tempFilePath);
183
+ },
184
+ fail(err) {
185
+ rs(d_res.tempFilePath);
186
+ }
187
+ });
188
+ // #endif
189
+ } else {
190
+ rj('not find tempFilePath');
191
+ }
192
+ },
193
+ fail(err) {
194
+ rj(err);
195
+ }
196
+ });
197
+ } else {
198
+ rs(url);
199
+ }
200
+ });
201
+ },
202
+ checkFile_PromiseFc(url) {
203
+ return new Promise((rs, rj) => {
204
+ uni.getSavedFileList({
205
+ success(res) {
206
+ let d = res.fileList;
207
+ let index = d.findIndex((item) => {
208
+ return item.filePath === url;
209
+ });
210
+ rs(index);
211
+ },
212
+ fail(err) {
213
+ rj(err);
214
+ }
215
+ });
216
+ });
217
+ },
218
+ removeSavedFile(path) {
219
+ uni.getSavedFileList({
220
+ success(res) {
221
+ let d = res.fileList;
222
+ let index = d.findIndex((item) => {
223
+ return item.filePath === path;
224
+ });
225
+ if (index >= 0)
226
+ uni.removeSavedFile({
227
+ filePath: path
228
+ });
229
+ }
230
+ });
231
+ },
232
+ fileNameInPath(path) {
233
+ let s = path.split('/');
234
+ return s[s.length - 1];
235
+ },
236
+ getImageInfo_PromiseFc(imgPath) {
237
+ return new Promise((rs, rj) => {
238
+ log('准备获取图片信息:' + imgPath);
239
+ imgPath = checkMPUrl(imgPath);
240
+ uni.getImageInfo({
241
+ src: imgPath,
242
+ success: (res) => {
243
+ log('获取图片信息成功:' + JSON.stringify(res));
244
+ rs(res);
245
+ },
246
+ fail: (err) => {
247
+ log('获取图片信息失败:' + JSON.stringify(err));
248
+ rj(err);
249
+ }
250
+ });
251
+ });
252
+ },
253
+ previewImage(urls) {
254
+ if (typeof urls == 'string') urls = [urls];
255
+ uni.previewImage({
256
+ urls
257
+ });
258
+ },
259
+ actionSheet(obj, cb) {
260
+ let sheetArray = [];
261
+ for (let i = 0; i < obj.array.length; i++) {
262
+ switch (obj.array[i]) {
263
+ case 'sinaweibo':
264
+ sheetArray[i] = '新浪微博';
265
+ break;
266
+ case 'qq':
267
+ sheetArray[i] = 'QQ';
268
+ break;
269
+ case 'weixin':
270
+ sheetArray[i] = '微信';
271
+ break;
272
+ case 'WXSceneSession':
273
+ sheetArray[i] = '微信好友';
274
+ break;
275
+ case 'WXSenceTimeline':
276
+ sheetArray[i] = '微信朋友圈';
277
+ break;
278
+ case 'WXSceneFavorite':
279
+ sheetArray[i] = '微信收藏';
280
+ break;
281
+ case 0:
282
+ sheetArray[i] = '图文链接';
283
+ break;
284
+ case 1:
285
+ sheetArray[i] = '纯文字';
286
+ break;
287
+ case 2:
288
+ sheetArray[i] = '纯图片';
289
+ break;
290
+ case 3:
291
+ sheetArray[i] = '音乐';
292
+ break;
293
+ case 4:
294
+ sheetArray[i] = '视频';
295
+ break;
296
+ case 5:
297
+ sheetArray[i] = '小程序';
298
+ break;
299
+ default:
300
+ break;
301
+ }
302
+ }
303
+ this.showActionSheet(sheetArray, cb);
304
+ },
305
+ showActionSheet(sheetArray, cb) {
306
+ uni.showActionSheet({
307
+ itemList: sheetArray,
308
+ success: (e) => {
309
+ if (cb && typeof cb == 'function') cb(e.tapIndex);
310
+ }
311
+ });
312
+ },
313
+ getProvider(type, cb, sheet) {
314
+ let _this = this;
315
+ uni.getProvider({
316
+ service: type,
317
+ success: function (res) {
318
+ if (sheet) {
319
+ let obj = {};
320
+ obj.array = res.provider;
321
+ _this.actionSheet(obj, function (index) {
322
+ if (cb && typeof cb == 'function') cb(res.provider[index]);
323
+ });
324
+ } else {
325
+ if (type == 'payment') {
326
+ let providers = res.provider;
327
+ let payTypeArray = [];
328
+ for (let i = 0; i < providers.length; i++) {
329
+ if (providers[i] == 'wxpay') {
330
+ payTypeArray[i] = {
331
+ name: '微信支付',
332
+ value: providers[i],
333
+ img: '/static/image/wei.png'
334
+ };
335
+ } else if (providers[i] == 'alipay') {
336
+ payTypeArray[i] = {
337
+ name: '支付宝支付',
338
+ value: providers[i],
339
+ img: '/static/image/ali.png'
340
+ };
341
+ }
342
+ }
343
+ if (cb && typeof cb == 'function') cb(payTypeArray);
344
+ } else {
345
+ if (cb && typeof cb == 'function') cb(res);
346
+ }
347
+ }
348
+ }
349
+ });
350
+ },
351
+ // #ifdef APP-PLUS
352
+ getShare(providerName, WXScene, shareType, title, summary, href, imageUrl, miniProgramObj, mediaUrl, scb, fcb) {
353
+ //miniProgram: {path: '', type: 0, webUrl: ''}
354
+ let _this = this;
355
+ if (typeof shareType == 'number' && !isNaN(shareType) && shareType >= 0) {
356
+ _this.readyShare(providerName, WXScene, shareType, title, summary, href, imageUrl, miniProgramObj, mediaUrl, scb, fcb);
357
+ } else {
358
+ _this.actionSheet(_this.shareTypeListSheetArray, function (index) {
359
+ _this.readyShare(
360
+ providerName,
361
+ WXScene,
362
+ _this.shareTypeListSheetArray.array[index],
363
+ title,
364
+ summary,
365
+ href,
366
+ imageUrl,
367
+ miniProgramObj,
368
+ mediaUrl,
369
+ scb,
370
+ fcb
371
+ );
372
+ });
373
+ }
374
+ },
375
+ readyShare(providerName, WXScene, shareType, title, summary, href, imageUrl, miniProgramObj, mediaUrl, scb, fcb) {
376
+ let _this = this;
377
+ let shareObjData = {};
378
+ switch (shareType) {
379
+ case 0:
380
+ shareObjData = {
381
+ href: href,
382
+ summary: summary,
383
+ imageUrl: imageUrl
384
+ };
385
+ break;
386
+ case 1:
387
+ shareObjData = {
388
+ summary: summary,
389
+ href: href
390
+ };
391
+ break;
392
+ case 2:
393
+ shareObjData = {
394
+ imageUrl: imageUrl
395
+ };
396
+ break;
397
+ case 3:
398
+ if (mediaUrl) {
399
+ _this.showToast('暂不支持此分享类型');
400
+ return;
401
+ }
402
+ shareObjData = {
403
+ mediaUrl: mediaUrl
404
+ };
405
+ break;
406
+ case 4:
407
+ if (mediaUrl) {
408
+ _this.showToast('暂不支持此分享类型');
409
+ return;
410
+ }
411
+ shareObjData = {
412
+ mediaUrl: mediaUrl
413
+ };
414
+ break;
415
+ case 5:
416
+ shareObjData = {
417
+ miniProgram: {
418
+ ...miniProgramObj,
419
+ id: miniProgramId,
420
+ type: miniProgramShareType
421
+ },
422
+ imageUrl: imageUrl
423
+ };
424
+ providerName = 'weixin';
425
+ break;
426
+ default:
427
+ _this.showToast('分享参数-shareType错误');
428
+ return;
429
+ break;
430
+ }
431
+ shareObjData.title = title;
432
+ _this.share(
433
+ providerName,
434
+ WXScene,
435
+ shareType,
436
+ shareObjData,
437
+ function (res) {
438
+ if (scb && typeof scb == 'function') scb(res);
439
+ },
440
+ function (err) {
441
+ if (fcb && typeof fcb == 'function') fcb(err);
442
+ }
443
+ );
444
+ },
445
+ share(providerName, WXScene, shareType, data, scb, fcb) {
446
+ let _this = this;
447
+ let shareObj = {
448
+ provider: '',
449
+ success: Function,
450
+ fail: Function
451
+ };
452
+ if (providerName && providerName != '') {
453
+ shareObj.provider = providerName;
454
+ if (providerName == 'weixin') {
455
+ _this.readyShareWXScene(WXScene, function (Scene) {
456
+ shareObj.scene = Scene;
457
+ _this.doingShare(shareObj, shareType, data, scb, fcb);
458
+ });
459
+ } else {
460
+ _this.doingShare(shareObj, shareType, data, scb, fcb);
461
+ }
462
+ } else {
463
+ _this.getProvider(
464
+ 'share',
465
+ function (name) {
466
+ shareObj.provider = name;
467
+ if (name == 'weixin') {
468
+ _this.readyShareWXScene(WXScene, function (Scene) {
469
+ shareObj.scene = Scene;
470
+ _this.doingShare(shareObj, shareType, data, scb, fcb);
471
+ });
472
+ } else {
473
+ _this.doingShare(shareObj, shareType, data, scb, fcb);
474
+ }
475
+ },
476
+ true
477
+ );
478
+ }
479
+ },
480
+ readyShareWXScene(WXScene, cb) {
481
+ let _this = this;
482
+ let WXScenetypelist = {
483
+ array: ['WXSceneSession', 'WXSenceTimeline', 'WXSceneFavorite']
484
+ };
485
+ if (WXScene && WXScene != '') {
486
+ if (cb && typeof cb == 'function') cb(WXScene);
487
+ } else {
488
+ _this.actionSheet(WXScenetypelist, function (index) {
489
+ if (cb && typeof cb == 'function') cb(WXScenetypelist.array[index]);
490
+ });
491
+ }
492
+ },
493
+ doingShare(shareObj, shareType, data, scb, fcb) {
494
+ shareObj.type = shareType;
495
+ if (data && data.title) shareObj.title = data.title;
496
+ switch (shareType) {
497
+ case 0: //图文链接
498
+ shareObj.href = data.href;
499
+ shareObj.summary = data.summary;
500
+ shareObj.imageUrl = data.imageUrl;
501
+ break;
502
+ case 1: //纯文字
503
+ shareObj.summary = data.summary;
504
+ shareObj.href = data.href;
505
+ break;
506
+ case 2: //纯图片
507
+ shareObj.imageUrl = data.imageUrl;
508
+ break;
509
+ case 3: //音乐
510
+ if (!data.mediaUrl) {
511
+ _this.showToast('暂不支持此分享类型');
512
+ return;
513
+ }
514
+ shareObj.mediaUrl = data.mediaUrl;
515
+ break;
516
+ case 4: //视频
517
+ if (!data.mediaUrl) {
518
+ _this.showToast('暂不支持此分享类型');
519
+ return;
520
+ }
521
+ shareObj.mediaUrl = data.mediaUrl;
522
+ break;
523
+ case 5: //小程序
524
+ if (miniProgramId == '') {
525
+ uni.showToast('未设置小程序ID, 请使用其他方式分享');
526
+ return;
527
+ }
528
+ let mp = {
529
+ id: miniProgramId
530
+ };
531
+ mp.path = data.miniProgram.path;
532
+ mp.type = data.miniProgram.type;
533
+ if (data.miniProgram.webUrl) mp.webUrl = data.miniProgram.webUrl;
534
+ shareObj.miniProgram = mp;
535
+ shareObj.imageUrl = data.imageUrl;
536
+ break;
537
+ default:
538
+ appJS.showToast('分享参数-shareType错误');
539
+ break;
540
+ }
541
+ shareObj.success = function (res) {
542
+ if (scb && typeof scb == 'function') scb(res);
543
+ };
544
+ shareObj.fail = function (err) {
545
+ if (fcb && typeof fcb == 'function') fcb(err);
546
+ };
547
+ log(JSON.stringify(shareObj));
548
+ uni.share(shareObj);
549
+ }
550
+ // #endif
551
+ };
552
+
553
+ function checkMPUrl(url) {
554
+ // #ifdef MP
555
+ if (process.env.NODE_ENV !== 'development') {
556
+ if (
557
+ url.substring(0, 4) === 'http' &&
558
+ url.substring(0, 5) !== 'https' &&
559
+ url.substring(0, 12) !== 'http://store' &&
560
+ url.substring(0, 10) !== 'http://tmp' &&
561
+ url.substring(0, 10) !== 'http://usr'
562
+ ) {
563
+ url = 'https' + url.substring(4, url.length);
564
+ }
565
+ }
566
+ // #endif
567
+ return url;
568
+ }
569
+
570
+ export default _app;