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:
yml2213
2026-08-29 13:13:57 +08:00
parent 9653dbe3ba
commit d6ab4d8699
6 changed files with 153 additions and 24 deletions
@@ -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")
+2
View File
@@ -279,6 +279,8 @@ class HuyaAccount(Base):
tag = Column(String(64), default="") tag = Column(String(64), default="")
remark = Column(String(256), default="") remark = Column(String(256), default="")
status = Column(String(32), default="imported") 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) points = Column(Integer, nullable=True)
game_name = Column(String(128), default="") game_name = Column(String(128), default="")
game_channel = Column(String(64), default="") game_channel = Column(String(64), default="")
+7
View File
@@ -283,6 +283,7 @@ def _account_out(account: HuyaAccount, include_cookie: bool = True) -> HuyaAccou
tag=account.tag or "", tag=account.tag or "",
remark=account.remark or "", remark=account.remark or "",
status=account.status or "", status=account.status or "",
login_channel=getattr(account, "login_channel", "") or "",
points=account.points, points=account.points,
game_name=account.game_name or "", game_name=account.game_name or "",
game_channel=account.game_channel 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 "", tag=account.tag or "",
remark=account.remark or "", remark=account.remark or "",
status=account.status or "", status=account.status or "",
login_channel=getattr(account, "login_channel", "") or "",
points=account.points, points=account.points,
game_name=account.game_name or "", game_name=account.game_name or "",
game_channel=account.game_channel or "", game_channel=account.game_channel or "",
@@ -555,6 +557,7 @@ def password_login_account(
if hasattr(account, "account_password") and req.password: if hasattr(account, "account_password") and req.password:
account.account_password = req.password account.account_password = req.password
account.status = "active" account.status = "active"
account.login_channel = "web"
db.commit() db.commit()
except ValueError as exc: except ValueError as exc:
raise HTTPException(status_code=502, detail=str(exc)) from 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: if hasattr(account, "account_password") and req.password:
account.account_password = req.password account.account_password = req.password
account.status = "active" account.status = "active"
account.login_channel = "app"
db.commit() db.commit()
except ValueError as exc: except ValueError as exc:
raise HTTPException(status_code=502, detail=str(exc)) from exc raise HTTPException(status_code=502, detail=str(exc)) from exc
@@ -662,6 +666,7 @@ def sms_login_account(
try: try:
account = upsert_huya_cookie(db, result.cookie, tag=req.tag, username_hint="") account = upsert_huya_cookie(db, result.cookie, tag=req.tag, username_hint="")
account.login_channel = "sms"
phone = (req.phone or "").strip() phone = (req.phone or "").strip()
if phone: if phone:
account.game_phone = phone account.game_phone = phone
@@ -921,6 +926,7 @@ def password_login_selected_accounts(
tag=account.tag or "", tag=account.tag or "",
username_hint=username, username_hint=username,
) )
saved.login_channel = "web"
success_count += 1 success_count += 1
results.append({ results.append({
"line": account.id, "line": account.id,
@@ -1053,6 +1059,7 @@ def app_password_login_selected_accounts(
username_hint=username, username_hint=username,
) )
saved.status = "active" saved.status = "active"
saved.login_channel = "app"
db.commit() db.commit()
success_count += 1 success_count += 1
results.append({ results.append({
+2
View File
@@ -409,6 +409,8 @@ class HuyaAccountOut(BaseModel):
tag: str = "" tag: str = ""
remark: str = "" remark: str = ""
status: str = "" status: str = ""
# 上次成功登录渠道: web / app / sms (空 = 仅导入 Cookie, 从未协议登录)
login_channel: str = ""
points: Optional[int] = None points: Optional[int] = None
game_name: str = "" game_name: str = ""
game_channel: str = "" game_channel: str = ""
+2
View File
@@ -451,6 +451,8 @@ export interface HuyaAccountItem {
tag: string; tag: string;
remark: string; remark: string;
status: string; status: string;
/** 上次成功登录渠道: web=旧版Web协议 / app=App协议(推荐) / sms=短信; 空=仅导入 */
login_channel?: string;
points: number | null; points: number | null;
game_name: string; game_name: string;
game_channel: string; game_channel: string;
+95 -24
View File
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useState } from 'react'; import { useCallback, useEffect, useMemo, useState } from 'react';
import { import {
Alert, Button, Card, Col, Input, Modal, Popconfirm, Row, Select, Space, Statistic, Table, Tag, Typography, Alert, Button, Card, Col, Divider, Input, Modal, Popconfirm, Row, Select, Space, Statistic, Table, Tag, Tooltip, Typography,
} from 'antd'; } from 'antd';
import { message } from '../utils/antdMessage'; import { message } from '../utils/antdMessage';
import type { TableProps } from 'antd'; import type { TableProps } from 'antd';
@@ -30,6 +30,13 @@ const STATUS_LABELS: Record<string, string> = {
invalid: '失效', invalid: '失效',
}; };
// 登录渠道展示 (对应后端 HuyaAccount.login_channel: web/app/sms)
const LOGIN_CHANNEL_LABELS: Record<string, { label: string; color: string }> = {
app: { label: 'App 协议', color: 'processing' },
web: { label: 'Web 旧版', color: 'warning' },
sms: { label: '短信', color: 'cyan' },
};
const STATUS_COLORS: Record<string, string> = { const STATUS_COLORS: Record<string, string> = {
imported: 'blue', imported: 'blue',
updated: 'cyan', updated: 'cyan',
@@ -321,6 +328,29 @@ export default function HuyaAccountsPage() {
} }
}; };
// 行内单账号登录: 复用批量端点, 只传该行 id (需已导入密码)
const [rowLoginKey, setRowLoginKey] = useState('');
const handleRowLogin = async (record: HuyaAccountItem, channel: 'app' | 'web') => {
setRowLoginKey(`${channel}-${record.id}`);
try {
const payload = { account_ids: [record.id], all_matching: false, search: '', tag: '' };
const result = channel === 'app'
? await huyaApi.appPasswordLoginSelected(payload)
: await huyaApi.passwordLoginSelected(payload);
setPasswordLoginResults(result.results || []);
setLoginModalTitle(channel === 'app' ? 'App 协议登录结果' : 'Web 旧版登录结果');
setPasswordLoginResultOpen(true);
const ok = (result.results || []).some((r) => r.success);
if (ok) { message.success('登录成功,Cookie 已保存'); } else { message.warning(result.message || '登录失败'); }
loadAccounts();
loadSummary();
} catch (e: unknown) {
message.error(getErrorMessage(e));
} finally {
setRowLoginKey('');
}
};
const handleWebLoginSelected = async () => { const handleWebLoginSelected = async () => {
if (selectedCount === 0) { if (selectedCount === 0) {
message.warning('请先选择虎牙账号'); message.warning('请先选择虎牙账号');
@@ -550,6 +580,18 @@ export default function HuyaAccountsPage() {
<Tag color={STATUS_COLORS[status] || 'default'}>{STATUS_LABELS[status] || status || '-'}</Tag> <Tag color={STATUS_COLORS[status] || 'default'}>{STATUS_LABELS[status] || status || '-'}</Tag>
), ),
}, },
{
title: '登录渠道',
dataIndex: 'login_channel',
width: 100,
align: 'center',
render: (channel: string) => {
const info = LOGIN_CHANNEL_LABELS[channel];
return info
? <Tag color={info.color}>{info.label}</Tag>
: <Tag></Tag>;
},
},
{ {
title: '更新时间', title: '更新时间',
dataIndex: 'updated_at', dataIndex: 'updated_at',
@@ -558,15 +600,38 @@ export default function HuyaAccountsPage() {
}, },
{ {
title: '操作', title: '操作',
width: 90, width: 150,
fixed: 'right', fixed: 'right',
align: 'center', align: 'center',
render: (_: unknown, record) => ( render: (_: unknown, record) => (
canDelete ? ( <Space size={4}>
<Popconfirm title="确认删除这条虎牙账号?" onConfirm={() => handleDelete(record.id)}> {canImport && record.has_password && (
<Button danger size="small" icon={<DeleteOutlined />} /> <>
</Popconfirm> <Tooltip title="App 协议登录此账号 (推荐)">
) : null <Button
size="small"
type="primary"
icon={<MobileOutlined />}
loading={rowLoginKey === `app-${record.id}`}
onClick={() => handleRowLogin(record, 'app')}
/>
</Tooltip>
<Tooltip title="Web 旧版协议登录此账号">
<Button
size="small"
icon={<LoginOutlined />}
loading={rowLoginKey === `web-${record.id}`}
onClick={() => handleRowLogin(record, 'web')}
/>
</Tooltip>
</>
)}
{canDelete && (
<Popconfirm title="确认删除这条虎牙账号?" onConfirm={() => handleDelete(record.id)}>
<Button danger size="small" icon={<DeleteOutlined />} />
</Popconfirm>
)}
</Space>
), ),
}, },
]; ];
@@ -605,27 +670,33 @@ export default function HuyaAccountsPage() {
</Button> </Button>
)} )}
{canImport && <Divider type="vertical" />}
{canImport && ( {canImport && (
<Button <Tooltip title="App 协议登录: 自动注册设备环境并过滑块, 推荐; 登录渠道将记为 App">
type="primary" <Button
disabled={selectedCount === 0} type="primary"
icon={<MobileOutlined />} disabled={selectedCount === 0}
loading={appPasswordLogging} icon={<MobileOutlined />}
onClick={handleAppLoginSelected} loading={appPasswordLogging}
> onClick={handleAppLoginSelected}
App ({selectedCount}) >
</Button> App ({selectedCount})
</Button>
</Tooltip>
)} )}
{canImport && ( {canImport && (
<Button <Tooltip title="旧版 Web 协议登录, 仅作兜底; 新账号请优先使用 App 协议登录">
disabled={selectedCount === 0} <Button
icon={<LoginOutlined />} disabled={selectedCount === 0}
loading={passwordLogging} icon={<LoginOutlined />}
onClick={handleWebLoginSelected} loading={passwordLogging}
> onClick={handleWebLoginSelected}
Web () >
</Button> Web ()
</Button>
</Tooltip>
)} )}
{canImport && <Divider type="vertical" />}
{canDelete && selectedCount > 0 && ( {canDelete && selectedCount > 0 && (
<Popconfirm title={`确认删除${selectedAllMatching ? '当前筛选下' : '选中的'} ${selectedCount} 条虎牙账号?`} onConfirm={handleDeleteSelected}> <Popconfirm title={`确认删除${selectedAllMatching ? '当前筛选下' : '选中的'} ${selectedCount} 条虎牙账号?`} onConfirm={handleDeleteSelected}>
<Button danger icon={<DeleteOutlined />}> <Button danger icon={<DeleteOutlined />}>