Yansen 5 年前
父节点
当前提交
7768677cbb
共有 1 个文件被更改,包括 27 次插入23 次删除
  1. 27
    23
      src/utils/tools.js

+ 27
- 23
src/utils/tools.js 查看文件

215
 }
215
 }
216
 
216
 
217
 export function toQueryString(o) {
217
 export function toQueryString(o) {
218
-  const obj = o || {}
219
-  return Object.keys(obj).map(key => `${key}=${obj[key]}`).join('&');
218
+  const obj = o || {};
219
+  return Object.keys(obj)
220
+    .map(key => `${key}=${obj[key]}`)
221
+    .join("&");
220
 }
222
 }
221
 
223
 
222
 /**
224
 /**
264
 
266
 
265
   switch (type) {
267
   switch (type) {
266
     case "avatar":
268
     case "avatar":
267
-      return url.replace("https://wx.qlogo.cn/", `${HOST}/qlogo/`);
269
+      return url
270
+        .replace("https://wx.qlogo.cn/", `${HOST}/qlogo/`)
271
+        .replace("https://thirdwx.qlogo.cn/", `${HOST}/thirdwx/`);
268
     case "alioss":
272
     case "alioss":
269
       return url
273
       return url
270
         .replace(ossPath, `${HOST}/alioss/`)
274
         .replace(ossPath, `${HOST}/alioss/`)
302
   }
306
   }
303
 }
307
 }
304
 
308
 
305
-export const wait = function (time = 500) {
309
+export const wait = function(time = 500) {
306
   return new Promise(res => {
310
   return new Promise(res => {
307
     setTimeout(() => {
311
     setTimeout(() => {
308
       res();
312
       res();
310
   });
314
   });
311
 };
315
 };
312
 
316
 
313
-export const getQueryString = function (str, name) {
317
+export const getQueryString = function(str, name) {
314
   var regex = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
318
   var regex = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
315
   var r = str.match(regex);
319
   var r = str.match(regex);
316
   if (r != null) return unescape(r[2]);
320
   if (r != null) return unescape(r[2]);
356
         ctx.strokeStyle = "#ffffff";
360
         ctx.strokeStyle = "#ffffff";
357
         ctx.clip(); //裁剪上面的圆形
361
         ctx.clip(); //裁剪上面的圆形
358
         ctx.drawImage(list[2].tempFilePath, 46, 856, 100, 100);
362
         ctx.drawImage(list[2].tempFilePath, 46, 856, 100, 100);
359
-        ctx.draw(false, function () {
363
+        ctx.draw(false, function() {
360
           Taro.canvasToTempFilePath({
364
           Taro.canvasToTempFilePath({
361
             canvasId: canvasName,
365
             canvasId: canvasName,
362
-            success: function ({ tempFilePath }) {
366
+            success: function({ tempFilePath }) {
363
               resolve(tempFilePath);
367
               resolve(tempFilePath);
364
             }
368
             }
365
           });
369
           });
368
       .catch(err => {
372
       .catch(err => {
369
         rtLog.error(
373
         rtLog.error(
370
           "下载图片失败, 图片地址 (" +
374
           "下载图片失败, 图片地址 (" +
371
-          `${_poster} , ${qrcode}, ${_avatarurl}` +
372
-          "), 错误消息: " +
373
-          (err.message || err.errMsg || err)
375
+            `${_poster} , ${qrcode}, ${_avatarurl}` +
376
+            "), 错误消息: " +
377
+            (err.message || err.errMsg || err)
374
         );
378
         );
375
       });
379
       });
376
   });
380
   });
394
 export const canvasToTempFilePath = (canvasName, callback) => {
398
 export const canvasToTempFilePath = (canvasName, callback) => {
395
   Taro.canvasToTempFilePath({
399
   Taro.canvasToTempFilePath({
396
     canvasId: canvasName,
400
     canvasId: canvasName,
397
-    success: function (data) {
401
+    success: function(data) {
398
       var tempFilePath = data.tempFilePath;
402
       var tempFilePath = data.tempFilePath;
399
       callback(tempFilePath);
403
       callback(tempFilePath);
400
     },
404
     },
401
-    fail: function (res) {
405
+    fail: function(res) {
402
       console.log(res);
406
       console.log(res);
403
     }
407
     }
404
   });
408
   });
412
       console.log("成功" + res1.savedFilePath);
416
       console.log("成功" + res1.savedFilePath);
413
       callback(res1.savedFilePath);
417
       callback(res1.savedFilePath);
414
     },
418
     },
415
-    fail: function (res) {
419
+    fail: function(res) {
416
       console.log("失败");
420
       console.log("失败");
417
     }
421
     }
418
   });
422
   });
421
 export const downloadFile = (imgUrl, callback) => {
425
 export const downloadFile = (imgUrl, callback) => {
422
   Taro.downloadFile({
426
   Taro.downloadFile({
423
     url: imgUrl,
427
     url: imgUrl,
424
-    success: function (param) {
428
+    success: function(param) {
425
       if (param.statusCode === 200) {
429
       if (param.statusCode === 200) {
426
         callback(param);
430
         callback(param);
427
       }
431
       }
428
     },
432
     },
429
-    fail: function (res) {
433
+    fail: function(res) {
430
       console.log("生成失败请稍候重试");
434
       console.log("生成失败请稍候重试");
431
     }
435
     }
432
   });
436
   });
533
       ctx.strokeStyle = "#ffffff";
537
       ctx.strokeStyle = "#ffffff";
534
       ctx.clip();
538
       ctx.clip();
535
       ctx.drawImage(list[1].tempFilePath, 50, 0, 400, 400, 249, 610, 130, 130);
539
       ctx.drawImage(list[1].tempFilePath, 50, 0, 400, 400, 249, 610, 130, 130);
536
-      ctx.draw(false, function () {
540
+      ctx.draw(false, function() {
537
         Taro.canvasToTempFilePath({
541
         Taro.canvasToTempFilePath({
538
           canvasId: canvasName,
542
           canvasId: canvasName,
539
-          success: function ({ tempFilePath }) {
543
+          success: function({ tempFilePath }) {
540
             resolve(tempFilePath);
544
             resolve(tempFilePath);
541
           }
545
           }
542
         });
546
         });
608
       ctx.clip(); //裁剪上面的圆形
612
       ctx.clip(); //裁剪上面的圆形
609
       ctx.drawImage(list[0].tempFilePath, 450, 100, 200, 200, 400, 100);
613
       ctx.drawImage(list[0].tempFilePath, 450, 100, 200, 200, 400, 100);
610
 
614
 
611
-      ctx.draw(false, function () {
615
+      ctx.draw(false, function() {
612
         Taro.canvasToTempFilePath({ canvasId: canvasName, quality: 1 }).then(
616
         Taro.canvasToTempFilePath({ canvasId: canvasName, quality: 1 }).then(
613
           ({ tempFilePath }) => {
617
           ({ tempFilePath }) => {
614
             resolve(tempFilePath);
618
             resolve(tempFilePath);
619
   });
623
   });
620
 };
624
 };
621
 
625
 
622
-export const isObject = function (value) {
626
+export const isObject = function(value) {
623
   var type = typeof value;
627
   var type = typeof value;
624
   return value != null && type === "object";
628
   return value != null && type === "object";
625
 };
629
 };
626
 
630
 
627
 //使用递归的方式实现数组、对象的深拷贝
631
 //使用递归的方式实现数组、对象的深拷贝
628
-export const deepClone = function (obj) {
632
+export const deepClone = function(obj) {
629
   if (!isObject(obj)) {
633
   if (!isObject(obj)) {
630
     throw new Error("obj 不是一个对象!");
634
     throw new Error("obj 不是一个对象!");
631
   }
635
   }
638
   return cloneObj;
642
   return cloneObj;
639
 };
643
 };
640
 
644
 
641
-export const validateAuth = function (name, callback) {
645
+export const validateAuth = function(name, callback) {
642
   Taro.getSetting().then(res => {
646
   Taro.getSetting().then(res => {
643
     const hasAuth = res.authSetting[name];
647
     const hasAuth = res.authSetting[name];
644
     if (hasAuth) {
648
     if (hasAuth) {
656
  * @param strict 是否严格模式
660
  * @param strict 是否严格模式
657
  * @returns `phoneNumber` 是中国的手机号码返回 `true`,否则返回 `false`
661
  * @returns `phoneNumber` 是中国的手机号码返回 `true`,否则返回 `false`
658
  */
662
  */
659
-export const isChineseMobilePhoneNumber = function (phoneNumber, strict) {
663
+export const isChineseMobilePhoneNumber = function(phoneNumber, strict) {
660
   if (strict === undefined) {
664
   if (strict === undefined) {
661
     strict = false;
665
     strict = false;
662
   }
666
   }
673
  * @returns `value` 是邮件地址返回 `true`,否则返回 `false`
677
  * @returns `value` 是邮件地址返回 `true`,否则返回 `false`
674
  * @see http://emailregex.com/
678
  * @see http://emailregex.com/
675
  */
679
  */
676
-export const isEmail = function (value) {
680
+export const isEmail = function(value) {
677
   var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
681
   var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
678
   return re.test(value);
682
   return re.test(value);
679
 };
683
 };