feat: 增加多品牌切换并继续拆分控制器
This commit is contained in:
1 parent
f4a93bba23
commit
045472035b
7 files changed
+126
-3
No files matched your search
+36
-1
@@ -2,7 +2,19 @@ import React, { Suspense, useState } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { App, Button, Card, Form, Input, Layout, Menu, Space, Typography, message } from "antd";
|
||||
import {
|
||||
App,
|
||||
Button,
|
||||
Card,
|
||||
Form,
|
||||
Input,
|
||||
Layout,
|
||||
Menu,
|
||||
Select,
|
||||
Space,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { createApiClient } from "./lib/api.js";
|
||||
const FeatureInquiriesPage = React.lazy(() =>
|
||||
import("./features/inquiries/InquiriesPage.js").then((module) => ({
|
||||
@@ -82,6 +94,19 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
|
||||
queryKey: ["admin-shell-brand"],
|
||||
queryFn: () => createApiClient().getAdminBrand(),
|
||||
});
|
||||
const memberships = useQuery({
|
||||
queryKey: ["admin-brand-memberships"],
|
||||
queryFn: () => createApiClient().listAdminBrands(),
|
||||
});
|
||||
const switchBrand = async (brandId: string) => {
|
||||
try {
|
||||
const result = await createApiClient().switchAdminBrand(brandId);
|
||||
localStorage.setItem("adminToken", result.token);
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "品牌切换失败");
|
||||
}
|
||||
};
|
||||
const page = location.pathname.split("/")[2] || "overview";
|
||||
const items = [
|
||||
{ key: "overview", label: "当前品牌概览" },
|
||||
@@ -117,6 +142,16 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
|
||||
<Space>
|
||||
<Typography.Text strong>{brand.data?.name || "当前品牌"}</Typography.Text>
|
||||
<Typography.Text type="secondary">品牌工作区</Typography.Text>
|
||||
<Select
|
||||
size="small"
|
||||
value={brand.data?.id}
|
||||
loading={memberships.isLoading}
|
||||
onChange={(value) => void switchBrand(value)}
|
||||
options={(memberships.data ?? []).map((item) => ({
|
||||
value: item.brand.id,
|
||||
label: item.brand.name,
|
||||
}))}
|
||||
/>
|
||||
</Space>
|
||||
<Button type="text" onClick={onLogout}>
|
||||
退出登录
|
||||
|
||||
Reference in new issue
Block a user