| | |
| | | package com.java110.web.core; |
| | | |
| | | import com.java110.common.util.Assert; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | import org.thymeleaf.dom.Element; |
| | | import org.thymeleaf.dom.Macro; |
| | | import org.thymeleaf.dom.Node; |
| | | import org.thymeleaf.exceptions.TemplateProcessingException; |
| | | import org.thymeleaf.processor.element.AbstractMarkupSubstitutionElementProcessor; |
| | | import org.thymeleaf.util.DOMUtils; |
| | | |
| | | import java.io.StringReader; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 组件 自定义标签功能类 |
| | |
| | | if (js != null) { |
| | | |
| | | js = dealJs(js, element); |
| | | js = dealJsAddComponentCode(js, element); |
| | | js = "<script type=\"text/javascript\">//<![CDATA[ \n" + js + "//]]>\n</script>"; |
| | | Node nodeJs = new Macro(js); |
| | | nodes.add(nodeJs); |
| | |
| | | } |
| | | |
| | | 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(":"); |
| | | if (!element.hasAttribute(types[0].trim())) { |
| | | throw new RuntimeException("未配置组件属性" + types[0]); |
| | | String attrKey = types[0].replace(" ", "") |
| | | .replace("\n", "") |
| | | .replace("\r", ""); |
| | | if (!element.hasAttribute(attrKey)) { |
| | | String componentName = element.getAttributeValue("name"); |
| | | logger.error("组件" + componentName + "未配置组件属性 " + attrKey); |
| | | throw new TemplateProcessingException("组件[" + componentName + "]未配置组件属性" + attrKey); |
| | | } |
| | | String vcType = element.getAttributeValue(types[0]); |
| | | js = js.replace(types[0], vcType); |
| | | |
| | | String vcType = element.getAttributeValue(attrKey); |
| | | 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; |
| | | } |
| | | |
| | |
| | | */ |
| | | private String dealJsAddComponentCode(String js, Element element) { |
| | | |
| | | return ""; |
| | | if (!element.hasAttribute("code")) { |
| | | return js; |
| | | } |
| | | |
| | | String code = element.getAttributeValue("code"); |
| | | |
| | | return js.replace("@vc_", code); |
| | | } |
| | | |
| | | /** |