@@ -9,6 +9,7 @@ import {
ReloadOutlined , SearchOutlined , SettingOutlined , ShoppingOutlined , StopOutlined ,
} from '@ant-design/icons' ;
import { huyaApi , type HuyaAccountItem , type HuyaConfig , type HuyaGoodsItem , type HuyaRechargeGoodsItem , type HuyaTaskItem } from '../api/modules' ;
import HuyaExternalCkImportModal from '../components/HuyaExternalCkImportModal' ;
import RealtimeLogPanel from '../components/RealtimeLogPanel' ;
import { usePermissions } from '../hooks/usePermissions' ;
import { useWebSocketLogs } from '../hooks/useWebSocketLogs' ;
@@ -69,6 +70,7 @@ function taskQrUrl(task: HuyaTaskItem | undefined): string {
export default function HuyaElitePage() {
const { can } = usePermissions ( ) ;
const canConfig = can ( 'huya:config' ) ;
const canImport = can ( 'huya:import' ) ;
const [ pool , setPool ] = useState < HuyaAccountItem [ ] > ( [ ] ) ;
const [ accounts , setAccounts ] = useState < HuyaAccountItem [ ] > ( [ ] ) ;
const [ selectedIds , setSelectedIds ] = useState < number [ ] > ( [ ] ) ;
@@ -90,6 +92,7 @@ export default function HuyaElitePage() {
const [ importTags , setImportTags ] = useState < string [ ] > ( [ ] ) ;
const [ importSelected , setImportSelected ] = useState < number [ ] > ( [ ] ) ;
const [ qrTask , setQrTask ] = useState < HuyaTaskItem | null > ( null ) ;
const [ ckImportOpen , setCkImportOpen ] = useState ( false ) ;
const [ config , setConfig ] = useState < HuyaConfig | null > ( null ) ;
const [ configDraft , setConfigDraft ] = useState < HuyaConfig | null > ( null ) ;
const [ configOpen , setConfigOpen ] = useState ( false ) ;
@@ -127,7 +130,7 @@ export default function HuyaElitePage() {
} , [ ] ) ;
useEffect ( ( ) = > { void load ( ) ; } , [ load ] ) ;
useEffect ( ( ) = > { if ( importOpen ) void huyaApi . listTags ( ) . then ( setImportTags ) . catch ( ( ) = > { } ) ; } , [ importOpen ] ) ;
useEffect ( ( ) = > { if ( importOpen || ckImportOpen ) void huyaApi . listTags ( ) . then ( setImportTags ) . catch ( ( ) = > { } ) ; } , [ ckImportOpen , importOpen ] ) ;
useEffect ( ( ) = > {
const active = tasks . some ( ( task ) = > [ 'planned' , 'pending' , 'running' ] . includes ( task . status ) ) ;
const timer = window . setInterval ( ( ) = > { void loadTasks ( ) ; } , ( active ? 3 : refreshInterval ) * 1000 ) ;
@@ -262,7 +265,7 @@ export default function HuyaElitePage() {
< / Space >
) ;
const accountsBody = < > < Space style = { { marginBottom : 8 , width : '100%' , justifyContent : 'space-between' } } wrap > < Input size = "small" allowClear prefix = { < SearchOutlined / > } placeholder = "搜索账号/昵称/游戏名" value = { search } onChange = { ( event ) = > setSearch ( event . target . value ) } style = { { width : 240 } } / > < Space > < Button size = "small" icon = { < ImportOutlined / > } onClick = { ( ) = > setImportOpen ( true ) } > 导 入 账 号 < / Button > { selectedIds . length > 0 && < Button size = "small" danger onClick = { ( ) = > void saveAccounts ( accounts . map ( ( item ) = > item . id ) . filter ( ( id ) = > ! selectedIds . includes ( id ) ) ) } > 移 出 选 中 < / Button > } < / Space > < / Space > < div className = "huya-account-table" > < Table rowKey = "id" size = "small" loading = { loading } tableLayout = "fixed" rowSelection = { { selectedRowKeys : selectedIds , onChange : ( keys ) = > setSelectedIds ( keys . map ( Number ) ) } } columns = { accountColumns } dataSource = { filteredAccounts } locale = { { emptyText : '工作台暂无账号,点击右上角「导入账号」添加' } } pagination = { { pageSize : 20 , showSizeChanger : true , showTotal : ( total ) = > ` 共 ${ total } 条 ` } } scroll = { { x : 1040 , y : 'calc(100vh - 300px)' } } onRow = { ( row ) = > ( { onClick : ( ) = > { const task = latestTask ( tasks , row . id ) ; if ( task && [ 'get_bind_qr' , 'create_recharge_order' ] . includes ( task . task_type ) && task . result ) void openQrTask ( task ) ; } , onContextMenu : ( event ) = > handleRowContextMenu ( row , event ) , style : { cursor : 'context-menu' } , title : '右键打开账号动作' } ) } / > < / div > < / > ;
const accountsBody = < > < Space style = { { marginBottom : 8 , width : '100%' , justifyContent : 'space-between' } } wrap > < Input size = "small" allowClear prefix = { < SearchOutlined / > } placeholder = "搜索账号/昵称/游戏名" value = { search } onChange = { ( event ) = > setSearch ( event . target . value ) } style = { { width : 240 } } / > < Space > < Button size = "small" icon = { < ImportOutlined / > } onClick = { ( ) = > setImportOpen ( true ) } > 导 入 账 号 < / Button > { canImport && < Button size = "small" icon = { < ImportOutlined / > } onClick = { ( ) = > setCkImportOpen ( true ) } > 导 入 外 部 CK < / Button > } { selectedIds . length > 0 && < Button size = "small" danger onClick = { ( ) = > void saveAccounts ( accounts . map ( ( item ) = > item . id ) . filter ( ( id ) = > ! selectedIds . includes ( id ) ) ) } > 移 出 选 中 < / Button > } < / Space > < / Space > < div className = "huya-account-table" > < Table rowKey = "id" size = "small" loading = { loading } tableLayout = "fixed" rowSelection = { { selectedRowKeys : selectedIds , onChange : ( keys ) = > setSelectedIds ( keys . map ( Number ) ) } } columns = { accountColumns } dataSource = { filteredAccounts } locale = { { emptyText : '工作台暂无账号,点击右上角「导入账号」添加' } } pagination = { { pageSize : 20 , showSizeChanger : true , showTotal : ( total ) = > ` 共 ${ total } 条 ` } } scroll = { { x : 1040 , y : 'calc(100vh - 300px)' } } onRow = { ( row ) = > ( { onClick : ( ) = > { const task = latestTask ( tasks , row . id ) ; if ( task && [ 'get_bind_qr' , 'create_recharge_order' ] . includes ( task . task_type ) && task . result ) void openQrTask ( task ) ; } , onContextMenu : ( event ) = > handleRowContextMenu ( row , event ) , style : { cursor : 'context-menu' } , title : '右键打开账号动作' } ) } / > < / div > < / > ;
const configField = ( key : Exclude < keyof HuyaConfig , 'updated_at' > , label : string ) = > configDraft && < Space key = { key } style = { { width : '100%' , justifyContent : 'space-between' } } > < Text > { label } < / Text > < Input value = { configDraft [ key ] || '' } onChange = { ( event ) = > setConfigDraft ( { . . . configDraft , [ key ] : event . target . value } ) } style = { { width : 300 } } / > < / Space > ;
const contextMenuStyle = contextMenu ? {
@@ -282,5 +285,6 @@ export default function HuyaElitePage() {
< Modal open = { qrTask !== null } title = { qrTask ? . task_type === 'create_recharge_order' ? '开通支付二维码' : '绑定二维码' } footer = { null } onCancel = { ( ) = > setQrTask ( null ) } centered > { qrTask && < div style = { { textAlign : 'center' } } > { resultText ( qrTask , 'mini_qrcode_image' ) ? < img src = { ` data:image/png;base64, ${ resultText ( qrTask , 'mini_qrcode_image' ) } ` } alt = "绑定二维码" style = { { width : 240 , height : 240 } } / > : < QRCode value = { resultText ( qrTask , 'pay_url' ) || resultText ( qrTask , 'bind_redirect_url' ) || 'https://zt.huya.com/b02faae1/pc/index.html' } size = { 240 } / > } < p > < Tag color = { TASK_COLORS [ qrTask . status ] || 'default' } > { qrTask . message || qrTask . status } < / Tag > < / p > { qrTask . task_type === 'create_recharge_order' && < Text type = "secondary" > 扫 码 后 订 单 状 态 会 自 动 轮 询 更 新 < / Text > } < / 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 = { 500 } > { 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 ( 'room_pid' , '直播间 PID' ) } { configField ( 'pay_channel' , '支付渠道' ) } < 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 > ;
}