<a-textarea
style="width: 50%"
ref="textarea"
@change="handleWatchContent"
@click="hanldeGetPosition"
class="textarea"
v-decorator="['workWeixinWelcomeMsg']"
>
</a-textarea>
<a-button class="custonBtn" @click="handleAddNickName" size="small">
#点击插入客户昵称#
</a-button>
handleWatchContent() {
const textareaContent = this.$refs.textarea.$el.selectionStart;
console.log(textareaContent);
this.position = textareaContent;
},
hanldeGetPosition() {
const textareaContent = this.$refs.textarea.$el.selectionStart;
this.position = textareaContent;
},
handleAddNickName() {
let content = "";
if (this.$refs.textarea.$el._value) {
content = this.$refs.textarea.$el._value;
} else {
content = "";
}
const value = content.split("");
const nickName = ["#客户昵称#"];
value.splice(this.position, 0, ...nickName);
const textContent = value.join("");
this.$refs.textarea.$el._value = textContent;
this.$nextTick(() => {
this.form.setFieldsValue({
workWeixinWelcomeMsg: textContent,
});
});
},
const Regex = item.text.content
item.text.content = Regex.replace(/%NICKNAME%/gi, '#客户昵称#')
return item.text.content
正则转换