"您的验证码为{tel}"
//解析的关键方法
smsTemplateData() {
let str = this.templateStr
let reg = /\$\{(.+?)\}/
let reg_g = /\$\{(.+?)\}/g
let result = str.match(reg_g)
let list = []
//解析${}中的变量组成数组(我们项目中${name}不用叫填写所以加了判断)
for (let i = 0; i < result.length; i++) {
let item = result[i]
if (item === '${name}') str = str.replace('${name}', '***')
else list.push(item.match(reg)[1])
}
this.templateVariableList = list
if (list.length > 0) {
list.forEach(item => {
str = str.replace('${' + item + '}', `<input class="self-input" id="${item}" />`)
})
}
this.templateStr = str
},
//提交表单的时候 获取·动态生成的Input的值
let obj = {}
let isFull = false
// 短信模版变量封装 js生成的输入框不能通过v-model绑定值,我是通过原生办法获取值的
if (this.templateVariableList.length > 0) {
this.templateVariableList.forEach(item => {
let realValue = document.getElementById(item).value
if (!realValue) isFull = true
})
if (isFull) return Toast('请完善通知内容!')
this.templateVariableList.forEach(item => {
let realValue = document.getElementById(item).value
obj[item] = realValue
})
}
this.model.templateData = obj