From 4ff738f377504fe8f2296df18cf7d0123641cdd9 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期四, 17 十月 2019 22:11:03 +0800
Subject: [PATCH] 优化调用微服务时的报错

---
 WebService/src/main/java/com/java110/web/core/VcCreateProcessor.java |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 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 112f89a..046e845 100644
--- a/WebService/src/main/java/com/java110/web/core/VcCreateProcessor.java
+++ b/WebService/src/main/java/com/java110/web/core/VcCreateProcessor.java
@@ -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());
@@ -117,11 +116,11 @@
             return js;
         }
 
-        tmpProTypes = tmpProTypes.contains("\r")? tmpProTypes.replace("\r", "") : tmpProTypes;
+        tmpProTypes = tmpProTypes.contains("\r") ? tmpProTypes.replace("\r", "") : tmpProTypes;
 
         String[] tmpType = tmpProTypes.contains("\n")
-                        ? tmpProTypes.split("\n")
-                        : tmpProTypes.split(",");
+                ? tmpProTypes.split("\n")
+                : tmpProTypes.split(",");
         StringBuffer propsJs = new StringBuffer("\nvar $props = {};\n");
         for (String type : tmpType) {
             if (StringUtils.isEmpty(type) || !type.contains(":")) {
@@ -135,13 +134,15 @@
             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].contains("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");
@@ -158,6 +159,19 @@
         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 鍙橀噺鍜� 鏂规硶閮藉姞鍏� 缁勪欢缂栫爜
      *

--
Gitblit v1.8.0