feat: 新增报告生成任务管理功能
parent
1e9803bada
commit
b0190e2c5f
@ -0,0 +1,214 @@
|
|||||||
|
<template>
|
||||||
|
<ElDrawer
|
||||||
|
:model-value="visible"
|
||||||
|
title="操作日志"
|
||||||
|
direction="rtl"
|
||||||
|
size="460px"
|
||||||
|
append-to-body
|
||||||
|
@update:model-value="(v: boolean) => emit('update:visible', v)"
|
||||||
|
>
|
||||||
|
<template v-if="taskId">
|
||||||
|
<!-- 任务简要信息 -->
|
||||||
|
<div v-if="task" class="task-summary">
|
||||||
|
<ElDescriptions :column="1" size="small" border>
|
||||||
|
<ElDescriptionsItem label="任务名称">{{ task.generation_name }}</ElDescriptionsItem>
|
||||||
|
<ElDescriptionsItem label="任务编号">
|
||||||
|
#{{ task.id }}
|
||||||
|
</ElDescriptionsItem>
|
||||||
|
</ElDescriptions>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 操作记录 -->
|
||||||
|
<div class="log-section">
|
||||||
|
<h4 class="section-title">操作记录</h4>
|
||||||
|
<ElTimeline v-loading="loading" class="log-timeline">
|
||||||
|
<ElTimelineItem
|
||||||
|
v-for="log in logList"
|
||||||
|
:key="log.id"
|
||||||
|
:timestamp="formatDateTime(log.created_time)"
|
||||||
|
placement="top"
|
||||||
|
:type="logType(log.action_type)"
|
||||||
|
:hollow="log.action_type === 'start_generation'"
|
||||||
|
>
|
||||||
|
<div class="log-card">
|
||||||
|
<div class="log-header">
|
||||||
|
<span class="log-action">{{ log.action_name }}</span>
|
||||||
|
<ElTag
|
||||||
|
size="small"
|
||||||
|
:type="logTagType(log.action_type)"
|
||||||
|
effect="light"
|
||||||
|
>
|
||||||
|
{{ logStatusText(log.action_type) }}
|
||||||
|
</ElTag>
|
||||||
|
</div>
|
||||||
|
<div class="log-operator">
|
||||||
|
<ElIcon><User /></ElIcon>
|
||||||
|
{{ log.operator_name || "系统" }}
|
||||||
|
</div>
|
||||||
|
<div v-if="log.description" class="log-desc">
|
||||||
|
{{ log.description }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ElTimelineItem>
|
||||||
|
<div v-if="!loading && logList.length === 0" class="empty-logs">
|
||||||
|
暂无操作记录
|
||||||
|
</div>
|
||||||
|
</ElTimeline>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</ElDrawer>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch } from "vue";
|
||||||
|
import { User } from "@element-plus/icons-vue";
|
||||||
|
import { GenerationTaskAPI } from "@/api/module_report/generation";
|
||||||
|
import type { GenerationTaskItem, GenerationLogItem, GenerationLogActionType } from "@/api/module_report/generation";
|
||||||
|
|
||||||
|
defineOptions({ name: "GenerationLogDrawer" });
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
visible: boolean;
|
||||||
|
taskId?: number | null;
|
||||||
|
task?: GenerationTaskItem | null;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"update:visible": [v: boolean];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const logList = ref<GenerationLogItem[]>([]);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [props.visible, props.taskId] as const,
|
||||||
|
([v, id]) => {
|
||||||
|
if (v && id) {
|
||||||
|
loadLogs(id);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
async function loadLogs(taskId: number) {
|
||||||
|
loading.value = true;
|
||||||
|
logList.value = [];
|
||||||
|
try {
|
||||||
|
const resp = await GenerationTaskAPI.listLogs({
|
||||||
|
report_generation_id: taskId,
|
||||||
|
page_no: 1,
|
||||||
|
page_size: 100,
|
||||||
|
});
|
||||||
|
logList.value = resp?.data?.data?.items ?? [];
|
||||||
|
} catch (e) {
|
||||||
|
logList.value = [];
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDateTime(value?: string): string {
|
||||||
|
if (!value) return "-";
|
||||||
|
const d = new Date(value);
|
||||||
|
if (Number.isNaN(d.getTime())) return value;
|
||||||
|
const pad = (n: number) => String(n).padStart(2, "0");
|
||||||
|
return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function logType(t: GenerationLogActionType): "primary" | "success" | "warning" | "danger" {
|
||||||
|
switch (t) {
|
||||||
|
case "create_task": return "primary";
|
||||||
|
case "start_generation": return "warning";
|
||||||
|
case "generation_success": return "success";
|
||||||
|
case "generation_failed": return "danger";
|
||||||
|
default: return "primary";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function logTagType(t: GenerationLogActionType): "primary" | "success" | "warning" | "danger" | "info" {
|
||||||
|
switch (t) {
|
||||||
|
case "create_task": return "primary";
|
||||||
|
case "start_generation": return "warning";
|
||||||
|
case "generation_success": return "success";
|
||||||
|
case "generation_failed": return "danger";
|
||||||
|
default: return "info";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function logStatusText(t: GenerationLogActionType): string {
|
||||||
|
switch (t) {
|
||||||
|
case "create_task": return "已创建";
|
||||||
|
case "start_generation": return "进行中";
|
||||||
|
case "generation_success": return "已生成";
|
||||||
|
case "generation_failed": return "生成失败";
|
||||||
|
default: return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.task-summary {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-section {
|
||||||
|
.section-title {
|
||||||
|
margin: 0 0 12px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #303133;
|
||||||
|
padding-left: 8px;
|
||||||
|
border-left: 3px solid #409eff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-card {
|
||||||
|
background: #f9fafb;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border: 1px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-action {
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #303133;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-operator {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-desc {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #606266;
|
||||||
|
line-height: 1.6;
|
||||||
|
background: #fff;
|
||||||
|
padding: 6px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-logs {
|
||||||
|
text-align: center;
|
||||||
|
color: #909399;
|
||||||
|
font-size: 13px;
|
||||||
|
padding: 24px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-timeline-item__timestamp) {
|
||||||
|
color: #909399;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -0,0 +1,88 @@
|
|||||||
|
<template>
|
||||||
|
<ElDialog
|
||||||
|
:model-value="visible"
|
||||||
|
title="任务详情"
|
||||||
|
width="640px"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
append-to-body
|
||||||
|
@update:model-value="(v: boolean) => emit('update:visible', v)"
|
||||||
|
>
|
||||||
|
<ElDescriptions v-if="task" :column="2" border size="default">
|
||||||
|
<ElDescriptionsItem label="任务名称" :span="2">
|
||||||
|
{{ task.generation_name }}
|
||||||
|
</ElDescriptionsItem>
|
||||||
|
<ElDescriptionsItem label="生成状态">
|
||||||
|
<ElTag :type="statusTagType(task.status)" effect="light">
|
||||||
|
{{ statusText(task.status) }}
|
||||||
|
</ElTag>
|
||||||
|
</ElDescriptionsItem>
|
||||||
|
<ElDescriptionsItem label="生成进度">
|
||||||
|
<ElProgress
|
||||||
|
v-if="task.status === 1"
|
||||||
|
:percentage="task.progress ?? 0"
|
||||||
|
:stroke-width="8"
|
||||||
|
status="success"
|
||||||
|
/>
|
||||||
|
<span v-else-if="task.status === 2" class="progress-text">已完成 100%</span>
|
||||||
|
<span v-else-if="task.status === 3" class="progress-text error">生成失败</span>
|
||||||
|
<span v-else class="progress-text">未开始</span>
|
||||||
|
</ElDescriptionsItem>
|
||||||
|
<ElDescriptionsItem label="生成人">
|
||||||
|
{{ task.generator_name || "-" }}
|
||||||
|
</ElDescriptionsItem>
|
||||||
|
<ElDescriptionsItem label="模板名称">
|
||||||
|
{{ task.template_name || "-" }}
|
||||||
|
</ElDescriptionsItem>
|
||||||
|
<ElDescriptionsItem label="创建时间">
|
||||||
|
{{ formatDateTime(task.created_time) }}
|
||||||
|
</ElDescriptionsItem>
|
||||||
|
<ElDescriptionsItem label="更新时间">
|
||||||
|
{{ formatDateTime(task.updated_time) }}
|
||||||
|
</ElDescriptionsItem>
|
||||||
|
<ElDescriptionsItem v-if="task.description" label="备注" :span="2">
|
||||||
|
{{ task.description }}
|
||||||
|
</ElDescriptionsItem>
|
||||||
|
</ElDescriptions>
|
||||||
|
<template #footer>
|
||||||
|
<ElButton @click="emit('update:visible', false)">关闭</ElButton>
|
||||||
|
</template>
|
||||||
|
</ElDialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { GenerationTaskItem } from "@/api/module_report/generation";
|
||||||
|
|
||||||
|
defineOptions({ name: "GenerationTaskDetailDialog" });
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
visible: boolean;
|
||||||
|
task?: GenerationTaskItem | null;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"update:visible": [v: boolean];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
function statusText(s: number) {
|
||||||
|
return ["待生成", "生成中", "已生成", "生成失败"][s] ?? "未知";
|
||||||
|
}
|
||||||
|
function statusTagType(s: number): "info" | "warning" | "success" | "danger" {
|
||||||
|
return ["info", "warning", "success", "danger"][s] as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDateTime(value?: string): string {
|
||||||
|
if (!value) return "-";
|
||||||
|
const d = new Date(value);
|
||||||
|
if (Number.isNaN(d.getTime())) return value;
|
||||||
|
const pad = (n: number) => String(n).padStart(2, "0");
|
||||||
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.progress-text {
|
||||||
|
font-size: 13px;
|
||||||
|
color: #606266;
|
||||||
|
&.error { color: #f56c6c; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Loading…
Reference in New Issue