From b784175e978b0fcfca8ca8bed7953ae4eacf49e8 Mon Sep 17 00:00:00 2001
From: shiyj <1098226878@qq.com>
Date: 星期一, 02 九月 2019 20:18:58 +0800
Subject: [PATCH] Merge branch 'master' of https://github.com/java110/MicroCommunity

---
 WebService/src/main/java/com/java110/web/core/VcCreateProcessor.java |   44 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/WebService/src/main/java/com/java110/web/core/VcCreateProcessor.java b/WebService/src/main/java/com/java110/web/core/VcCreateProcessor.java
index da57636..b066aef 100644
--- a/WebService/src/main/java/com/java110/web/core/VcCreateProcessor.java
+++ b/WebService/src/main/java/com/java110/web/core/VcCreateProcessor.java
@@ -58,7 +58,7 @@
         //灏嗙粍寤哄悕绉板啓鍏ョ粍寤篐TML 绗竴涓爣绛句腑
         addDataComponent(elements, componentName);
 
-       htmlModel.addModel(modelFactory.parse(context.getTemplateData(), doc.body().children().toString()));
+        htmlModel.addModel(modelFactory.parse(context.getTemplateData(), doc.body().children().toString()));
 
         String css = VueComponentTemplate.findTemplateByComponentCode(componentName + "." + VueComponentTemplate.COMPONENT_CSS);
         if (css != null) {
@@ -72,9 +72,8 @@
 
             js = dealJs(js, tag);
             js = dealJsAddComponentCode(js, tag);
-            js = "<script type=\"text/javascript\">//<![CDATA[ \n" + js + "//]]>\n</script>";
+            js = "<script type=\"text/javascript\" "+DIV_PROPERTY_COMPONENT+"=\""+componentName+"\">//<![CDATA[ \n" + js + "//]]>\n</script>";
             htmlModel.add(modelFactory.createText(js));
-
         }
 
         logger.debug("瑙f瀽瀹屾垚缁勪欢{},{}", componentName, new Date().getTime());
@@ -86,7 +85,7 @@
     /**
      * 鍔犲叆缁勪欢鍚嶇О鍒� HTML涓� 鏂逛究瀹氫綅闂
      *
-     * @param elements        椤甸潰鑺傜偣
+     * @param elements      椤甸潰鑺傜偣
      * @param componentCode 缁勪欢缂栫爜
      */
     private void addDataComponent(Elements elements, String componentCode) {
@@ -99,7 +98,7 @@
      * 澶勭悊js
      *
      * @param tag 椤甸潰鍏冪礌
-     * @param js      js鏂囦欢鍐呭
+     * @param js  js鏂囦欢鍐呭
      * @return js 鏂囦欢鍐呭
      */
     private String dealJs(String js, IProcessableElementTag tag) {
@@ -117,23 +116,33 @@
             return js;
         }
 
-        String[] tmpType = tmpProTypes.split(",");
+        tmpProTypes = tmpProTypes.contains("\r")? tmpProTypes.replace("\r", "") : tmpProTypes;
+
+        String[] tmpType = tmpProTypes.contains("\n")
+                        ? tmpProTypes.split("\n")
+                        : tmpProTypes.split(",");
         StringBuffer propsJs = new StringBuffer("\nvar $props = {};\n");
         for (String type : tmpType) {
             if (StringUtils.isEmpty(type) || !type.contains(":")) {
                 continue;
             }
             String[] types = type.split(":");
-            String attrKey = types[0].replace(" ", "")
+            String attrKey = "";
+            if (types[0].contains("//")) {
+                attrKey = types[0].substring(0, types[0].indexOf("//"));
+            }
+            attrKey = types[0].replace(" ", "")
                     .replace("\n", "")
                     .replace("\r", "");
-            if (!tag.hasAttribute(attrKey)) {
+            if (!tag.hasAttribute(attrKey) && !types[1].contains("=")) {
                 String componentName = tag.getAttributeValue("name");
                 logger.error("缁勪欢" + componentName + "鏈厤缃粍浠跺睘鎬� " + attrKey);
                 throw new TemplateProcessingException("缁勪欢[" + componentName + "]鏈厤缃粍浠跺睘鎬�" + attrKey);
             }
             String vcType = tag.getAttributeValue(attrKey);
-            if (types[1].equals("vc.propTypes.string")) {
+            if(!tag.hasAttribute(attrKey) && types[1].contains("=")) {
+                vcType = dealJsPropTypesDefault(types[1]);
+            }else if (types[1].contains("vc.propTypes.string")) {
                 vcType = "'" + vcType + "'";
             }
             propsJs.append("$props." + attrKey + "=" + vcType + ";\n");
@@ -150,14 +159,27 @@
         return js;
     }
 
+
+    private String dealJsPropTypesDefault(String typeValue){
+         int startPos = typeValue.indexOf("=") + 1;
+         int endPos = typeValue.length();
+         if(typeValue.contains(",")){
+             endPos = typeValue.indexOf(",");
+         }else if(typeValue.contains("//")){
+             endPos = typeValue.indexOf("//");
+         }
+
+         return typeValue.substring(startPos,endPos);
+    }
+
     /**
      * 澶勭悊js 鍙橀噺鍜� 鏂规硶閮藉姞鍏� 缁勪欢缂栫爜
      *
      * @param tag 椤甸潰鍏冪礌
-     * @param js      js鏂囦欢鍐呭
+     * @param js  js鏂囦欢鍐呭
      * @return js 鏂囦欢鍐呭
      */
-    private String dealJsAddComponentCode(String js,IProcessableElementTag tag) {
+    private String dealJsAddComponentCode(String js, IProcessableElementTag tag) {
 
         if (!tag.hasAttribute("code")) {
             return js;

--
Gitblit v1.8.0