请求账号1的问题
This commit is contained in:
parent
377ae3b966
commit
c23db4aba0
|
|
@ -51,7 +51,7 @@ const AccountSelector = ({ onChanged }) => {
|
|||
}, [accountId, onChanged])
|
||||
|
||||
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 (acc.some((x) => x.id === cur.id)) return acc
|
||||
acc.push(cur)
|
||||
|
|
|
|||
|
|
@ -267,6 +267,7 @@ const ConfigPanel = () => {
|
|||
}
|
||||
|
||||
const loadAccountTradingStatus = async () => {
|
||||
if (!accountId) return
|
||||
try {
|
||||
const res = await api.getAccountTradingStatus(accountId)
|
||||
setAccountTradingStatus(res)
|
||||
|
|
@ -278,9 +279,10 @@ const ConfigPanel = () => {
|
|||
}
|
||||
|
||||
const loadCurrentAccountMeta = async (targetAccountId = null) => {
|
||||
// 使用传入的 accountId 或当前的 accountId(确保使用最新的值)
|
||||
const targetId = targetAccountId !== null ? targetAccountId : accountId
|
||||
if (!targetId) return null
|
||||
try {
|
||||
// 使用传入的 accountId 或当前的 accountId(确保使用最新的值)
|
||||
const targetId = targetAccountId !== null ? targetAccountId : accountId
|
||||
// 统一使用getAccounts获取所有账号(管理员会返回所有账号,普通用户返回自己的)
|
||||
// 这样可以确保获取到完整的status等信息
|
||||
const list = await api.getAccounts()
|
||||
|
|
@ -463,13 +465,9 @@ const ConfigPanel = () => {
|
|||
const prevAccountIdRef = useRef(accountId)
|
||||
|
||||
useEffect(() => {
|
||||
// 如果 accountId 变化了(不是初始化),刷新页面
|
||||
// if (prevAccountIdRef.current !== null && prevAccountIdRef.current !== accountId) {
|
||||
// // accountId 变化时,刷新页面以确保所有状态都正确更新
|
||||
// window.location.reload()
|
||||
// return
|
||||
// }
|
||||
|
||||
// 如果没有选中账号,不加载数据
|
||||
if (!accountId) return
|
||||
|
||||
// 初始化时,更新 ref 并加载数据
|
||||
prevAccountIdRef.current = accountId
|
||||
loadConfigMeta()
|
||||
|
|
@ -480,8 +478,10 @@ const ConfigPanel = () => {
|
|||
|
||||
const timer = setInterval(() => {
|
||||
// 定时器中使用最新的 accountId
|
||||
loadAccountTradingStatus()
|
||||
loadCurrentAccountMeta(accountId)
|
||||
if (accountId) {
|
||||
loadAccountTradingStatus()
|
||||
loadCurrentAccountMeta(accountId)
|
||||
}
|
||||
}, 3000)
|
||||
|
||||
return () => clearInterval(timer)
|
||||
|
|
|
|||
|
|
@ -31,17 +31,21 @@ const ACCOUNT_ID_STORAGE_KEY = 'ats_account_id';
|
|||
export const getCurrentAccountId = () => {
|
||||
try {
|
||||
const v = localStorage.getItem(ACCOUNT_ID_STORAGE_KEY);
|
||||
const n = parseInt(v || '1', 10);
|
||||
return Number.isFinite(n) && n > 0 ? n : 1;
|
||||
const n = parseInt(v, 10);
|
||||
return Number.isFinite(n) && n > 0 ? n : null;
|
||||
} catch (e) {
|
||||
return 1;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const setCurrentAccountId = (accountId) => {
|
||||
try {
|
||||
const n = parseInt(String(accountId || '1'), 10);
|
||||
localStorage.setItem(ACCOUNT_ID_STORAGE_KEY, String(Number.isFinite(n) && n > 0 ? n : 1));
|
||||
const n = parseInt(String(accountId), 10);
|
||||
if (Number.isFinite(n) && n > 0) {
|
||||
localStorage.setItem(ACCOUNT_ID_STORAGE_KEY, String(n));
|
||||
} else {
|
||||
localStorage.removeItem(ACCOUNT_ID_STORAGE_KEY);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
|
@ -88,7 +92,11 @@ const withAccountHeaders = (headers = {}, accountIdOverride = null) => {
|
|||
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的辅助函数,避免双斜杠和格式问题
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ const getInitialViewingUserId = () => {
|
|||
const getInitialAccountId = () => {
|
||||
try {
|
||||
const v = localStorage.getItem(ACCOUNT_ID_STORAGE_KEY)
|
||||
const n = parseInt(v || '1', 10)
|
||||
return Number.isFinite(n) && n > 0 ? n : 1
|
||||
const n = parseInt(v, 10)
|
||||
return Number.isFinite(n) && n > 0 ? n : null
|
||||
} catch (e) {
|
||||
return 1
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user