shiyj
2019-09-02 b784175e978b0fcfca8ca8bed7953ae4eacf49e8
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("解析完成组件{},{}", componentName, new Date().getTime());
@@ -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,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 变量和 方法都加入 组件编码
     *