TaskManagement.vue
7.8 KB
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
<template>
<div class="task-management">
<el-card class="box-card">
<!-- 搜索栏 -->
<el-form :inline="true" class="demo-form-inline">
<el-form-item label="任务名称">
<el-input v-model="search.name" placeholder="任务名称"></el-input>
</el-form-item>
<el-button type="primary" @click="fetchTasks">搜索</el-button>
<el-button type="success" @click="showCreateForm">新建任务</el-button>
</el-form>
<!-- 任务列表 -->
<el-table
:data="tasksTableData"
border
style="width: 100%"
@selection-change="handleSelectionChange">
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column prop="name" label="任务名称"></el-table-column>
<el-table-column prop="cronExpression" label="Cron表达式"></el-table-column>
<el-table-column prop="query" label="状态">
<template slot-scope="scope">
{{ scope.row.query || '待执行' }}
</template>
</el-table-column>
<el-table-column label="操作" width="250">
<template slot-scope="scope">
<el-button size="mini" @click="showEditorm(scope.$index, scope.row)">编辑</el-button>
<el-popconfirm
confirm-button-text="好的"
cancel-button-text="不用了"
icon="el-icon-info"
icon-color="red"
title="确定删除该商品吗?"
@confirm="handleDelete(scope.$index, scope.row)"
>
<el-button
type="danger"
slot="reference"
>删除</el-button>
</el-popconfirm>
<el-button size="mini" type="primary" @click="showHistory(scope.row.id)">历史记录</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<el-pagination
layout="prev, pager, next"
:total="total"
@current-change="handlePageChange">
</el-pagination>
<!-- 新建/编辑弹窗 -->
<el-dialog :title="dialogMap[dialogStatus]" :visible.sync="dialogVisible" width="40%">
<el-form :model="from" label-width="100px">
<el-form-item label="任务名称">
<el-input v-model="from.name"></el-input>
</el-form-item>
<el-form-item label="Cron表达式">
<el-input v-model="from.cronExpression"></el-input>
</el-form-item>
<el-form-item label="查询密钥">
<el-input v-model="from.apiKey"></el-input>
</el-form-item>
<el-form-item label="查询类别">
<el-input v-model="from.categoryId"></el-input>
</el-form-item>
<el-form-item label="查询内容">
<el-input type="textarea" v-model="from.inputs"></el-input>
</el-form-item>
<!-- 其他字段... -->
</el-form>
<span slot="footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="dialogStatus==='create'?outerVisible_add():outerVisible_edit()">保存</el-button>
</span>
</el-dialog>
<!-- 历史记录弹窗 -->
<task-history
:visible="historyVisible"
:task-id="currentTaskId"
@close="historyVisible = false">
</task-history>
</el-card>
</div>
</template>
<script>
import TaskHistory from './TaskHistory.vue';
import api from '../../../api/task/index';
export default {
components: {TaskHistory},
data() {
return {
from:{
id: undefined,
name: "",
cronExpression: "",
query: "",
inputs: "",
username: "",
conversationId: "",
apiKey: "",
responseMode: "",
createdAt: "",
updatedAt:"",
categoryId: 0
},
tasksTableData: [],
search: {name: ''},
dialogVisible: false,
dialogTitle: '新建任务',
currentTask: {},
currentTaskId: 0,
historyVisible: false,
selectedTasks: [],
total:0,
dialogStatus:'create',
dialogMap:{
update: '编辑',
create: '添加'
},
};
},
methods: {
async outerVisible_add(){
try {
const res = await api.createTask(this.from);
if(res.data.code=='200'){
this.$message.success('任务新增成功');
}else{
this.$message.success('任务新增失败');
}
this.dialogVisible=false;
this.fetchTasks();
} catch (e) {
this.$message.error('新增任务失败');
}
},
async outerVisible_edit(){
try {
const res = await api.updateTask(this.from.id,this.from);
if(res.data.code=='200'){
this.$message.success('任务更新成功');
}else{
this.$message.success('任务更新失败');
}
this.dialogVisible=false;
this.fetchTasks();
} catch (e) {
this.$message.error('任务更新失败');
}
},
handlePageChange(){},
showCreateForm(){
this.dialogStatus='create';
this.dialogVisible=true;
},
handleSelectionChange(){},
async showHistory(id){
this.currentTaskId=id;
this.historyVisible=true;
},
async handleDelete(index,row){
const res = await api.deleteTask(row.id);
if(res.data.code=='200'){
this.$message.success('任务删除成功');
}else{
this.$message.success('任务删除失败');
}
this.fetchTasks();
},
showEditForm(index,row){
console.log(row)
this.dialogStatus='update';
this.from=row;
this.dialogVisible=true;
},
async fetchTasks() {
try {
const res = await api.getAllTasks();
this.tasksTableData = res.data.data;
} catch (e) {
this.$message.error('加载任务失败');
}
},
// 其他方法...
},
created() {
this.fetchTasks();
}
};
</script>