diff --git a/src/views/schedule/log/LogDetailModal.vue b/src/views/schedule/log/LogDetailModal.vue index 9e788e2..4992c00 100644 --- a/src/views/schedule/log/LogDetailModal.vue +++ b/src/views/schedule/log/LogDetailModal.vue @@ -1,24 +1,26 @@ @@ -31,18 +33,47 @@ const { width } = useWindowSize() const queryForm = reactive({}) const dataList = ref([]) const loading = ref(false) -// 查询列表数据 -const getInstanceList = async (query: JobInstanceQuery = { ...queryForm }) => { - try { - loading.value = true - const res = await listJobInstance(query) - dataList.value = res.data - } finally { - loading.value = false +const activeId = ref('') +const statusList = { + '1': { + title: '待处理', + color: 'gray' + }, + '2': { + title: '运行中', + color: 'cyan' + }, + '3': { + title: '成功', + color: 'green' + }, + '4': { + title: '已失败', + color: 'red' + }, + '5': { + title: '已停止', + color: 'purple' + }, + '6': { + title: '已取消', + color: 'orange' } } + const visible = ref(false) + +// 格式化日志 +const formatLog = (log: any) => { + const date = new Date(Number.parseInt(log.time_stamp)) + return `${dayjs(date).format('YYYY-MM-DD HH:mm:ss')} ${log.level} [${log.thread}] ${log.location} - ${log.message}` +} + +const content = ref('') +const setIntervalNode = ref() + + // 详情 const onDetail = (record: JobLogResp) => { visible.value = true @@ -52,15 +83,9 @@ const onDetail = (record: JobLogResp) => { getInstanceList() } -// 格式化日志 -const formatLog = (log: any) => { - const date = new Date(Number.parseInt(log.time_stamp)) - return `${dayjs(date).format('YYYY-MM-DD HH:mm:ss')} ${log.level} [${log.thread}] ${log.location} - ${log.message}` -} - -const content = ref('') // 日志输出 const onLogDetail = async (record: JobInstanceResp) => { + activeId.value = record?.id // todo startId根据第一次查询 如果有返回!=0则需要在查一次 const res = await listJobInstanceLog({ taskBatchId: record.taskBatchId, @@ -72,8 +97,65 @@ const onLogDetail = async (record: JobInstanceResp) => { }) content.value = res.data.message.map(formatLog).join('\n') } - +const onStartInfo = (record: JobInstanceResp) => { + content.value = '' + clearInterval(setIntervalNode.value) + setIntervalNode.value = setInterval(() => { + onLogDetail(record) + }, 1000) +} +// 查询列表数据 +const getInstanceList = async (query: JobInstanceQuery = { ...queryForm }) => { + try { + loading.value = true + const res = await listJobInstance(query) + dataList.value = res.data + onStartInfo(dataList.value[0]) + } finally { + loading.value = false + } +} +const closed = () => { + clearInterval(setIntervalNode.value) +} +onUnmounted(() => { + clearInterval(setIntervalNode.value) +}) defineExpose({ onDetail }) - +