wuxw
2019-05-06 2b759ab5e5d708c4c9a6b4a093103c026667cf38
WebService/src/main/java/com/java110/web/core/VueComponentElement.java
@@ -100,21 +100,35 @@
        }
        String[] tmpType = 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(" ", "").replace("\n", "");
            String attrKey = types[0].replace(" ", "")
                    .replace("\n", "")
                    .replace("\r", "");
            if (!element.hasAttribute(attrKey)) {
                String componentName = element.getAttributeValue("name");
                logger.error("组件[%s]未配置组件属性 %s", componentName, attrKey);
                logger.error("组件" + componentName + "未配置组件属性 " + attrKey);
                throw new TemplateProcessingException("组件[" + componentName + "]未配置组件属性" + attrKey);
            }
            String vcType = element.getAttributeValue(attrKey);
            js = js.replace(attrKey, "'" + vcType + "'");
            if (types[1].equals("vc.propTypes.string")) {
                vcType = "'" + vcType + "'";
            }
            propsJs.append("$props." + attrKey + "=" + vcType + ";\n");
        }
        //将propsJs 插入到 第一个 { 之后
        int position = js.indexOf("{");
        if (position < 0) {
            String componentName = element.getAttributeValue("name");
            logger.error("组件" + componentName + "对应js 未包含 {}  ");
            throw new TemplateProcessingException("组件" + componentName + "对应js 未包含 {}  ");
        }
        js = new StringBuffer(js).insert(position + 1, propsJs).toString();
        return js;
    }