feat: 收口多品牌与模板构建基础
This commit is contained in:
1 parent
0425a1c672
commit
77224ea51f
317 files changed
+11290
-1158
No files matched your search
+128
-13
@@ -49,13 +49,27 @@ const FeatureCapabilitiesPage = React.lazy(() =>
|
||||
default: module.CapabilitiesPage,
|
||||
})),
|
||||
);
|
||||
const FeatureMembersPage = React.lazy(() =>
|
||||
import("./features/team/MembersPage.js").then((module) => ({
|
||||
default: module.MembersPage,
|
||||
})),
|
||||
);
|
||||
const FeaturePublicationPage = React.lazy(() =>
|
||||
import("./features/publication/PublicationPage.js").then((module) => ({
|
||||
default: module.PublicationPage,
|
||||
})),
|
||||
);
|
||||
import { BrowserRouter, Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom";
|
||||
import "antd/dist/reset.css";
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
const api = createApiClient;
|
||||
|
||||
function Login({ onLogin }: { onLogin: () => void }) {
|
||||
function Login({
|
||||
onLogin,
|
||||
}: {
|
||||
onLogin: (session: { role: string; mustChangePassword: boolean }) => void;
|
||||
}) {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
async function submit(values: { username: string; password: string }) {
|
||||
@@ -63,7 +77,9 @@ function Login({ onLogin }: { onLogin: () => void }) {
|
||||
try {
|
||||
const result = await api().loginAdmin(values.username, values.password);
|
||||
localStorage.setItem("adminToken", result.token);
|
||||
onLogin();
|
||||
localStorage.setItem("adminRole", result.role);
|
||||
localStorage.setItem("adminMustChangePassword", String(result.mustChangePassword));
|
||||
onLogin(result);
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "登录失败");
|
||||
} finally {
|
||||
@@ -87,7 +103,60 @@ function Login({ onLogin }: { onLogin: () => void }) {
|
||||
);
|
||||
}
|
||||
|
||||
function Dashboard({ onLogout }: { onLogout: () => void }) {
|
||||
function ChangePassword({ onComplete }: { onComplete: () => void }) {
|
||||
const [form] = Form.useForm<{
|
||||
currentPassword: string;
|
||||
newPassword: string;
|
||||
confirmPassword: string;
|
||||
}>();
|
||||
const [loading, setLoading] = useState(false);
|
||||
async function submit(values: {
|
||||
currentPassword: string;
|
||||
newPassword: string;
|
||||
confirmPassword: string;
|
||||
}) {
|
||||
if (values.newPassword !== values.confirmPassword) {
|
||||
message.error("两次输入的新密码不一致");
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
await api().changeAdminPassword(values.currentPassword, values.newPassword);
|
||||
localStorage.setItem("adminMustChangePassword", "false");
|
||||
message.success("密码已更新");
|
||||
onComplete();
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "密码更新失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Card title="首次登录需要修改密码" style={{ maxWidth: 420, margin: "120px auto" }}>
|
||||
<Typography.Paragraph type="secondary">请先设置只有你本人知道的新密码。</Typography.Paragraph>
|
||||
<Form form={form} layout="vertical" onFinish={submit}>
|
||||
<Form.Item name="currentPassword" label="初始密码" rules={[{ required: true }]}>
|
||||
<Input.Password />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="newPassword"
|
||||
label="新密码"
|
||||
rules={[{ required: true, min: 8, message: "请输入至少 8 位新密码" }]}
|
||||
>
|
||||
<Input.Password />
|
||||
</Form.Item>
|
||||
<Form.Item name="confirmPassword" label="确认新密码" rules={[{ required: true }]}>
|
||||
<Input.Password />
|
||||
</Form.Item>
|
||||
<Button type="primary" htmlType="submit" loading={loading} block>
|
||||
保存新密码
|
||||
</Button>
|
||||
</Form>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function Dashboard({ onLogout, role }: { onLogout: () => void; role: string }) {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const brand = useQuery({
|
||||
@@ -109,13 +178,31 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
|
||||
};
|
||||
const page = location.pathname.split("/")[2] || "overview";
|
||||
const items = [
|
||||
{ key: "overview", label: "当前品牌概览" },
|
||||
{ key: "brand", label: "当前品牌表达" },
|
||||
{ key: "trust", label: "信任内容" },
|
||||
{ key: "services", label: "业务提供项" },
|
||||
{ key: "workspace", label: "模板与设置" },
|
||||
{ key: "capabilities", label: "能力插件" },
|
||||
{ key: "inquiries", label: "咨询记录" },
|
||||
{
|
||||
type: "group" as const,
|
||||
label: "日常经营",
|
||||
children: [
|
||||
{ key: "overview", label: "当前品牌概览" },
|
||||
{ key: "publication", label: "配置与发布" },
|
||||
{ key: "brand", label: "品牌表达" },
|
||||
{ key: "trust", label: "信任内容" },
|
||||
{ key: "services", label: "业务提供项" },
|
||||
{ key: "inquiries", label: "咨询记录" },
|
||||
],
|
||||
},
|
||||
...(role === "editor"
|
||||
? []
|
||||
: [
|
||||
{
|
||||
type: "group" as const,
|
||||
label: "系统管理",
|
||||
children: [
|
||||
{ key: "workspace", label: "模板与设置" },
|
||||
{ key: "capabilities", label: "能力插件" },
|
||||
{ key: "members", label: "团队成员" },
|
||||
],
|
||||
},
|
||||
]),
|
||||
];
|
||||
return (
|
||||
<Layout style={{ minHeight: "100vh" }}>
|
||||
@@ -163,9 +250,20 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
|
||||
<Suspense fallback={<Card loading />}>
|
||||
<Routes>
|
||||
<Route path="/admin/overview" element={<FeatureOverviewPage />} />
|
||||
<Route
|
||||
path="/admin/publication"
|
||||
element={<FeaturePublicationPage canManageTemplate={role !== "editor"} />}
|
||||
/>
|
||||
<Route path="/admin/brand" element={<FeatureBrandPage />} />
|
||||
<Route path="/admin/workspace" element={<FeatureWorkspacePage />} />
|
||||
<Route path="/admin/capabilities" element={<FeatureCapabilitiesPage />} />
|
||||
{role === "editor" ? null : (
|
||||
<Route path="/admin/workspace" element={<FeatureWorkspacePage />} />
|
||||
)}
|
||||
{role === "editor" ? null : (
|
||||
<Route path="/admin/capabilities" element={<FeatureCapabilitiesPage />} />
|
||||
)}
|
||||
{role === "editor" ? null : (
|
||||
<Route path="/admin/members" element={<FeatureMembersPage />} />
|
||||
)}
|
||||
<Route path="/admin/trust" element={<FeatureTrustContentPage />} />
|
||||
<Route path="/admin/services" element={<FeatureServicesPage />} />
|
||||
<Route path="/admin/inquiries" element={<FeatureInquiriesPage />} />
|
||||
@@ -180,6 +278,10 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
|
||||
|
||||
function Root() {
|
||||
const [loggedIn, setLoggedIn] = useState(Boolean(localStorage.getItem("adminToken")));
|
||||
const [role, setRole] = useState(localStorage.getItem("adminRole") || "owner");
|
||||
const [mustChangePassword, setMustChangePassword] = useState(
|
||||
localStorage.getItem("adminMustChangePassword") === "true",
|
||||
);
|
||||
React.useEffect(() => {
|
||||
const expire = () => {
|
||||
message.warning("登录状态已失效,请重新登录");
|
||||
@@ -190,9 +292,22 @@ function Root() {
|
||||
}, []);
|
||||
const logout = () => {
|
||||
localStorage.removeItem("adminToken");
|
||||
localStorage.removeItem("adminRole");
|
||||
localStorage.removeItem("adminMustChangePassword");
|
||||
setLoggedIn(false);
|
||||
};
|
||||
return loggedIn ? <Dashboard onLogout={logout} /> : <Login onLogin={() => setLoggedIn(true)} />;
|
||||
if (!loggedIn)
|
||||
return (
|
||||
<Login
|
||||
onLogin={(session) => {
|
||||
setRole(session.role);
|
||||
setMustChangePassword(session.mustChangePassword);
|
||||
setLoggedIn(true);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
if (mustChangePassword) return <ChangePassword onComplete={() => setMustChangePassword(false)} />;
|
||||
return <Dashboard onLogout={logout} role={role} />;
|
||||
}
|
||||
createRoot(document.getElementById("app")!).render(
|
||||
<React.StrictMode>
|
||||
|
||||
Reference in new issue
Block a user