feat(web): 虎牙账号管理界面优化 — 登录渠道区分 (Web 旧版 / App 协议 / 短信)
后端: - HuyaAccount 新增 login_channel 字段 + 迁移 20260829_0030 (启动自动升级) - 5 个登录端点成功后记录渠道: web/app 批量与单账号 + 短信 - HuyaAccountOut 输出 login_channel 前端: - 账号表新增『登录渠道』列 (App 协议/Web 旧版/短信/仅导入) - 工具栏登录按钮分组: App 协议登录(primary 推荐) 与 Web 登录(旧版, Tooltip 说明) - 行内操作新增单账号 App/Web 登录按钮 (复用批量端点传单 id) - tsc + vite build 通过
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""虎牙账号增加登录渠道字段 (区分 Web 旧版 / App 协议登录)。
|
||||
|
||||
Revision ID: 20260829_0030
|
||||
Revises: 20260814_0029
|
||||
Create Date: 2026-08-29
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision: str = "20260829_0030"
|
||||
down_revision: Union[str, None] = "20260814_0029"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""huya_accounts 新增 login_channel (上次成功登录渠道)。"""
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
if not inspector.has_table("huya_accounts"):
|
||||
return
|
||||
columns = {column["name"] for column in inspector.get_columns("huya_accounts")}
|
||||
if "login_channel" not in columns:
|
||||
op.add_column("huya_accounts", sa.Column("login_channel", sa.String(16), nullable=False, server_default=""))
|
||||
indexes = {index["name"] for index in inspector.get_indexes("huya_accounts")}
|
||||
if "ix_huya_accounts_login_channel" not in indexes:
|
||||
op.create_index("ix_huya_accounts_login_channel", "huya_accounts", ["login_channel"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""移除 login_channel 字段。"""
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
if not inspector.has_table("huya_accounts"):
|
||||
return
|
||||
indexes = {index["name"] for index in inspector.get_indexes("huya_accounts")}
|
||||
if "ix_huya_accounts_login_channel" in indexes:
|
||||
op.drop_index("ix_huya_accounts_login_channel", table_name="huya_accounts")
|
||||
columns = {column["name"] for column in inspector.get_columns("huya_accounts")}
|
||||
if "login_channel" in columns:
|
||||
op.drop_column("huya_accounts", "login_channel")
|
||||
@@ -279,6 +279,8 @@ class HuyaAccount(Base):
|
||||
tag = Column(String(64), default="")
|
||||
remark = Column(String(256), default="")
|
||||
status = Column(String(32), default="imported")
|
||||
# 上次成功登录渠道: web=旧版Web协议 / app=App协议(推荐) / sms=短信; 空=仅导入Cookie
|
||||
login_channel = Column(String(16), default="", index=True)
|
||||
points = Column(Integer, nullable=True)
|
||||
game_name = Column(String(128), default="")
|
||||
game_channel = Column(String(64), default="")
|
||||
|
||||
@@ -283,6 +283,7 @@ def _account_out(account: HuyaAccount, include_cookie: bool = True) -> HuyaAccou
|
||||
tag=account.tag or "",
|
||||
remark=account.remark or "",
|
||||
status=account.status or "",
|
||||
login_channel=getattr(account, "login_channel", "") or "",
|
||||
points=account.points,
|
||||
game_name=account.game_name or "",
|
||||
game_channel=account.game_channel or "",
|
||||
@@ -308,6 +309,7 @@ def _account_out_light(account: HuyaAccount, *, has_password: bool = False) -> H
|
||||
tag=account.tag or "",
|
||||
remark=account.remark or "",
|
||||
status=account.status or "",
|
||||
login_channel=getattr(account, "login_channel", "") or "",
|
||||
points=account.points,
|
||||
game_name=account.game_name or "",
|
||||
game_channel=account.game_channel or "",
|
||||
@@ -555,6 +557,7 @@ def password_login_account(
|
||||
if hasattr(account, "account_password") and req.password:
|
||||
account.account_password = req.password
|
||||
account.status = "active"
|
||||
account.login_channel = "web"
|
||||
db.commit()
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=502, detail=str(exc)) from exc
|
||||
@@ -597,6 +600,7 @@ def app_password_login_account(
|
||||
if hasattr(account, "account_password") and req.password:
|
||||
account.account_password = req.password
|
||||
account.status = "active"
|
||||
account.login_channel = "app"
|
||||
db.commit()
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=502, detail=str(exc)) from exc
|
||||
@@ -662,6 +666,7 @@ def sms_login_account(
|
||||
|
||||
try:
|
||||
account = upsert_huya_cookie(db, result.cookie, tag=req.tag, username_hint="")
|
||||
account.login_channel = "sms"
|
||||
phone = (req.phone or "").strip()
|
||||
if phone:
|
||||
account.game_phone = phone
|
||||
@@ -921,6 +926,7 @@ def password_login_selected_accounts(
|
||||
tag=account.tag or "",
|
||||
username_hint=username,
|
||||
)
|
||||
saved.login_channel = "web"
|
||||
success_count += 1
|
||||
results.append({
|
||||
"line": account.id,
|
||||
@@ -1053,6 +1059,7 @@ def app_password_login_selected_accounts(
|
||||
username_hint=username,
|
||||
)
|
||||
saved.status = "active"
|
||||
saved.login_channel = "app"
|
||||
db.commit()
|
||||
success_count += 1
|
||||
results.append({
|
||||
|
||||
@@ -409,6 +409,8 @@ class HuyaAccountOut(BaseModel):
|
||||
tag: str = ""
|
||||
remark: str = ""
|
||||
status: str = ""
|
||||
# 上次成功登录渠道: web / app / sms (空 = 仅导入 Cookie, 从未协议登录)
|
||||
login_channel: str = ""
|
||||
points: Optional[int] = None
|
||||
game_name: str = ""
|
||||
game_channel: str = ""
|
||||
|
||||
Reference in New Issue
Block a user