Browse Source

REPORT-53159 【智能联动】组件拖入时,tab中的js引用多个组件,只会替换一次

feature/10.0
hades 3 years ago
parent
commit
d35c06b20b
  1. 22
      designer-base/src/main/java/com/fr/design/mod/ContentReplaceUtil.java
  2. 65
      designer-base/src/test/java/com/fr/design/mod/ContentReplaceUtilTest.java

22
designer-base/src/main/java/com/fr/design/mod/ContentReplaceUtil.java

@ -1,5 +1,8 @@
package com.fr.design.mod;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author hades
* @version 10.0
@ -10,7 +13,24 @@ public class ContentReplaceUtil {
public static final String EQ_STRING = "=";
public static String replaceContent(String content, String oldName, String newName) {
return content.replaceAll(generateStr(oldName), generateStr(newName));
String oldNameUpper = oldName.toUpperCase();
Matcher m = Pattern.compile(oldName + "|" + oldNameUpper).matcher(content);
StringBuilder sb = new StringBuilder();
int last = 0;
while (m.find()) {
sb.append(content, last, m.start());
if (oldNameUpper.equals(m.group())) {
// 处理大写情况
sb.append(newName.toUpperCase());
} else {
// 默认情况
sb.append(newName);
}
last = m.end();
}
sb.append(content.substring(last));
return sb.toString();
}
private static String generateStr(String str) {

65
designer-base/src/test/java/com/fr/design/mod/ContentReplaceUtilTest.java

@ -0,0 +1,65 @@
package com.fr.design.mod;
import junit.framework.TestCase;
import org.junit.Assert;
/**
* @author hades
* @version 10.0
* Created by hades on 2021/6/2
*/
public class ContentReplaceUtilTest extends TestCase {
public void testReplaceContent() {
String text = "setTimeout(function() {\n" +
"\n" +
"\t$(\"div[widgetname=DATEEDITOR0]\").css({\n" +
"\n" +
"\t\t'opacity': '0.3'\n" +
"\n" +
"\t});\n" +
"\n" +
"}, 50);\n" +
"var a = \"dateEditor0\"";
String oldName = "dateEditor0";
String newName = "dateEditor00";
String result = "setTimeout(function() {\n" +
"\n" +
"\t$(\"div[widgetname=DATEEDITOR00]\").css({\n" +
"\n" +
"\t\t'opacity': '0.3'\n" +
"\n" +
"\t});\n" +
"\n" +
"}, 50);\n" +
"var a = \"dateEditor00\"";
Assert.assertEquals(result, ContentReplaceUtil.replaceContent(text, oldName, newName));
String text1 = "setInterval(function() {\n" +
"\t//获取当前body中tab的索引位置\n" +
" var aa = _g().getWidgetByName(\"tabpane00\").getShowIndex();\n" +
" //根据tab索引轮播tab块,索引从0开始,到最后一个tab块后跳转到第一个\n" +
"\tif(aa == TAB轮播-测试-2) {\n" +
" _g().getWidgetByName('tabpane00').showCardByIndex(0);\n" +
" } else {\n" +
"\n" +
" _g().getWidgetByName('tabpane00').showCardByIndex(aa + TAB轮播-测试-1);\n" +
" }\n" +
"}, TAB轮播-测试-2000);";
String oldName1 = "tabpane00";
String newName1 = "tabpane0";
String result1 = "setInterval(function() {\n" +
"\t//获取当前body中tab的索引位置\n" +
" var aa = _g().getWidgetByName(\"tabpane0\").getShowIndex();\n" +
" //根据tab索引轮播tab块,索引从0开始,到最后一个tab块后跳转到第一个\n" +
"\tif(aa == TAB轮播-测试-2) {\n" +
" _g().getWidgetByName('tabpane0').showCardByIndex(0);\n" +
" } else {\n" +
"\n" +
" _g().getWidgetByName('tabpane0').showCardByIndex(aa + TAB轮播-测试-1);\n" +
" }\n" +
"}, TAB轮播-测试-2000);";
Assert.assertEquals(result1, ContentReplaceUtil.replaceContent(text1, oldName1, newName1));
}
}
Loading…
Cancel
Save