实现虎牙密码登录
This commit is contained in:
@@ -4,6 +4,8 @@ import type {
|
||||
HuyaConfig,
|
||||
HuyaCookieImportResult,
|
||||
HuyaGoodsItem,
|
||||
HuyaPasswordLoginRequest,
|
||||
HuyaPasswordLoginResult,
|
||||
HuyaRechargeGoodsItem,
|
||||
HuyaTaskBatchRequest,
|
||||
HuyaTaskBatchResult,
|
||||
@@ -18,6 +20,8 @@ export const huyaApi = {
|
||||
api.get<HuyaAccountItem[], HuyaAccountItem[]>('/huya/accounts', { params }),
|
||||
importCookies: (text: string, tag: string = '') =>
|
||||
api.post<HuyaCookieImportResult, HuyaCookieImportResult>('/huya/accounts/import-cookies', { text, tag }),
|
||||
passwordLogin: (data: HuyaPasswordLoginRequest) =>
|
||||
api.post<HuyaPasswordLoginResult, HuyaPasswordLoginResult>('/huya/accounts/password-login', data),
|
||||
deleteAccount: (id: number) => api.delete<MessageResponse, MessageResponse>(`/huya/accounts/${id}`),
|
||||
deleteAccounts: (accountIds: number[]) =>
|
||||
api.delete<MessageDeletedResponse, MessageDeletedResponse>('/huya/accounts/batch', { params: { account_ids: accountIds.join(',') } }),
|
||||
|
||||
@@ -136,6 +136,18 @@ export interface HuyaCookieImportResult extends MessageCountResponse {
|
||||
skipped: number;
|
||||
}
|
||||
|
||||
export interface HuyaPasswordLoginRequest {
|
||||
username: string;
|
||||
password: string;
|
||||
tag?: string;
|
||||
cookie?: string;
|
||||
}
|
||||
|
||||
export interface HuyaPasswordLoginResult extends MessageResponse {
|
||||
account: HuyaAccountItem;
|
||||
sdid: string;
|
||||
}
|
||||
|
||||
export interface HuyaConfig {
|
||||
room_pid: string;
|
||||
sid: string;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
Button, Card, Col, Input, message, Modal, Popconfirm, Row, Space, Statistic, Table, Tag, Typography,
|
||||
Button, Card, Col, Form, Input, message, Modal, Popconfirm, Row, Space, Statistic, Table, Tag, Typography,
|
||||
} from 'antd';
|
||||
import type { TableProps } from 'antd';
|
||||
import { DeleteOutlined, ImportOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
|
||||
import { DeleteOutlined, ImportOutlined, LoginOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
|
||||
import { huyaApi, type HuyaAccountItem } from '../api/modules';
|
||||
import { usePermissions } from '../hooks/usePermissions';
|
||||
import { formatTime } from '../utils/time';
|
||||
@@ -15,6 +15,7 @@ const { TextArea } = Input;
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
imported: '已导入',
|
||||
updated: '已更新',
|
||||
login_success: '登录成功',
|
||||
active: '正常',
|
||||
invalid: '失效',
|
||||
};
|
||||
@@ -22,10 +23,18 @@ const STATUS_LABELS: Record<string, string> = {
|
||||
const STATUS_COLORS: Record<string, string> = {
|
||||
imported: 'blue',
|
||||
updated: 'cyan',
|
||||
login_success: 'success',
|
||||
active: 'success',
|
||||
invalid: 'error',
|
||||
};
|
||||
|
||||
interface PasswordLoginFormValues {
|
||||
username: string;
|
||||
password: string;
|
||||
tag?: string;
|
||||
cookie?: string;
|
||||
}
|
||||
|
||||
export default function HuyaAccountsPage() {
|
||||
const [accounts, setAccounts] = useState<HuyaAccountItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -33,6 +42,8 @@ export default function HuyaAccountsPage() {
|
||||
const [importText, setImportText] = useState('');
|
||||
const [importTag, setImportTag] = useState('');
|
||||
const [importing, setImporting] = useState(false);
|
||||
const [passwordLoginOpen, setPasswordLoginOpen] = useState(false);
|
||||
const [passwordLogging, setPasswordLogging] = useState(false);
|
||||
const [searchText, setSearchText] = useState('');
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||
const [pageSize, setPageSize] = useState(() => {
|
||||
@@ -40,6 +51,7 @@ export default function HuyaAccountsPage() {
|
||||
return v ? Number(v) || 20 : 20;
|
||||
});
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [passwordLoginForm] = Form.useForm<PasswordLoginFormValues>();
|
||||
const { can } = usePermissions();
|
||||
|
||||
const canManage = can('huya:account');
|
||||
@@ -98,6 +110,37 @@ export default function HuyaAccountsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const openPasswordLogin = () => {
|
||||
passwordLoginForm.resetFields();
|
||||
setPasswordLoginOpen(true);
|
||||
};
|
||||
|
||||
const closePasswordLogin = () => {
|
||||
if (passwordLogging) return;
|
||||
setPasswordLoginOpen(false);
|
||||
passwordLoginForm.resetFields();
|
||||
};
|
||||
|
||||
const handlePasswordLogin = async (values: PasswordLoginFormValues) => {
|
||||
setPasswordLogging(true);
|
||||
try {
|
||||
const result = await huyaApi.passwordLogin({
|
||||
username: values.username.trim(),
|
||||
password: values.password,
|
||||
tag: values.tag?.trim() || '',
|
||||
cookie: values.cookie?.trim() || '',
|
||||
});
|
||||
message.success(result.message || '登录成功,Cookie 已保存');
|
||||
setPasswordLoginOpen(false);
|
||||
passwordLoginForm.resetFields();
|
||||
loadAccounts();
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
} finally {
|
||||
setPasswordLogging(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
await huyaApi.deleteAccount(id);
|
||||
@@ -228,6 +271,11 @@ export default function HuyaAccountsPage() {
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
)}
|
||||
{canManage && (
|
||||
<Button icon={<LoginOutlined />} onClick={openPasswordLogin}>
|
||||
密码登录
|
||||
</Button>
|
||||
)}
|
||||
{canManage && (
|
||||
<Button type="primary" icon={<ImportOutlined />} onClick={() => setImportOpen(true)}>
|
||||
粘贴 CK
|
||||
@@ -317,6 +365,51 @@ export default function HuyaAccountsPage() {
|
||||
</Paragraph>
|
||||
</Space>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
title="虎牙密码登录"
|
||||
open={passwordLoginOpen}
|
||||
onCancel={closePasswordLogin}
|
||||
onOk={() => passwordLoginForm.submit()}
|
||||
okText="登录并保存"
|
||||
cancelButtonProps={{ disabled: passwordLogging }}
|
||||
confirmLoading={passwordLogging}
|
||||
maskClosable={!passwordLogging}
|
||||
closable={!passwordLogging}
|
||||
width={560}
|
||||
>
|
||||
<Form
|
||||
form={passwordLoginForm}
|
||||
layout="vertical"
|
||||
requiredMark={false}
|
||||
onFinish={handlePasswordLogin}
|
||||
disabled={passwordLogging}
|
||||
>
|
||||
<Form.Item
|
||||
name="username"
|
||||
label="账号"
|
||||
rules={[{ required: true, message: '请输入虎牙账号' }]}
|
||||
>
|
||||
<Input autoComplete="username" placeholder="手机号、邮箱或虎牙账号" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="password"
|
||||
label="密码"
|
||||
rules={[{ required: true, message: '请输入密码' }]}
|
||||
>
|
||||
<Input.Password autoComplete="current-password" placeholder="虎牙登录密码" />
|
||||
</Form.Item>
|
||||
<Form.Item name="tag" label="标签">
|
||||
<Input placeholder="可选,保存到账号标签" />
|
||||
</Form.Item>
|
||||
<Form.Item name="cookie" label="预置 Cookie">
|
||||
<TextArea
|
||||
rows={3}
|
||||
placeholder="可选;若已有 hdid/sdid 等风控 Cookie,可粘贴在这里"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user