diff --git a/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js b/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js index 93355c2a..3fbb71b1 100644 --- a/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js +++ b/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js @@ -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() {