# 库位管理页面改造 — 实现计划 > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. **Goal:** 将库位管理页面从树形表格+右侧窄面板改为左右布局(左侧 el-tree 树形列表 + 右侧货架行格子卡片),并新增批量生成格子功能。 **Architecture:** 前端完全重写 `index.vue`,参考 `user/index.vue` 的 el-tree 侧边栏模式。后端新增一个批量创建格子的 API 端点(rows×cols 参数 → 一次事务创建多个 slot)。前端格子区域使用 CSS flex 按行分组展示,每行左侧有行标(A/B/C),格子内编号+状态在第一行,下方预留空间。 **Tech Stack:** FastAPI + SQLAlchemy(后端),Vue 3 + Element Plus + SCSS(前端) --- ## File Structure | File | Action | Responsibility | |------|--------|---------------| | `backend/app/crud/storage_facility.py` | Modify | 新增 `batch_create_slots()` 函数 | | `backend/app/api/operations.py` | Modify | 新增 `POST /storage-facility-slots/batch` 端点 | | `web-admin/src/api/admin.ts` | Modify | 新增 `fetchBatchCreateSlots()` 函数 | | `web-admin/src/views/operations/storage-facility/index.vue` | Rewrite | 完全重写为 el-tree + 货架行布局 | --- ### Task 1: 后端 — 批量创建格子 CRUD 函数 **Files:** - Modify: `backend/app/crud/storage_facility.py` (在文件末尾 `soft_delete_slot` 之后追加) - [ ] **Step 1: 在 `storage_facility.py` 末尾添加 `batch_create_slots` 函数** 在 `backend/app/crud/storage_facility.py` 文件末尾追加以下函数(在 `soft_delete_slot` 函数之后): ```python def batch_create_slots( db: Session, *, facility_node_id: str, rows: int, cols: int, code_prefix: str = "", tenant_no: str = "zkxw", user_id: Optional[str] = None, ) -> List[Dict[str, Any]]: """Batch create rows×cols slots for a leaf facility node in a single transaction.""" fid = (facility_node_id or "").strip() if not fid: raise ValueError("所属设施节点不能为空") if rows < 1 or cols < 1: raise ValueError("行数和列数必须大于 0") if rows > 50 or cols > 50: raise ValueError("单次最多生成 50×50 = 2500 个格子") node = db.query(BizStorageFacility).filter( and_(BizStorageFacility.id == fid, BizStorageFacility.del_flag == 0) ).first() if not node: raise ValueError("所属设施节点不存在") if not node.is_leaf: raise ValueError("只能为叶子节点创建格子") prefix = (code_prefix or "").strip() now = datetime.now() slots: List[BizStorageFacilitySlot] = [] for r in range(1, rows + 1): for c in range(1, cols + 1): code = f"{prefix}{r}-{c}" if prefix else f"{r}-{c}" order = (r - 1) * cols + c obj = BizStorageFacilitySlot( id=generate_uuid(), facility_node_id=fid, slot_code=code, slot_status="空", tenant_no=tenant_no, order_num=order, remark=None, create_by=user_id, create_dept_id="", create_time=now, update_by=user_id, update_time=now, del_flag=0, ) db.add(obj) slots.append(obj) db.commit() for s in slots: db.refresh(s) return [_slot_to_dict(s) for s in slots] ``` - [ ] **Step 2: 验证语法无误** Run: `cd /Users/wuzilong/work/00code/zkxw/backend && source venv/bin/activate && python -c "from app.crud.storage_facility import batch_create_slots; print('OK')"` Expected: `OK` --- ### Task 2: 后端 — 批量创建格子 API 端点 **Files:** - Modify: `backend/app/api/operations.py` (在 `StorageSlotCreateBody` 类之后、`list_storage_slots` 端点之前插入) - [ ] **Step 1: 添加 Pydantic body model 和 API 端点** 在 `backend/app/api/operations.py` 中,在 `StorageSlotCreateBody` 类定义之后(约第 377 行之后),添加 body model: ```python class StorageSlotBatchCreateBody(BaseModel): model_config = ConfigDict(populate_by_name=True) facility_node_id: str = Field(..., alias="facilityNodeId") rows: int = Field(..., ge=1, le=50) cols: int = Field(..., ge=1, le=50) code_prefix: Optional[str] = Field("", alias="codePrefix") ``` 然后在 `@router.post("/storage-facility-slots")` 端点之前(`StorageSlotBatchCreateBody` 定义之后),添加批量创建端点: ```python @router.post("/storage-facility-slots/batch") async def batch_create_storage_slots( body: StorageSlotBatchCreateBody, user: dict = Depends(require_admin_or_super_admin), db: Session = Depends(get_db), ): try: tenant_no = _get_tenant_no(db, user) items = storage_facility_svc.batch_create_slots( db, facility_node_id=body.facility_node_id, rows=body.rows, cols=body.cols, code_prefix=body.code_prefix, tenant_no=tenant_no, user_id=user.get("user_id"), ) return success_response(items, message=f"批量创建 {len(items)} 个格子成功") except ValueError as e: return error_response(400, str(e)) ``` **重要**:这个端点必须放在 `/storage-facility-slots` 路由之前,否则 FastAPI 会把 `batch` 当做 `{slot_id}` 参数匹配。 - [ ] **Step 2: 验证语法无误** Run: `cd /Users/wuzilong/work/00code/zkxw/backend && source venv/bin/activate && python -c "from app.api.operations import router; print('OK')"` Expected: `OK` --- ### Task 3: 前端 — 添加批量创建 API 函数 **Files:** - Modify: `web-admin/src/api/admin.ts` (在 `fetchCreateStorageSlot` 函数之后) - [ ] **Step 1: 在 `admin.ts` 中 `fetchCreateStorageSlot` 之后添加批量创建函数** 在 `web-admin/src/api/admin.ts` 中,在 `fetchCreateStorageSlot` 函数(第 1336-1338 行)之后插入: ```typescript export function fetchBatchCreateSlots(data: { facilityNodeId: string; rows: number; cols: number; codePrefix?: string }) { return request.post({ url: '/web/admin/storage-facility-slots/batch', params: data }) } ``` - [ ] **Step 2: 验证 lint 通过** Run: `cd /Users/wuzilong/work/00code/zkxw/web-admin && npx eslint src/api/admin.ts --no-error-on-unmatched-pattern 2>&1 | tail -5` Expected: 无错误输出 --- ### Task 4: 前端 — 重写库位管理页面 **Files:** - Rewrite: `web-admin/src/views/operations/storage-facility/index.vue` - Reference: `web-admin/src/views/system/user/index.vue` (el-tree 侧边栏模式) - Reference: `web-admin/storage-redesign-prototype.html` (视觉原型) 这是最大的任务。完全重写页面,从树形表格+窄面板 → el-tree 侧边栏 + 货架行格子布局。 - [ ] **Step 1: 重写整个 index.vue** 用以下完整内容替换 `web-admin/src/views/operations/storage-facility/index.vue` 的全部内容。 **关键设计决策:** 1. **左侧 el-tree** — 参考 `user/index.vue` 的 `w-[280px] shrink-0 border-r` 布局。使用 `el-tree` 组件 + `buildTree()` 构建树形数据。树节点通过 `@node-click` 触发右侧面板更新。 2. **右侧货架行格子** — 使用 flex 布局,按行分组。每行由行标 `.shelf-label` + 格子容器 `.shelf-cells` 组成。每个格子 `.shelf-cell` 内编号+状态在顶部一行,下方预留空间。 3. **批量生成** — 点击"批量生成格子"弹出 dialog,输入行数、列数、编码前缀。确认后调用 `fetchBatchCreateSlots`。 4. **格子编辑** — 点击格子弹出编辑 dialog,修改编码和状态。 5. **节点 CRUD** — el-tree 节点 hover 显示操作按钮(新增子节点、编辑、删除),点击弹出 dialog。 **完整代码如下:** ```vue 库位管理 维护库位设施树结构,以及叶子节点的格子管理。 库位树 新增 {{ data.nodeName }} 叶 + 编辑 删除 {{ selectedNode.nodeName }} {{ buildTreePathLabelFromFlat(selectedNode.id, flatList, { nameKey: 'nodeName' }) }} — 格子管理 共 {{ slotList.length }} 个格子 批量生成格子 清空格子 {{ row.label }} {{ cell.slotCode }} {{ cell.slotStatus || '空' }} — 取消 确定 取消 确定 编码前缀 生成格式:前缀+行号-列号,如 A-1-1 将生成 {{ batchForm.rows * batchForm.cols }} 个格子({{ batchForm.rows }} 行 × {{ batchForm.cols }} 列) 取消 确认生成 ``` - [ ] **Step 2: 验证 lint 通过** Run: `cd /Users/wuzilong/work/00code/zkxw/web-admin && npx eslint src/views/operations/storage-facility/index.vue --no-error-on-unmatched-pattern 2>&1 | tail -10` Expected: 无错误输出 - [ ] **Step 3: 验证 dev server 正常** Run: `cd /Users/wuzilong/work/00code/zkxw/web-admin && npx vite build --mode development 2>&1 | tail -5` Expected: 构建成功,无编译错误 --- ## Self-Review **Spec coverage:** - ✅ 左侧 el-tree 树形列表(自由层级) - ✅ 右侧货架行布局格子展示(最末层叶子节点) - ✅ 编号+状态在格子顶部一行 - ✅ 下方预留空间 - ✅ 批量生成格子(指定行列数) - ✅ 格子点击编辑(dialog) - ✅ 节点 CRUD(弹窗) - ✅ 节点删除级联删除子节点和格子 **Placeholder scan:** 无 TBD/TODO/待定内容。所有代码完整。 **Type consistency:** 所有函数签名、变量名前后一致。`fetchBatchCreateSlots` 在 admin.ts 定义并在 index.vue 中使用。
维护库位设施树结构,以及叶子节点的格子管理。