diff --git a/backend/api/routes/stats.py b/backend/api/routes/stats.py
index 266ac9f..606a2d2 100644
--- a/backend/api/routes/stats.py
+++ b/backend/api/routes/stats.py
@@ -135,7 +135,7 @@ async def get_dashboard_data(account_id: int = Depends(get_account_id)):
logger.warning(f"获取实时持仓失败: {positions_error}", exc_info=True)
# 回退到数据库记录
try:
- db_trades = Trade.get_all(status='open')[:10]
+ db_trades = Trade.get_all(status='open', account_id=account_id)[:10]
# 格式化数据库记录,添加 entry_value_usdt 字段
open_trades = []
for trade in db_trades:
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index 700b32f..294b4fa 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -13,51 +13,26 @@ import Login from './components/Login'
import { api, clearAuthToken } from './services/api'
import {
setCurrentUser,
- setViewingUserId,
setUsers,
- switchUser,
selectCurrentUser,
- selectViewingUserId,
selectUsers,
selectIsAdmin,
- selectEffectiveUserId,
} from './store/appSlice'
import './App.css'
function App() {
const dispatch = useDispatch()
const currentUser = useSelector(selectCurrentUser)
- const viewingUserId = useSelector(selectViewingUserId)
- const users = useSelector(selectUsers)
const isAdmin = useSelector(selectIsAdmin)
- const effectiveUserId = useSelector(selectEffectiveUserId)
const [checking, setChecking] = useState(true)
- const [showUserPopover, setShowUserPopover] = useState(false)
- const userPopoverRef = React.useRef(null)
const refreshMe = async () => {
try {
const u = await api.me()
dispatch(setCurrentUser(u))
- const isAdminValue = (u?.role || '') === 'admin'
-
- // 管理员:加载用户列表
- if (isAdminValue) {
- try {
- const userList = await api.getUsers()
- const usersArray = Array.isArray(userList) ? userList : []
- dispatch(setUsers(usersArray))
- // 如果viewingUserId未设置或不在列表中,设置为当前登录用户
- const currentUserId = parseInt(String(u?.id || ''), 10)
- if (!viewingUserId || !usersArray.some((user) => parseInt(String(user?.id || ''), 10) === viewingUserId)) {
- dispatch(setViewingUserId(currentUserId))
- }
- } catch (e) {
- console.error('加载用户列表失败:', e)
- }
- }
+ // 不再加载用户列表,去掉用户切换功能
} catch (e) {
dispatch(setCurrentUser(null))
} finally {
@@ -65,31 +40,6 @@ function App() {
}
}
- // 点击外部关闭popover
- React.useEffect(() => {
- const handleClickOutside = (event) => {
- if (userPopoverRef.current && !userPopoverRef.current.contains(event.target)) {
- setShowUserPopover(false)
- }
- }
- if (showUserPopover) {
- document.addEventListener('mousedown', handleClickOutside)
- return () => document.removeEventListener('mousedown', handleClickOutside)
- }
- }, [showUserPopover])
-
- // 当前查看的用户信息
- const currentViewingUser = users.find((u) => parseInt(String(u?.id || ''), 10) === viewingUserId)
-
- const handleSwitchUser = (userId) => {
- const nextUserId = parseInt(String(userId || ''), 10)
- if (Number.isFinite(nextUserId) && nextUserId > 0) {
- dispatch(switchUser(nextUserId))
- setShowUserPopover(false)
- // 触发自定义事件,保持向后兼容
- window.dispatchEvent(new CustomEvent('ats:user:switched', { detail: { userId: nextUserId } }))
- }
- }
useEffect(() => {
refreshMe()
@@ -132,88 +82,16 @@ function App() {
) : null}
- {isAdmin ? (
-
-
- {showUserPopover && (
-
-
- 切换用户视角
-
-
- {users.map((u) => (
-
handleSwitchUser(u.id)}
- style={{
- padding: '12px 16px',
- cursor: 'pointer',
- transition: 'background-color 0.2s',
- borderBottom: '1px solid #f0f0f0',
- background: viewingUserId === u.id ? '#e3f2fd' : 'white'
- }}
- onMouseEnter={(e) => {
- if (viewingUserId !== u.id) e.currentTarget.style.background = '#f5f5f5'
- }}
- onMouseLeave={(e) => {
- if (viewingUserId !== u.id) e.currentTarget.style.background = 'white'
- }}
- >
-
- {u.username || 'user'} {u.role === 'admin' ? '(管理员)' : ''}
-
-
- {u.status === 'active' ? '启用' : '禁用'}
-
-
- ))}
-
-
- )}
-
- ) : (
-
- {currentUser?.username ? currentUser.username : 'user'}
-
- )}
+
+ {currentUser?.username ? currentUser.username : 'user'}
+ {isAdmin ? '(管理员)' : ''}
+