feat: 新增 superadmin 角色和数据清空功能

后端:
- User.Role enum 增加 superadmin,启动时 ALTER TABLE 兼容已有 DB
- 新增 SuperAdminOnly() 中间件
- 新增 POST /api/v1/admin/clear-data 接口(按表名白名单删除,多租户隔离)

前端:
- AppUser/AuthUser 支持 role 字段持久化与传递
- 数据导入 Tab 末尾增加「危险操作 — 数据清空」区块(仅 superadmin 可见)
- 支持多选:入库单/出库单/库存管理/商品详情/往来单位
- 红色警告框 + 二次确认弹窗(需手动输入"确认清空")

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-05-19 01:07:56 +08:00
parent 56e0d9d5b2
commit 86738c903e
10 changed files with 351 additions and 4 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ CREATE TABLE IF NOT EXISTS `users` (
`password_hash` VARCHAR(255) NOT NULL COMMENT 'bcrypt',
`real_name` VARCHAR(50) DEFAULT NULL,
`phone` VARCHAR(30) DEFAULT NULL,
`role` ENUM('admin','operator','readonly') NOT NULL DEFAULT 'operator',
`role` ENUM('admin','operator','readonly','superadmin') NOT NULL DEFAULT 'operator',
`is_active` TINYINT(1) NOT NULL DEFAULT 1,
`custom_fields` JSON DEFAULT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,