Browse Source

fix: 欢迎语 - replaceAll兼容问题

zhengxy 1 year ago
parent
commit
3cf6adcd60

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

445
 
445
 
446
           let msg_list = dataInfo.welcomeMsg;
446
           let msg_list = dataInfo.welcomeMsg;
447
           msg_list.forEach((item) => {
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
             item.attachments = item.attachments && item.attachments != '' ? JSON.parse(item.attachments) : [];
455
             item.attachments = item.attachments && item.attachments != '' ? JSON.parse(item.attachments) : [];
450
             if(item.weeks){
456
             if(item.weeks){
451
               item.weeks = item.weeks.split(',')
457
               item.weeks = item.weeks.split(',')
643
         }else{
649
         }else{
644
           item.weeks = ''
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
         item.attachments = item.attachments == '' || item.attachments&&item.attachments.length == 0 ? '' : JSON.stringify(item.attachments)
659
         item.attachments = item.attachments == '' || item.attachments&&item.attachments.length == 0 ? '' : JSON.stringify(item.attachments)
648
       })
660
       })
649
       this.$loading(this.$loadingConfig)
661
       this.$loading(this.$loadingConfig)

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

193
           this.name = res.rst.name;
193
           this.name = res.rst.name;
194
           let msg_list = res.rst.msg_list;
194
           let msg_list = res.rst.msg_list;
195
           msg_list.forEach((item) => {
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
             item.attachments = item.attachments && item.attachments != '' ? JSON.parse(item.attachments) : [];
203
             item.attachments = item.attachments && item.attachments != '' ? JSON.parse(item.attachments) : [];
198
             if(item.weeks){
204
             if(item.weeks){
199
               item.weeks = item.weeks.split(',')
205
               item.weeks = item.weeks.split(',')
353
           item.weeks = ''
359
           item.weeks = ''
354
         }
360
         }
355
         // item.weeks = item.weeks.join(',');
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
         item.attachments = item.attachments == '' || item.attachments&&item.attachments.length == 0 ? '' : JSON.stringify(item.attachments)
371
         item.attachments = item.attachments == '' || item.attachments&&item.attachments.length == 0 ? '' : JSON.stringify(item.attachments)
358
       })
372
       })
359
       this.$loading(this.$loadingConfig)
373
       this.$loading(this.$loadingConfig)