|
|
@@ -13,10 +13,11 @@ export interface Film {
|
|
|
interface PrintState {
|
|
|
films: Film[];
|
|
|
activeFilmId: string;
|
|
|
- /**
|
|
|
- * 本质是 sop instance uid
|
|
|
+ /**
|
|
|
+ * 存储选中的格子,格式为 `${filmId}-${cellIndex}`
|
|
|
+ * 例如: ["1-0", "1-1", "2-0"] 表示胶片1的格子0和1,胶片2的格子0被选中
|
|
|
*/
|
|
|
- selectedImageIndex: string | null; // 当前选中的图像在格子中的索引
|
|
|
+ selectedCells: string[];
|
|
|
}
|
|
|
|
|
|
const initialFilm: Film = {
|
|
|
@@ -32,7 +33,7 @@ const initialFilm: Film = {
|
|
|
const initialState: PrintState = {
|
|
|
films: [initialFilm],
|
|
|
activeFilmId: '1',
|
|
|
- selectedImageIndex: null,
|
|
|
+ selectedCells: [],
|
|
|
};
|
|
|
|
|
|
const printSlice = createSlice({
|
|
|
@@ -68,7 +69,7 @@ const printSlice = createSlice({
|
|
|
// 切换当前胶片
|
|
|
setActiveFilm: (state, action: PayloadAction<string>) => {
|
|
|
state.activeFilmId = action.payload;
|
|
|
- state.selectedImageIndex = null; // 切换胶片时清除选中
|
|
|
+ state.selectedCells = []; // 切换胶片时清除所有选中
|
|
|
},
|
|
|
|
|
|
// 设置胶片布局
|
|
|
@@ -103,20 +104,42 @@ const printSlice = createSlice({
|
|
|
film.orientation = film.orientation === 'horizontal' ? 'vertical' : 'horizontal';
|
|
|
},
|
|
|
|
|
|
- // 设置选中的图像格子
|
|
|
- setSelectedImageIndex: (state, action: PayloadAction<string | null>) => {
|
|
|
- state.selectedImageIndex = action.payload;
|
|
|
+ // Toggle 选中/取消选中格子
|
|
|
+ toggleCellSelection: (state, action: PayloadAction<string>) => {
|
|
|
+ const cellId = action.payload;
|
|
|
+ const index = state.selectedCells.indexOf(cellId);
|
|
|
+ if (index > -1) {
|
|
|
+ state.selectedCells.splice(index, 1); // 取消选中
|
|
|
+ } else {
|
|
|
+ state.selectedCells.push(cellId); // 选中
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 清空所有选中
|
|
|
+ clearAllSelections: (state) => {
|
|
|
+ state.selectedCells = [];
|
|
|
},
|
|
|
|
|
|
// 删除选中的图像
|
|
|
- deleteSelectedImage: (state) => {
|
|
|
- if (state.selectedImageIndex === null) return;
|
|
|
+ deleteSelectedImages: (state) => {
|
|
|
+ if (state.selectedCells.length === 0) return;
|
|
|
|
|
|
const film = state.films.find((f) => f.id === state.activeFilmId);
|
|
|
if (!film) return;
|
|
|
|
|
|
- film.images[state.selectedImageIndex] = null;
|
|
|
- state.selectedImageIndex = null;
|
|
|
+ // 解析选中的格子并删除对应图像
|
|
|
+ state.selectedCells.forEach(cellId => {
|
|
|
+ const [filmId, cellIndexStr] = cellId.split('-');
|
|
|
+ if (filmId === state.activeFilmId) {
|
|
|
+ const cellIndex = parseInt(cellIndexStr, 10);
|
|
|
+ if (cellIndex >= 0 && cellIndex < film.images.length) {
|
|
|
+ film.images[cellIndex] = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 清空选中状态
|
|
|
+ state.selectedCells = [];
|
|
|
},
|
|
|
|
|
|
// 添加图像到指定格子
|
|
|
@@ -138,8 +161,9 @@ export const {
|
|
|
setActiveFilm,
|
|
|
setFilmLayout,
|
|
|
toggleFilmOrientation,
|
|
|
- setSelectedImageIndex,
|
|
|
- deleteSelectedImage,
|
|
|
+ toggleCellSelection,
|
|
|
+ clearAllSelections,
|
|
|
+ deleteSelectedImages,
|
|
|
addImageToCell,
|
|
|
} = printSlice.actions;
|
|
|
|