请求账号1的问题

This commit is contained in:
薇薇安 2026-02-03 13:12:36 +08:00
parent 377ae3b966
commit c23db4aba0
4 changed files with 29 additions and 21 deletions

View File

@ -51,7 +51,7 @@ const AccountSelector = ({ onChanged }) => {
}, [accountId, onChanged]) }, [accountId, onChanged])
const list = Array.isArray(accounts) ? accounts : [] const list = Array.isArray(accounts) ? accounts : []
const options = (list.length ? list : [{ id: 1, name: 'default' }]).reduce((acc, cur) => { const options = list.reduce((acc, cur) => {
if (!cur || !cur.id) return acc if (!cur || !cur.id) return acc
if (acc.some((x) => x.id === cur.id)) return acc if (acc.some((x) => x.id === cur.id)) return acc
acc.push(cur) acc.push(cur)

View File

@ -267,6 +267,7 @@ const ConfigPanel = () => {
} }
const loadAccountTradingStatus = async () => { const loadAccountTradingStatus = async () => {
if (!accountId) return
try { try {
const res = await api.getAccountTradingStatus(accountId) const res = await api.getAccountTradingStatus(accountId)
setAccountTradingStatus(res) setAccountTradingStatus(res)
@ -278,9 +279,10 @@ const ConfigPanel = () => {
} }
const loadCurrentAccountMeta = async (targetAccountId = null) => { const loadCurrentAccountMeta = async (targetAccountId = null) => {
try {
// 使 accountId accountId使 // 使 accountId accountId使
const targetId = targetAccountId !== null ? targetAccountId : accountId const targetId = targetAccountId !== null ? targetAccountId : accountId
if (!targetId) return null
try {
// 使getAccounts // 使getAccounts
// status // status
const list = await api.getAccounts() const list = await api.getAccounts()
@ -463,12 +465,8 @@ const ConfigPanel = () => {
const prevAccountIdRef = useRef(accountId) const prevAccountIdRef = useRef(accountId)
useEffect(() => { useEffect(() => {
// accountId //
// if (prevAccountIdRef.current !== null && prevAccountIdRef.current !== accountId) { if (!accountId) return
// // accountId
// window.location.reload()
// return
// }
// ref // ref
prevAccountIdRef.current = accountId prevAccountIdRef.current = accountId
@ -480,8 +478,10 @@ const ConfigPanel = () => {
const timer = setInterval(() => { const timer = setInterval(() => {
// 使 accountId // 使 accountId
if (accountId) {
loadAccountTradingStatus() loadAccountTradingStatus()
loadCurrentAccountMeta(accountId) loadCurrentAccountMeta(accountId)
}
}, 3000) }, 3000)
return () => clearInterval(timer) return () => clearInterval(timer)

View File

@ -31,17 +31,21 @@ const ACCOUNT_ID_STORAGE_KEY = 'ats_account_id';
export const getCurrentAccountId = () => { export const getCurrentAccountId = () => {
try { try {
const v = localStorage.getItem(ACCOUNT_ID_STORAGE_KEY); const v = localStorage.getItem(ACCOUNT_ID_STORAGE_KEY);
const n = parseInt(v || '1', 10); const n = parseInt(v, 10);
return Number.isFinite(n) && n > 0 ? n : 1; return Number.isFinite(n) && n > 0 ? n : null;
} catch (e) { } catch (e) {
return 1; return null;
} }
}; };
export const setCurrentAccountId = (accountId) => { export const setCurrentAccountId = (accountId) => {
try { try {
const n = parseInt(String(accountId || '1'), 10); const n = parseInt(String(accountId), 10);
localStorage.setItem(ACCOUNT_ID_STORAGE_KEY, String(Number.isFinite(n) && n > 0 ? n : 1)); if (Number.isFinite(n) && n > 0) {
localStorage.setItem(ACCOUNT_ID_STORAGE_KEY, String(n));
} else {
localStorage.removeItem(ACCOUNT_ID_STORAGE_KEY);
}
} catch (e) { } catch (e) {
// ignore // ignore
} }
@ -88,7 +92,11 @@ const withAccountHeaders = (headers = {}, accountIdOverride = null) => {
currentAccountIdFromStore = aid; currentAccountIdFromStore = aid;
} }
} }
return withAuthHeaders({ ...headers, 'X-Account-Id': String(aid) }); const finalHeaders = { ...headers };
if (aid) {
finalHeaders['X-Account-Id'] = String(aid);
}
return withAuthHeaders(finalHeaders);
}; };
// 构建API URL的辅助函数避免双斜杠和格式问题 // 构建API URL的辅助函数避免双斜杠和格式问题

View File

@ -21,10 +21,10 @@ const getInitialViewingUserId = () => {
const getInitialAccountId = () => { const getInitialAccountId = () => {
try { try {
const v = localStorage.getItem(ACCOUNT_ID_STORAGE_KEY) const v = localStorage.getItem(ACCOUNT_ID_STORAGE_KEY)
const n = parseInt(v || '1', 10) const n = parseInt(v, 10)
return Number.isFinite(n) && n > 0 ? n : 1 return Number.isFinite(n) && n > 0 ? n : null
} catch (e) { } catch (e) {
return 1 return null
} }
} }