From 7863867a5c258d6b5bb9ef134e4a94d5ede3bd0d Mon Sep 17 00:00:00 2001 From: xudan Date: Thu, 11 Sep 2025 10:05:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84point-detail-card?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=EF=BC=8C=E4=BC=98=E5=8C=96=E5=BA=93=E4=BD=8D?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=95=B4=E5=90=88BinTaskManagerService?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB?= =?UTF-8?q?=E6=80=A7=E5=92=8C=E7=BB=B4=E6=8A=A4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/card/point-detail-card.vue | 95 ++--------- src/services/bintask-manager.service.ts | 188 +++++++++++++--------- 2 files changed, 123 insertions(+), 160 deletions(-) diff --git a/src/components/card/point-detail-card.vue b/src/components/card/point-detail-card.vue index a011ae2..3e78c16 100644 --- a/src/components/card/point-detail-card.vue +++ b/src/components/card/point-detail-card.vue @@ -1,12 +1,7 @@ @@ -290,7 +217,7 @@ const binTaskData = computed(() => {
diff --git a/src/services/bintask-manager.service.ts b/src/services/bintask-manager.service.ts index 7681500..8426ecd 100644 --- a/src/services/bintask-manager.service.ts +++ b/src/services/bintask-manager.service.ts @@ -23,44 +23,15 @@ export class BinTaskManagerService { public getBinTaskData(pointName: string, locationName: string): BinTaskItem[] { if (!pointName || !locationName) return []; - try { - const rawData = this.editor.getBinLocationsList(); - if (!rawData) return []; + const targetLocation = this.findBinLocation(pointName, locationName); + if (!targetLocation) return []; - const binLocationGroups = Array.isArray(rawData) - ? (rawData as BinLocationGroup[]) - : (rawData as BinLocationsList)?.binLocationsList; - - if (!binLocationGroups || !Array.isArray(binLocationGroups)) return []; - - const allBinLocations = binLocationGroups - .filter((group) => group && Array.isArray(group.binLocationList)) - .flatMap((group) => group.binLocationList) - .filter((item) => item && typeof item === 'object'); - - const targetLocation = allBinLocations.find( - (item) => item.pointName === pointName && item.instanceName === locationName - ); - - if (!targetLocation || !targetLocation.property || !Array.isArray(targetLocation.property)) { - return []; - } - - const binTaskProperty = targetLocation.property.find((prop) => prop && prop.key === 'binTask'); - if (!binTaskProperty || !binTaskProperty.stringValue) { - return []; - } - - try { - return JSON.parse(binTaskProperty.stringValue.replace(/\n/g, '').trim()); - } catch (error) { - console.error('解析BinTask数据失败:', error); - return []; - } - } catch (error) { - console.error('获取BinTask数据失败:', error); + const binTaskProperty = targetLocation.property?.find((prop) => prop && prop.key === 'binTask'); + if (!binTaskProperty || !binTaskProperty.stringValue) { return []; } + + return this.parseBinTask(binTaskProperty.stringValue); } /** @@ -71,49 +42,19 @@ export class BinTaskManagerService { public getPointBinTaskData(pointName: string): Record { if (!pointName) return {}; - try { - const rawData = this.editor.getBinLocationsList(); - if (!rawData) return {}; + const pointLocations = this.getPointBinLocations(pointName); + const result: Record = {}; - const binLocationGroups = Array.isArray(rawData) - ? (rawData as BinLocationGroup[]) - : (rawData as BinLocationsList)?.binLocationsList; + pointLocations.forEach((location) => { + if (location.instanceName) { + const binTaskProperty = location.property?.find((prop) => prop && prop.key === 'binTask'); + result[location.instanceName] = binTaskProperty && binTaskProperty.stringValue + ? this.parseBinTask(binTaskProperty.stringValue) + : []; + } + }); - if (!binLocationGroups || !Array.isArray(binLocationGroups)) return {}; - - const allBinLocations = binLocationGroups - .filter((group) => group && Array.isArray(group.binLocationList)) - .flatMap((group) => group.binLocationList) - .filter((item) => item && typeof item === 'object'); - - const pointLocations = allBinLocations.filter( - (item) => item.pointName === pointName - ); - - const result: Record = {}; - - pointLocations.forEach((location) => { - if (location.instanceName && location.property && Array.isArray(location.property)) { - const binTaskProperty = location.property.find((prop) => prop && prop.key === 'binTask'); - if (binTaskProperty && binTaskProperty.stringValue) { - try { - const binTasks = JSON.parse(binTaskProperty.stringValue.replace(/\n/g, '').trim()); - result[location.instanceName] = binTasks; - } catch (error) { - console.error('解析库位BinTask数据失败:', error, location); - result[location.instanceName] = []; - } - } else { - result[location.instanceName] = []; - } - } - }); - - return result; - } catch (error) { - console.error('获取动作点BinTask数据失败:', error); - return {}; - } + return result; } /** @@ -138,6 +79,66 @@ export class BinTaskManagerService { return binTaskData.length; } + /** + * 解析库位任务数据 + * @param binTaskString 库位任务字符串 + * @returns 解析后的任务数据 + */ + public parseBinTask(binTaskString: string): BinTaskItem[] { + try { + return JSON.parse(binTaskString.replace(/\n/g, '').trim()); + } catch (error) { + console.error('解析库位任务数据失败:', error); + return []; + } + } + + /** + * 获取任务中的所有操作 + * @param task 任务对象 + * @returns 操作对象映射 + */ + public getTaskOperations(task: BinTaskItem): Record { + if (!task || typeof task !== 'object') return {}; + + const operations: Record = {}; + + // 遍历任务对象的所有属性,查找操作对象 + for (const [key, value] of Object.entries(task)) { + if (value && typeof value === 'object' && 'operation' in value) { + operations[key] = value; + } + } + + return operations; + } + + /** + * 获取当前动作点对应的库位任务数据(用于显示) + * @param pointName 动作点名称 + * @returns 库位任务数据列表 + */ + public getPointBinTaskDataForDisplay(pointName: string): Array<{ + instanceName: string; + binTasks: BinTaskItem[]; + }> { + if (!pointName) return []; + + const pointLocations = this.getPointBinLocations(pointName); + + return pointLocations + .map((item) => { + const binTaskProperty = item.property?.find((prop) => prop && prop.key === 'binTask'); + return { + instanceName: item.instanceName || '未知库位', + binTasks: binTaskProperty && binTaskProperty.stringValue + ? this.parseBinTask(binTaskProperty.stringValue) + : [], + }; + }) + .filter((item) => item.binTasks.length > 0); + } + //#endregion //#region 数据转换相关 @@ -399,6 +400,41 @@ export class BinTaskManagerService { return Array.isArray(binLocationGroups) ? binLocationGroups : []; } + /** + * 获取所有库位数据 + * @returns 所有库位数据数组 + */ + private getAllBinLocations(): any[] { + const binLocationGroups = this.getBinLocationGroups(); + return binLocationGroups + .filter((group) => group && Array.isArray(group.binLocationList)) + .flatMap((group) => group.binLocationList) + .filter((item) => item && typeof item === 'object'); + } + + /** + * 查找指定动作点和库位的库位数据 + * @param pointName 动作点名称 + * @param locationName 库位名称 + * @returns 库位数据,如果未找到则返回null + */ + private findBinLocation(pointName: string, locationName: string): any | null { + const allBinLocations = this.getAllBinLocations(); + return allBinLocations.find( + (item) => item.pointName === pointName && item.instanceName === locationName + ) || null; + } + + /** + * 获取指定动作点的所有库位数据 + * @param pointName 动作点名称 + * @returns 库位数据数组 + */ + private getPointBinLocations(pointName: string): any[] { + const allBinLocations = this.getAllBinLocations(); + return allBinLocations.filter((item) => item.pointName === pointName); + } + /** * 检查库位项是否存在 * @param pointName 动作点名称