|
|
1
|
+<template>
|
|
|
2
|
+ <div class="task-management">
|
|
|
3
|
+ <el-card class="box-card">
|
|
|
4
|
+ <!-- 搜索栏 -->
|
|
|
5
|
+ <el-form :inline="true" class="demo-form-inline">
|
|
|
6
|
+ <el-form-item label="任务名称">
|
|
|
7
|
+ <el-input v-model="search.name" placeholder="任务名称"></el-input>
|
|
|
8
|
+ </el-form-item>
|
|
|
9
|
+ <el-button type="primary" @click="fetchTasks">搜索</el-button>
|
|
|
10
|
+ <el-button type="success" @click="showCreateForm">新建任务</el-button>
|
|
|
11
|
+ </el-form>
|
|
|
12
|
+
|
|
|
13
|
+ <!-- 任务列表 -->
|
|
|
14
|
+ <el-table
|
|
|
15
|
+ :data="tasksTableData"
|
|
|
16
|
+ border
|
|
|
17
|
+ style="width: 100%"
|
|
|
18
|
+ @selection-change="handleSelectionChange">
|
|
|
19
|
+ <el-table-column
|
|
|
20
|
+ type="selection"
|
|
|
21
|
+ width="55">
|
|
|
22
|
+ </el-table-column>
|
|
|
23
|
+ <el-table-column prop="name" label="任务名称"></el-table-column>
|
|
|
24
|
+ <el-table-column prop="cronExpression" label="Cron表达式"></el-table-column>
|
|
|
25
|
+ <el-table-column prop="query" label="状态">
|
|
|
26
|
+ <template slot-scope="scope">
|
|
|
27
|
+ {{ scope.row.query || '待执行' }}
|
|
|
28
|
+ </template>
|
|
|
29
|
+ </el-table-column>
|
|
|
30
|
+ <el-table-column label="操作" width="250">
|
|
|
31
|
+ <template slot-scope="scope">
|
|
|
32
|
+ <el-button size="mini" @click="showEditorm(scope.$index, scope.row)">编辑</el-button>
|
|
|
33
|
+ <el-popconfirm
|
|
|
34
|
+ confirm-button-text="好的"
|
|
|
35
|
+ cancel-button-text="不用了"
|
|
|
36
|
+ icon="el-icon-info"
|
|
|
37
|
+ icon-color="red"
|
|
|
38
|
+ title="确定删除该商品吗?"
|
|
|
39
|
+ @confirm="handleDelete(scope.$index, scope.row)"
|
|
|
40
|
+ >
|
|
|
41
|
+ <el-button
|
|
|
42
|
+ type="danger"
|
|
|
43
|
+ slot="reference"
|
|
|
44
|
+ >删除</el-button>
|
|
|
45
|
+ </el-popconfirm>
|
|
|
46
|
+ <el-button size="mini" type="primary" @click="showHistory(scope.row.id)">历史记录</el-button>
|
|
|
47
|
+ </template>
|
|
|
48
|
+ </el-table-column>
|
|
|
49
|
+ </el-table>
|
|
|
50
|
+
|
|
|
51
|
+ <!-- 分页 -->
|
|
|
52
|
+ <el-pagination
|
|
|
53
|
+ layout="prev, pager, next"
|
|
|
54
|
+ :total="total"
|
|
|
55
|
+ @current-change="handlePageChange">
|
|
|
56
|
+ </el-pagination>
|
|
|
57
|
+
|
|
|
58
|
+ <!-- 新建/编辑弹窗 -->
|
|
|
59
|
+ <el-dialog :title="dialogMap[dialogStatus]" :visible.sync="dialogVisible" width="40%">
|
|
|
60
|
+ <el-form :model="from" label-width="100px">
|
|
|
61
|
+ <el-form-item label="任务名称">
|
|
|
62
|
+ <el-input v-model="from.name"></el-input>
|
|
|
63
|
+ </el-form-item>
|
|
|
64
|
+ <el-form-item label="Cron表达式">
|
|
|
65
|
+ <el-input v-model="from.cronExpression"></el-input>
|
|
|
66
|
+ </el-form-item>
|
|
|
67
|
+ <el-form-item label="查询密钥">
|
|
|
68
|
+ <el-input v-model="from.apiKey"></el-input>
|
|
|
69
|
+ </el-form-item>
|
|
|
70
|
+ <el-form-item label="查询类别">
|
|
|
71
|
+ <el-input v-model="from.categoryId"></el-input>
|
|
|
72
|
+ </el-form-item>
|
|
|
73
|
+ <el-form-item label="查询内容">
|
|
|
74
|
+ <el-input type="textarea" v-model="from.inputs"></el-input>
|
|
|
75
|
+ </el-form-item>
|
|
|
76
|
+ <!-- 其他字段... -->
|
|
|
77
|
+ </el-form>
|
|
|
78
|
+ <span slot="footer">
|
|
|
79
|
+ <el-button @click="dialogVisible = false">取消</el-button>
|
|
|
80
|
+<el-button type="primary" @click="dialogStatus==='create'?outerVisible_add():outerVisible_edit()">保存</el-button>
|
|
|
81
|
+</span>
|
|
|
82
|
+ </el-dialog>
|
|
|
83
|
+
|
|
|
84
|
+ <!-- 历史记录弹窗 -->
|
|
|
85
|
+ <task-history
|
|
|
86
|
+ :visible="historyVisible"
|
|
|
87
|
+ :task-id="currentTaskId"
|
|
|
88
|
+ @close="historyVisible = false">
|
|
|
89
|
+ </task-history>
|
|
|
90
|
+ </el-card>
|
|
|
91
|
+ </div>
|
|
|
92
|
+</template>
|
|
|
93
|
+
|
|
|
94
|
+<script>
|
|
|
95
|
+ import TaskHistory from './TaskHistory.vue';
|
|
|
96
|
+ import api from '../../../api/task/index';
|
|
|
97
|
+
|
|
|
98
|
+ export default {
|
|
|
99
|
+ components: {TaskHistory},
|
|
|
100
|
+ data() {
|
|
|
101
|
+ return {
|
|
|
102
|
+ from:{
|
|
|
103
|
+ id: undefined,
|
|
|
104
|
+ name: "",
|
|
|
105
|
+ cronExpression: "",
|
|
|
106
|
+ query: "",
|
|
|
107
|
+ inputs: "",
|
|
|
108
|
+ username: "",
|
|
|
109
|
+ conversationId: "",
|
|
|
110
|
+ apiKey: "",
|
|
|
111
|
+ responseMode: "",
|
|
|
112
|
+ createdAt: "",
|
|
|
113
|
+ updatedAt:"",
|
|
|
114
|
+ categoryId: 0
|
|
|
115
|
+ },
|
|
|
116
|
+ tasksTableData: [],
|
|
|
117
|
+ search: {name: ''},
|
|
|
118
|
+ dialogVisible: false,
|
|
|
119
|
+ dialogTitle: '新建任务',
|
|
|
120
|
+ currentTask: {},
|
|
|
121
|
+ currentTaskId: 0,
|
|
|
122
|
+ historyVisible: false,
|
|
|
123
|
+ selectedTasks: [],
|
|
|
124
|
+ total:0,
|
|
|
125
|
+ dialogStatus:'create',
|
|
|
126
|
+ dialogMap:{
|
|
|
127
|
+ update: '编辑',
|
|
|
128
|
+ create: '添加'
|
|
|
129
|
+ },
|
|
|
130
|
+ };
|
|
|
131
|
+ },
|
|
|
132
|
+ methods: {
|
|
|
133
|
+ async outerVisible_add(){
|
|
|
134
|
+ try {
|
|
|
135
|
+ const res = await api.createTask(this.from);
|
|
|
136
|
+ if(res.data.code=='200'){
|
|
|
137
|
+ this.$message.success('任务新增成功');
|
|
|
138
|
+ }else{
|
|
|
139
|
+ this.$message.success('任务新增失败');
|
|
|
140
|
+ }
|
|
|
141
|
+ this.dialogVisible=false;
|
|
|
142
|
+ this.fetchTasks();
|
|
|
143
|
+ } catch (e) {
|
|
|
144
|
+ this.$message.error('新增任务失败');
|
|
|
145
|
+ }
|
|
|
146
|
+ },
|
|
|
147
|
+ async outerVisible_edit(){
|
|
|
148
|
+ try {
|
|
|
149
|
+ const res = await api.updateTask(this.from.id,this.from);
|
|
|
150
|
+ if(res.data.code=='200'){
|
|
|
151
|
+ this.$message.success('任务更新成功');
|
|
|
152
|
+ }else{
|
|
|
153
|
+ this.$message.success('任务更新失败');
|
|
|
154
|
+ }
|
|
|
155
|
+ this.dialogVisible=false;
|
|
|
156
|
+ this.fetchTasks();
|
|
|
157
|
+ } catch (e) {
|
|
|
158
|
+ this.$message.error('任务更新失败');
|
|
|
159
|
+ }
|
|
|
160
|
+ },
|
|
|
161
|
+ handlePageChange(){},
|
|
|
162
|
+ showCreateForm(){
|
|
|
163
|
+ this.dialogStatus='create';
|
|
|
164
|
+ this.dialogVisible=true;
|
|
|
165
|
+ },
|
|
|
166
|
+ handleSelectionChange(){},
|
|
|
167
|
+ async showHistory(id){
|
|
|
168
|
+ this.currentTaskId=id;
|
|
|
169
|
+ this.historyVisible=true;
|
|
|
170
|
+ },
|
|
|
171
|
+ async handleDelete(index,row){
|
|
|
172
|
+ const res = await api.deleteTask(row.id);
|
|
|
173
|
+ if(res.data.code=='200'){
|
|
|
174
|
+ this.$message.success('任务删除成功');
|
|
|
175
|
+ }else{
|
|
|
176
|
+ this.$message.success('任务删除失败');
|
|
|
177
|
+ }
|
|
|
178
|
+ this.fetchTasks();
|
|
|
179
|
+ },
|
|
|
180
|
+ showEditForm(index,row){
|
|
|
181
|
+ console.log(row)
|
|
|
182
|
+ this.dialogStatus='update';
|
|
|
183
|
+ this.from=row;
|
|
|
184
|
+ this.dialogVisible=true;
|
|
|
185
|
+ },
|
|
|
186
|
+ async fetchTasks() {
|
|
|
187
|
+ try {
|
|
|
188
|
+ const res = await api.getAllTasks();
|
|
|
189
|
+ this.tasksTableData = res.data.data;
|
|
|
190
|
+ } catch (e) {
|
|
|
191
|
+ this.$message.error('加载任务失败');
|
|
|
192
|
+ }
|
|
|
193
|
+ },
|
|
|
194
|
+ // 其他方法...
|
|
|
195
|
+ },
|
|
|
196
|
+ created() {
|
|
|
197
|
+ this.fetchTasks();
|
|
|
198
|
+ }
|
|
|
199
|
+ };
|
|
|
200
|
+</script> |