2 changed files with 213 additions and 1 deletions
@ -0,0 +1,212 @@ |
|||
<script setup lang="ts"> |
|||
import { onMounted, reactive } from "vue"; |
|||
import { AgGridVue } from "ag-grid-vue3"; |
|||
import { localeText as localeTextCn } from "@/components/yvTable/yv-aggrid-cn.locale"; |
|||
import { Request } from "@ease-forge/shared"; |
|||
import type { GridOptions } from "ag-grid-enterprise"; |
|||
import type { GridApi, GridReadyEvent } from "ag-grid-community"; |
|||
|
|||
defineOptions({ |
|||
name: 'TaskView', |
|||
}); |
|||
|
|||
// 定义 Props 类型 |
|||
interface TaskViewProps { |
|||
} |
|||
|
|||
// 读取组件 props 属性 |
|||
const props = withDefaults(defineProps<TaskViewProps>(), {}); |
|||
|
|||
// 定义 State 类型 |
|||
interface TaskViewState { |
|||
loading: boolean; |
|||
grid1Data: Array<any>; |
|||
} |
|||
|
|||
// state 属性 |
|||
const state = reactive<TaskViewState>({ |
|||
loading: false, |
|||
grid1Data: [], |
|||
}); |
|||
|
|||
// 定义 Data 类型 |
|||
interface TaskViewData { |
|||
gridSetting: Partial<GridOptions>; |
|||
api?: GridApi; |
|||
} |
|||
|
|||
// 内部数据 |
|||
const data: TaskViewData = { |
|||
gridSetting: { |
|||
localeText: localeTextCn, |
|||
// suppressNoRowsOverlay: true, |
|||
// suppressLoadingOverlay: true, |
|||
// 选择行配置 |
|||
rowSelection: "single", |
|||
// rowModelType: "", |
|||
columnDefs: [ |
|||
{ field: 'id', headerName: 'id', editable: false, hide: true }, |
|||
{ field: 'envId', headerName: '环境ID', hide: true }, |
|||
{ field: 'type', headerName: '类型', width: 120 }, |
|||
{ field: 'status', headerName: '状态', width: 120 }, |
|||
{ field: 'err', headerName: '异常' }, |
|||
{ field: 'payload', headerName: '任务负载', width: 600 }, |
|||
{ field: 'priority', headerName: '优先级', width: 120 }, |
|||
{ field: 'info', headerName: '任务明细', width: 800 }, |
|||
{ field: '_raw.createAt', headerName: '创建时间', editable: false }, |
|||
{ field: '_raw.createBy', headerName: '创建人', editable: false }, |
|||
{ field: '_raw.updateAt', headerName: '最后更新时间', editable: false }, |
|||
{ field: '_raw.updateBy', headerName: '更新人', editable: false }, |
|||
], |
|||
treeData: true, |
|||
getDataPath: data => data.path, |
|||
autoGroupColumnDef: { |
|||
headerName: '任务', |
|||
field: 'title', |
|||
width: 300, |
|||
}, |
|||
groupDefaultExpanded: -1, |
|||
onGridReady(event: GridReadyEvent) { |
|||
data.api = event.api; |
|||
}, |
|||
}, |
|||
}; |
|||
onMounted(reload); |
|||
|
|||
async function reload() { |
|||
state.loading = true; |
|||
const data = await Request.request.get("/api/workbench/LccTask@allRcsTask").finally(() => state.loading = false); |
|||
state.grid1Data = toTreeData(data); |
|||
} |
|||
|
|||
function toTreeData(data: Array<any>) { |
|||
if (!data) return []; |
|||
const BizTaskType = { |
|||
MOVE: "移动任务", |
|||
CHARGE: "充电任务", |
|||
CARRY: "搬运任务", |
|||
LOAD: "装载任务", |
|||
UNLOAD: "卸载任务", |
|||
}; |
|||
const PlanTaskType = { |
|||
MOVE: "移动任务", |
|||
MOVE_BACKWARD: "移动任务", |
|||
ROTATION: "旋转任务", |
|||
LOAD: "取货任务", |
|||
UNLOAD: "装载任务", |
|||
CHARGE: "充电任务", |
|||
FINISH: "完成任务", |
|||
}; |
|||
const BizTaskStatus = { |
|||
WAITING_FOR_DISPATCH: "待调度", |
|||
DEVICE_EXECUTING: "设备执行中", |
|||
PAUSED: "暂停执行", |
|||
DISPATCH_ERROR: "调度异常", |
|||
PLANNING_ERROR: "规划异常", |
|||
DEVICE_ERROR: "设备执行异常", |
|||
}; |
|||
const PlanTaskStatus = { |
|||
PENDING: "等待执行", |
|||
EXECUTING: "执行中", |
|||
FINISHED: "执行成功", |
|||
ERROR: "执行失败", |
|||
}; |
|||
const tree: Array<any> = []; |
|||
for (let biz of data) { |
|||
const bizNode: any = { |
|||
_raw: biz, |
|||
path: [biz.bizTaskId], |
|||
id: biz.bizTaskId, |
|||
envId: biz.envId, |
|||
type: BizTaskType[biz.bizType], |
|||
title: biz.bizTaskDescription, |
|||
status: BizTaskStatus[biz.bizTaskStatus], |
|||
// status: biz.bizTaskStatus, |
|||
err: biz.bizTaskErrorInfo, |
|||
payload: biz.bizTaskPayload, |
|||
priority: biz.priority, |
|||
info: `托盘ID: ${biz.lpn}, 任务起始点: ${biz.taskFrom}, 任务目标点: ${biz.taskTo}, 执行器ID: ${biz.allocatedExecutorId}`, |
|||
children: [], |
|||
}; |
|||
const taskPlans: Array<any> = biz.taskPlans; |
|||
for (let plan of taskPlans) { |
|||
const planNode: any = { |
|||
_raw: plan, |
|||
path: [biz.bizTaskId, plan.planTaskId], |
|||
id: plan.planTaskId, |
|||
envId: plan.envId, |
|||
type: PlanTaskType[plan.planType], |
|||
title: plan.planTaskDescription, |
|||
status: PlanTaskStatus[plan.planTaskStatus], |
|||
err: plan.planTaskErrorInfo, |
|||
payload: plan.planTaskPayload, |
|||
priority: plan.seq, |
|||
info: `背负托盘ID: ${plan.loadLpn}, 目标点ID: ${plan.targetId},目标点货架列: ${plan.targetBay}, 目标点货架层: ${plan.targetLevel}, 目标点货架格: ${plan.targetCell}, 目标点旋转角度: ${plan.targetRotation}, 执行器ID: ${plan.executorId}`, |
|||
children: [], |
|||
}; |
|||
const taskDevices: Array<any> = plan.taskDevices; |
|||
for (let device of taskDevices) { |
|||
const deviceNode: any = { |
|||
_raw: device, |
|||
path: [biz.bizTaskId, plan.planTaskId, device.deviceTaskId], |
|||
id: device.deviceTaskId, |
|||
envId: device.envId, |
|||
type: device.deviceType, |
|||
title: device.deviceTaskDescription, |
|||
status: device.deviceTaskStatus, |
|||
err: device.deviceTaskErrorInfo, |
|||
payload: device.deviceTaskPayload, |
|||
priority: device.seq, |
|||
info: `报文类型: ${device.packetType}, 报文目标点: ${device.packetEndPoint}, 报文内容: ${device.packetPayload}, 执行器ID: ${device.deviceItemId}`, |
|||
children: [], |
|||
}; |
|||
// planNode.children.push(deviceNode); |
|||
tree.push(deviceNode); |
|||
} |
|||
// bizNode.children.push(planNode); |
|||
tree.push(planNode); |
|||
} |
|||
tree.push(bizNode); |
|||
} |
|||
return tree; |
|||
} |
|||
|
|||
interface TaskViewExpose { |
|||
state: TaskViewState; |
|||
data: TaskViewData; |
|||
} |
|||
|
|||
const expose: TaskViewExpose = { |
|||
state, |
|||
data, |
|||
}; |
|||
// 定义组件公开内容 |
|||
defineExpose(expose); |
|||
|
|||
export type { |
|||
TaskViewProps, |
|||
TaskViewState, |
|||
} |
|||
</script> |
|||
|
|||
<template> |
|||
<div class="task-view"> |
|||
<AgGridVue |
|||
ref="gridRef" |
|||
:class="['ag-theme-alpine', 'yv-table', 'hi-light-selected-row','allow-vertical-line', 'grid1']" |
|||
v-bind="{...data.gridSetting}" |
|||
:modelValue="state.grid1Data" |
|||
> |
|||
</AgGridVue> |
|||
</div> |
|||
</template> |
|||
|
|||
<style scoped> |
|||
.task-view { |
|||
height: 100%; |
|||
} |
|||
|
|||
.task-view > .grid1 { |
|||
height: 100%; |
|||
} |
|||
</style> |
|||
Loading…
Reference in new issue