2 Commits f7569e6247 ... d8939905b4

Autor SHA1 Mensagem Data
  zhangyuantao d8939905b4 feat: 添加元素时检查重名 1 ano atrás
  zhangyuantao 68c9638892 feat: 元素增加功能 1 ano atrás

+ 18 - 2
src/main/java/com/tao/controller/AppElementController.java

@@ -9,9 +9,7 @@ import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.servlet.http.HttpServletRequest;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @ClassName AppElementController
@@ -80,4 +78,22 @@ public class AppElementController {
         }
     }
 
+    @PostMapping("/add")
+    @ResponseBody
+    public AjaxResult addElement(AppElement appElement) {
+        appElementService.insertAppElement(appElement);
+        return AjaxResult.success("添加成功");
+    }
+
+    @GetMapping("/verifyName")
+    @ResponseBody
+    public AjaxResult findElementByName(String elementName) {
+        AppElement appElement = appElementService.selectAppElementByName(elementName);
+        if (appElement != null) {
+            return AjaxResult.error("已存在同名元素");
+        } else {
+            return AjaxResult.success("未重复");
+        }
+    }
+
 }

+ 7 - 0
src/main/java/com/tao/mapper/AppElementMapper.java

@@ -21,6 +21,13 @@ public interface AppElementMapper {
      */
     public AppElement selectAppElementById(Long id);
 
+    /**
+     * @param elementName
+     * @return com.tao.pojo.AppElement
+     * @Description 根据类型来查找元素集合
+     */
+    public AppElement selectAppElementByName(String elementName);
+
     /**
      * @param pageID
      * @return java.util.List<com.tao.pojo.AppElement>

+ 7 - 0
src/main/java/com/tao/service/AppElementService.java

@@ -21,6 +21,13 @@ public interface AppElementService {
      */
     public AppElement selectAppElementById(Long id);
 
+    /**
+     * @param elementName
+     * @return com.tao.pojo.AppElement
+     * @Description 根据类型来查找元素集合
+     */
+    public AppElement selectAppElementByName(String elementName);
+
     /**
      * @param pageID
      * @return java.util.List<com.tao.pojo.AppElement>

+ 10 - 0
src/main/java/com/tao/service/impl/AppElementServiceImpl.java

@@ -156,6 +156,16 @@ public class AppElementServiceImpl implements AppElementService {
         return appElementMapper.selectAppElementById(id);
     }
 
+    /**
+     * @param elementName
+     * @return com.tao.pojo.AppElement
+     * @Description 根据类型来查找元素集合
+     */
+    @Override
+    public AppElement selectAppElementByName(String elementName) {
+        return appElementMapper.selectAppElementByName(elementName);
+    }
+
     /**
      * @param pageID
      * @return java.util.List<com.tao.pojo.AppElement>

+ 5 - 0
src/main/resources/mybatis/mapper/AppElementMapper.xml

@@ -41,6 +41,11 @@
         where e.element_id = #{elementID}
     </select>
 
+    <select id="selectAppElementByName" parameterType="String" resultMap="AppElementResult">
+        <include refid="selectAppElementVo"/>
+        where e.element_name = #{elementName}
+    </select>
+
     <select id="selectAppElementListByPageID" parameterType="Long" resultMap="AppElementResult">
         <include refid="selectAppElementVo"/>
         where e.page_id = #{pageID}

+ 118 - 8
src/main/resources/templates/add.html

@@ -2,18 +2,128 @@
 <html lang="en">
 <head>
     <meta charset="UTF-8">
-    <title>Title</title>
+    <title>addElement</title>
+    <link rel="stylesheet" href="./layui/css/layui.css" media="all">
+    <script type="text/javascript" src="./layui/layui.js"></script>
 </head>
 <body>
-
-<h1>你好</h1>
-
+<div style="margin: 50px 0px 0px 50px">
+    <form class="layui-form layui-form-pane" action="">
+        <div class="layui-form-item layui-hide">
+            <label class="layui-form-label" style="width: 16%">元素所属页面</label>
+            <div class="layui-input-inline" style="width: 76%">
+                <input id="pageID" type="text" name="pageID" autocomplete="off" class="layui-input">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label" style="width: 16%">元素名</label>
+            <div class="layui-input-inline" style="width: 76%">
+                <input type="text" name="elementName" required lay-verify="required|elementName" placeholder="请输入元素名" autocomplete="off" class="layui-input">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label" style="width: 20%">Android端定位</label>
+            <div class="layui-input-inline" style="width: 18%">
+                <select name="androidType">
+                    <option value=""></option>
+                    <option value="id">id</option>
+                    <option value="xpath">xpath</option>
+                </select>
+            </div>
+            <div class="layui-input-inline" style="width: 53%">
+                <input type="text" name="elementAndroidLocate" placeholder="请输入定位值" autocomplete="off" class="layui-input">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label" style="width: 20%">IOS端定位</label>
+            <div class="layui-input-inline" style="width: 18%">
+                <select name="IOSType">
+                    <option value=""></option>
+                    <option value="predicate">predicate</option>
+                    <option value="xpath">xpath</option>
+                </select>
+            </div>
+            <div class="layui-input-inline" style="width: 53%">
+                <input type="text" name="elementIOSLocate" placeholder="请输入定位值" autocomplete="off" class="layui-input">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label" style="width: 16%">元素备注</label>
+            <div class="layui-input-inline" style="width: 76%">
+                <input type="text" name="elementRemark" required lay-verify="required" placeholder="请输入元素备注" autocomplete="off" class="layui-input">
+            </div>
+        </div>
+        <div class="layui-form-item layui-hide">
+            <label class="layui-form-label" style="width: 16%">元素类型</label>
+            <div class="layui-input-inline" style="width: 76%">
+                <input type="text" name="elementType" autocomplete="off" class="layui-input" value="1">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <div class="layui-input-inline">
+                <button class="layui-btn" lay-submit lay-filter="preAddElement">立即提交</button>
+                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
+            </div>
+        </div>
+    </form>
+</div>
 </body>
 <script>
-    let pageID = ""
-    function test1(obj1) {
-        pageID = obj1
+
+    layui.use(['form', 'layer'], function () {
+        const form = layui.form
+            , $ = layui.$;
+
+        //提交
+        form.on('submit(preAddElement)', function (data) {
+            data.field.elementAndroidLocate = "'" + data.field.androidType + "': '" + data.field.elementAndroidLocate + "'";
+            data.field.elementIOSLocate = "'" + data.field.IOSType + "': '" + data.field.elementIOSLocate + "'";
+            $.ajax({
+                type: 'post',
+                url: '/element/add',
+                dataType: 'json',
+                data: data.field,
+                success: function (res) {
+                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
+                    parent.layer.msg(res.msg, {shade: 0.3, time: 2000});
+                    parent.layui.table.reload('myTable', {
+                        where: {
+                            pageID: data.field.pageID
+                        }
+                    });
+                    parent.layer.close(index); //再执行关闭
+                },
+                error: function (errMsg) {
+                    console.log(errMsg);
+                }
+            })
+            return false;
+        });
+
+        form.verify({
+            elementName: function (value, item) { //value:表单的值、item:表单的DOM对象
+                let code = 500;
+                $.ajax({
+                    async: false,
+                    url: '/element/verifyName',
+                    type: 'GET',
+                    data: {elementName: value},
+                    dataType: 'json',
+                    timeout: 30000,
+                    success: function (response) {
+                        code = response.code;
+                    }
+                });
+                if (code === 500) {
+                    return '元素重名啦~';
+                }
+            }
+        });
+    });
+
+    function child(obj) {
+        document.getElementById("pageID").setAttribute("value", obj);
     }
-    console.log("子组件" + pageID);
+
 </script>
 </html>

+ 6 - 5
src/main/resources/templates/index.html

@@ -55,7 +55,7 @@
         <script id="itemData" type="text/html">
             {{# layui.each(d, function(index, item){ }}
             <dd><a class="pageRequest" href="#"
-                   data-param="{&quot;elementType&quot;: 0, &quot;pageID&quot;: &quot;{{ item.pageID }}&quot;}">{{
+                   data-param="{&quot;pageID&quot;: &quot;{{ item.pageID }}&quot;}">{{
                 item.pageName }}</a></dd>
             {{# }); }}
             {{# if(d.length === 0){ }}
@@ -311,6 +311,10 @@
                 , color: 'black' // 字体颜色
                 , bgColor: 'white' // 背景色
             }
+            , initSort: {
+                field: 'elementType' //排序字段,对应 cols 设定的各字段名
+                ,type: 'desc' //排序方式  asc: 升序、desc: 降序、null: 默认排序
+            }
             , cols: [
                 [
                     {title: '#', width: 50, children: '#expandAll', childWidth: 'full'},
@@ -351,15 +355,12 @@
                         let iframe = window['layui-layer-iframe' + index];
                         console.log(iframe);
                         // console.log("父组件" + pageID);
-                        iframe.test1("123123");
+                        iframe.child(pageID);
                     }
                 });
             }
         });
-
     });
-
-
 </script>
 </body>
 </html>