feat(huya): 统一实时商品目录并增加兑换代理开关
This commit is contained in:
@@ -177,6 +177,10 @@ export const huyaApi = {
|
||||
getConfig: () => api.get<HuyaConfig, HuyaConfig>('/huya/config'),
|
||||
updateConfig: (data: Partial<HuyaConfig>) => api.put<HuyaConfig, HuyaConfig>('/huya/config', data),
|
||||
listGoods: () => api.get<HuyaGoodsItem[], HuyaGoodsItem[]>('/huya/goods'),
|
||||
listLiveGoods: (accountId: number) =>
|
||||
api.get<HuyaGoodsItem[], HuyaGoodsItem[]>('/huya/goods/live', {
|
||||
params: { account_id: accountId, _ts: Date.now() },
|
||||
}),
|
||||
listRechargeGoods: () => api.get<HuyaRechargeGoodsItem[], HuyaRechargeGoodsItem[]>('/huya/recharge-goods'),
|
||||
/** 工作台导入外部 CK: 入库并把账号加入自己的工作台 (text 每行一条 CK) */
|
||||
importWorkbenchCookies: (data: HuyaExternalCkImportRequest) =>
|
||||
|
||||
@@ -1251,6 +1251,8 @@ export interface HuyaConfig {
|
||||
points_page_id: string;
|
||||
/** 可选覆盖:页签 ID,逗号分隔;留空自动拉全部页签 */
|
||||
points_tab_ids: string;
|
||||
/** 精英宝典兑换是否使用全局代理;默认 0,仅兑换链路生效 */
|
||||
exchange_use_proxy: string;
|
||||
updated_at: string | null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import type { MouseEvent } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
Button, Card, Input, InputNumber, Modal, QRCode, Select, Space, Spin, Table, Tag, Tooltip, Typography,
|
||||
Button, Card, Input, InputNumber, Modal, QRCode, Select, Space, Spin, Switch, Table, Tag, Tooltip, Typography,
|
||||
} from 'antd';
|
||||
import type { TableProps } from 'antd';
|
||||
import {
|
||||
@@ -27,6 +27,7 @@ const PAGE_SIZE_KEY = 'huya_elite_page_size';
|
||||
const RECHARGE_SPU_KEY = 'huya_elite_recharge_spu';
|
||||
const RECHARGE_COUNT_KEY = 'huya_elite_recharge_count';
|
||||
const ELITE_SPU_KEY = 'huya_elite_elite_spu';
|
||||
const EXCHANGE_PROXY_ENABLED_VALUES = new Set(['1', 'true', 'on', 'yes']);
|
||||
// 与后端 ELITE_HANDBOOK_SPU_IDS 对齐:精英宝典单独一块,不和其他开通商品混在一个下拉里
|
||||
const ELITE_HANDBOOK_SPU_IDS = ['hy-8328015', 'hy-5879340', 'hy-3845257', 'hy-2947756'];
|
||||
const ELITE_HANDBOOK_NAME_KEYWORD = '精英宝典';
|
||||
@@ -199,6 +200,7 @@ export default function HuyaElitePage() {
|
||||
const [selectedIds, setSelectedIds] = useState<number[]>([]);
|
||||
const [tasks, setTasks] = useState<HuyaTaskItem[]>([]);
|
||||
const [goods, setGoods] = useState<HuyaGoodsItem[]>([]);
|
||||
const [goodsLoading, setGoodsLoading] = useState(false);
|
||||
const [selectedGoodsId, setSelectedGoodsId] = useState('');
|
||||
const [rechargeGoods, setRechargeGoods] = useState<HuyaRechargeGoodsItem[]>([]);
|
||||
const [selectedRechargeSpu, setSelectedRechargeSpu] = useState(savedRechargeSpu);
|
||||
@@ -239,6 +241,7 @@ export default function HuyaElitePage() {
|
||||
const [configSaving, setConfigSaving] = useState(false);
|
||||
const [contextMenu, setContextMenu] = useState<{ x: number; y: number; accountIds: number[] } | null>(null);
|
||||
const tasksLoading = useRef(false);
|
||||
const liveGoodsRequestId = useRef(0);
|
||||
const qrTaskFetchId = useRef<number | null>(null);
|
||||
const qrImageCacheRef = useRef<Map<number, string>>(new Map());
|
||||
const logs = useWebSocketLogs();
|
||||
@@ -246,9 +249,9 @@ export default function HuyaElitePage() {
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const [poolResult, workbenchResult, goodsResult, rechargeGoodsResult, taskResult] = await Promise.all([
|
||||
const [poolResult, workbenchResult, rechargeGoodsResult, taskResult] = await Promise.all([
|
||||
huyaApi.listAccounts({ include_cookie: false }), huyaApi.listWorkbenchAccounts(SCOPE),
|
||||
huyaApi.listGoods(), huyaApi.listRechargeGoods(), huyaApi.listTasks(undefined, SCOPE),
|
||||
huyaApi.listRechargeGoods(), huyaApi.listTasks(undefined, SCOPE),
|
||||
]);
|
||||
setPool(poolResult);
|
||||
const byId = new Map(poolResult.map((item) => [item.id, item]));
|
||||
@@ -258,7 +261,6 @@ export default function HuyaElitePage() {
|
||||
}
|
||||
setAccounts(storedIds.map((id) => byId.get(Number(id))).filter((item): item is HuyaAccountItem => Boolean(item)));
|
||||
setSelectedIds((prev) => prev.filter((id) => storedIds.includes(id)));
|
||||
setGoods(goodsResult);
|
||||
setRechargeGoods(rechargeGoodsResult);
|
||||
setTasks(taskResult);
|
||||
} catch (error) { message.error(getErrorMessage(error)); } finally { setLoading(false); }
|
||||
@@ -270,6 +272,36 @@ export default function HuyaElitePage() {
|
||||
try { setTasks(await huyaApi.listTasks(undefined, SCOPE)); } catch { /* 下一轮刷新 */ } finally { tasksLoading.current = false; }
|
||||
}, []);
|
||||
|
||||
const loadLiveGoods = useCallback(async (accountId: number | null) => {
|
||||
const requestId = ++liveGoodsRequestId.current;
|
||||
if (!accountId) {
|
||||
setGoods([]);
|
||||
setSelectedGoodsId('');
|
||||
return;
|
||||
}
|
||||
setGoodsLoading(true);
|
||||
try {
|
||||
const result = await huyaApi.listLiveGoods(accountId);
|
||||
if (liveGoodsRequestId.current !== requestId) return;
|
||||
setGoods(result);
|
||||
setSelectedGoodsId((current) => (
|
||||
result.some((item) => item.product_id === current)
|
||||
? current
|
||||
: result[0]?.product_id || ''
|
||||
));
|
||||
} catch (error) {
|
||||
if (liveGoodsRequestId.current !== requestId) return;
|
||||
setGoods([]);
|
||||
setSelectedGoodsId('');
|
||||
message.error(`实时商品加载失败:${getErrorMessage(error)}`);
|
||||
} finally {
|
||||
if (liveGoodsRequestId.current === requestId) setGoodsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const goodsAccountId = selectedIds[0] ?? accounts[0]?.id ?? null;
|
||||
useEffect(() => { void loadLiveGoods(goodsAccountId); }, [goodsAccountId, loadLiveGoods]);
|
||||
|
||||
useEffect(() => { void load(); }, [load]);
|
||||
useEffect(() => { if (importOpen || ckImportOpen) void huyaApi.listTags().then(setImportTags).catch(() => {}); }, [ckImportOpen, importOpen]);
|
||||
useEffect(() => {
|
||||
@@ -622,7 +654,7 @@ export default function HuyaElitePage() {
|
||||
<div className="huya-operation-section"><div className="huya-operation-title"><QrcodeOutlined /><span>绑定与查询</span></div><div className="huya-action-grid">
|
||||
<Button size="small" type="primary" icon={<SearchOutlined />} onClick={() => void startTask('query_all')} disabled={starting || !selectedIds.length}>一键查询</Button><Button size="small" icon={<QrcodeOutlined />} onClick={() => void startTask('get_bind_qr')} disabled={starting || !selectedIds.length}>绑定二维码</Button><Button size="small" icon={<SearchOutlined />} onClick={() => void startTask('query_game_name')} disabled={starting || !selectedIds.length}>查询角色</Button><Button size="small" icon={<CheckCircleOutlined />} onClick={() => void startTask('confirm_bind')} disabled={starting || !selectedIds.length}>确认绑定</Button><Button size="small" icon={<SearchOutlined />} onClick={() => void startTask('query_points')} disabled={starting || !selectedIds.length}>刷新积分</Button><Button size="small" onClick={() => void startTask('query_act_tasks')} disabled={starting || !selectedIds.length}>宝典任务</Button><Button size="small" onClick={() => void startTask('query_exchange_records')} disabled={starting || !selectedIds.length}>兑换记录</Button>
|
||||
</div></div>
|
||||
<div className="huya-operation-section"><div className="huya-operation-title"><ShoppingOutlined /><span>兑换</span></div><Select size="small" showSearch optionFilterProp="label" value={selectedGoodsId || undefined} onChange={setSelectedGoodsId} options={filteredGoods.map((item) => ({ value: item.product_id, label: item.label }))} placeholder="选择兑换商品" style={{ width: '100%' }} /><div className="huya-action-grid"><Button size="small" icon={<ReloadOutlined />} onClick={() => void startTask('refresh_goods')} disabled={starting || !selectedIds.length}>刷新商品</Button><Button size="small" type="primary" icon={<ShoppingOutlined />} onClick={() => void startTask('exchange_goods')} disabled={starting || !selectedIds.length || !selectedGoodsId}>兑换商品</Button></div></div>
|
||||
<div className="huya-operation-section"><div className="huya-operation-title"><ShoppingOutlined /><span>兑换</span></div><Select size="small" showSearch optionFilterProp="label" loading={goodsLoading} disabled={!goodsAccountId || goodsLoading || !goods.length} value={selectedGoodsId || undefined} onChange={setSelectedGoodsId} options={filteredGoods.map((item) => ({ value: item.product_id, label: item.label }))} placeholder={goodsLoading ? '正在读取实时商品' : !goodsAccountId ? '请先选择账号' : '暂无实时商品'} style={{ width: '100%' }} /><div className="huya-action-grid"><Button size="small" icon={<ReloadOutlined />} loading={goodsLoading} onClick={() => void loadLiveGoods(goodsAccountId)} disabled={starting || !goodsAccountId || goodsLoading}>刷新商品</Button><Button size="small" type="primary" icon={<ShoppingOutlined />} onClick={() => void startTask('exchange_goods')} disabled={starting || !selectedIds.length || !selectedGoodsId || goodsLoading}>兑换商品</Button></div></div>
|
||||
<div className="huya-operation-section"><div className="huya-operation-title"><GiftOutlined /><span>开通宝典</span></div>{eliteRechargeGoods.length > 1 ? <Select size="small" showSearch optionFilterProp="label" value={selectedEliteGoods?.spu_id} onChange={selectEliteGoods} options={eliteRechargeGoods.map((item) => ({ value: item.spu_id, label: rechargeGoodsLabel(item) }))} style={{ width: '100%' }} /> : <Text style={{ fontSize: 12 }} ellipsis>{selectedEliteGoods ? `${rechargeGoodsLabel(selectedEliteGoods)}${rechargeEliteLimit < RECHARGE_COUNT_MAX ? ` · 限购 ${rechargeEliteLimit} 份` : ''}` : '列表里还没有精英宝典,请先刷新开通商品'}</Text>}<Button block size="small" type="primary" icon={<QrcodeOutlined />} onClick={() => { if (selectedEliteGoods) void startTask('create_recharge_order', selectedIds, { spu: selectedEliteGoods.spu_id, count: 1 }); }} disabled={starting || !selectedIds.length || !selectedEliteGoods} style={{ marginTop: 6 }}>确认开通宝典并生成支付码</Button></div>
|
||||
<div className="huya-operation-section"><div className="huya-operation-title"><ShoppingOutlined /><span>其他开通商品</span></div><Select size="small" showSearch optionFilterProp="label" value={selectedRechargeSpu || undefined} onChange={selectRechargeGoods} options={otherRechargeGoods.map((item) => ({ value: item.spu_id, label: rechargeGoodsLabel(item) }))} placeholder="先刷新开通商品" style={{ width: '100%' }} /><div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 6 }}><Text type="secondary" style={{ fontSize: 12 }}>数量</Text><InputNumber size="small" min={1} max={rechargeBuyLimit} value={rechargeCountValue} onChange={changeRechargeCount} style={{ width: 80 }} /><Text type="secondary" style={{ fontSize: 12 }}>{rechargeAmountText}{rechargeBuyLimit < RECHARGE_COUNT_MAX ? ` · 限购 ${rechargeBuyLimit} 份` : ''}</Text></div><Button block size="small" type="primary" icon={<QrcodeOutlined />} onClick={() => void startTask('create_recharge_order')} disabled={starting || !selectedIds.length || !selectedRechargeSpu} style={{ marginTop: 6 }}>{rechargeCountValue > 1 ? `确认充值并生成支付码 ×${rechargeCountValue}` : '确认充值并生成支付码'}</Button><Button block size="small" icon={<ReloadOutlined />} onClick={() => void startTask('refresh_recharge_goods')} disabled={starting || !selectedIds.length} style={{ marginTop: 6 }}>刷新开通商品</Button></div>
|
||||
<RealtimeLogPanel logs={logs.logs} connected={logs.connected} title="实时日志" emptyText="暂无任务日志" height={150} collapsible defaultVisible={false} />
|
||||
@@ -727,7 +759,7 @@ export default function HuyaElitePage() {
|
||||
</div>}
|
||||
</Modal>
|
||||
<Modal open={importOpen} title="导入精英宝典账号" onCancel={() => setImportOpen(false)} onOk={() => { void saveAccounts([...new Set([...accounts.map((item) => item.id), ...importSelected])]).then(() => { setImportSelected([]); setImportOpen(false); }).catch((error) => message.error(getErrorMessage(error))); }} okText="导入" cancelText="取消"><Input.Search allowClear placeholder="搜索账号" value={importSearch} onChange={(event) => setImportSearch(event.target.value)} style={{ marginBottom: 8 }} /><Select allowClear placeholder="标签" value={importTag || undefined} onChange={(value) => setImportTag(value || '')} options={importTags.map((tag) => ({ value: tag, label: tag }))} style={{ width: '100%', marginBottom: 8 }} /><Table rowKey="id" size="small" dataSource={pool.filter((item) => !accounts.some((current) => current.id === item.id) && (!importSearch || [item.uid, item.nickname, item.username].some((value) => String(value || '').includes(importSearch))) && (!importTag || item.tag === importTag))} columns={[{ title: '账号', render: (_value, row) => row.nickname || row.username || row.uid }, { title: '标签', dataIndex: 'tag' }]} pagination={{ pageSize: 8 }} rowSelection={{ selectedRowKeys: importSelected, onChange: (keys) => setImportSelected(keys.map(Number)) }} /></Modal>
|
||||
<Modal open={configOpen} title="精英宝典设置" onCancel={() => setConfigOpen(false)} onOk={() => void saveConfig()} confirmLoading={configSaving} okText="保存" cancelText="取消" width={560}>{configLoading ? <div style={{ padding: 24, textAlign: 'center' }}>加载中...</div> : configDraft && <Space direction="vertical" size={10} style={{ width: '100%' }}>{configField('sid', '活动 SID')}{configField('bind_act_id', '绑定活动 ID')}{configField('outer_act_id', '外部活动 ID')}{configField('bind_gid', '绑定 gid')}{configField('room_pid', '直播间 PID')}{configField('pay_channel', '支付渠道')}{configField('points_page_code', '积分中心 pageCode')}{configField('points_source_id', '积分中心 sourceId')}{configField('points_scene', '积分中心 scene')}{configField('points_page_id', '页签 pageId(可选)')}{configField('points_tab_ids', '页签 IDs(可选)')}<Space style={{ width: '100%', justifyContent: 'space-between' }}><Text>空闲轮询间隔(秒)</Text><InputNumber min={5} max={60} value={refreshInterval} onChange={(value) => { const next = Math.min(60, Math.max(5, value || 15)); setRefreshInterval(next); localStorage.setItem('huya_elite_refresh_interval', String(next)); }} style={{ width: 300 }} /></Space></Space>}</Modal>
|
||||
<Modal open={configOpen} title="精英宝典设置" onCancel={() => setConfigOpen(false)} onOk={() => void saveConfig()} confirmLoading={configSaving} okText="保存" cancelText="取消" width={560}>{configLoading ? <div style={{ padding: 24, textAlign: 'center' }}>加载中...</div> : configDraft && <Space direction="vertical" size={10} style={{ width: '100%' }}>{configField('sid', '活动 SID')}{configField('bind_act_id', '绑定活动 ID')}{configField('outer_act_id', '外部活动 ID')}{configField('bind_gid', '绑定 gid')}{configField('room_pid', '直播间 PID')}{configField('pay_channel', '支付渠道')}{configField('points_page_code', '积分中心 pageCode')}{configField('points_source_id', '积分中心 sourceId')}{configField('points_scene', '积分中心 scene')}{configField('points_page_id', '页签 pageId(可选)')}{configField('points_tab_ids', '页签 IDs(可选)')}<Space style={{ width: '100%', justifyContent: 'space-between' }} align="center"><div><Text>兑换使用代理</Text><br /><Text type="secondary">默认关闭;开启后兑换链路使用全局代理配置</Text></div><Switch checked={EXCHANGE_PROXY_ENABLED_VALUES.has(String(configDraft.exchange_use_proxy || '0').toLowerCase())} onChange={(checked) => setConfigDraft({ ...configDraft, exchange_use_proxy: checked ? '1' : '0' })} /></Space><Space style={{ width: '100%', justifyContent: 'space-between' }}><Text>空闲轮询间隔(秒)</Text><InputNumber min={5} max={60} value={refreshInterval} onChange={(value) => { const next = Math.min(60, Math.max(5, value || 15)); setRefreshInterval(next); localStorage.setItem('huya_elite_refresh_interval', String(next)); }} style={{ width: 300 }} /></Space></Space>}</Modal>
|
||||
<HuyaExternalCkImportModal open={ckImportOpen} onClose={() => setCkImportOpen(false)} tags={importTags} scope={SCOPE} onImported={(result) => { localStorage.setItem('huya_elite_workbench_account_ids', JSON.stringify(result.account_ids)); void load(); }} />
|
||||
</div>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user