Преглед на файлове

代码暂存 未开发完成

wuxw преди 7 години
родител
ревизия
3e77432495

+ 60 - 1
WebService/src/main/java/com/java110/web/core/VueComponentElement.java

@@ -1,5 +1,7 @@
 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.Arguments;
@@ -12,7 +14,9 @@ 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;
 
 /**
  * 组件 自定义标签功能类
@@ -24,6 +28,8 @@ public class VueComponentElement extends AbstractMarkupSubstitutionElementProces
 
     private static final String DIV_PROPERTY_COMPONENT = "data-component";
 
+    private static final int DEFAULT_PRECEDENCE = 1000;
+
 
     protected VueComponentElement(String elementName) {
         super(elementName);
@@ -36,6 +42,7 @@ public class VueComponentElement extends AbstractMarkupSubstitutionElementProces
         List<Node> nodes = new ArrayList<>();
         //获取模板名称
         String componentName = element.getAttributeValue("name");
+
         logger.debug("正在解析组件{}", componentName);
         String html = VueComponentTemplate.findTemplateByComponentCode(componentName + "." + VueComponentTemplate.COMPONENT_HTML);
         if (html == null) {
@@ -60,6 +67,8 @@ public class VueComponentElement extends AbstractMarkupSubstitutionElementProces
         //js
         String js = VueComponentTemplate.findTemplateByComponentCode(componentName + "." + VueComponentTemplate.COMPONENT_JS);
         if (js != null) {
+
+            js = dealJs(js, element);
             js = "<script type=\"text/javascript\">//<![CDATA[ \n" + js + "//]]>\n</script>";
             Node nodeJs = new Macro(js);
             nodes.add(nodeJs);
@@ -69,6 +78,56 @@ public class VueComponentElement extends AbstractMarkupSubstitutionElementProces
         return nodes;
     }
 
+    /**
+     * 处理js
+     *
+     * @param element 页面元素
+     * @param js      js文件内容
+     * @return js 文件内容
+     */
+    private String dealJs(String js, Element element) {
+
+        //在js 中检测propTypes 属性
+        if (!js.contains("propTypes")) {
+            return js;
+        }
+
+        //解析propTypes信息
+        String tmpProTypes = js.substring(js.indexOf("propTypes"));
+        tmpProTypes = tmpProTypes.substring(tmpProTypes.indexOf("{") + 1, tmpProTypes.indexOf("}")).trim();
+
+        if (StringUtils.isEmpty(tmpProTypes)) {
+            return js;
+        }
+
+        String[] tmpType = tmpProTypes.split(",");
+        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 vcType = element.getAttributeValue(types[0]);
+            js = js.replace(types[0], vcType);
+
+        }
+        return js;
+    }
+
+    /**
+     * 处理js 变量和 方法都加入 组件编码
+     *
+     * @param element 页面元素
+     * @param js      js文件内容
+     * @return js 文件内容
+     */
+    private String dealJsAddComponentCode(String js, Element element) {
+
+        return "";
+    }
+
     /**
      * 加入组件名称到 HTML中 方便定位问题
      *
@@ -82,6 +141,6 @@ public class VueComponentElement extends AbstractMarkupSubstitutionElementProces
 
     @Override
     public int getPrecedence() {
-        return 1000;
+        return DEFAULT_PRECEDENCE;
     }
 }

+ 18 - 16
WebService/src/main/java/com/java110/web/core/VueComponentTemplate.java

@@ -10,7 +10,7 @@ import java.util.Map;
  * 静态资源文件加载器
  * Created by wuxw on 2019/3/18.
  */
-public class VueComponentTemplate extends PackageScanner{
+public class VueComponentTemplate extends PackageScanner {
 
     /**
      * 默认扫描路径
@@ -36,27 +36,28 @@ public class VueComponentTemplate extends PackageScanner{
     /**
      * HTML 文件缓存器
      */
-    private final static Map<String,String> componentTemplate = new HashMap<>();
+    private final static Map<String, String> componentTemplate = new HashMap<>();
 
 
     /**
      * 初始化 组件信息
      */
-    public static void initComponent(String scanPath){
+    public static void initComponent(String scanPath) {
         VueComponentTemplate vueComponentTemplate = new VueComponentTemplate();
-        vueComponentTemplate.packageScanner(scanPath,COMPONENT_JS);
-        vueComponentTemplate.packageScanner(scanPath,COMPONENT_HTML);
-        vueComponentTemplate.packageScanner(scanPath,COMPONENT_CSS);
+        vueComponentTemplate.packageScanner(scanPath, COMPONENT_JS);
+        vueComponentTemplate.packageScanner(scanPath, COMPONENT_HTML);
+        vueComponentTemplate.packageScanner(scanPath, COMPONENT_CSS);
     }
 
 
     /**
      * 根据组件编码查询模板
+     *
      * @param componentCode
      * @return
      */
     public static String findTemplateByComponentCode(String componentCode) {
-        if(componentTemplate.containsKey(componentCode)){
+        if (componentTemplate.containsKey(componentCode)) {
             return componentTemplate.get(componentCode);
         }
 
@@ -66,27 +67,28 @@ public class VueComponentTemplate extends PackageScanner{
 
     /**
      * 处理资源
+     *
      * @param filePath
      */
-    protected void handleResource(String filePath){
+    protected void handleResource(String filePath) {
         Reader reader = null;
         String sb = "";
-        try{
+        try {
             InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(filePath);
-            reader = new InputStreamReader(inputStream,"UTF-8");
+            reader = new InputStreamReader(inputStream, "UTF-8");
             int tempChar;
             StringBuffer b = new StringBuffer();
             while ((tempChar = reader.read()) != -1) {
-                    b.append((char) tempChar);
+                b.append((char) tempChar);
             }
             sb = b.toString();
-            if(!StringUtils.isEmpty(sb)){
-                componentTemplate.put(filePath.substring(filePath.lastIndexOf(File.separator)+1,filePath.length()),sb);
+            if (!StringUtils.isEmpty(sb)) {
+                componentTemplate.put(filePath.substring(filePath.lastIndexOf(File.separator) + 1, filePath.length()), sb);
             }
-        }catch (IOException e){
+        } catch (IOException e) {
             e.printStackTrace();
-        }finally {
-            if(reader != null){
+        } finally {
+            if (reader != null) {
                 try {
                     reader.close();
                 } catch (IOException e) {

+ 42 - 0
WebService/src/main/resources/components/room-select-floor/roomSelectFloor.html

@@ -0,0 +1,42 @@
+<div class="row">
+    <div class="col-lg-12">
+        <div class="ibox ">
+            <div class="ibox-title">
+                <h5>小区楼信息</h5>
+                <div class="ibox-tools" style="top:10px;">
+                    <button type="button" class="btn btn-primary btn-sm" v-on:click="openSearchFloorModel()">
+                        <i class="glyphicon glyphicon-search"></i> 选择小区楼</button>
+                    <button type="button" class="btn btn-primary btn-sm"
+                            v-if="floorInfo.floorId != null && floorInfo.floorId != ''"
+                            style="margin-left:10px" v-on:click="openAddRoomModel()">
+                        <i class="glyphicon glyphicon-plus" ></i> 添加房屋</button>
+                </div>
+            </div>
+            <div class="ibox-content">
+                <div class="row">
+                    <div class="col-sm-3">
+                        <div class="form-group">
+                            <label class="col-form-label" >小区楼ID:</label>
+                            <label class="">{{floorInfo.floorId}}</label>
+                        </div>
+                    </div>
+                    <div class="col-sm-3">
+                        <div class="form-group">
+                            <label class="col-form-label">名称:</label>
+                            <label class="">{{floorInfo.floorName}}</label>
+                        </div>
+                    </div>
+                    <div class="col-sm-3">
+                        <div class="form-group">
+                            <label class="col-form-label" >编号:</label>
+                            <label class="">{{floorInfo.floorNum}}</label>
+                        </div>
+                    </div>
+
+                </div>
+            </div>
+        </div>
+    </div>
+    <vc:create name="searchFloor"></vc:create>
+    <!--<vc:create name="addRoom"></vc:create>-->
+</div>

+ 42 - 0
WebService/src/main/resources/components/room-select-floor/roomSelectFloor.js

@@ -0,0 +1,42 @@
+/**
+    权限组
+**/
+(function(vc){
+
+    vc.extends({
+        propTypes: {
+            @OpenAddUnitModelName:string
+        },
+        data:{
+            floorInfo:{
+                floorId:"",
+                floorName:"",
+                floorNum:""
+            }
+        },
+        _initMethod:function(){
+
+        },
+        _initEvent:function(){
+            vc.on('unitSelectFloor','chooseFloor',function(_floor){
+                vc.component.floorInfo = _floor;
+            });
+
+        },
+        methods:{
+
+            openSearchFloorModel:function(){
+                vc.emit('searchFloor','openSearchFloorModel',{});
+            },
+            openAddUnitModel:function(){
+                vc.emit(@OpenAddUnitModelName,'addUnitModel',{
+                    floorId:vc.component.floorInfo.floorId
+                });
+            },
+            roomSelectFloorCallBack:function(obj){
+                console.log("回调函数",obj);
+            }
+        }
+    });
+
+})(window.vc);

+ 3 - 0
WebService/src/main/resources/components/room/room.html

@@ -1,4 +1,7 @@
 <div id="component" class="wrapper wrapper-content animated fadeInRight ecommerce">
+    <vc:create name="roomSelectFloor"
+               @OpenAddUnitModelName="AddRoom"
+    ></vc:create>
     <div class="row">
         <div class="col-lg-12">
             <div class="ibox">

+ 1 - 1
WebService/src/main/resources/components/unit/unit.html

@@ -30,7 +30,7 @@
                                 {{unit.layerCount}}
                             </td>
                             <td>
-                                {{unit.lift}}
+                                {{unit.lift == '1010'?'有':'无'}}
                             </td>
                             <td>
                                 {{unit.userName}}

WebService/src/main/resources/views/room.html → WebService/src/main/resources/views/roomFlow.html


+ 34 - 0
WebService/src/test/java/com/java110/web/core/VueComponentElementTest.java

@@ -0,0 +1,34 @@
+package com.java110.web.core;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class VueComponentElementTest {
+
+    @Test
+    public void getMarkupSubstitutes() {
+    }
+
+    @Test
+    public void testSubString(){
+        String js = "vc.extends({\n" +
+                "        propTypes: {\n" +
+                "            @OpenAddUnitModelName:string\n" +
+                "        },\n" +
+                "        data:{\n" +
+                "            floorInfo:{\n" +
+                "                floorId:\"\",\n" +
+                "                floorName:\"\",\n" +
+                "                floorNum:\"\"\n" +
+                "            }\n" +
+                "        },";
+
+        //解析propTypes信息
+        String tmpProTypes = js.substring(js.indexOf("propTypes"));
+        tmpProTypes = tmpProTypes.substring(tmpProTypes.indexOf("{")+1, tmpProTypes.indexOf("}")).trim();
+
+        System.out.println(tmpProTypes);
+
+    }
+}