Commit 3a823290 by caoyanzhi

fix: 修复短信营销-短信模板插入链接的bug

parent 85d51411
......@@ -136,6 +136,31 @@ export default {
name: 'add-temp',
components: { linktools },
data() {
const valiContent = (rules, value, callback) => {
// 如果是通过链接小工具生成的链接,并且链接前或者后无空格时,自动补齐空格
if (Array.isArray(this.insertLink.inserted)) {
this.insertLink.inserted.forEach(el => {
// 校验content中所有链接的前面或者后面都有一个空格
const reg = new RegExp(`${el}`, 'g');
value = value.replace(reg, (str, index) => {
if (value[index - 1] != ' ') {
str = ' ' + str;
}
if (value[index + str.length] != ' ') {
str = str + ' ';
}
return str;
});
});
}
this.form.content = value;
// 如果是复制的链接,提示链接后面需要保留一个空格,如果用户不添加空格则无法保存
const urlReg = /(\shttps?|ftp|file):\/\/[-A-Za-z0-9+&@#\/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|]\s/g;
if (!urlReg.test(value)) {
return callback(new Error('链接前面和后面需要保留一个空格!'));
}
callback();
};
return {
loading: false,
form: {
......@@ -150,7 +175,10 @@ export default {
rules: {
title: { required: true, message: '请输入模板名称', trigger: 'blur' },
type: { required: true, message: '请选择短信类型', trigger: 'blur' },
content: { required: true, message: '请输入短信内容', trigger: 'blur' },
content: [
{ required: true, message: '请输入短信内容', trigger: 'blur' },
{ validator: valiContent, trigger: 'blur' }
],
remark: { required: true, message: '请输入申请说明', trigger: 'blur' }
},
editFlag: this.$route.meta.type === 'edit',
......@@ -163,7 +191,8 @@ export default {
// 插入小程序链接相关
insertLink: {
show: false,
link: ''
link: '',
inserted: [] // 已经插入到短信内容的链接,用来校验在短信文本中链接前后是否有空格
},
// 转换链接
transferLink: {
......@@ -300,6 +329,7 @@ export default {
this.insertLink.show = false;
this.reduceLink.show = false;
this.transferLink.show = false;
this.insertLink.inserted.push(this.insertLink.link);
}
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment