wuxw
2019-12-01 60ec7702688efdc3cb82f3064f3c4a90c1e47736
java110-front/src/main/java/com/java110/front/core/VcCreateProcessor.java
@@ -59,7 +59,7 @@
        //将组建名称写入组建HTML 第一个标签中
        addDataComponent(elements, componentName);
        htmlModel.addModel(modelFactory.parse(context.getTemplateData(), doc.body().children().toString()));
        htmlModel.addModel(modelFactory.parse(context.getTemplateData(), dealHtmlThis(tag, doc.body().children().toString())));
        String css = VueComponentTemplate.findTemplateByComponentCode(componentName + "." + VueComponentTemplate.COMPONENT_CSS);
        if (css != null) {
@@ -74,12 +74,34 @@
            js = dealNameSpace(js, tag);
            js = dealJsAddComponentCode(js, tag);
            js = "<script type=\"text/javascript\" " + DIV_PROPERTY_COMPONENT + "=\"" + componentName + "\">//<![CDATA[ \n" + js + "//]]>\n</script>";
            htmlModel.add(modelFactory.createText(js));
            htmlModel.add(modelFactory.createText(dealHtmlJs(tag, js)));
        }
        logger.debug("解析完成组件{},{}", componentName, new Date().getTime());
        structureHandler.replaceWith(htmlModel, true);
    }
    private String dealHtmlThis(IProcessableElementTag tag, String html) {
        if (!tag.hasAttribute("namespace")) {
            return html;
        }
        String namespace = tag.getAttributeValue("namespace");
        return html.replace("this.", namespace + "_");
    }
    private String dealHtmlJs(IProcessableElementTag tag, String js) {
        if (!tag.hasAttribute("namespace")) {
            return js;
        }
        String namespace = tag.getAttributeValue("namespace");
        return js.replace("this.", "vc.component."+namespace + "_");
    }
@@ -207,15 +229,16 @@
        String namespace = "";
        if (!tag.hasAttribute("namespace")) {
            namespace = DEFAULT_NAMESPACE;
        } else {
            namespace = tag.getAttributeValue("namespace");
        }
        namespace = tag.getAttributeValue("namespace");
        //js对象中插入namespace 值
        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:" + namespace.trim() + ",\n" + tmpProTypes.substring(pos, tmpProTypes.length());
                + "\nnamespace:'" + namespace.trim() + "',\n" + tmpProTypes.substring(pos, tmpProTypes.length());
        int position = js.indexOf("{");
        String propsJs = "\n$namespace='" + namespace.trim() + "';\n";
        js = new StringBuffer(js).insert(position + 1, propsJs).toString();