From 05aad1deddada9f60b4474d1b7c5cfc588ac0e36 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Fri, 30 Sep 2022 16:19:17 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-75998=20=E5=AE=8C=E5=96=84=E6=AD=A3?= =?UTF-8?q?=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=8C=B9=E9=85=8D=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E3=80=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A7=E4=BB=B6=E4=BA=8B=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E5=9B=9E=E8=B0=83=E5=87=BD=E6=95=B0=E4=B8=AD=E7=9A=84?= =?UTF-8?q?JS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SearchExportJSFormulaAction.java | 6 +- .../actions/replace/utils/SearchJSUtils.java | 25 ++++ .../actions/replace/utils/ShowValueUtils.java | 8 +- .../replace/utils/ShowValueUtilsTest.java | 107 ++++++++++++++++++ 4 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 designer-realize/src/test/java/com/fr/design/actions/replace/utils/ShowValueUtilsTest.java diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/highlight/javascript/SearchExportJSFormulaAction.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/highlight/javascript/SearchExportJSFormulaAction.java index d19970c218..32b5721a52 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/highlight/javascript/SearchExportJSFormulaAction.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/highlight/javascript/SearchExportJSFormulaAction.java @@ -27,7 +27,7 @@ public class SearchExportJSFormulaAction implements SearchJSFormula { @Override public void searchJSFormulaFromOther(List formulaInfos, ITContent content, JavaScript javaScript) { - //如果导出当前模板,可以存公式的地方就是命名方式-自定义 + //如果导出当前模板,可以存公式的地方就是命名方式-自定义、参数设置 if (((ExportJavaScript) javaScript).isCurrentTemplate()) { content.addOtherPos(Toolkit.i18nText("Fine-Design_Basic_Export_JS_Template_Current")); dealSingleJavaScript(formulaInfos, content, ((ExportJavaScript) javaScript).getCurrentTemplateJavaScript()); @@ -42,6 +42,8 @@ public class SearchExportJSFormulaAction implements SearchJSFormula { } } + + public boolean isListExist(List list) { return list != null && list.size() > 0; } @@ -57,8 +59,8 @@ public class SearchExportJSFormulaAction implements SearchJSFormula { formulaInfos.add(new FormulaInfo(newContent)); } if (!javaScript.isExtendParameters()) { - ITContent paraContent = ITContent.copy(content); for (ParameterProvider parameter : javaScript.getParameters()) { + ITContent paraContent = ITContent.copy(content); if (parameter.getValue() instanceof Formula) { paraContent.addOtherPos(Toolkit.i18nText("Fine-Design_Basic_Base_Value")); paraContent.setReplaceObject(parameter.getValue()); diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/utils/SearchJSUtils.java b/designer-realize/src/main/java/com/fr/design/actions/replace/utils/SearchJSUtils.java index a63dabeb77..d04b02aa26 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/utils/SearchJSUtils.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/utils/SearchJSUtils.java @@ -12,6 +12,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.form.event.Listener; import com.fr.form.ui.Widget; import com.fr.general.GeneralUtils; +import com.fr.js.Commit2DBJavaScript; import com.fr.js.JavaScript; import com.fr.js.JavaScriptImpl; import com.fr.js.NameJavaScript; @@ -49,10 +50,34 @@ public class SearchJSUtils { ITContent newContent = ITContent.copy(content); newContent.setReplaceObject(listener); SearchJSUtils.addJSInfos(jsInfos, new JSInfo(newContent)); + } else if (javaScript instanceof Commit2DBJavaScript){ + dealCommit2DBJS(jsInfos, content, (Commit2DBJavaScript) javaScript); } } } + private static void dealCommit2DBJS(List jsInfos, ITContent content, Commit2DBJavaScript javaScript) { + if (!javaScript.getDBManipulation().isEmpty()) { + //处理回调函数 + dealWithCallBack(jsInfos, content, javaScript); + } + } + + private static void dealWithCallBack(List jsInfos, ITContent content, Commit2DBJavaScript commit2DBJavaScript) { + JavaScript javaScript = commit2DBJavaScript.getCallBack(); + ITContent newContent = ITContent.copy(content); + newContent.addOtherPos( + Toolkit.i18nText("Fine-Design_Basic_Set_Callback_Function") + ); + if (javaScript instanceof JavaScriptImpl) { + newContent.setReplaceObject(javaScript); + jsInfos.add(new JSInfo(newContent)); + } else if (javaScript instanceof Commit2DBJavaScript){ + dealCommit2DBJS(jsInfos, newContent, (Commit2DBJavaScript) javaScript); + } + } + + /** * 获取HtmlLabel数组 * diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/utils/ShowValueUtils.java b/designer-realize/src/main/java/com/fr/design/actions/replace/utils/ShowValueUtils.java index d7baa0a733..b7b46539b3 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/utils/ShowValueUtils.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/utils/ShowValueUtils.java @@ -59,9 +59,11 @@ public class ShowValueUtils { private static List specialCharList = new ArrayList<>(); static { - //正则特殊字符:? * () [] {} ^ $ . + //正则特殊字符:? * () [] {} ^ $ . \ + | //如果是? 并采用通配符 ,会自动转成“.” 所以 ? 不用处理 //$同理 + specialCharList.add("\\"); + specialCharList.add("/"); specialCharList.add("*"); specialCharList.add("("); specialCharList.add(")"); @@ -71,6 +73,10 @@ public class ShowValueUtils { specialCharList.add("}"); specialCharList.add("^"); specialCharList.add("."); + specialCharList.add("+"); + specialCharList.add("|"); + specialCharList.add("!"); + } /** diff --git a/designer-realize/src/test/java/com/fr/design/actions/replace/utils/ShowValueUtilsTest.java b/designer-realize/src/test/java/com/fr/design/actions/replace/utils/ShowValueUtilsTest.java new file mode 100644 index 0000000000..d31511bddc --- /dev/null +++ b/designer-realize/src/test/java/com/fr/design/actions/replace/utils/ShowValueUtilsTest.java @@ -0,0 +1,107 @@ +package com.fr.design.actions.replace.utils; + +import junit.framework.TestCase; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-09-30 + */ +public class ShowValueUtilsTest extends TestCase { + + + public void testChangeRegex() { + + /** + * 字符"." + */ + String regex = "."; + String str = "=\"通配符:我(){}[]是*cu/r?y+单!^个字|+符串/?\\?.\""; + Pattern pattern = Pattern.compile(ShowValueUtils.changeRegex(regex)); + Matcher matcher = pattern.matcher(str); + assertTrue(matcher.find()); + while (matcher.find()){ + assertEquals(".", matcher.group()); + } + + /** + * 字符"?" + */ + regex = "??."; + pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); + Matcher matcher1 = pattern.matcher(str); + assertTrue(matcher1.find()); + while (matcher1.find()){ + assertEquals("\\?.", matcher1.group()); + } + + /** + * 字符"\" + */ + regex = "?\\"; + pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); + Matcher matcher2 = pattern.matcher(str); + assertTrue(matcher2.find()); + while (matcher2.find()){ + assertEquals("?\\", matcher2.group()); + } + + /** + * 字符"/" + */ + regex = "/"; + pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); + Matcher matcher3 = pattern.matcher(str); + assertTrue(matcher3.find()); + while (matcher3.find()){ + assertEquals("/", matcher3.group()); + } + + /** + * 字符"*" + */ + regex = "*"; + pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); + Matcher matcher4 = pattern.matcher(str); + assertTrue(matcher4.find()); + while (matcher4.find()){ + assertEquals("*", matcher4.group()); + } + + /** + * 字符"(){}[]" + */ + regex = "(){}[]"; + pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); + Matcher matcher5 = pattern.matcher(str); + assertTrue(matcher5.find()); + while (matcher5.find()){ + assertEquals("(){}[]", matcher5.group()); + } + + /** + * 字符"^" + */ + regex = "!^"; + pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); + Matcher matcher6 = pattern.matcher(str); + assertTrue(matcher6.find()); + while (matcher6.find()){ + assertEquals("!^", matcher6.group()); + } + + /** + * 字符"|+" + */ + regex = "|+"; + pattern =Pattern.compile(ShowValueUtils.changeRegex(regex)); + Matcher matcher7 = pattern.matcher(str); + assertTrue(matcher7.find()); + while (matcher7.find()){ + assertEquals("|+", matcher7.group()); + } + } +} \ No newline at end of file