HistoryTaskView.vue 3.4 KB
<template>
	<div class="cmc-table-page">
		<div class="task-section">
			<div class="table-wrapper">
				<table class="task-table">
					<thead>
						<tr>
							<th>任务ID</th>
							<th>任务类型</th>
							<th>库区</th>
							<th>任务起始位置</th>
							<th>任务目标位置</th>
							<th>托盘编码</th>
							<th>任务优先级</th>
							<th>任务状态</th>
							<th>执行设备</th>
							<!-- 🔥 只给这列加 class -->
							<th class="time-column">任务开始时间</th>
							<th>任务持续时间</th>
						</tr>
					</thead>
					<tbody>
						<tr
							v-for="(item, index) in taskList"
							:key="index"
							:class="{
								'green-text': item.taskDurationSeconds <= 10,
								'yellow-text': item.taskDurationSeconds > 10 && item.taskDurationSeconds < 60,
								'red-text': item.taskDurationSeconds >= 60,
							}"
						>
							<td>{{ item.taskId }}</td>
							<td>{{ item.taskTypeDescription }}</td>
							<td>{{ item.zoneCodeDescription }}</td>
							<td>{{ item.fromLocation }}</td>
							<td>{{ item.toLocation }}</td>
							<td>{{ item.containerCode }}</td>
							<td>{{ item.taskPriority }}</td>
							<td>{{ item.taskStatusDescription }}</td>
							<td>{{ item.executionEquipmentId }}</td>
							<!-- 🔥 只给这列加 class -->
							<td class="time-column">{{ item.taskStartTime }}</td>
							<td>{{ item.taskDurationSecondsFormat }}</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</template>

<script>
import { CMC_OFFLINE_TASK_API } from '@/api/cmcApi'

export default {
	name: 'HistoryTaskView',
	props: {
		userName: {
			type: String,
			default: '',
		},
	},
	watch: {
		userName: {
			immediate: true,
			handler(newVal) {
				if (newVal) {
					// this.getData()
				}
			},
		},
	},
	data() {
		return {
			baseUrlOffOne: CMC_OFFLINE_TASK_API,
			baseUrlOnLineOne: window.appConfig.baseUrlintHistory,
			sysData: {},
			taskList: [],
			direction: 'rtl',
			device: {},
			temp: 0,
			refreshTimer: null,
		}
	},
	methods: {
		getAGVDataOne() {
			const opt = {
				urlSuffix: window.baseOnLineOrOff ? `${this.baseUrlOnLineOne}?zoneCode=${this.userName}` : `${this.baseUrlOffOne}?zoneCode=${this.userName}`,
				logTitle: '历史任务列表',
				isUrlALL: true,
				headers: window.baseOnLineOrOff,
				header: window.baseOnLineOrOff,
				type: 'post',
			}
			const callBackFn = (res) => {
				if (!this.ajaxSuccessDataBefore(res, opt.logTitle)) return
				res.data.result.forEach((x) => {
					x.taskDurationSeconds = Number((x.taskDurationSeconds / 60).toFixed(2))
				})
				this.taskList = res.data.result
			}
			''.ajax(this, opt, callBackFn)
		},
		ajaxSuccessDataBefore(res, title) {
			if (!res || !res.data || res.data.result == null || res.data.result.length === 0) {
				this.sysData = []
				''.Log(`${title}无数据`, 'getData')
				return false
			}
			return true
		},
		intInterval() {
			if (this.refreshTimer) {
				clearInterval(this.refreshTimer)
			}
			this.refreshTimer = setInterval(() => {
				this.getAGVDataOne()
			}, 10000)
		},
		pauseApiRequest() {
			if (this.refreshTimer) {
				clearInterval(this.refreshTimer)
				this.refreshTimer = null
			}
		},
	},
	mounted() {
		this.getAGVDataOne()
		this.intInterval()
	},
	beforeDestroy() {
		this.pauseApiRequest()
	},
	activated() {
		this.intInterval()
	},
	deactivated() {
		this.pauseApiRequest()
	},
}
</script>

<style src="../../styles/cmc-table.css"></style>