Commit 8e6fae5a authored by lijin's avatar lijin

优化广告任务执行

parent 6bea7a14
import request from '@/utils/request'
export function getCampaignTaskDetailById(id) {
return request({
url: process.env.PUTIN_API + `/campaign-task-details/${id}`,
method: 'get'
})
}
export function getCampaignTaskDetails(params) {
return request({
url: process.env.PUTIN_API + '/campaign-task-details',
method: 'get',
params
})
}
......@@ -90,7 +90,7 @@
@click="handleEdit(scope.row)">编辑</el-button>
<el-button
size="mini"
type="info"
type="success"
@click="handleDetail(scope.row)">详情</el-button>
<el-button
v-if="scope.row.status === 1"
......@@ -103,11 +103,11 @@
type="success"
disabled
>开始</el-button>
<el-button
<!-- <el-button
v-if="scope.row.status === 4"
size="mini"
type="warning"
@click="handleRetry(scope.row)">重试</el-button>
@click="handleRetry(scope.row)">重试</el-button> -->
</template>
</el-table-column>
</el-table>
......@@ -138,12 +138,51 @@
<el-button type="primary" @click="submitForm">确 定</el-button>
</div>
</el-dialog>
<!-- 计划任务详情对话框 -->
<el-dialog
title="计划任务详情"
:visible.sync="detailVisible"
width="80%"
>
<el-table :data="currentTaskDetail" border>
<el-table-column prop="id" label="ID"></el-table-column>
<el-table-column prop="advertiserId" label="广告账户ID"></el-table-column>
<el-table-column prop="campaignId" label="广告计划ID"></el-table-column>
<el-table-column prop="adgroupId" label="广告组ID"></el-table-column>
<el-table-column prop="startTime" label="开始时间">
<template slot-scope="scope">
{{ scope.row.startTime ? moment(scope.row.startTime).format('YYYY-MM-DD HH:mm:ss') : '' }}
</template>
</el-table-column>
<el-table-column prop="finishTime" label="结束时间">
<template slot-scope="scope">
{{ scope.row.finishTime ? moment(scope.row.finishTime).format('YYYY-MM-DD HH:mm:ss') : '' }}
</template>
</el-table-column>
<el-table-column label="执行时间" width="150">
<template slot-scope="scope">
{{ calculateDuration(scope.row) }}
</template>
</el-table-column>
<el-table-column prop="status" label="状态">
<template slot-scope="scope">
<el-tag :type="getStatusType(scope.row.status)">
{{ getStatusText(scope.row.status) }}
</el-tag>
</template>
</el-table-column>
</el-table>
</el-dialog>
</div>
</template>
<script>
import CampaignTemplateSelector from '@/components/GroupSelectors/CampaignTemplateSelector'
import { getCampaignTaskList, createCampaignTask, updateCampaignTask } from '@/api/campaignTask'
import { getCampaignTaskDetailById, getCampaignTaskDetails } from '@/api/campaignTaskDetail'
import axios from 'axios'
import moment from 'moment'
......@@ -180,7 +219,10 @@ export default {
{ required: true, message: '请选择计划模板', trigger: 'change' }
]
},
templateMap: new Map()
templateMap: new Map(),
detailVisible: false,
errorReasonVisible: false,
currentTaskDetail: null
}
},
created() {
......@@ -302,16 +344,32 @@ export default {
},
handleDetail(row) {
// TODO: 实现详情查看功能
console.log('查看详情:', row)
this.detailVisible = true;
this.detailLoading = true;
this.currentTaskDetail = null;
getCampaignTaskDetails({taskId: row.id}).then(response => {
if (response.status === 200) {
this.currentTaskDetail = response.result.data;
} else {
this.$message.error(response.msg || '获取任务详情失败');
}
}).catch(error => {
console.error('获取任务详情失败:', error);
this.$message.error('获取任务详情失败: ' + error.message);
}).finally(() => {
this.detailLoading = false;
});
},
async handleStart(row) {
try {
const response = await axios.post(process.env.PUTIN_API + `/campaign-tasks/start?campaignTaskId=${row.id}`)
if (response.status == 200 &&response.data && response.data.result && response.data.result.data) {
if (response.status == 200) {
this.$message.success('任务开始成功')
this.fetchData()
} else {
this.$message.error('任务开始失败')
}
} catch (error) {
console.error('Failed to start task:', error)
......@@ -348,6 +406,21 @@ export default {
}
}
})
},
showErrorReason() {
this.errorReasonVisible = true;
},
formatJson(jsonString) {
try {
// 如果是字符串,则解析为JSON对象
const jsonObj = typeof jsonString === 'string' ? JSON.parse(jsonString) : jsonString;
// 美化格式
return JSON.stringify(jsonObj, null, 2);
} catch (e) {
return jsonString;
}
}
}
}
......@@ -459,4 +532,8 @@ export default {
.el-pagination__sizes {
margin-left: 10px;
}
.mt-3 {
margin-top: 1rem;
}
</style>
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