1
2024-01-24 67fb3bd7367fdf8a5b2186d4ff1c0f4d572c6d91
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>任务首页</title>
    <meta name="author" content="小柒2012" />
    <meta name="site" content="https://blog.52itstyle.com" />
    <link rel="stylesheet" th:href="@{/iview/iview.css}">
    <script th:src="@{/libs/jquery-3.2.1.min.js}" type="text/javascript"></script>
    <script th:src="@{/libs/vue.min.js}" type="text/javascript"></script>
    <script th:src="@{/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/iview/iview.min.js}" type="text/javascript"></script>
    <script th:src="@{/common.js}" type="text/javascript"></script>
    <style type="text/css">
    [v-cloak] {
              display: none;
            }
    </style>
</head>
<body>
<div id="app" v-cloak>
        <div style="margin-bottom: 6px;margin: 30px">
            <i-input v-model="content" placeholder="任务名称"  style="width: 300px"></i-input>
            <i-button type="primary" @click="search()" icon="ios-search">搜索</i-button>
            <i-button type="primary" @click="empty()" icon="ios-close-empty">清空</i-button>
            <i-button type="info" style="float: right;" @click="add()" icon="person-add">新增</i-button>
        </div>
        <div style="margin-bottom: 6px;margin: 30px">
            <template> 
                <i-table border :content="self" :columns="tableTitle" :data="JobData"></i-table>
                 <br>
                <Page  style="float: right;" :current="pageNo" :total="tableSize" :page-size="pageSize"  @on-change="changePage" @on-page-size-change="changePageSize" show-elevator show-sizer show-total></Page>
            </template>
        </div>
</div>
<script type="text/javascript">
var vm = new Vue({
    el : '#app',
    data : {
        content : '',
        pageNo : 1,
        pageSize : 10,
        jobName : "",
        JobData : [],
        tableSize : 50,
        tableTitle:[ {
            key : "jobName",
            title : "任务名称"
        }, {
            key : "jobGroup",
            title : "任务分组"
        }, {
            key : "description",
            title : "描述"
        }, {
            key : "jobClassName",
            title : "执行类"
        },{
            key : "jobMethodName",
            title : "执行方法"
        },{
            key : "cronExpression",
            title : "执行时间"
        }, {
            title : '操作',
            key : 'action',
            width : 300,
            align : 'left',
            render : function(h, params) {
                var functionList = [];
                //执行
                var trigger = h('Button', {
                    props : {
                        type : 'primary',
                        size : 'small',
                        icon : 'ios-play'
                    },
                    style : {
                        marginRight : '8px'
                    },
                    on : {
                        click : function() {
                            vm.trigger(params.row.jobName,params.row.jobGroup);
                        }
                    }
                }, '执行');
                functionList.push(trigger);
                //修改
                var edit = h('Button', {
                    props : {
                        type : 'primary',
                        size : 'small',
                        icon : 'edit'
                    },
                    style : {
                        marginRight : '8px'
                    },
                    on : {
                        click : function() {
                            vm.edit(params.row);
                        }
                    }
                }, '修改');
                functionList.push(edit);
                //移除
                var remove = h('Button', {
                    props : {
                        type : 'primary',
                        size : 'small',
                        icon : 'close'
                    },
                    style : {
                        marginRight : '8px'
                    },
                    on : {
                        click : function() {
                            vm.remove(params.row.jobName,params.row.jobGroup);
                        }
                    }
                }, '移除');
                functionList.push(remove);
                if(params.row.triggerState=="PAUSED"){
                    //恢复
                    var resume = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'ios-reload'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.resume(params.row.jobName,params.row.jobGroup);
                            }
                        }
                    }, '恢复');
                    functionList.push(resume);
                }else{
                    //停止
                    var pause = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'ios-pause'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.pause(params.row.jobName,params.row.jobGroup);
                            }
                        }
                    }, '停止');
                    functionList.push(pause);
                }
                // 返回方法集合
                return h('div', functionList);
            }
        }]
        
    },
    methods : {
        //搜索
        search : function(){
             $.ajax({
                    url:"../job/list",
                    type:"post",
                    data:{'jobName':this.content,"pageNo":this.pageNo,'pageSize':this.pageSize},
                    success: function(result) {
 
                    }
            });
        },
        empty : function(){
            vm.content = '';
            this.list();
        },
        //任务列表(自行实现分页)
        list : function() {
            $.ajax({
                url:"../job/list",
                type:"post",
                data:{'time':(new Date()).toString(),"pageNo":this.pageNo,'pageSize':this.pageSize},
                success: function(result) {
                    vm.JobData = result.msg.pageData;
                    vm.tableSize = result.msg.totalCount;
                }
            });
        },
        //触发任务
        trigger : function(jobName,jobGroup){
            $.ajax({
                url:"../job/trigger",
                type:"post",
                data:{'time':(new Date()).toString(),"jobName":jobName,'jobGroup':jobGroup},
                success: function(result) {
                    if(result.code=="0"){
                        vm.$Notice.success({
                            desc:  '任务执行成功'
                        });
                    }
                }
            });
        },
        //停止任务
        pause : function(jobName,jobGroup){
            $.ajax({
                url:"../job/pause",
                type:"post",
                data:{'time':(new Date()).toString(),"jobName":jobName,'jobGroup':jobGroup},
                success: function(result) {
                    if(result.code=="0"){
                        vm.$Notice.success({
                            desc:  '停止任务成功'
                        });
                        vm.list();
                    }
                }
            });
        },
        //恢复任务
        resume : function(jobName,jobGroup){
            $.ajax({
                url:"../job/resume",
                type:"post",
                data:{'time':(new Date()).toString(),"jobName":jobName,'jobGroup':jobGroup},
                success: function(result) {
                    if(result.code=="0"){
                        vm.$Notice.success({
                            desc:  '恢复任务成功'
                        });
                        vm.list();
                    }
                }
            });
        },
        //新建任务
        add : function(){
            dialogOpen({
                title: '新增',
                url: 'task/add.shtml',
                scroll : true,
                width: '500px',
                height: '500px',
                yes : function(iframeId) {
                    top.frames[iframeId].vm.acceptClick();
                },
            });  
        },
        edit : function(quartz){
            dialogOpen({
                title: '修改',
                url: 'task/add.shtml',
                scroll : true,
                width: '500px',
                height: '500px',
                success : function(iframeId){
                    top.frames[iframeId].vm.formQuartz = quartz;
                },
                yes : function(iframeId) {
                    top.frames[iframeId].vm.acceptClick();
                },
            });
        },
        //移除任务
        remove : function(jobName,jobGroup){
            var that = this;
            top.layer.confirm('确定要移除任务吗?', {
                  btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    url:"../job/remove",
                    type:"post",
                    data:{'time':(new Date()).toString(),"jobName":jobName,'jobGroup':jobGroup},
                    success: function(result) {
                        if(result.code=="0"){
                            top.layer.msg('任务移除成功', {icon: 1});
                            window.setTimeout(that.list(),1500); 
                        }
                    }
                });
            }, function(){
              
            });
        },
        reload :  function(){
            this.load();
        },
        changePage : function(pageNo) {
            vm.pageNo = pageNo;
            vm.load();
        },
        changePageSize : function(pageSize) {
            vm.pageSize = pageSize;
            vm.load();
        }
    },
    created : function() {
        this.list();
    }
})
 
</script>
</body>
</html>