| | |
| | | |
| | | import java.io.StringReader; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | //获取模板名称 |
| | | String componentName = element.getAttributeValue("name"); |
| | | |
| | | logger.debug("正在解析组件{}", componentName); |
| | | logger.debug("正在解析组件{},{}", componentName, new Date().getTime()); |
| | | String html = VueComponentTemplate.findTemplateByComponentCode(componentName + "." + VueComponentTemplate.COMPONENT_HTML); |
| | | if (html == null) { |
| | | throw new RuntimeException("在缓存中未找到组件【" + componentName + "】"); |
| | |
| | | nodes.add(nodeJs); |
| | | } |
| | | |
| | | logger.debug("解析完成组件{},{}", componentName, new Date().getTime()); |
| | | |
| | | return nodes; |
| | | } |
| | |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |