Commit 944a7e39 authored by hzl's avatar hzl

feat: 一键执行

parent 75ea1aff
...@@ -42,6 +42,15 @@ ...@@ -42,6 +42,15 @@
<!-- Table Header actions --> <!-- Table Header actions -->
<div class="header-actions"> <div class="header-actions">
<el-button type="primary" @click="showAddDialog">创建任务</el-button> <el-button type="primary" @click="showAddDialog">创建任务</el-button>
<el-button
type="success"
icon="el-icon-video-play"
class="batch-execute-btn"
@click="batchExecuteTasks"
:loading="batchExecuteLoading"
:disabled="!hasExecutableTasks">
一键执行
</el-button>
<div class="header-right"> <div class="header-right">
<el-button icon="el-icon-refresh" @click="fetchData">刷新</el-button> <el-button icon="el-icon-refresh" @click="fetchData">刷新</el-button>
</div> </div>
...@@ -861,6 +870,7 @@ export default { ...@@ -861,6 +870,7 @@ export default {
return { return {
loading: false, loading: false,
startLoading: false, // 新增:任务启动loading状态 startLoading: false, // 新增:任务启动loading状态
batchExecuteLoading: false, // 新增:批量执行loading状态
condition: { condition: {
templateId: null, templateId: null,
status: null, status: null,
...@@ -1099,6 +1109,16 @@ export default { ...@@ -1099,6 +1109,16 @@ export default {
campaignLocationGroups: [], campaignLocationGroups: [],
} }
}, },
computed: {
// 计算是否有可执行的任务(只包括状态为1未执行的任务)
hasExecutableTasks() {
return this.tableData.some(row => row.status === 1);
},
// 获取当前页可执行的任务列表(只包括状态为1未执行的任务)
executableTasks() {
return this.tableData.filter(row => row.status === 1);
}
},
created() { created() {
this.fetchData() this.fetchData()
this.initGroupOptions() this.initGroupOptions()
...@@ -1367,6 +1387,69 @@ export default { ...@@ -1367,6 +1387,69 @@ export default {
} }
}, },
// 批量执行任务
async batchExecuteTasks() {
if (!this.hasExecutableTasks) {
this.$message.warning('当前页没有可执行的任务');
return;
}
const executableTasks = this.executableTasks;
const taskCount = executableTasks.length;
// 确认对话框
const confirmResult = await this.$confirm(
`确定要执行当前页的 ${taskCount} 个任务吗?`,
'批量执行确认',
{
confirmButtonText: '确定执行',
cancelButtonText: '取消',
type: 'warning'
}
).catch(() => false);
if (!confirmResult) {
return;
}
this.batchExecuteLoading = true;
try {
// 调用批量执行接口
const response = await axios.post(process.env.PUTIN_API + '/campaign-tasks/batch-start', {
taskIds: executableTasks.map(task => task.id)
});
if (response.status === 200) {
const result = response.data;
if (result.status === 200) {
const successCount = (result.result && result.result.successCount) || 0;
const failCount = (result.result && result.result.failCount) || 0;
if (successCount > 0) {
this.$message.success(`批量执行完成:成功 ${successCount} 个,失败 ${failCount} 个`);
} else {
this.$message.error('所有任务执行失败');
}
// 刷新数据
this.fetchData();
} else {
this.$message.error(result.msg || '批量执行失败');
}
} else {
this.$message.error('批量执行失败');
}
} catch (error) {
console.error('批量执行失败:', error);
const errorMessage = error.response && error.response.data && error.response.data.message ?
error.response.data.message : error.message;
this.$message.error('批量执行失败:' + errorMessage);
} finally {
this.batchExecuteLoading = false;
}
},
submitForm() { submitForm() {
this.$refs.form.validate(async valid => { this.$refs.form.validate(async valid => {
if (valid) { if (valid) {
...@@ -2368,6 +2451,8 @@ export default { ...@@ -2368,6 +2451,8 @@ export default {
margin: 20px 0; margin: 20px 0;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center;
gap: 10px;
} }
.header-right { .header-right {
...@@ -2375,6 +2460,24 @@ export default { ...@@ -2375,6 +2460,24 @@ export default {
gap: 10px; gap: 10px;
} }
.batch-execute-btn {
background: linear-gradient(135deg, #67c23a 0%, #85ce61 100%);
border: none;
box-shadow: 0 2px 8px rgba(103, 194, 58, 0.3);
transition: all 0.3s ease;
}
.batch-execute-btn:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(103, 194, 58, 0.4);
}
.batch-execute-btn:disabled {
background: #c0c4cc;
box-shadow: none;
transform: none;
}
.el-tag { .el-tag {
margin-right: 5px; margin-right: 5px;
margin-bottom: 5px; margin-bottom: 5px;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment