Explorar el Código

feat: 元素增加功能

zhangyuantao hace 1 año
padre
commit
68c9638892

+ 7 - 0
src/main/java/com/tao/controller/AppElementController.java

@@ -80,4 +80,11 @@ public class AppElementController {
         }
     }
 
+    @PostMapping("/add")
+    @ResponseBody
+    public AjaxResult addElement(AppElement appElement) {
+        appElementService.insertAppElement(appElement);
+        return AjaxResult.success("添加成功");
+    }
+
 }

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

@@ -2,18 +2,109 @@
 <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" 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;
+        });
+
+    });
+
+    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>