|
| 1 | +<template> |
| 2 | + <el-popover placement="top" :width="450" trigger="hover"> |
| 3 | + <template #default> |
| 4 | + <el-row :gutter="3" v-for="status in statusTable" :key="status.type"> |
| 5 | + <el-col :span="4">{{ taskTypeMap[status.type] }} </el-col> |
| 6 | + <el-col :span="4"> |
| 7 | + <el-text v-if="status.state === State.SUCCESS || status.state === State.REVOKED"> |
| 8 | + <el-icon class="success"><SuccessFilled /></el-icon> |
| 9 | + {{ stateMap[status.state](status.type) }} |
| 10 | + </el-text> |
| 11 | + <el-text v-else-if="status.state === State.FAILURE"> |
| 12 | + <el-icon class="danger"><CircleCloseFilled /></el-icon> |
| 13 | + {{ stateMap[status.state](status.type) }} |
| 14 | + </el-text> |
| 15 | + <el-text v-else-if="status.state === State.STARTED"> |
| 16 | + <el-icon class="is-loading primary"><Loading /></el-icon> |
| 17 | + {{ stateMap[status.state](status.type) }} |
| 18 | + </el-text> |
| 19 | + <el-text v-else-if="status.state === State.PENDING"> |
| 20 | + <el-icon class="is-loading primary"><Loading /></el-icon> |
| 21 | + {{ stateMap[status.state](status.type) }} |
| 22 | + </el-text> |
| 23 | + </el-col> |
| 24 | + <el-col :span="5"> |
| 25 | + 完成 |
| 26 | + {{ |
| 27 | + Object.keys(status.aggs ? status.aggs : {}) |
| 28 | + .filter((k) => k == State.SUCCESS) |
| 29 | + .map((k) => status.aggs[k]) |
| 30 | + .reduce((x: any, y: any) => x + y, 0) |
| 31 | + }}/{{ |
| 32 | + Object.values(status.aggs ? status.aggs : {}).reduce((x: any, y: any) => x + y, 0) |
| 33 | + }} |
| 34 | + </el-col> |
| 35 | + <el-col :span="9"> |
| 36 | + {{ |
| 37 | + status.time |
| 38 | + ? status.time[ |
| 39 | + status.state == State.REVOKED ? State.REVOKED : State.PENDING |
| 40 | + ]?.substring(0, 19) |
| 41 | + : undefined |
| 42 | + }} |
| 43 | + </el-col> |
| 44 | + </el-row> |
| 45 | + </template> |
| 46 | + <template #reference> |
| 47 | + <el-text v-if="aggStatus?.value === State.SUCCESS || aggStatus?.value === State.REVOKED"> |
| 48 | + <el-icon class="success"><SuccessFilled /></el-icon> |
| 49 | + {{ stateMap[aggStatus.value](aggStatus.key) }} |
| 50 | + </el-text> |
| 51 | + <el-text v-else-if="aggStatus?.value === State.FAILURE"> |
| 52 | + <el-icon class="danger"><CircleCloseFilled /></el-icon> |
| 53 | + {{ stateMap[aggStatus.value](aggStatus.key) }} |
| 54 | + </el-text> |
| 55 | + <el-text v-else-if="aggStatus?.value === State.STARTED"> |
| 56 | + <el-icon class="is-loading primary"><Loading /></el-icon> |
| 57 | + {{ stateMap[aggStatus.value](aggStatus.key) }} |
| 58 | + </el-text> |
| 59 | + <el-text v-else-if="aggStatus?.value === State.PENDING"> |
| 60 | + <el-icon class="is-loading primary"><Loading /></el-icon> |
| 61 | + {{ stateMap[aggStatus.value](aggStatus.key) }} |
| 62 | + </el-text> |
| 63 | + </template> |
| 64 | + </el-popover> |
| 65 | +</template> |
| 66 | +<script setup lang="ts"> |
| 67 | +import { computed } from 'vue' |
| 68 | +import { |
| 69 | + Status, |
| 70 | + TaskType, |
| 71 | + State, |
| 72 | + type TaskTypeInterface, |
| 73 | + type StateInterface |
| 74 | +} from '@/utils/status' |
| 75 | +import { merge, mergeWith } from 'lodash' |
| 76 | +const props = defineProps<{ status: string; statusMeta: any }>() |
| 77 | +
|
| 78 | +const checkList: Array<string> = [ |
| 79 | + State.REVOKE, |
| 80 | + State.STARTED, |
| 81 | + State.PENDING, |
| 82 | + State.REVOKED, |
| 83 | + State.FAILURE, |
| 84 | + State.SUCCESS |
| 85 | +] |
| 86 | +const aggStatus = computed(() => { |
| 87 | + for (const i in checkList) { |
| 88 | + const state = checkList[i] |
| 89 | + const index = props.status.indexOf(state) |
| 90 | + if (index > -1) { |
| 91 | + return { key: index + 1, value: state } |
| 92 | + } |
| 93 | + } |
| 94 | +}) |
| 95 | +const startedMap = { |
| 96 | + [TaskType.EMBEDDING]: '索引中', |
| 97 | + [TaskType.GENERATE_PROBLEM]: '生成中', |
| 98 | + [TaskType.SYNC]: '同步中' |
| 99 | +} |
| 100 | +const taskTypeMap = { |
| 101 | + [TaskType.EMBEDDING]: '向量化', |
| 102 | + [TaskType.GENERATE_PROBLEM]: '生成问题', |
| 103 | + [TaskType.SYNC]: '同步' |
| 104 | +} |
| 105 | +const stateMap: any = { |
| 106 | + [State.PENDING]: (type: number) => '排队中', |
| 107 | + [State.STARTED]: (type: number) => startedMap[type], |
| 108 | + [State.REVOKE]: (type: number) => '取消中', |
| 109 | + [State.REVOKED]: (type: number) => '成功', |
| 110 | + [State.FAILURE]: (type: number) => '失败', |
| 111 | + [State.SUCCESS]: (type: number) => '成功' |
| 112 | +} |
| 113 | +
|
| 114 | +const parseAgg = (agg: { count: number; status: string }) => { |
| 115 | + const status = new Status(agg.status) |
| 116 | + return Object.keys(TaskType) |
| 117 | + .map((key) => { |
| 118 | + const value = TaskType[key as keyof TaskTypeInterface] |
| 119 | + return { [value]: { [status.task_status[value]]: agg.count } } |
| 120 | + }) |
| 121 | + .reduce((x, y) => ({ ...x, ...y }), {}) |
| 122 | +} |
| 123 | +
|
| 124 | +const customizer: (x: any, y: any) => any = (objValue: any, srcValue: any) => { |
| 125 | + if (objValue == undefined && srcValue) { |
| 126 | + return srcValue |
| 127 | + } |
| 128 | + if (srcValue == undefined && objValue) { |
| 129 | + return objValue |
| 130 | + } |
| 131 | + // 如果是数组,我们将元素进行聚合 |
| 132 | + if (typeof objValue === 'object' && typeof srcValue === 'object') { |
| 133 | + // 若是object类型的对象,我们进行递归 |
| 134 | + return mergeWith(objValue, srcValue, customizer) |
| 135 | + } else { |
| 136 | + // 否则,单纯的将值进行累加 |
| 137 | + return objValue + srcValue |
| 138 | + } |
| 139 | +} |
| 140 | +const aggs = computed(() => { |
| 141 | + return (props.statusMeta.aggs ? props.statusMeta.aggs : []) |
| 142 | + .map((agg: any) => { |
| 143 | + return parseAgg(agg) |
| 144 | + }) |
| 145 | + .reduce((x: any, y: any) => { |
| 146 | + return mergeWith(x, y, customizer) |
| 147 | + }, {}) |
| 148 | +}) |
| 149 | +
|
| 150 | +const statusTable = computed(() => { |
| 151 | + return Object.keys(TaskType) |
| 152 | + .map((key) => { |
| 153 | + const value = TaskType[key as keyof TaskTypeInterface] |
| 154 | + console.log(props.statusMeta.state_time[value], value) |
| 155 | + const parseStatus = new Status(props.status) |
| 156 | + return { |
| 157 | + type: value, |
| 158 | + state: parseStatus.task_status[value], |
| 159 | + aggs: aggs.value[value], |
| 160 | + time: props.statusMeta.state_time[value] |
| 161 | + } |
| 162 | + }) |
| 163 | + .filter((item) => item.state !== State.IGNORED) |
| 164 | +}) |
| 165 | +</script> |
| 166 | +<style lang="scss" scoped></style> |
0 commit comments