TaskOperationPanel.vue 24.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802
<template>
	<div class="children-body">
		<div class="children-top-container" id="scrollBox">
			<!-- WMS 模块 -->
			<div class="children-item">
				<div class="children-title">WMS</div>
				<div class="square-box">
					<div v-for="(item, index) in wmsData" :key="item.ButtonID || item.ButtonName || index">
						<u-subsection v-if="item.ButtonShowType === 'SwitchButton'" v-model="item.Start" :list="item.ButtonName" @tab-change="(val) => handleSubsectionChange(val, item)" />
						<el-switch v-if="item.ButtonShowType === 'RadioButton'" v-model="value" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
						<!-- 动态wms按钮 -->
						<button
							v-if="item.ButtonShowType === 'DefaultButton' && !isWmsCancelDisabled(item)"
							@mousedown="handleDown(item, 'wms')"
							@mouseup="handleUp(item, 'wms')"
							@mouseleave="handleUp(item, 'wms')"
							class="reset-btn"
							:style="{
								backgroundColor: item.ButtonStatus == 'True' ? item.ButtonTurnOnColor : item.ButtonTurnOffColor,
							}"
						>
							{{ item.ButtonName }}
						</button>
						<button
							v-else-if="item.ButtonShowType === 'DefaultButton'"
							:disabled="true"
							tabindex="-1"
							class="reset-btn disabled"
							:style="{
								backgroundColor: '#999',
							}"
						>
							{{ item.ButtonName }}
						</button>
					</div>
				</div>
			</div>

			<!-- WCS 模块 - 修改为动态接口加载 -->
			<div class="children-item" v-show="isWcsTaskReceived && wcsData.length > 0">
				<div class="children-title">WCS</div>
				<div class="square-box">
					<div v-for="(item, index) in wcsData" :key="item.ButtonID || item.ButtonName || index">
						<u-subsection v-if="item.ButtonShowType === 'SwitchButton'" v-model="item.Start" :list="item.ButtonName" @tab-change="(val) => handleSubsectionChange(val, item)" />
						<el-switch v-if="item.ButtonShowType === 'RadioButton'" v-model="value" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
						<!-- 动态WCS按钮 -->
						<button
							v-if="item.ButtonShowType === 'DefaultButton'"
							@mousedown="handleDown(item, 'wcs')"
							@mouseup="handleUp(item, 'wcs')"
							@mouseleave="handleUp(item, 'wcs')"
							class="reset-btn"
							:style="{
								backgroundColor: item.ButtonStatus == 'True' ? item.ButtonTurnOnColor : item.ButtonTurnOffColor,
							}"
						>
							{{ item.ButtonName }}
						</button>
					</div>
				</div>
			</div>

			<!-- 执行设备 模块 -->
			<div class="children-item" v-show="isequipment">
				<div class="children-title">{{ localTitleEquipment }}</div>
				<div class="square-box">
					<button
						v-for="(item, index) in equipmentData"
						:key="item.ButtonID || item.ButtonName || index"
						@mousedown="handleDown(item, 'equipment')"
						@mouseup="handleUp(item, 'equipment')"
						@mouseleave="handleUp(item, 'equipment')"
						class="reset-btn"
						:style="{
							backgroundColor: item.ButtonStatus == 'True' ? item.ButtonTurnOnColor : item.ButtonTurnOffColor,
						}"
					>
						{{ item.ButtonName }}
					</button>
				</div>
			</div>

			<!-- 开始库位 模块 -->
			<div class="children-item" v-show="isstartLocationt">
				<div class="children-title">{{ localTitlestartLocationt }}</div>
				<div class="square-box">
					<button
						v-for="(item, index) in startLocationtData"
						:key="item.ButtonID || item.ButtonName || index"
						@mousedown="handleDown(item, 'startLocation')"
						@mouseup="handleUp(item, 'startLocation')"
						@mouseleave="handleUp(item, 'startLocation')"
						class="reset-btn"
						:style="{
							backgroundColor: item.ButtonStatus == 'True' ? item.ButtonTurnOnColor : item.ButtonTurnOffColor,
						}"
					>
						{{ item.ButtonName }}
					</button>
				</div>
			</div>

			<!-- 结束库位 模块 -->
			<div class="children-item" v-show="isendLocationt">
				<div class="children-title">{{ localTitleendLocationt }}</div>
				<div class="square-box">
					<button
						v-for="(item, index) in endLocationtData"
						:key="item.ButtonID || item.ButtonName || index"
						@mousedown="handleDown(item, 'endLocation')"
						@mouseup="handleUp(item, 'endLocation')"
						@mouseleave="handleUp(item, 'endLocation')"
						class="reset-btn"
						:style="{
							backgroundColor: item.ButtonStatus == 'True' ? item.ButtonTurnOnColor : item.ButtonTurnOffColor,
						}"
					>
						{{ item.ButtonName }}
					</button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import USubsection from './subsection.vue' // 保持原有路径
const WMS_CANCEL_LOCK_STAGES = ['设备接收任务', '设备执行开始', '设备执行完成', 'WCS确认完成', 'WMS确认完成']

export default {
	components: {
		USubsection,
	},
	props: {
		// 基础配置参数
		TaskId: {
			type: Number,
			default: 1234,
		},
		currentTaskId: {
			type: [Number, String],
			default: null,
		},
		baseUrlButton: {
			type: String,
			default: 'http://127.0.0.1:6002/api/BulletinBoard/Mes/V1/ReadData1',
		},
		baseUrlOffTwo: {
			type: String,
			default: 'http://127.0.0.1:6002/api/BulletinBoard/Mes/V1/ReadData1',
		},
		// 权限/状态控制
		qustData: {
			type: Array,
			default: () => [],
		},
		// 透传的标题(由父组件传递初始值,子组件内部更新)
		titleEquipment: {
			type: String,
			default: '',
		},
		titlestartLocationt: {
			type: String,
			default: '',
		},
		titleendLocationt: {
			type: String,
			default: '',
		},
	},
	data() {
		return {
			localTitleEquipment: this.titleEquipment,
			localTitlestartLocationt: this.titlestartLocationt,
			localTitleendLocationt: this.titleendLocationt,
			sysData: {},
			// 按钮数据(迁移自父组件)
			equipmentData: [],
			startLocationtData: [],
			endLocationtData: [],
			wmsData: [],
			wcsData: [],
			// 显示控制(迁移自父组件)
			isWmsCancelTaskLocked: false,
			isWcsTaskReceived: false,
			isequipment: false,
			isendLocationt: false,
			isstartLocationt: false,
			// 定时器(迁移自父组件)
			equipmentRefreshTimer: null,
			startLocationRefreshTimer: null,
			endLocationRefreshTimer: null,
			wcsRefreshTimer: null,
			updateTimer: null,
			// 缓存数据(迁移自父组件)
			lastExecutionEquipmentId: null,
			lastFromLocation: null,
			lastToLocation: null,
			lastPermissionData: null,
			lastEquipmentData: [],
			lastStartLocationData: [],
			lastEndLocationData: [],
			lastWcsData: [],
			// 原有子组件状态
			isLongPress: false,
			pressTimer: null,
			value: true,
			currentButtonContext: null,
			lastSwitchActiveTab: null,
			lastSwitchList: [],
			tabClickTimer: null,
		}
	},
	watch: {
		// 监听qustData变化,处理权限和按钮数据(迁移自父组件)
		qustData: {
			immediate: true,
			deep: true,
			handler(newVal) {
				if (!newVal || newVal.length === 0) {
					this.clearModuleData()
					return
				}

				// 提取关键字段
				const currentId = newVal[0]?.executionEquipmentId
				const currentFrom = newVal[0]?.fromLocation
				const currentTo = newVal[0]?.toLocation

				// 防抖处理
				if (this.updateTimer) {
					clearTimeout(this.updateTimer)
				}

				this.updateTimer = setTimeout(() => {
					this.handleQuDataUpdate(newVal, currentId, currentFrom, currentTo)
				}, 100)
			},
		},
		titleEquipment: {
			immediate: true,
			handler(newVal) {
				this.localTitleEquipment = newVal
			},
		},
		titlestartLocationt: {
			immediate: true,
			handler(newVal) {
				this.localTitlestartLocationt = newVal
			},
		},
		titleendLocationt: {
			immediate: true,
			handler(newVal) {
				this.localTitleendLocationt = newVal
			},
		},
	},
	methods: {
		// 统一从接口响应中提取首个按钮列表,避免重复 Object.values(...) 计算。
		getButtonListFromResponse(res) {
			return Object.values(res?.data?.data || {})[0] || []
		},
		// 判断两份列表数据是否一致(使用 JSON 快照比较,保持现有行为不变)。
		isListChanged(newList, oldList) {
			return JSON.stringify(newList) !== JSON.stringify(oldList)
		},
		// ========== 迁移自父组件的核心方法 ==========
		// 任务主数据变化后的统一入口:处理权限、标题和各模块数据刷新。
		handleQuDataUpdate(newVal, currentId, currentFrom, currentTo) {
			const newValString = JSON.stringify(newVal)
			if (newValString !== this.lastPermissionData) {
				this.updatePermissionWMS(newVal)
				this.updatePermissionWCS(newVal)
				this.lastPermissionData = newValString
			}
			const hasRealChange = currentId !== this.lastExecutionEquipmentId || currentFrom !== this.lastFromLocation || currentTo !== this.lastToLocation
			if (!hasRealChange) {
				return
			}
			this.lastExecutionEquipmentId = currentId
			this.lastFromLocation = currentFrom
			this.lastToLocation = currentTo

			// 修正:修改本地变量,而非直接修改props
			this.localTitleEquipment = currentId || ''
			this.localTitlestartLocationt = currentFrom || ''
			this.localTitleendLocationt = currentTo || ''

			this.getEquipmentData(currentId)
			this.startLocation(currentFrom)
			this.endLocation(currentTo)
		},
		// 拉取 WMS 按钮并同步“取消任务”禁用状态。
		updatePermissionWMS(newVal) {
			const opt = {
				urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
				logTitle: 'WMS',
				isUrlALL: true,
				headers: window.baseOnLineOrOff,
				header: window.baseOnLineOrOff,
				type: 'post',
				data: {
					requestMethod: 'post',
					requestUrl: '/api/Button/GetEquipmentButtonByEquipmentIDs',
					requestService: 'WCS',
					requestBody: ['WMS'],
				},
			}
			''.ajax(this, opt, (res) => {
				const realList = this.getButtonListFromResponse(res)
				this.wmsData = realList
				this.isWmsCancelTaskLocked = this.shouldDisableWmsCancelTask(newVal)
			})
		},
		// 判断当前按钮是否处于“取消任务且被锁定”的禁用状态。
		isWmsCancelDisabled(item) {
			return this.isWmsCancelTaskLocked && this.isWmsCancelButton(item)
		},
		// 判断是否是“取消任务”按钮(用于只禁用目标按钮,不影响其它按钮)。
		isWmsCancelButton(item) {
			return String(item?.ButtonName || '').includes('取消任务')
		},
		// 只要任务阶段命中任一锁定阶段,就禁用 WMS 的“取消任务”按钮。
		shouldDisableWmsCancelTask(statusList) {
			const lockedStageMap = new Map((statusList || []).map((item) => [item.key, String(item?.value ?? '').trim()]))
			return WMS_CANCEL_LOCK_STAGES.some((stageKey) => !!lockedStageMap.get(stageKey))
		},
		// 根据任务状态控制 WCS 区块显隐,并按需拉取/清空数据。
		updatePermissionWCS(newVal) {
			const wcsTaskItem = newVal.find((item) => item.key === 'WCS接收任务')
			const shouldShowWcs = !!(wcsTaskItem && (wcsTaskItem.value ?? '').trim() !== '')
			if (shouldShowWcs !== this.isWcsTaskReceived) {
				this.isWcsTaskReceived = shouldShowWcs
				this.$nextTick(() => {
					if (shouldShowWcs) {
						this.getWcsData()
					} else {
						this.clearWcsData()
					}
				})
			}
		},
		// 拉取执行设备按钮,并开启 2 秒轮询;仅在数据变化时更新视图。
		getEquipmentData(equipmentId) {
			if (this.equipmentRefreshTimer) {
				clearInterval(this.equipmentRefreshTimer)
				this.equipmentRefreshTimer = null
			}
			if (!equipmentId) {
				this.isequipment = false
				this.equipmentData = []
				this.lastEquipmentData = []
				return
			}
			const fetchEquipmentData = () => {
				const opt = {
					urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
					logTitle: '执行设备',
					isUrlALL: true,
					headers: window.baseOnLineOrOff,
					header: window.baseOnLineOrOff,
					type: 'post',
					data: {
						requestMethod: 'post',
						requestUrl: '/api/Button/GetEquipmentButtonByEquipmentIDs',
						requestService: 'WCS',
						requestBody: [equipmentId],
					},
				}
				''.ajax(this, opt, (res) => {
					const realList = this.getButtonListFromResponse(res)
					if (this.isListChanged(realList, this.lastEquipmentData)) {
						this.equipmentData = realList
						this.isequipment = realList.length > 0
						this.lastEquipmentData = JSON.parse(JSON.stringify(realList))
						this.$forceUpdate()
					}
				})
			}
			fetchEquipmentData()
			this.equipmentRefreshTimer = setInterval(fetchEquipmentData, 2000)
		},
		// 拉取 WCS 按钮,并开启 2 秒轮询;仅在开关状态变化时更新视图。
		getWcsData() {
			if (this.wcsRefreshTimer) {
				clearInterval(this.wcsRefreshTimer)
				this.wcsRefreshTimer = null
			}
			if (!this.isWcsTaskReceived) {
				this.wcsData = []
				this.lastWcsData = []
				return
			}
			const fetchWcsData = () => {
				const opt = {
					urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
					logTitle: 'WCS模块',
					isUrlALL: true,
					headers: window.baseOnLineOrOff,
					header: window.baseOnLineOrOff,
					type: 'post',
					data: {
						requestMethod: 'post',
						requestUrl: '/api/Button/GetEquipmentButtonByEquipmentIDs',
						requestService: 'WCS',
						requestBody: ['WCS'],
					},
				}
				''.ajax(this, opt, async (res) => {
					const realList = this.getButtonListFromResponse(res)
					for (const x of realList) {
						if (x.ButtonShowType === 'SwitchButton') {
							await this.SwitchData(x)
						}
					}
					const isStartChanged = this.isWcsDataStartChanged(realList, this.lastWcsData)
					if (isStartChanged) {
						this.wcsData = realList
						this.lastWcsData = JSON.parse(JSON.stringify(realList))
						this.$forceUpdate()
					}
				})
			}
			fetchWcsData()
			this.wcsRefreshTimer = setInterval(fetchWcsData, 2000)
		},
		// 对比 WCS 列表中的 Start 字段,决定是否需要刷新界面。
		isWcsDataStartChanged(newList, oldList) {
			if (newList.length !== oldList.length) return true
			for (let i = 0; i < newList.length; i++) {
				const newItem = newList[i]
				const oldItem = oldList[i]
				if (newItem.Start !== oldItem.Start) {
					return true
				}
			}
			return false
		},
		// 清空 WCS 模块数据并停止轮询。
		clearWcsData() {
			if (this.wcsRefreshTimer) {
				clearInterval(this.wcsRefreshTimer)
				this.wcsRefreshTimer = null
			}
			this.wcsData = []
			this.lastWcsData = []
			this.isWcsTaskReceived = false
			this.$forceUpdate()
		},
		// 读取 WCS 的开关当前值,并转换成前端组件所需格式。
		SwitchData(data) {
			return new Promise((resolve) => {
				const opt = {
					urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
					logTitle: 'WCS模块',
					isUrlALL: true,
					headers: window.baseOnLineOrOff,
					header: window.baseOnLineOrOff,
					type: 'post',
					data: {
						requestMethod: data.ButtonRequestType,
						requestUrl: data.ButtonStatusPLCAddress,
						requestService: 'WCS',
						requestBody: [''],
					},
				}
				''.ajax(this, opt, (res) => {
					data.ButtonName = data.ButtonName.split('-').map((item) => ({ label: item }))
					data.Start = res.data.data == true ? 1 : 2
					resolve(data)
				})
			})
		},
		// 拉取开始库位按钮,并开启 2 秒轮询;仅在数据变化时更新视图。
		startLocation(currentFrom) {
			if (this.startLocationRefreshTimer) {
				clearInterval(this.startLocationRefreshTimer)
				this.startLocationRefreshTimer = null
			}
			if (!currentFrom) {
				this.isstartLocationt = false
				this.startLocationtData = []
				this.lastStartLocationData = []
				return
			}
			const fetchStartLocationData = () => {
				const opt = {
					urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
					logTitle: '开始库位',
					isUrlALL: true,
					headers: window.baseOnLineOrOff,
					header: window.baseOnLineOrOff,
					type: 'post',
					data: {
						requestMethod: 'post',
						requestUrl: '/api/Button/GetEquipmentButtonByEquipmentIDs',
						requestService: 'WCS',
						requestBody: [currentFrom],
					},
				}
				''.ajax(this, opt, (res) => {
					const realList = this.getButtonListFromResponse(res)
					if (this.isListChanged(realList, this.lastStartLocationData)) {
						this.startLocationtData = realList
						this.isstartLocationt = realList.length > 0
						this.lastStartLocationData = JSON.parse(JSON.stringify(realList))
						this.$forceUpdate()
					}
				})
			}
			fetchStartLocationData()
			this.startLocationRefreshTimer = setInterval(fetchStartLocationData, 2000)
		},
		// 拉取目标库位按钮,并开启 2 秒轮询;仅在数据变化时更新视图。
		endLocation(currentTo) {
			if (this.endLocationRefreshTimer) {
				clearInterval(this.endLocationRefreshTimer)
				this.endLocationRefreshTimer = null
			}
			if (!currentTo) {
				this.isendLocationt = false
				this.endLocationtData = []
				this.lastEndLocationData = []
				return
			}
			const fetchEndLocationData = () => {
				const opt = {
					urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
					logTitle: '目标库位',
					isUrlALL: true,
					headers: window.baseOnLineOrOff,
					header: window.baseOnLineOrOff,
					type: 'post',
					data: {
						requestMethod: 'post',
						requestUrl: '/api/Button/GetEquipmentButtonByEquipmentIDs',
						requestService: 'WCS',
						requestBody: [currentTo],
					},
				}
				''.ajax(this, opt, (res) => {
					const realList = this.getButtonListFromResponse(res)
					if (this.isListChanged(realList, this.lastEndLocationData)) {
						this.endLocationtData = realList
						this.isendLocationt = realList.length > 0
						this.lastEndLocationData = JSON.parse(JSON.stringify(realList))
						this.$forceUpdate()
					}
				})
			}
			fetchEndLocationData()
			this.endLocationRefreshTimer = setInterval(fetchEndLocationData, 2000)
		},
		// 页面上下文切换或无任务时,清空模块数据并关闭所有轮询。
		clearModuleData() {
			if (this.equipmentRefreshTimer) clearInterval(this.equipmentRefreshTimer)
			if (this.startLocationRefreshTimer) clearInterval(this.startLocationRefreshTimer)
			if (this.endLocationRefreshTimer) clearInterval(this.endLocationRefreshTimer)
			if (this.wcsRefreshTimer) clearInterval(this.wcsRefreshTimer)
			this.equipmentRefreshTimer = null
			this.startLocationRefreshTimer = null
			this.endLocationRefreshTimer = null
			this.wcsRefreshTimer = null
			this.equipmentData = []
			this.startLocationtData = []
			this.endLocationtData = []
			this.wcsData = []
			this.isequipment = false
			this.isendLocationt = false
			this.isstartLocationt = false
			this.isWmsCancelTaskLocked = false
			this.isWcsTaskReceived = false
			this.localTitleEquipment = ''
			this.localTitlestartLocationt = ''
			this.localTitleendLocationt = ''
			this.lastExecutionEquipmentId = null
			this.lastFromLocation = null
			this.lastToLocation = null
			this.lastPermissionData = null
			this.lastEquipmentData = []
			this.lastStartLocationData = []
			this.lastEndLocationData = []
			this.lastWcsData = []
		},

		// ========== 原有子组件方法 ==========
		// 鼠标按下时启动长按计时;WMS 禁用按钮直接拦截。
		handleDown(item, moduleType) {
			if (moduleType === 'wms' && this.isWmsCancelDisabled(item)) {
				return
			}
			this.isLongPress = false
			clearTimeout(this.pressTimer)
			this.currentButtonContext = { item, moduleType }
			this.pressTimer = setTimeout(() => {
				this.isLongPress = true
				this.apiLongPress(item, moduleType)
			}, 500)
		},
		// 鼠标抬起时结束长按;若已触发长按则发送 release 指令。
		handleUp(item, moduleType) {
			clearTimeout(this.pressTimer)
			if (this.isLongPress) {
				this.apiRelease(item, moduleType)
			}
			this.isLongPress = false
			this.currentButtonContext = null
		},
		// 长按触发的按下动作:WMS 走业务动作,WCS/设备/库位走统一按钮动作接口。
		apiLongPress(item, moduleType) {
			if (moduleType == 'wms') {
				if (item.EquipmentButtonActions.length == 1) {
					this.wcsPressbtn(item, moduleType)
				}
			} else {
				let logTitle = '执行设备'
				let requestBody = {
					equipmentID: item.EquipmentID,
					buttonID: item.ButtonID,
					buttonActionType: 'press',
				}
				if (moduleType === 'wcs') {
					logTitle = 'WCS模块'
				} else if (moduleType === 'startLocation') {
					logTitle = '开始库位'
				} else if (moduleType === 'endLocation') {
					logTitle = '结束库位'
				}
				const opt = {
					urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
					logTitle: logTitle,
					isUrlALL: true,
					headers: window.baseOnLineOrOff,
					header: window.baseOnLineOrOff,
					type: 'post',
					data: {
						requestMethod: 'post',
						requestUrl: '/api/Button/SendEquipmentButtonAction',
						requestService: 'WCS',
						requestBody: requestBody,
					},
				}
				''.ajax(this, opt, (res) => {
					if (res.data.code == 200) {
						this.$message({
							message: res.data.message,
							type: 'success',
						})
					} else {
						this.$message({
							message: res.data.message,
							type: 'warning',
						})
					}
				})
			}
		},
		// 触发 WMS 按钮动作(如取消任务),并优先使用当前选中任务 ID。
		wcsPressbtn(item) {
			const firstAction = item?.EquipmentButtonActions?.[0]
			if (!firstAction || !firstAction.ActionPLCAddress) {
				this.$message({
					message: 'WMS按钮动作配置缺失,无法执行',
					type: 'warning',
				})
				return
			}
			const resolvedTaskId = this.currentTaskId ?? this.qustData?.[0]?.taskId ?? this.TaskId
			let requestBody = { id: resolvedTaskId }
			const opt = {
				urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
				logTitle: 'wms按下',
				isUrlALL: true,
				headers: window.baseOnLineOrOff,
				header: window.baseOnLineOrOff,
				type: 'post',
				data: {
					requestMethod: 'post',
					requestUrl: firstAction.ActionPLCAddress,
					requestService: 'WMS',
					requestBody: requestBody,
				},
			}
			''.ajax(this, opt, (res) => {
				if (res.data.code == 200) {
					this.$message({
						message: res.data.message,
						type: 'success',
					})
				} else {
					this.$message({
						message: res.data.message,
						type: 'warning',
					})
				}
			})
		},
		// 长按结束后的 release 动作,仅对非 WMS 模块有效。
		apiRelease(item, moduleType) {
			if (moduleType == 'wms') {
				return
			}
			let logTitle = '执行设备'
			let requestBody = {
				equipmentID: item.EquipmentID,
				buttonID: item.ButtonID,
				buttonActionType: 'release',
			}
			if (moduleType === 'wcs') {
				logTitle = 'WCS模块'
			} else if (moduleType === 'startLocation') {
				logTitle = '开始库位'
			} else if (moduleType === 'endLocation') {
				logTitle = '结束库位'
			}
			const opt = {
				urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
				logTitle: logTitle,
				isUrlALL: true,
				headers: window.baseOnLineOrOff,
				header: window.baseOnLineOrOff,
				type: 'post',
				data: {
					requestMethod: 'post',
					requestUrl: '/api/Button/SendEquipmentButtonAction',
					requestService: 'WCS',
					requestBody: requestBody,
				},
			}
			''.ajax(this, opt, (res) => {
				if (res.data.code == 200) {
					this.$message({
						message: res.data.message,
						type: 'success',
					})
				} else {
					this.$message({
						message: res.data.message,
						type: 'warning',
					})
				}
			})
		},
		// 处理滑动开关的切换请求,按选中项发送对应 PLC 指令。
		handleSubsectionChange(activeValue, itemData) {
			let requestBody = ''
			let tempUrl = ''
			let tempTpel = ''
			if (activeValue == 1) {
				requestBody = itemData.EquipmentButtonActions[0].ActionWriteValue
				tempUrl = itemData.EquipmentButtonActions[0].ActionPLCAddress
				tempTpel = itemData.EquipmentButtonActions[0].ActionRequestType
			} else {
				requestBody = itemData.EquipmentButtonActions[1].ActionWriteValue
				tempUrl = itemData.EquipmentButtonActions[1].ActionPLCAddress
				tempTpel = itemData.EquipmentButtonActions[1].ActionRequestType
			}
			const opt = {
				urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
				logTitle: '大滑动开关',
				isUrlALL: true,
				headers: window.baseOnLineOrOff,
				header: window.baseOnLineOrOff,
				type: 'post',
				data: {
					requestMethod: tempTpel,
					requestUrl: tempUrl,
					requestService: 'WCS',
					requestBody: requestBody,
				},
			}
			''.ajax(this, opt, (res) => {
				if (res.data.code == 200) {
					this.$message({
						message: res.data.message,
						type: 'success',
					})
				} else {
					this.$message({
						message: res.data.message,
						type: 'warning',
					})
				}
			})
		},
	},
	beforeDestroy() {
		// 清理所有定时器
		if (this.pressTimer) clearTimeout(this.pressTimer)
		if (this.tabClickTimer) clearTimeout(this.tabClickTimer)
		if (this.updateTimer) clearTimeout(this.updateTimer)
		if (this.equipmentRefreshTimer) clearInterval(this.equipmentRefreshTimer)
		if (this.startLocationRefreshTimer) clearInterval(this.startLocationRefreshTimer)
		if (this.endLocationRefreshTimer) clearInterval(this.endLocationRefreshTimer)
		if (this.wcsRefreshTimer) clearInterval(this.wcsRefreshTimer)
	},
}
</script>

<!-- 样式无需修改,原样式文件路径保持不变 -->
<style src="./taskModel.css" scoped></style>