From da9910eef1f3c53320d7ff564dac82565de15ed0 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期日, 01 十二月 2019 12:11:27 +0800
Subject: [PATCH] 优化命名空间
---
java110-front/src/main/java/com/java110/front/core/VcCreateProcessor.java | 26 +++++++++++++++-----------
1 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/java110-front/src/main/java/com/java110/front/core/VcCreateProcessor.java b/java110-front/src/main/java/com/java110/front/core/VcCreateProcessor.java
index d53f0a8..6c3f9a5 100644
--- a/java110-front/src/main/java/com/java110/front/core/VcCreateProcessor.java
+++ b/java110-front/src/main/java/com/java110/front/core/VcCreateProcessor.java
@@ -90,7 +90,9 @@
String namespace = tag.getAttributeValue("namespace");
- return html.replace("this.", namespace + "_");
+ return html.replace("this.", namespace + "_")
+ .replaceAll("(id)+( )*+=+( )*+'", "id='" + namespace + "_")
+ .replaceAll("(id)+( )*+=+( )*+\"", "id=\"" + namespace + "_");
}
private String dealHtmlJs(IProcessableElementTag tag, String js) {
@@ -101,7 +103,14 @@
String namespace = tag.getAttributeValue("namespace");
- return js.replace("this.", "vc.component."+namespace + "_");
+ js = js.replace("this.", "vc.component." + namespace + "_")
+ .replaceAll("(\\$)+( )*+(\\()+( )*+\'+#", "\\$('#" + namespace + "_")
+ .replaceAll("(\\$)+( )*+(\\()+( )*+\"+#", "\\$(\"#" + namespace + "_");
+
+ //灏� 鐩戝惉涔熷仛浼樺寲
+ js = js.replaceAll("(vc.on)+\\('", "vc.on('" + namespace + "','");
+ js = js.replaceAll("(vc.on)+\\(\"", "vc.on(\"" + namespace + "\",\"");
+ return js;
}
@@ -240,21 +249,16 @@
js = js.substring(0, extPos) + tmpProTypes.substring(0, pos).trim()
+ "\nnamespace:'" + namespace.trim() + "',\n" + tmpProTypes.substring(pos, tmpProTypes.length());
int position = js.indexOf("{");
- String propsJs = "\n$namespace='" + namespace.trim() + "';\n";
+ String propsJs = "\nvar $namespace='" + namespace.trim() + "';\n";
js = new StringBuffer(js).insert(position + 1, propsJs).toString();
return js;
}
public static void main(String[] args) {
- String js = "(function (vc, vm) {vc.extends({a:'123'})})";
- int extPos = js.indexOf("vc.extends");
- String tmpProTypes = js.substring(extPos);
- int pos = tmpProTypes.indexOf("{") + 1;
- js = js.substring(0, extPos) + tmpProTypes.substring(0, pos).trim() + "\nnamespace:" + DEFAULT_NAMESPACE + ",\n" + tmpProTypes.substring(pos, tmpProTypes.length());
- int position = js.indexOf("{");
- String propsJs = "\n$namespace=" + DEFAULT_NAMESPACE + ";\n";
- js = new StringBuffer(js).insert(position + 1, propsJs).toString();
+ String js = "123$ ( '#av').val()";
+ js = js.replaceAll("(\\$)+( )*+(\\()+( )*+\'+#", "\\$('#abg_");
System.out.println(js);
+
}
}
--
Gitblit v1.8.0