需求:选择下拉框内容,光标处加入下拉框内容,然后清空下拉框
界面:
在内容中输入,然后下拉框中选择内容,输入框中自动加上{下拉框选的内容},然后清空下拉框.
具体代码实现为:
<el-input
v-model="form.text"
type="textarea"
maxlength="4000"
size="mini"
rows="6"
@change="handleChangeContent"
@blur="campaignNameBlur"
></el-input>
<el-select
v-model="form.textVariable"
placeholder="变量"
class="ml-10"
size="mini"
@change="handleChangeContent"
>
<el-option v-for="item in textOptions" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
/**
* @description 获取焦点事件
*/
campaignNameBlur(e) {
this.campaignNameIndex = e.srcElement.selectionStart;
},
/**
* @description 改变内容后面下拉框的时候
*/
handleTextVariable(val) {
if (this.form.text) {
let index = this.campaignNameIndex;
let name = this.form.text;
this.form.text = name.slice(0, index) + `{${val}}` + name.slice(index);
} else {
this.form.text = `{${val}}`;
}
}
/**
* @description 改变通知设置的内容
*/
handleChangeContent() {
let content;
if (this.form.textVariable) {
this.handleTextVariable(this.form.textVariable);
this.form.textVariable = '';
}
//加载到xml中 不需要的可以去掉
content = `${this.form.text}`;
this.updateCurrentExtensions(
'flowable:Field',
this.bpmnInstances.moddle.create('flowable:Field', {name: 'content', string: content}),
'content'
);
},
有一个更简单的demo 比这个少一些交互
参考链接