From d03b16dd76299bd94195e08e7861bddf4f253932 Mon Sep 17 00:00:00 2001 From: liyongshun <971387674@qq.com> Date: Fri, 6 May 2022 12:25:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E8=A1=8C=E6=96=87=E6=9C=AC=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E7=BD=AE=E6=B7=BB=E5=8A=A0=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/salaryItem/formalFormModal.js | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js b/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js index fce3af79..72e54ab7 100644 --- a/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js +++ b/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js @@ -127,6 +127,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; @@ -141,9 +165,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() {