diff --git a/README.md b/README.md index 625b3da..5ca8e6e 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,7 @@ POST /api/open/v1/orders/ship-notify 实际上订单页只显示了自营商户这一家。 商户上下文的来源是前端 `localStorage.merchant_id`,只会在「平台商户」页点「成员」时被写入。 +顶栏会常驻显示「当前商户:xxx」,点旁边的「退出商户视角」即可回到默认商户(自营商户)。 需要看某个下游商户的订单时,用「下游订单」页的商户筛选即可,不必切换上下文。 ## 目录结构 diff --git a/frontend/src/layouts/MainLayout.tsx b/frontend/src/layouts/MainLayout.tsx index ea0c7d8..fd4a8db 100644 --- a/frontend/src/layouts/MainLayout.tsx +++ b/frontend/src/layouts/MainLayout.tsx @@ -229,6 +229,16 @@ export default function MainLayout() { return localStorage.getItem(SIDEBAR_COLLAPSED_KEY) === 'true' }) const { user, logout, refreshProfile, isAdmin, merchant, merchantPermissions } = useAuth() + // 管理员的商户上下文来自 localStorage(即请求头 X-Merchant-ID 的来源), + // 之前只会在「平台商户」页点「成员」时被写入,界面上没有任何提示—— + // 管理员很容易以为自己看的是全平台数据,实际被静默框定在某个商户里。 + const [activeMerchantId] = useState(() => localStorage.getItem('merchant_id')) + const merchantContextLabel = merchant?.name || (activeMerchantId ? `商户 #${activeMerchantId}` : '默认商户') + const exitMerchantContext = () => { + localStorage.removeItem('merchant_id') + // 整页刷新:上下文变了,当前页已经加载的数据也必须按新上下文重新取一遍。 + window.location.reload() + } const [passwordOpen, setPasswordOpen] = useState(false) const [passwordSaving, setPasswordSaving] = useState(false) const [passwordForm] = Form.useForm() @@ -421,6 +431,22 @@ export default function MainLayout() {
{isAdmin && ( + + + 当前商户:{merchantContextLabel} + + + {activeMerchantId && ( + + + + )}