Yansen 5 年之前
父節點
當前提交
7768677cbb
共有 1 個檔案被更改,包括 27 行新增23 行删除
  1. 27
    23
      src/utils/tools.js

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

@@ -215,8 +215,10 @@ export function parseQueryString(queryString) {
215 215
 }
216 216
 
217 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,7 +266,9 @@ export function getDownloadURL(url, type) {
264 266
 
265 267
   switch (type) {
266 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 272
     case "alioss":
269 273
       return url
270 274
         .replace(ossPath, `${HOST}/alioss/`)
@@ -302,7 +306,7 @@ export function throttle(callback, time = 500) {
302 306
   }
303 307
 }
304 308
 
305
-export const wait = function (time = 500) {
309
+export const wait = function(time = 500) {
306 310
   return new Promise(res => {
307 311
     setTimeout(() => {
308 312
       res();
@@ -310,7 +314,7 @@ export const wait = function (time = 500) {
310 314
   });
311 315
 };
312 316
 
313
-export const getQueryString = function (str, name) {
317
+export const getQueryString = function(str, name) {
314 318
   var regex = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
315 319
   var r = str.match(regex);
316 320
   if (r != null) return unescape(r[2]);
@@ -356,10 +360,10 @@ export const makeProjectPoster = res => {
356 360
         ctx.strokeStyle = "#ffffff";
357 361
         ctx.clip(); //裁剪上面的圆形
358 362
         ctx.drawImage(list[2].tempFilePath, 46, 856, 100, 100);
359
-        ctx.draw(false, function () {
363
+        ctx.draw(false, function() {
360 364
           Taro.canvasToTempFilePath({
361 365
             canvasId: canvasName,
362
-            success: function ({ tempFilePath }) {
366
+            success: function({ tempFilePath }) {
363 367
               resolve(tempFilePath);
364 368
             }
365 369
           });
@@ -368,9 +372,9 @@ export const makeProjectPoster = res => {
368 372
       .catch(err => {
369 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,11 +398,11 @@ export const removeLocalFile = callback => {
394 398
 export const canvasToTempFilePath = (canvasName, callback) => {
395 399
   Taro.canvasToTempFilePath({
396 400
     canvasId: canvasName,
397
-    success: function (data) {
401
+    success: function(data) {
398 402
       var tempFilePath = data.tempFilePath;
399 403
       callback(tempFilePath);
400 404
     },
401
-    fail: function (res) {
405
+    fail: function(res) {
402 406
       console.log(res);
403 407
     }
404 408
   });
@@ -412,7 +416,7 @@ export const saveFile = (tempFilePath, callback) => {
412 416
       console.log("成功" + res1.savedFilePath);
413 417
       callback(res1.savedFilePath);
414 418
     },
415
-    fail: function (res) {
419
+    fail: function(res) {
416 420
       console.log("失败");
417 421
     }
418 422
   });
@@ -421,12 +425,12 @@ export const saveFile = (tempFilePath, callback) => {
421 425
 export const downloadFile = (imgUrl, callback) => {
422 426
   Taro.downloadFile({
423 427
     url: imgUrl,
424
-    success: function (param) {
428
+    success: function(param) {
425 429
       if (param.statusCode === 200) {
426 430
         callback(param);
427 431
       }
428 432
     },
429
-    fail: function (res) {
433
+    fail: function(res) {
430 434
       console.log("生成失败请稍候重试");
431 435
     }
432 436
   });
@@ -533,10 +537,10 @@ export const makeCardPoster = data => {
533 537
       ctx.strokeStyle = "#ffffff";
534 538
       ctx.clip();
535 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 541
         Taro.canvasToTempFilePath({
538 542
           canvasId: canvasName,
539
-          success: function ({ tempFilePath }) {
543
+          success: function({ tempFilePath }) {
540 544
             resolve(tempFilePath);
541 545
           }
542 546
         });
@@ -608,7 +612,7 @@ export const makeCardShareImg = data => {
608 612
       ctx.clip(); //裁剪上面的圆形
609 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 616
         Taro.canvasToTempFilePath({ canvasId: canvasName, quality: 1 }).then(
613 617
           ({ tempFilePath }) => {
614 618
             resolve(tempFilePath);
@@ -619,13 +623,13 @@ export const makeCardShareImg = data => {
619 623
   });
620 624
 };
621 625
 
622
-export const isObject = function (value) {
626
+export const isObject = function(value) {
623 627
   var type = typeof value;
624 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 633
   if (!isObject(obj)) {
630 634
     throw new Error("obj 不是一个对象!");
631 635
   }
@@ -638,7 +642,7 @@ export const deepClone = function (obj) {
638 642
   return cloneObj;
639 643
 };
640 644
 
641
-export const validateAuth = function (name, callback) {
645
+export const validateAuth = function(name, callback) {
642 646
   Taro.getSetting().then(res => {
643 647
     const hasAuth = res.authSetting[name];
644 648
     if (hasAuth) {
@@ -656,7 +660,7 @@ export const validateAuth = function (name, callback) {
656 660
  * @param strict 是否严格模式
657 661
  * @returns `phoneNumber` 是中国的手机号码返回 `true`,否则返回 `false`
658 662
  */
659
-export const isChineseMobilePhoneNumber = function (phoneNumber, strict) {
663
+export const isChineseMobilePhoneNumber = function(phoneNumber, strict) {
660 664
   if (strict === undefined) {
661 665
     strict = false;
662 666
   }
@@ -673,7 +677,7 @@ export const isChineseMobilePhoneNumber = function (phoneNumber, strict) {
673 677
  * @returns `value` 是邮件地址返回 `true`,否则返回 `false`
674 678
  * @see http://emailregex.com/
675 679
  */
676
-export const isEmail = function (value) {
680
+export const isEmail = function(value) {
677 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 682
   return re.test(value);
679 683
 };