ERP-node/frontend/stores/tableDisplayStore.ts

114 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-11-05 10:23:00 +09:00
/**
*
*
*/
interface TableDisplayState {
data: any[];
columnOrder: string[];
sortBy: string | null;
sortOrder: "asc" | "desc";
tableName: string;
// 🆕 엑셀 다운로드 개선을 위한 추가 필드
filterConditions?: Record<string, any>; // 필터 조건
searchTerm?: string; // 검색어
visibleColumns?: string[]; // 화면 표시 컬럼
columnLabels?: Record<string, string>; // 컬럼 라벨
currentPage?: number; // 현재 페이지
pageSize?: number; // 페이지 크기
totalItems?: number; // 전체 항목 수
2025-11-05 10:23:00 +09:00
}
class TableDisplayStore {
private state: Map<string, TableDisplayState> = new Map();
private listeners: Set<() => void> = new Set();
/**
*
* @param tableName
* @param data
* @param columnOrder
* @param sortBy
* @param sortOrder
* @param options (, )
2025-11-05 10:23:00 +09:00
*/
setTableData(
tableName: string,
data: any[],
columnOrder: string[],
sortBy: string | null,
sortOrder: "asc" | "desc",
options?: {
filterConditions?: Record<string, any>;
searchTerm?: string;
visibleColumns?: string[];
columnLabels?: Record<string, string>;
currentPage?: number;
pageSize?: number;
totalItems?: number;
}
2025-11-05 10:23:00 +09:00
) {
this.state.set(tableName, {
data,
columnOrder,
sortBy,
sortOrder,
tableName,
...options,
2025-11-05 10:23:00 +09:00
});
this.notifyListeners();
}
/**
*
* @param tableName
*/
getTableData(tableName: string): TableDisplayState | undefined {
return this.state.get(tableName);
2025-11-05 10:23:00 +09:00
}
/**
*
*/
getAllTableData(): Map<string, TableDisplayState> {
return new Map(this.state);
}
/**
*
* @param tableName
*/
clearTableData(tableName: string) {
this.state.delete(tableName);
this.notifyListeners();
}
/**
*
*/
clearAll() {
this.state.clear();
this.notifyListeners();
}
/**
*
*/
subscribe(listener: () => void) {
this.listeners.add(listener);
return () => {
this.listeners.delete(listener);
};
}
private notifyListeners() {
this.listeners.forEach((listener) => listener());
}
}
// 싱글톤 인스턴스
export const tableDisplayStore = new TableDisplayStore();