admin
2020-11-10 e130e13ef0cc4a827aa2c8d9e47d619a4cea40d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <title>配置管理</title>
        <link rel="stylesheet" type="text/css" href="../../css/doui.min.css"/>
        <script src="../../js/doui.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="../../js/requestHost.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
            doui.importLoad({
                importArray: [
                    // 雷打不动
                    getHostPath() + "js/jquery.min.js",
                    getHostPath() + "js/vue.min.js",
                    // 字体图标
                    getHostPath() + "fontAdmin/iconfont.css",
                    getHostPath() + "font/iconfont.css",
                    // dom模板
                    getHostPath() + "css/admin-all.css",
                    getHostPath() + "js/admin-creat.js",
                    
                    getHostPath() + "js/verify.js",
                ],
            });
        </script>
    </head>
    <body class="fontPC">
        <div class="winSizeBox">
            
            <!-- =============================================================== 搜索筛选(顶部) -->
            <div id="thisHeader" style="width:7.5rem;"></div>
            
            <!-- =============================================================== 表格 -->
            <div id="thisTable" class="admin-main-overHeader"></div>
            
        </div>
    </body>
</html>
 
<script type="text/javascript">
    // doui准备完毕
    doui.onReady({
        success: function ()
        {
            // ----------------------------------------------------- 顶部
            // 生成顶部筛选项dom
            adminDom.header.creat({ el: "#thisHeader" });
            // 输入搜索
            adminDom.header.input({ placeholder: "根据选择填写", })
            
            // ----------------------------------------------------- 表格
            // 表格dom创建
            adminDom.table.creat({
                el: "#thisTable",
                // 搜索触发
                touchSearch: function (optC) 
                {
                    doui.showLoading({ content: "加载列表" });
                    doui.request({
                        type: "jsonp",
                        url: gethttp() + "/admin/new/api/v1/redpack/config/query",
                        data: {
                            pageIndex: optC.table.page, // 页码
                            pageSize: optC.table.pageSize, // 每页数量
                            key: optC.input[0].result, // 搜索关键字
                        },
                        success: function (res)
                        {
                            doui.hideLoading();
                            if (res.code != 0) { doui.showToast({ content: res.msg }); }
                            else 
                            {
                                // 申明 表格内容数据
                                var mo_tr = []; // tr组
                                for (var i = 0, mo = res.data.result_list; i < mo.length; i++)
                                {
                                    // 当前行
                                    var thatTr = {
                                        check: false,
                                        td: [
                                            { title: "ID", key: mo[i].id, value: mo[i].id },
                                            { title: "名称", key: mo[i].name, value: mo[i].name },
                                            { title: "标识", key: mo[i].key, value: mo[i].key },
                                            { title: "值", key: mo[i].value, value: mo[i].value },
                                            { title: "备注", key: mo[i].remark, value: mo[i].remark },
                                            { title: "生效时间", key: mo[i].validTime, value: mo[i].startTime },
                                            { title: "更新时间", key: mo[i].updateTime, value: mo[i].updateTime },
                                        ]
                                    };
                                    
                                    // 将当前行放入tr组
                                    mo_tr.push(thatTr);
                                }
                                // 更新表格的数据
                                adminDom.table.opt({ pageMax: res.data.pe.totalPage }); // 最大页码
                                adminDom.table.tbody({ tr: mo_tr }); // 内容数据
                            }
                        }
                    });
                },
            });
            // 表格设置
            adminDom.table.opt({ pageSize: 20, });
            // 表格头排
            adminDom.table.thead({
                th: [
                    { title: "ID", width: "0.3rem", orderUp: "", orderDown: "" },
                    { title: "名称", width: "0.4rem", orderUp: "", orderDown: "",
                        edit: { type: "text" },
                    },
                    { title: "标识", width: "0.4rem", orderUp: "", orderDown: "",
                        edit: { type: "text" },
                    },
                    { title: "值", width: "0.6rem", orderUp: "", orderDown: "",
                        edit: { type: "text" },
                    },
                    { title: "备注", width: "0.5rem", orderUp: "", orderDown: "",
                        edit: { type: "text" },
                    },
                    { title: "生效时间", width: "0.4rem", orderUp: "", orderDown: "",
                        edit: { type: "datetime-local" },
                    },
                    { title: "更新时间", width: "0.4rem", orderUp: "", orderDown: ""},
                ]
            });
            
            // 工具栏
            adminDom.table.tools({
                show: true,
                list: [
                    { "title": "新建", "name": "add", "icon": "fi fi-plus" }, 
                    //{ "title": "删除", "name": "del", "icon": "fi fi-trash" },
                    { "title": "修改", "name": "edit", "icon": "fi fi-edit-box" }, 
                ],
                touch: function (back)
                {
                    // 新建
                    if (back.toolName == "add")
                    {
                        // 修改弹框创建
                        adminDom.editTan.creat({
                            el: ".winSizeBox",
                            touchSubmit: function (thereData) 
                            {
                                // 当前数据
                                var item = thereData.list;
                                doui.showLoading("正在新建");
                                // 请求数据
                                var mydata = {
                                    name: item[1].key, 
                                    key: item[2].key, 
                                    value: item[3].key, 
                                    remark: item[4].key, 
                                };
                                if(verifyString(item[5].key)){ mydata.validTime = item[5].key; }
                                
                                // 信息上传
                                doui.upload({
                                    url: gethttp() + "/admin/new/api/v1/redpack/config/save",
                                    data: mydata,
                                    success: function (res) 
                                    {
                                        doui.hideLoading();
                                        if (res.code != 0) { doui.showToast(res.msg); }
                                        else { doui.showToast("新建成功"); adminDom.editTan.remove(); vm_table.search(); }
                                    }
                                });
                            },
                        });
                        adminDom.editTan.opt({ title: "新建" });
                        adminDom.editTan.thereData({ show: false, });
                    }
                    
                    // 删除
                    else if (back.toolName == "del")
                    {
                        // 被选中的行id组构建
                        var zu_id = new Array();
                        for (var i = 0, mo = back.list; i < mo.length; i++) { zu_id.push(mo[i][0].key); }
                        // 发起请求
                        doui.showLoading("正在删除");
                        doui.request({
                            type: "jsonp",
                            url: gethttp() + "/admin/new/api/v1/redpack/config/delete",
                            data: { idArray: zu_id },
                            success: function (res)
                            {
                                doui.hideLoading();
                                if (res.code != 0) { doui.showToast(res.msg); }
                                else { doui.showToast("删除成功"); vm_table.search(); }
                            }
                        });
                    }
                    
                    // 修改列表
                    else if (back.toolName == "edit")
                    {
                        if (back.list.length > 1) { doui.showToast({ content: "一次只能操作一个" }); return false; }
                        
                        // 修改弹框创建
                        adminDom.editTan.creat({
                            el: ".winSizeBox",
                            touchSubmit: function (thereData) 
                            {
                                // 当前数据
                                var item = thereData.list;
                                doui.showLoading("正在修改");
                                // 请求数据
                                var mydata = {
                                    id: item[0].key, 
                                    name: item[1].key,
                                    key: item[2].key, 
                                    value: item[3].key, 
                                    remark: item[4].key, 
                                };
                                if(verifyString(item[5].key)){ mydata.validTime = item[5].key; }
                                
                                // 信息上传
                                doui.upload({
                                    url: gethttp() + "/admin/new/api/v1/redpack/config/save",
                                    data: mydata,
                                    success: function (res) 
                                    {
                                        doui.hideLoading();
                                        if (res.code != 0) { doui.showToast(res.msg); }
                                        else { doui.showToast("修改成功"); adminDom.editTan.remove(); vm_table.search(); }
                                    }
                                });
                            },
                        });
                        adminDom.editTan.opt({ title: "修改" });
                        adminDom.editTan.thereData({ show: true, list: back.list[0] });
                    }
                }
            });
            
            // ----------------------------------------------------- 初始操作
            // 模拟搜索点击
            vm_table.search();
        }
    });
    
</script>