|
|
<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> |
...
|
...
|
|