Ver Código Fonte

fix: 欢迎语 - replaceAll兼容问题

zhengxy 1 ano atrás
pai
commit
3cf6adcd60

+ 14 - 2
project/src/components/channelCode/createChannelCode.vue

@@ -445,7 +445,13 @@ export default {
445 445
 
446 446
           let msg_list = dataInfo.welcomeMsg;
447 447
           msg_list.forEach((item) => {
448
-            item.content = item.content ? item.content.replaceAll('%NICKNAME%', '「客户昵称」') : '';
448
+            // S 坑:部分浏览器不支持 replaceAll 方法
449
+            if (String.prototype.replaceAll) {
450
+              item.content = item.content ? item.content.replaceAll('%NICKNAME%', '「客户昵称」') : '';
451
+            } else {
452
+              item.content = item.content ? item.content.replace(/\%NICKNAME\%/g, '「客户昵称」') : '';
453
+            }
454
+            // E 坑:部分浏览器不支持 replaceAll 方法
449 455
             item.attachments = item.attachments && item.attachments != '' ? JSON.parse(item.attachments) : [];
450 456
             if(item.weeks){
451 457
               item.weeks = item.weeks.split(',')
@@ -643,7 +649,13 @@ export default {
643 649
         }else{
644 650
           item.weeks = ''
645 651
         }
646
-        item.content = item.content.replaceAll('「客户昵称」', '%NICKNAME%')
652
+        // S 坑:部分浏览器不支持 replaceAll 方法
653
+        if (String.prototype.replaceAll) {
654
+          item.content = item.content.replaceAll('「客户昵称」', '%NICKNAME%')
655
+        } else {
656
+          item.content = item.content.replace(/「客户昵称」/g, '%NICKNAME%')
657
+        }
658
+        // E 坑:部分浏览器不支持 replaceAll 方法
647 659
         item.attachments = item.attachments == '' || item.attachments&&item.attachments.length == 0 ? '' : JSON.stringify(item.attachments)
648 660
       })
649 661
       this.$loading(this.$loadingConfig)

+ 16 - 2
project/src/components/customOperate/welcom_message.vue

@@ -193,7 +193,13 @@ export default {
193 193
           this.name = res.rst.name;
194 194
           let msg_list = res.rst.msg_list;
195 195
           msg_list.forEach((item) => {
196
-            item.content = item.content ? item.content.replaceAll('%NICKNAME%', '「客户昵称」') : '';
196
+            // S 坑:部分浏览器不支持 replaceAll 方法
197
+            if (String.prototype.replaceAll) {
198
+              item.content = item.content ? item.content.replaceAll('%NICKNAME%', '「客户昵称」') : '';
199
+            } else {
200
+              item.content = item.content ? item.content.replace(/\%NICKNAME\%/g, '「客户昵称」') : '';
201
+            }
202
+            // E 坑:部分浏览器不支持 replaceAll 方法
197 203
             item.attachments = item.attachments && item.attachments != '' ? JSON.parse(item.attachments) : [];
198 204
             if(item.weeks){
199 205
               item.weeks = item.weeks.split(',')
@@ -353,7 +359,15 @@ export default {
353 359
           item.weeks = ''
354 360
         }
355 361
         // item.weeks = item.weeks.join(',');
356
-        item.content = item.content.replaceAll('「客户昵称」', '%NICKNAME%')
362
+
363
+        // S 坑:部分浏览器不支持 replaceAll 方法
364
+        if (String.prototype.replaceAll) {
365
+          item.content = item.content.replaceAll('「客户昵称」', '%NICKNAME%')
366
+        } else {
367
+          item.content = item.content.replace(/「客户昵称」/g, '%NICKNAME%')
368
+        }
369
+        // E 坑:部分浏览器不支持 replaceAll 方法
370
+
357 371
         item.attachments = item.attachments == '' || item.attachments&&item.attachments.length == 0 ? '' : JSON.stringify(item.attachments)
358 372
       })
359 373
       this.$loading(this.$loadingConfig)