From ba8707edce069705cfea7e1616f72283f74e67ed Mon Sep 17 00:00:00 2001
From: 18516761980 <4761516tqsxp>
Date: 星期二, 01 三月 2022 08:30:40 +0800
Subject: [PATCH] .

---
 src/main/webapp/static/js/itemTable.js |  153 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 153 insertions(+), 0 deletions(-)

diff --git a/src/main/webapp/static/js/itemTable.js b/src/main/webapp/static/js/itemTable.js
new file mode 100644
index 0000000..8c5c063
--- /dev/null
+++ b/src/main/webapp/static/js/itemTable.js
@@ -0,0 +1,153 @@
+layui.config({
+    base: baseUrl + "/static/layui/lay/modules/"  // 閰嶇疆妯″潡鎵�鍦ㄧ殑鐩綍
+}).use(['table','laydate', 'form',  'admin'], function() {
+    var table = layui.table;
+    var $ = layui.jquery;
+    var layer = layui.layer;
+    var layDate = layui.laydate;
+    var form = layui.form;
+    var admin = layui.admin;
+
+    /****************************************** 宸﹁竟琛� *************************************************/
+
+    var insTb = table.render({
+        elem: '#originTable',
+        url: baseUrl + '/item/list/auth',
+        height: 'full-100',
+        headers: {token: localStorage.getItem('token')},
+        request: {
+            pageName: 'curr',
+            pageSize: 'limit'
+        },
+        parseData: function (res) {
+            return {
+                'code': res.code,
+                'msg': res.msg,
+                'count': res.data.total,
+                'data': res.data.records
+            }
+        },
+        response: {
+            statusCode: 200
+        },
+        /*toolbar: ['<p>',
+            '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>娣诲姞</button>&nbsp;',
+            '<button lay-event="edit" class="layui-btn layui-btn-sm layui-btn-warm icon-btn"><i class="layui-icon">&#xe642;</i>淇敼</button>&nbsp;',
+            '<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon">&#xe640;</i>鍒犻櫎</button>',
+            '</p>'].join(''),*/
+        defaultToolbar: [],
+        cols: [[
+            {field: 'id', title: '缂栧彿', width: 70, align: 'center'},
+            {field: 'name', title: '椤圭洰鍚嶇О'}
+        ]],
+        done: function (res, curr, count) {
+            $('#dictTable+.layui-table-view .layui-table-body tbody>tr:first').trigger('click');
+        }
+    });
+
+    /* 琛ㄦ牸鎼滅储 */
+    form.on('submit(originTableSearch)', function (data) {
+        insTb.reload({where: {name: data.field.name}});
+        return false;
+    });
+
+    /* 琛ㄦ牸鎼滅储 */
+    form.on('submit(originTbReset)', function (data) {
+        insTb.reload();
+        insTb2.reload({where: {item_id: null}, page: {curr: 1}});
+        return false;
+    });
+
+    /* 琛ㄦ牸澶村伐鍏锋爮鐐瑰嚮浜嬩欢 */
+    table.on('toolbar(originTable)', function (obj) {
+        if (obj.event === 'add') { // 娣诲姞
+            showEdit();
+        } else if (obj.event === 'edit') { // 淇敼
+            if (selObj == null) {
+                return;
+            }
+            showEdit(selObj.data);
+        } else if (obj.event === 'del') { // 鍒犻櫎
+            if (selObj == null) {
+                return;
+            }
+            doDel(selObj);
+        }
+    });
+
+    /* 鐩戝惉琛屽崟鍑讳簨浠� */
+    var selObj;
+    table.on('row(originTable)', function (obj) {
+        selObj = obj;
+        obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
+        insTb2.reload({where: {item_id: obj.data.id}, page: {curr: 1}});
+    });
+
+    /* 鏄剧ず琛ㄥ崟寮圭獥 */
+    function showEdit(mData) {
+        admin.open({
+            type: 1,
+            title: (mData ? '淇敼' : '娣诲姞') + '椤圭洰',
+            content: $('#hostEditDialog').html(),
+            success: function (layero, dIndex) {
+                // 鍥炴樉琛ㄥ崟鏁版嵁
+                form.val('hostEditForm', mData);
+                // 琛ㄥ崟鎻愪氦浜嬩欢
+                form.on('submit(hostEditSubmit)', function (data) {
+                    var loadIndex = layer.load(2);
+                    $.ajax({
+                        url: baseUrl+"/host/"+(mData?'update':'add')+"/auth",
+                        headers: {'token': localStorage.getItem('token')},
+                        data: data.field,
+                        method: 'POST',
+                        success: function (res) {
+                            layer.close(loadIndex);
+                            selObj = null;
+                            if (res.code === 200){
+                                layer.close(dIndex);
+                                layer.msg(res.msg, {icon: 1});
+                                insTb.reload();
+                            } else if (res.code === 403){
+                                top.location.href = baseUrl+"/";
+                            } else {
+                                layer.msg(res.msg, {icon: 2});
+                            }
+                        }
+                    })
+                    return false;
+                });
+            }
+        });
+    }
+
+    /* 鍒犻櫎 */
+    function doDel(obj) {
+        layer.confirm('纭畾瑕佸垹闄ゆ鍗曟嵁绫诲瀷鍚楋紵', {
+            skin: 'layui-layer-admin',
+            shade: .1
+        }, function (i) {
+            layer.close(i);
+            var loadIndex = layer.load(2);
+            $.ajax({
+                url: baseUrl+"/host/delete/one/auth",
+                headers: {'token': localStorage.getItem('token')},
+                data: {param: JSON.stringify(obj.data)},
+                method: 'POST',
+                success: function (res) {
+                    selObj = null;
+                    layer.close(loadIndex);
+                    if (res.code === 200){
+                        layer.closeAll();
+                        insTb.reload();
+                        $('#dictTable+.layui-table-view .layui-table-body tbody>tr:first').trigger('click');
+                    } else if (res.code === 403){
+                        top.location.href = baseUrl+"/";
+                    } else {
+                        layer.msg(res.msg, {icon: 2});
+                    }
+                }
+            })
+        });
+    }
+
+})

--
Gitblit v1.9.1