feat(web): 虎牙设备绑定页多选批量解绑 — rowSelection 跨页保留 + 全选全部 + 批量接口
- routers/huya.py: POST /api/huya/device-bindings/batch-delete (去重/跳过无记录/删画像+指纹目录) - schemas.py: HuyaDeviceBindingsBatchDeleteRequest - DeviceBindingsPage: 多选(rowSelection preserve) / 全选全部 / 解绑选中(N) + loading, 刷新后清理失效选中 - api/huya.ts + types.ts: deleteDeviceBindings 与响应类型 验证: 批量解绑逻辑单测 OK; 77 后端单测 OK; tsc + vite build OK
This commit is contained in:
@@ -57,6 +57,7 @@ from ..schemas import (
|
||||
HuyaConfigOut,
|
||||
HuyaConfigUpdate,
|
||||
HuyaCookieImport,
|
||||
HuyaDeviceBindingsBatchDeleteRequest,
|
||||
HuyaGoodsOut,
|
||||
HuyaPasswordAccountImport,
|
||||
HuyaPasswordLoginRequest,
|
||||
@@ -1824,3 +1825,45 @@ def delete_device_binding(account: str, db: Session = Depends(get_db), current:
|
||||
removed_state = True
|
||||
return {"ok": True, "account": account, "profile_removed": True, "fp_state_removed": removed_state,
|
||||
"message": "已解绑, 下次 App 协议登录将自动生成全新设备环境并重新注册"}
|
||||
|
||||
|
||||
def _unbind_device_accounts(accounts: list[str]) -> tuple[list[str], list[str]]:
|
||||
"""批量解绑实现: 返回 (成功解绑账号, 无绑定记录的账号)。"""
|
||||
profiles = _load_profile_db()
|
||||
removed: list[str] = []
|
||||
missing: list[str] = []
|
||||
seen = set()
|
||||
for account in accounts:
|
||||
account = (account or "").strip()
|
||||
if not account or account in seen:
|
||||
continue
|
||||
seen.add(account)
|
||||
if account not in profiles:
|
||||
missing.append(account)
|
||||
continue
|
||||
profiles.pop(account)
|
||||
state_dir = _fp_state_dir(account)
|
||||
if state_dir.exists():
|
||||
shutil.rmtree(state_dir, ignore_errors=True)
|
||||
removed.append(account)
|
||||
if removed:
|
||||
_save_profile_db(profiles)
|
||||
return removed, missing
|
||||
|
||||
|
||||
@router.post("/device-bindings/batch-delete")
|
||||
def delete_device_bindings(
|
||||
req: HuyaDeviceBindingsBatchDeleteRequest,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(get_current_user),
|
||||
):
|
||||
"""批量解绑: 一次删除多个账号的设备画像与指纹状态。"""
|
||||
_require_huya_perm(current, "huya:import")
|
||||
removed, missing = _unbind_device_accounts(req.accounts)
|
||||
if not removed:
|
||||
raise HTTPException(status_code=404, detail="所选账号均没有设备绑定记录")
|
||||
message = f"已批量解绑 {len(removed)} 个账号"
|
||||
if missing:
|
||||
message += f",{len(missing)} 个账号无绑定记录已跳过"
|
||||
message += ",下次 App 协议登录将自动生成全新设备环境并重新注册"
|
||||
return {"ok": True, "removed": removed, "missing": missing, "message": message}
|
||||
|
||||
@@ -397,6 +397,11 @@ class HuyaPasswordLoginSelectedRequest(BaseModel):
|
||||
force_new_device: bool = False
|
||||
|
||||
|
||||
class HuyaDeviceBindingsBatchDeleteRequest(BaseModel):
|
||||
"""批量解绑设备:删除账号画像与 hydevice 指纹状态。"""
|
||||
accounts: list[str] = Field(..., min_length=1)
|
||||
|
||||
|
||||
class HuyaAccountOut(BaseModel):
|
||||
id: int
|
||||
uid: str = ""
|
||||
|
||||
Reference in New Issue
Block a user