This commit is contained in:
MustangDeng 2022-05-07 14:47:31 +08:00
commit d6b7357949
1 changed files with 26 additions and 3 deletions

View File

@ -141,6 +141,30 @@ export default class FormalFormModal extends React.Component {
})
}
/**
* name: 获取文本框光标位置
* param {*} obj
* param {*} str
* return {*}
*/
insertText = (obj,str) => {
if (document.selection) {
let sel = document.selection.createRange();
sel.text = str;
} else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
let startPos = obj.selectionStart,
endPos = obj.selectionEnd,
cursorPos = startPos,
tmpStr = obj.value;
obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
cursorPos += str.length;
obj.selectionStart = obj.selectionEnd = cursorPos;
obj.focus();
} else {
obj.value += str;
}
}
// 字段点击回调
handleFieldClick(item) {
this.field = item;
@ -155,9 +179,8 @@ export default class FormalFormModal extends React.Component {
orderIndex: this.parameters.length
}
this.parameters.push(parameterItem)
this.setState({
value: this.state.value + fieldName
})
let propsTextarea = this.contentProps.refs.textareaNormal.refs.input.refs.input; // 获取dom节点实例
let position = this.insertText(propsTextarea,fieldName); // 光标的位置
}
render() {