mirror of
				https://github.com/continew-org/continew-admin-ui.git
				synced 2025-10-31 22:57:15 +08:00 
			
		
		
		
	chore: 优化任务日志详情
This commit is contained in:
		| @@ -1,24 +1,26 @@ | |||||||
| <template> | <template> | ||||||
|   <a-modal |   <a-modal v-model:visible="visible" title="任务日志详情" :width="width >= 1500 ? 1500 : '100%'" :footer="false" | ||||||
|     v-model:visible="visible" |     @close="closed"> | ||||||
|     title="任务日志详情" |     <div style="display: flex; min-height: 600px;"> | ||||||
|     :width="width >= 1500 ? 1500 : '100%'" |       <div style="padding: 10px 10px;"> | ||||||
|     :footer="false" |         <div class="job_list"> | ||||||
|   > |           <div :class="`job_list_item ${item.id === activeId ? 'active' : ''}`" v-for="item in dataList" :key="item.id" | ||||||
|     <a-layout style="height: 500px"> |             @click="onStartInfo(item)"> | ||||||
|       <a-layout-sider :resize-directions="['right']"> |             <div class="content"> | ||||||
|         <a-tabs size="large" position="left"> |               <span class="title">{{ item.clientInfo.split('@')[1] }}</span> | ||||||
|           <a-tab-pane v-for="item in dataList" :key="item.id"> |               <span class="status"> | ||||||
|             <template #title> |                 <a-tag bordered :color="statusList[item.taskStatus].color">{{ statusList[item.taskStatus].title | ||||||
|               <span @click="onLogDetail(item)">{{ item.clientInfo.split('@')[1] }}</span> |                   }}</a-tag> | ||||||
|             </template> |               </span> | ||||||
|           </a-tab-pane> |             </div> | ||||||
|         </a-tabs> |           </div> | ||||||
|       </a-layout-sider> |         </div> | ||||||
|       <a-layout-content> |       </div> | ||||||
|  |       <div> | ||||||
|         <GiCodeView :code-json="content" /> |         <GiCodeView :code-json="content" /> | ||||||
|       </a-layout-content> |       </div> | ||||||
|     </a-layout> |     </div> | ||||||
|  |  | ||||||
|   </a-modal> |   </a-modal> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
| @@ -31,18 +33,47 @@ const { width } = useWindowSize() | |||||||
| const queryForm = reactive<JobInstanceQuery>({}) | const queryForm = reactive<JobInstanceQuery>({}) | ||||||
| const dataList = ref<JobInstanceResp[]>([]) | const dataList = ref<JobInstanceResp[]>([]) | ||||||
| const loading = ref(false) | const loading = ref(false) | ||||||
| // 查询列表数据 | const activeId = ref<string | number>('') | ||||||
| const getInstanceList = async (query: JobInstanceQuery = { ...queryForm }) => { | const statusList = { | ||||||
|   try { |   '1': { | ||||||
|     loading.value = true |     title: '待处理', | ||||||
|     const res = await listJobInstance(query) |     color: 'gray' | ||||||
|     dataList.value = res.data |   }, | ||||||
|   } finally { |   '2': { | ||||||
|     loading.value = false |     title: '运行中', | ||||||
|  |     color: 'cyan' | ||||||
|  |   }, | ||||||
|  |   '3': { | ||||||
|  |     title: '成功', | ||||||
|  |     color: 'green' | ||||||
|  |   }, | ||||||
|  |   '4': { | ||||||
|  |     title: '已失败', | ||||||
|  |     color: 'red' | ||||||
|  |   }, | ||||||
|  |   '5': { | ||||||
|  |     title: '已停止', | ||||||
|  |     color: 'purple' | ||||||
|  |   }, | ||||||
|  |   '6': { | ||||||
|  |     title: '已取消', | ||||||
|  |     color: 'orange' | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| const visible = ref(false) | 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<NodeJS.Timeout>() | ||||||
|  |  | ||||||
|  |  | ||||||
| // 详情 | // 详情 | ||||||
| const onDetail = (record: JobLogResp) => { | const onDetail = (record: JobLogResp) => { | ||||||
|   visible.value = true |   visible.value = true | ||||||
| @@ -52,15 +83,9 @@ const onDetail = (record: JobLogResp) => { | |||||||
|   getInstanceList() |   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) => { | const onLogDetail = async (record: JobInstanceResp) => { | ||||||
|  |   activeId.value = record?.id | ||||||
|   // todo startId根据第一次查询 如果有返回!=0则需要在查一次 |   // todo startId根据第一次查询 如果有返回!=0则需要在查一次 | ||||||
|   const res = await listJobInstanceLog({ |   const res = await listJobInstanceLog({ | ||||||
|     taskBatchId: record.taskBatchId, |     taskBatchId: record.taskBatchId, | ||||||
| @@ -72,8 +97,65 @@ const onLogDetail = async (record: JobInstanceResp) => { | |||||||
|   }) |   }) | ||||||
|   content.value = res.data.message.map(formatLog).join('\n') |   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 }) | defineExpose({ onDetail }) | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
| <style scoped lang="scss"></style> | <style scoped lang="scss"> | ||||||
|  | .job_list { | ||||||
|  |   position: relative; | ||||||
|  |   width: 100%; | ||||||
|  |   border: 1px solid var(--color-neutral-3); | ||||||
|  |  | ||||||
|  |   .job_list_item { | ||||||
|  |     padding: 8px 10px; | ||||||
|  |     cursor: pointer; | ||||||
|  |  | ||||||
|  |     &:not(:last-child) { | ||||||
|  |       border-bottom: 2px dashed var(--color-neutral-3); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     &:hover { | ||||||
|  |       background-color: var(--color-neutral-2); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     .content { | ||||||
|  |       display: flex; | ||||||
|  |       justify-content: space-between; | ||||||
|  |       justify-items: center; | ||||||
|  |  | ||||||
|  |       .title { | ||||||
|  |         margin-right: 20px; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   .active { | ||||||
|  |     border-bottom: 2px solid $color-theme !important; | ||||||
|  |     background-color: var(--color-neutral-3) !important; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | </style> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 秋帆
					秋帆