From 6f0c1044ad5260da62a8158d59f3702a495dc7f0 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 16:11:56 +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 --- .../excelEditor/extendCodeMirror.js | 25 ++++++++------ .../hrmSalary/components/excelEditor/index.js | 34 ++++++++++++++++--- .../hrmSalary/pages/equationEditor/index.js | 6 ++-- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/pc4mobx/hrmSalary/components/excelEditor/extendCodeMirror.js b/pc4mobx/hrmSalary/components/excelEditor/extendCodeMirror.js index 342f2761..e1b34b44 100644 --- a/pc4mobx/hrmSalary/components/excelEditor/extendCodeMirror.js +++ b/pc4mobx/hrmSalary/components/excelEditor/extendCodeMirror.js @@ -1,11 +1,11 @@ // extendCodeMirror.js /* eslint-disable */ -import * as CodeMirror from 'codemirror'; +import * as CodeMirror from "codemirror"; CodeMirror.extendMode("css", { commentStart: "/*", commentEnd: "*/", - newlineAfterToken: function(type, content) { + newlineAfterToken: function (type, content) { return /^[;{}]$/.test(content); } }); @@ -14,9 +14,9 @@ CodeMirror.extendMode("javascript", { commentStart: "/*", commentEnd: "*/", // FIXME semicolons inside of for - newlineAfterToken: function(type, content, textAfter, state) { + newlineAfterToken: function (type, content, textAfter, state) { if (this.jsonMode) { - return /^[\[,{]$/.test(content) || /^}/.test(textAfter)|| /^]/.test(textAfter); + return /^[\[,{]$/.test(content) || /^}/.test(textAfter) || /^]/.test(textAfter); } else { if (content == ";" && state.lexical && state.lexical.type == ")") return false; return /^[;{}]$/.test(content) && !/^;/.test(textAfter); @@ -27,7 +27,7 @@ CodeMirror.extendMode("javascript", { CodeMirror.extendMode("xml", { commentStart: "", - newlineAfterToken: function(type, content, textAfter) { + newlineAfterToken: function (type, content, textAfter) { return type == "tag" && />$/.test(content) || /^ { + const { isFormter } = this.state; + if (isFormter) { + const script_length = this.editorRef.getValue().length; + const startPos = { line: 0, ch: 0, sticky: null }; + const endPos = this.editorRef.doc.posFromIndex(script_length); + this.editorRef.setSelection(startPos, endPos); + this.editorRef.autoFormatRange(startPos, endPos); + this.editorRef.commentRange(true, startPos, endPos); + } else { + this.editorRef.undo(); + this.editorRef.undo(); + } + }; insertText = text => { const cursor = this.editorRef.getCursor(); this.editorRef.replaceRange(text, cursor); @@ -78,6 +98,7 @@ class ExcelEditor extends Component { }; render() { + const { isFormter } = this.state; const { groupParams = {} } = this.props; const { referenceType } = groupParams; return ( @@ -95,12 +116,11 @@ class ExcelEditor extends Component { }} options={{ lineNumbers: false, - mode: { name: this.props.type === "sql" ? "text/x-sql" : "application/json" }, + mode: "javascript", autofocus: false, styleActiveLine: true, lineWrapping: true, - foldGutter: true, - gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"], + matchBrackets: true, lint: false, indentUnit: 2, cursorHeight: 0.85, @@ -130,9 +150,13 @@ class ExcelEditor extends Component { + onClick={() => this.setState({ value: "" })}>C + } diff --git a/pc4mobx/hrmSalary/pages/equationEditor/index.js b/pc4mobx/hrmSalary/pages/equationEditor/index.js index a31d97d1..ffcc361c 100644 --- a/pc4mobx/hrmSalary/pages/equationEditor/index.js +++ b/pc4mobx/hrmSalary/pages/equationEditor/index.js @@ -15,12 +15,12 @@ class Index extends Component { render() { return (
- + {}}/> this.setState({ visible: false })} + onCancel={() => this.setState({ visible: false })} > - + {}}/>
);