From d2f7aa8d0044b6fab373acc0827fdaa886dfb0e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E6=B0=B8=E9=A1=BA?= <971387674@qq.com> Date: Fri, 28 Apr 2023 10:51:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81-=E5=85=AC=E5=BC=8F=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hrmSalary/components/excelEditor/index.js | 97 ++----------------- .../hrmSalary/pages/equationEditor/index.js | 20 +++- .../pages/salaryItem/formalFormModal.js | 6 +- 3 files changed, 28 insertions(+), 95 deletions(-) diff --git a/pc4mobx/hrmSalary/components/excelEditor/index.js b/pc4mobx/hrmSalary/components/excelEditor/index.js index b04ce534..42237ec6 100644 --- a/pc4mobx/hrmSalary/components/excelEditor/index.js +++ b/pc4mobx/hrmSalary/components/excelEditor/index.js @@ -1,5 +1,4 @@ import React, { Component } from "react"; -import ReactDOM from "react-dom"; import { Button } from "antd"; import { Controlled as CodeMirror } from "react-codemirror2"; import { keyboardBaseBtns } from "./constants"; @@ -34,71 +33,12 @@ class ExcelEditor extends Component { insertText = text => { const cursor = this.editorRef.getCursor(); this.editorRef.replaceRange(text, cursor); + this.editorRef.refresh(); + this.editorRef.focus(); }; - replaceToWidget = (editor, data, value, inlineWidgetOpts) => { + replaceToWidget = (editor) => { editor.getAllMarks().forEach(m => m.clear()); - editor.refresh(); - editor.focus(); - // let posInfos = _.flatMap(_.keys(inlineWidgetOpts), widgetName => { - // let { regex, render } = inlineWidgetOpts[widgetName]; - // let res = [], newRe = new RegExp(regex, "g"), m; - // do { - // m = newRe.exec(value); - // if (m) { - // const mountToDom = document.createElement("span"); - // let text = m[0]; - // res.push({ - // widgetName, - // text, - // startAt: m.index, - // endAt: m.index + text.length, - // render: () => { - // let x = `((...args) => args)${text.replace(new RegExp(`^${widgetName}`), "")}`; - // let args = eval(x); - // return render(...args); - // }, - // mountToDom: mountToDom - // }); - // } - // } while (m); - // return res; - // }); - // posInfos.forEach(posInfo => { - // let from = { line: 0, ch: posInfo.startAt }; - // let to = { line: 0, ch: posInfo.endAt }; - // editor.markText(from, to, { - // replacedWith: posInfo.mountToDom, - // clearWhenEmpty: false - // }); - // }); - // this.setState({ - // widgets: posInfos - // }, () => { - // editor.refresh(); - // editor.focus(); - // }); - }; - /* - * Author: 黎永顺 - * Description:格式化 - * Params: - * Date: 2023/4/13 - */ - autoFormatSelection = () => { - let editor = this.editorRef.editor; - if (this.props.type != "sql") { - const script_length = editor.getValue().length; - const startPos = { line: 0, ch: 0, sticky: null }; - const endPos = editor.doc.posFromIndex(script_length); - // editor.setSelection(startPos, endPos); - // editor.autoFormatRange(startPos, endPos); - // editor.commentRange(false, startPos, endPos); - } else { - let splCont = ""; - splCont = editor.getValue(); - // editor.setValue(sqlFormatter.format(splCont)); - } }; handleVariSelect = str => this.insertText(`{${str}}`); handleFuncSelect = str => { @@ -107,6 +47,8 @@ class ExcelEditor extends Component { this.timer = setTimeout(() => { const { line, ch } = this.editorRef.getCursor(); this.editorRef.setCursor({ line, ch: ch - 1 }); + this.editorRef.refresh(); + this.editorRef.focus(); }, 100); }; handleEditorRedo = () => { @@ -137,17 +79,6 @@ class ExcelEditor extends Component { }; render() { - const inlineWidgetOpts = { - useObject: { - regex: /useObject\("[^)]+"\)/, - render: (objId) => { - return ( - {objId} - ); - } - } - }; - const { widgets } = this.state; const { groupParams = {} } = this.props; const { referenceType } = groupParams; return ( @@ -158,10 +89,11 @@ class ExcelEditor extends Component { editorDidMount={editor => this.editorRef = editor} value={this.state.value} onBeforeChange={(editor, data, value) => { + console.log(value); this.setState({ value }); }} onChange={(editor, data, value) => { - this.replaceToWidget(editor, data, value, inlineWidgetOpts); + this.replaceToWidget(editor, data, value); }} options={{ lineNumbers: false, @@ -179,11 +111,6 @@ class ExcelEditor extends Component { }} onKeyDown={(_, { keyCode }) => keyCode === 8 && this.handleBackSpaceRedo()} /> - {widgets.map((w, i) => { - return ( - - ); - })} { referenceType !== "sql" && @@ -220,13 +147,3 @@ class ExcelEditor extends Component { } export default ExcelEditor; - -class Widget extends React.Component { - render() { - let { info } = this.props; - return ReactDOM.createPortal( - info.render(), - info.mountToDom - ); - } -} diff --git a/pc4mobx/hrmSalary/pages/equationEditor/index.js b/pc4mobx/hrmSalary/pages/equationEditor/index.js index e205a1a5..a31d97d1 100644 --- a/pc4mobx/hrmSalary/pages/equationEditor/index.js +++ b/pc4mobx/hrmSalary/pages/equationEditor/index.js @@ -1,10 +1,28 @@ import React, { Component } from "react"; +import { Button, Modal } from "antd"; import ExcelEditor from "../../components/excelEditor"; class Index extends Component { + constructor(props) { + super(props); + this.state = { + title: "DialogTitle", + visible: false, + lvisible: false + }; + } + render() { return ( - +
+ + + this.setState({ visible: false })} + > + + +
); } } diff --git a/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js b/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js index 20001e4e..719b103b 100644 --- a/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js +++ b/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js @@ -65,7 +65,7 @@ export default class FormalFormModal extends React.Component { this.setState({ value: data.formula, returnType: data.returnType, - validateType: data.validateType, + validateType: data.validateType }); // salaryAcctImportTemplateParam(groupParams); }); @@ -428,9 +428,7 @@ export default class FormalFormModal extends React.Component { } - - {/*value={value} groupParams={groupParams}*/} - {/*onChange={(value) => this.handleChange(value)}*/} + this.handleChange(value)}/> {/*
*/} {/* this.contentProps = input}*/}