This commit is contained in:
薇薇安 2026-01-22 22:32:49 +08:00
parent a7e1e6ca0a
commit 76bde06a4f

View File

@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react' import React, { useState, useEffect, useRef } from 'react'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { useSelector, useDispatch } from 'react-redux' import { useSelector, useDispatch } from 'react-redux'
import { api } from '../services/api' import { api } from '../services/api'
@ -264,13 +264,15 @@ const ConfigPanel = () => {
} }
} }
const loadCurrentAccountMeta = async () => { const loadCurrentAccountMeta = async (targetAccountId = null) => {
try { try {
// 使 accountId accountId使
const targetId = targetAccountId !== null ? targetAccountId : accountId
// 使getAccounts // 使getAccounts
// status // status
const list = await api.getAccounts() const list = await api.getAccounts()
const accounts = Array.isArray(list) ? list : [] const accounts = Array.isArray(list) ? list : []
const meta = accounts.find((a) => parseInt(String(a?.id || '0'), 10) === parseInt(String(accountId || '0'), 10)) const meta = accounts.find((a) => parseInt(String(a?.id || '0'), 10) === parseInt(String(targetId || '0'), 10))
// statusmetastatus'active' // statusmetastatus'active'
if (meta) { if (meta) {
meta.status = meta.status || 'active' meta.status = meta.status || 'active'
@ -444,20 +446,33 @@ const ConfigPanel = () => {
} }
} }
// 使 ref accountId
const prevAccountIdRef = useRef(accountId)
useEffect(() => { useEffect(() => {
// accountId
if (prevAccountIdRef.current !== null && prevAccountIdRef.current !== accountId) {
// accountId
window.location.reload()
return
}
// ref
prevAccountIdRef.current = accountId
loadConfigMeta() loadConfigMeta()
loadConfigs() loadConfigs()
checkFeasibility() checkFeasibility()
loadAccountTradingStatus() loadAccountTradingStatus()
loadCurrentAccountMeta() loadCurrentAccountMeta(accountId)
const timer = setInterval(() => { const timer = setInterval(() => {
// 使 accountId
loadAccountTradingStatus() loadAccountTradingStatus()
loadCurrentAccountMeta() loadCurrentAccountMeta(accountId)
}, 3000) }, 3000)
return () => clearInterval(timer) return () => clearInterval(timer)
}, []) }, [accountId]) // accountId
// accountIdonChanged // accountIdonChanged
@ -478,16 +493,7 @@ const ConfigPanel = () => {
} }
} }
// account meta // accountId useEffect
useEffect(() => {
setMessage('')
setLoading(true)
loadCurrentAccountMeta().then(() => {
loadConfigs()
checkFeasibility()
loadAccountTradingStatus()
})
}, [accountId]) // accountId
const checkFeasibility = async () => { const checkFeasibility = async () => {
setCheckingFeasibility(true) setCheckingFeasibility(true)
@ -884,11 +890,6 @@ const ConfigPanel = () => {
<div className="system-section"> <div className="system-section">
<div className="system-header"> <div className="system-header">
<h3>我的交易进程当前账号 #{accountId}</h3> <h3>我的交易进程当前账号 #{accountId}</h3>
<button type="button" className="system-btn" onClick={() => {
console.log(currentAccountMeta)
}} title="打印当前账号信息">
打印当前账号信息
</button>
<div className="system-status"> <div className="system-status">
<span className={`system-status-badge ${accountTradingStatus?.running ? 'running' : 'stopped'}`}> <span className={`system-status-badge ${accountTradingStatus?.running ? 'running' : 'stopped'}`}>
{accountTradingStatus?.running ? '运行中' : '未运行/未知'} {accountTradingStatus?.running ? '运行中' : '未运行/未知'}