"您的驗(yàn)證碼為{tel}"
//解析的關(guān)鍵方法
smsTemplateData() {
let str = this.templateStr
let reg = /\$\{(.+?)\}/
let reg_g = /\$\{(.+?)\}/g
let result = str.match(reg_g)
let list = []
//解析${}中的變量組成數(shù)組(我們項(xiàng)目中${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
},
//提交表單的時(shí)候 獲取·動(dòng)態(tài)生成的Input的值
let obj = {}
let isFull = false
// 短信模版變量封裝 js生成的輸入框不能通過(guò)v-model綁定值,我是通過(guò)原生辦法獲取值的
if (this.templateVariableList.length > 0) {
this.templateVariableList.forEach(item => {
let realValue = document.getElementById(item).value
if (!realValue) isFull = true
})
if (isFull) return Toast('請(qǐng)完善通知內(nèi)容!')
this.templateVariableList.forEach(item => {
let realValue = document.getElementById(item).value
obj[item] = realValue
})
}
this.model.templateData = obj
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者