refactor: 更新BinTaskManagerService,重命名区域注释,优化库位处理逻辑,确保数据一致性,调整binTask数据格式化方式
This commit is contained in:
parent
c41263d39f
commit
c9033a4c18
@ -140,7 +140,7 @@ export class BinTaskManagerService {
|
|||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region 数据编辑相关
|
//#region 数据转换相关
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析BinTask数据为可编辑的格式
|
* 解析BinTask数据为可编辑的格式
|
||||||
@ -178,6 +178,10 @@ export class BinTaskManagerService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region 工具方法
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取值的类型
|
* 获取值的类型
|
||||||
* @param value 任意值
|
* @param value 任意值
|
||||||
@ -237,7 +241,7 @@ export class BinTaskManagerService {
|
|||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region 场景更新相关
|
//#region 场景数据更新相关
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新库位的BinTask配置
|
* 更新库位的BinTask配置
|
||||||
@ -246,11 +250,19 @@ export class BinTaskManagerService {
|
|||||||
* @param binTasks BinTask配置数据
|
* @param binTasks BinTask配置数据
|
||||||
*/
|
*/
|
||||||
public updateBinTask(pointName: string, locationName: string, binTasks: BinTaskItem[]): void {
|
public updateBinTask(pointName: string, locationName: string, binTasks: BinTaskItem[]): void {
|
||||||
const binLocationGroups = this.getBinLocationGroups();
|
let binLocationGroups = this.getBinLocationGroups();
|
||||||
if (binLocationGroups.length === 0) return;
|
|
||||||
|
// 如果没有任何库位组,创建一个默认组
|
||||||
|
if (binLocationGroups.length === 0) {
|
||||||
|
binLocationGroups = [{
|
||||||
|
binLocationList: []
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
// 查找目标库位
|
// 查找目标库位
|
||||||
let targetLocation: any = null;
|
let targetLocation: any = null;
|
||||||
|
let targetGroup: any = null;
|
||||||
|
|
||||||
for (const group of binLocationGroups) {
|
for (const group of binLocationGroups) {
|
||||||
if (group && Array.isArray(group.binLocationList)) {
|
if (group && Array.isArray(group.binLocationList)) {
|
||||||
const location = group.binLocationList.find(
|
const location = group.binLocationList.find(
|
||||||
@ -258,14 +270,30 @@ export class BinTaskManagerService {
|
|||||||
);
|
);
|
||||||
if (location) {
|
if (location) {
|
||||||
targetLocation = location;
|
targetLocation = location;
|
||||||
|
targetGroup = group;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果没找到库位,创建一个新的库位条目
|
||||||
if (!targetLocation) {
|
if (!targetLocation) {
|
||||||
console.warn(`未找到库位: ${pointName} - ${locationName}`);
|
// 使用第一个组,如果不存在则创建
|
||||||
return;
|
if (!targetGroup) {
|
||||||
|
targetGroup = binLocationGroups[0];
|
||||||
|
if (!targetGroup.binLocationList) {
|
||||||
|
targetGroup.binLocationList = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建新的库位条目
|
||||||
|
targetLocation = {
|
||||||
|
pointName: pointName,
|
||||||
|
instanceName: locationName,
|
||||||
|
property: []
|
||||||
|
};
|
||||||
|
|
||||||
|
targetGroup.binLocationList.push(targetLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保property数组存在
|
// 确保property数组存在
|
||||||
@ -278,14 +306,15 @@ export class BinTaskManagerService {
|
|||||||
if (!binTaskProperty) {
|
if (!binTaskProperty) {
|
||||||
binTaskProperty = {
|
binTaskProperty = {
|
||||||
key: 'binTask',
|
key: 'binTask',
|
||||||
type: 'string',
|
type: 'json',
|
||||||
stringValue: ''
|
stringValue: ''
|
||||||
};
|
};
|
||||||
targetLocation.property.push(binTaskProperty);
|
targetLocation.property.push(binTaskProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新binTask数据
|
// 更新binTask数据 - 使用格式化的JSON字符串,保持与解析时一致的格式
|
||||||
binTaskProperty.stringValue = JSON.stringify(binTasks);
|
binTaskProperty.stringValue = JSON.stringify(binTasks, null, 4);
|
||||||
|
binTaskProperty.type = 'json';
|
||||||
|
|
||||||
// 更新原始场景数据
|
// 更新原始场景数据
|
||||||
this.updateOriginalSceneData(binLocationGroups);
|
this.updateOriginalSceneData(binLocationGroups);
|
||||||
@ -365,7 +394,7 @@ export class BinTaskManagerService {
|
|||||||
|
|
||||||
const binLocationGroups = Array.isArray(rawData)
|
const binLocationGroups = Array.isArray(rawData)
|
||||||
? (rawData as BinLocationGroup[])
|
? (rawData as BinLocationGroup[])
|
||||||
: (rawData as { binLocationsList: BinLocationGroup[] })?.binLocationsList;
|
: (rawData as BinLocationsList)?.binLocationsList;
|
||||||
|
|
||||||
return Array.isArray(binLocationGroups) ? binLocationGroups : [];
|
return Array.isArray(binLocationGroups) ? binLocationGroups : [];
|
||||||
}
|
}
|
||||||
@ -406,176 +435,4 @@ export class BinTaskManagerService {
|
|||||||
*/
|
*/
|
||||||
export interface TaskData {
|
export interface TaskData {
|
||||||
operations: Record<string, Record<string, any>>;
|
operations: Record<string, Record<string, any>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* BinTask编辑器操作接口
|
|
||||||
*/
|
|
||||||
export interface BinTaskEditorOperations {
|
|
||||||
// 任务操作
|
|
||||||
addTask: () => void;
|
|
||||||
removeTask: (taskIndex: number) => void;
|
|
||||||
|
|
||||||
// 操作操作
|
|
||||||
addOperation: (taskIndex: number) => void;
|
|
||||||
removeOperation: (taskIndex: number, opKey: string) => void;
|
|
||||||
updateOperationKey: (taskIndex: number, oldKey: string, newKey: string) => void;
|
|
||||||
|
|
||||||
// 属性操作
|
|
||||||
addProperty: (taskIndex: number, opKey: string) => void;
|
|
||||||
removeProperty: (taskIndex: number, opKey: string, propKey: string) => void;
|
|
||||||
updatePropertyKey: (taskIndex: number, opKey: string, oldPropKey: string, newPropKey: string) => void;
|
|
||||||
updatePropertyValue: (taskIndex: number, opKey: string, propKey: string, value: any) => void;
|
|
||||||
changeValueType: (taskIndex: number, opKey: string, propKey: string, newType: string) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BinTask编辑器状态管理
|
|
||||||
*/
|
|
||||||
export class BinTaskEditorState {
|
|
||||||
private taskList: TaskData[] = [];
|
|
||||||
private operations: BinTaskEditorOperations;
|
|
||||||
private manager: BinTaskManagerService;
|
|
||||||
|
|
||||||
constructor(operations: BinTaskEditorOperations, manager?: BinTaskManagerService) {
|
|
||||||
this.operations = operations;
|
|
||||||
this.manager = manager || new BinTaskManagerService({} as any); // 提供默认值
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取任务列表
|
|
||||||
*/
|
|
||||||
public getTaskList(): TaskData[] {
|
|
||||||
return this.taskList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置任务列表
|
|
||||||
*/
|
|
||||||
public setTaskList(taskList: TaskData[]): void {
|
|
||||||
this.taskList = taskList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载初始数据
|
|
||||||
*/
|
|
||||||
public loadInitialData(initialData: BinTaskItem[]): void {
|
|
||||||
this.taskList = this.manager.parseBinTaskData(initialData);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取保存数据
|
|
||||||
*/
|
|
||||||
public getSaveData(): BinTaskItem[] {
|
|
||||||
return this.manager.convertToBinTaskData(this.taskList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加任务
|
|
||||||
*/
|
|
||||||
public addTask(): void {
|
|
||||||
this.taskList.push({ operations: {} });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除任务
|
|
||||||
*/
|
|
||||||
public removeTask(taskIndex: number): void {
|
|
||||||
this.taskList.splice(taskIndex, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加操作
|
|
||||||
*/
|
|
||||||
public addOperation(taskIndex: number): void {
|
|
||||||
const task = this.taskList[taskIndex];
|
|
||||||
if (task) {
|
|
||||||
const newOpKey = this.manager.generateUniqueKey('operation');
|
|
||||||
task.operations[newOpKey] = this.manager.createNewOperation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除操作
|
|
||||||
*/
|
|
||||||
public removeOperation(taskIndex: number, opKey: string): void {
|
|
||||||
const task = this.taskList[taskIndex];
|
|
||||||
if (task && task.operations[opKey]) {
|
|
||||||
delete task.operations[opKey];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新操作键名
|
|
||||||
*/
|
|
||||||
public updateOperationKey(taskIndex: number, oldKey: string, newKey: string): void {
|
|
||||||
const task = this.taskList[taskIndex];
|
|
||||||
if (task && task.operations[oldKey] && newKey && newKey !== oldKey) {
|
|
||||||
const operation = task.operations[oldKey];
|
|
||||||
delete task.operations[oldKey];
|
|
||||||
task.operations[newKey] = operation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加属性
|
|
||||||
*/
|
|
||||||
public addProperty(taskIndex: number, opKey: string): void {
|
|
||||||
const task = this.taskList[taskIndex];
|
|
||||||
if (task && task.operations[opKey]) {
|
|
||||||
const newPropKey = this.manager.generateUniqueKey('property');
|
|
||||||
task.operations[opKey][newPropKey] = this.manager.createNewProperty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除属性
|
|
||||||
*/
|
|
||||||
public removeProperty(taskIndex: number, opKey: string, propKey: string): void {
|
|
||||||
const task = this.taskList[taskIndex];
|
|
||||||
if (task && task.operations[opKey] && task.operations[opKey][propKey] !== undefined) {
|
|
||||||
delete task.operations[opKey][propKey];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新属性键名
|
|
||||||
*/
|
|
||||||
public updatePropertyKey(
|
|
||||||
taskIndex: number,
|
|
||||||
opKey: string,
|
|
||||||
oldPropKey: string,
|
|
||||||
newPropKey: string
|
|
||||||
): void {
|
|
||||||
const task = this.taskList[taskIndex];
|
|
||||||
if (task && task.operations[opKey] &&
|
|
||||||
task.operations[opKey][oldPropKey] !== undefined &&
|
|
||||||
newPropKey && newPropKey !== oldPropKey) {
|
|
||||||
const value = task.operations[opKey][oldPropKey];
|
|
||||||
delete task.operations[opKey][oldPropKey];
|
|
||||||
task.operations[opKey][newPropKey] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新属性值
|
|
||||||
*/
|
|
||||||
public updatePropertyValue(taskIndex: number, opKey: string, propKey: string, value: any): void {
|
|
||||||
const task = this.taskList[taskIndex];
|
|
||||||
if (task && task.operations[opKey]) {
|
|
||||||
task.operations[opKey][propKey] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 改变值类型
|
|
||||||
*/
|
|
||||||
public changeValueType(taskIndex: number, opKey: string, propKey: string, newType: string): void {
|
|
||||||
const task = this.taskList[taskIndex];
|
|
||||||
if (task && task.operations[opKey] && task.operations[opKey][propKey] !== undefined) {
|
|
||||||
const currentValue = task.operations[opKey][propKey];
|
|
||||||
const newValue = this.manager.convertValueType(currentValue, newType);
|
|
||||||
task.operations[opKey][propKey] = newValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user