功能迭代

This commit is contained in:
张锐 committed 2026-11-30 14:54:24 +08:00
1 parent d1844ce9a2
commit 617371be3e
13 files changed
+884 -138

No files matched your search

+510 -50
View File
@@ -1,71 +1,531 @@
import { FormEvent, useEffect, useState } from "react";
import { KeyRound, LogOut, Plus, Save, Share2, Store, Trash2, UserRound } from "lucide-react";
import {
KeyRound,
LogOut,
Plus,
Save,
Share2,
Store,
Trash2,
UserRound,
} from "lucide-react";
import { apiPost } from "./api";
import type { Account } from "./LoginPage";
import { getCurrentSiteCode } from "./siteContext";
type StoreProfile = { siteCode: string; storeName: string; description: string; industry: string };
type SocialChannel = { platform: string; displayName: string; profileUrl: string; shareEnabled: boolean; floatingEnabled: boolean; enabled: boolean; sortNo: number };
type StoreProfile = {
siteCode: string;
storeName: string;
description: string;
industry: string;
domain: string;
};
type SocialChannel = {
platform: string;
displayName: string;
profileUrl: string;
shareEnabled: boolean;
floatingEnabled: boolean;
enabled: boolean;
sortNo: number;
};
type SettingsTab = "store" | "account" | "social";
const SOCIAL_PLATFORMS = ["FACEBOOK", "X", "LINKEDIN", "YOUTUBE", "INSTAGRAM", "WHATSAPP", "PINTEREST", "TIKTOK", "LINE", "TUMBLR", "EMAIL"];
const SOCIAL_PLATFORMS = [
"FACEBOOK",
"X",
"LINKEDIN",
"YOUTUBE",
"INSTAGRAM",
"WHATSAPP",
"PINTEREST",
"TIKTOK",
"LINE",
"TUMBLR",
"EMAIL",
];
export default function SettingsPage({ account, onAccount, onLogout, tab }: { account: Account; onAccount: (value: Account) => void; onLogout: () => void; tab: SettingsTab }) {
export default function SettingsPage({
account,
onAccount,
onLogout,
tab,
}: {
account: Account;
onAccount: (value: Account) => void;
onLogout: () => void;
tab: SettingsTab;
}) {
const siteCode = getCurrentSiteCode();
const [store, setStore] = useState<StoreProfile>({ siteCode, storeName: "", description: "", industry: "" });
const [profile, setProfile] = useState({ username: account.username, displayName: account.displayName });
const [password, setPassword] = useState({ currentPassword: "", newPassword: "", confirmPassword: "" });
const [store, setStore] = useState<StoreProfile>({
siteCode,
storeName: "",
description: "",
industry: "",
domain: "",
});
const [profile, setProfile] = useState({
username: account.username,
displayName: account.displayName,
});
const [password, setPassword] = useState({
currentPassword: "",
newPassword: "",
confirmPassword: "",
});
const [socialChannels, setSocialChannels] = useState<SocialChannel[]>([]);
const [message, setMessage] = useState("");
const [error, setError] = useState("");
useEffect(() => {
apiPost<StoreProfile>("/store/detail", { siteCode }).then(setStore).catch(cause => setError(cause instanceof Error ? cause.message : "加载失败"));
if (tab === "social") apiPost<{ items: SocialChannel[] }>("/social-channels/list", { siteCode }).then(data => setSocialChannels(data.items || [])).catch(cause => setError(cause instanceof Error ? cause.message : "社媒渠道加载失败"));
apiPost<StoreProfile>("/store/detail", { siteCode })
.then(setStore)
.catch((cause) =>
setError(cause instanceof Error ? cause.message : "加载失败"),
);
if (tab === "social")
apiPost<{ items: SocialChannel[] }>("/social-channels/list", { siteCode })
.then((data) => setSocialChannels(data.items || []))
.catch((cause) =>
setError(cause instanceof Error ? cause.message : "社媒渠道加载失败"),
);
}, [siteCode, tab]);
const run = async (operation: () => Promise<void>, success: string) => { try { setError(""); setMessage(""); await operation(); setMessage(success); } catch (cause) { setError(cause instanceof Error ? cause.message : "操作失败"); } };
const saveStore = (event: FormEvent) => { event.preventDefault(); void run(async () => setStore(await apiPost("/store/save", store)), "店铺信息已保存"); };
const saveProfile = (event: FormEvent) => { event.preventDefault(); void run(async () => onAccount(await apiPost("/auth/account", profile)), "账户资料已更新"); };
const savePassword = (event: FormEvent) => { event.preventDefault(); void run(async () => { await apiPost("/auth/password", password); setPassword({ currentPassword: "", newPassword: "", confirmPassword: "" }); }, "密码已修改"); };
const logout = () => void run(async () => { await apiPost("/auth/logout"); onLogout(); }, "");
const run = async (operation: () => Promise<void>, success: string) => {
try {
setError("");
setMessage("");
await operation();
setMessage(success);
} catch (cause) {
setError(cause instanceof Error ? cause.message : "操作失败");
}
};
const saveStore = (event: FormEvent) => {
event.preventDefault();
void run(
async () => setStore(await apiPost("/store/save", store)),
"店铺信息已保存",
);
};
const saveProfile = (event: FormEvent) => {
event.preventDefault();
void run(
async () => onAccount(await apiPost("/auth/account", profile)),
"账户资料已更新",
);
};
const savePassword = (event: FormEvent) => {
event.preventDefault();
void run(async () => {
await apiPost("/auth/password", password);
setPassword({
currentPassword: "",
newPassword: "",
confirmPassword: "",
});
}, "密码已修改");
};
const logout = () =>
void run(async () => {
await apiPost("/auth/logout");
onLogout();
}, "");
/** 新增一个尚未使用的平台渠道。 */
const addSocialChannel = () => {
const platform = SOCIAL_PLATFORMS.find(item => !socialChannels.some(channel => channel.platform === item));
if (!platform) { setError("所有支持的社媒平台均已配置"); return; }
setSocialChannels([...socialChannels, { platform, displayName: platform === "X" ? "X" : platform.charAt(0) + platform.slice(1).toLowerCase(), profileUrl: "", shareEnabled: true, floatingEnabled: false, enabled: true, sortNo: (socialChannels.length + 1) * 10 }]);
const platform = SOCIAL_PLATFORMS.find(
(item) => !socialChannels.some((channel) => channel.platform === item),
);
if (!platform) {
setError("所有支持的社媒平台均已配置");
return;
}
setSocialChannels([
...socialChannels,
{
platform,
displayName:
platform === "X"
? "X"
: platform.charAt(0) + platform.slice(1).toLowerCase(),
profileUrl: "",
shareEnabled: true,
floatingEnabled: false,
enabled: true,
sortNo: (socialChannels.length + 1) * 10,
},
]);
};
/** 更新指定社媒渠道。 */
const updateSocialChannel = (index: number, patch: Partial<SocialChannel>) => setSocialChannels(current => current.map((item, itemIndex) => itemIndex === index ? { ...item, ...patch } : item));
const updateSocialChannel = (index: number, patch: Partial<SocialChannel>) =>
setSocialChannels((current) =>
current.map((item, itemIndex) =>
itemIndex === index ? { ...item, ...patch } : item,
),
);
/** 保存整组社媒渠道配置。 */
const saveSocialChannels = (event: FormEvent) => { event.preventDefault(); void run(async () => { await apiPost("/social-channels/save", { siteCode, items: socialChannels }); }, "社媒渠道已保存"); };
const saveSocialChannels = (event: FormEvent) => {
event.preventDefault();
void run(async () => {
await apiPost("/social-channels/save", {
siteCode,
items: socialChannels,
});
}, "社媒渠道已保存");
};
const titles: Record<SettingsTab, [string, string]> = { store: ["店铺信息", "维护网站名称、行业和店铺介绍。"], account: ["账户与安全", "维护登录账户、显示名称和密码。"], social: ["社媒渠道", "配置产品分享入口和全站右侧悬浮联系渠道。"] };
return <div className="account-settings">
<header><div><h1>{titles[tab][0]}</h1><p>{titles[tab][1]}</p></div><button className="secondary" onClick={logout}><LogOut size={17}/>退出登录</button></header>
{(message || error) && <div className={error ? "settings-message error" : "settings-message"}>{error || message}</div>}
{tab === "store" && <div className="settings-layout">
<form className="profile-card" onSubmit={saveStore}><div className="profile-card-title"><Store/><div><h2>店铺信息</h2><p>用于运营后台识别当前网站和业务所属行业。</p></div></div><label><span>店铺名称</span><input required maxLength={100} value={store.storeName} onChange={event => setStore({ ...store, storeName: event.target.value })}/></label><label><span>所属行业</span><input required maxLength={100} value={store.industry} onChange={event => setStore({ ...store, industry: event.target.value })} placeholder="例如:工业设备"/></label><label className="wide"><span>店铺描述</span><textarea rows={5} maxLength={1000} value={store.description || ""} onChange={event => setStore({ ...store, description: event.target.value })}/></label><div className="profile-actions"><button className="primary"><Save size={17}/>保存店铺信息</button></div></form>
</div>}
{tab === "account" && <div className="settings-layout settings-account-layout">
<div className="settings-side">
<form className="profile-card" onSubmit={saveProfile}><div className="profile-card-title"><UserRound/><div><h2>账户资料</h2><p>账户名用于登录,显示名称用于后台识别。</p></div></div><label><span>登录账户</span><input required minLength={4} maxLength={50} value={profile.username} onChange={event => setProfile({ ...profile, username: event.target.value })}/></label><label><span>显示名称</span><input required maxLength={50} value={profile.displayName} onChange={event => setProfile({ ...profile, displayName: event.target.value })}/></label><div className="profile-actions"><button className="primary"><Save size={17}/>保存账户资料</button></div></form>
<form className="profile-card" onSubmit={savePassword}><div className="profile-card-title"><KeyRound/><div><h2>修改密码</h2><p>新密码需与当前密码不同。</p></div></div><label><span>当前密码</span><input required type="password" autoComplete="current-password" value={password.currentPassword} onChange={event => setPassword({ ...password, currentPassword: event.target.value })}/></label><label><span>新密码</span><input required type="password" minLength={8} maxLength={64} autoComplete="new-password" value={password.newPassword} onChange={event => setPassword({ ...password, newPassword: event.target.value })}/></label><label><span>确认新密码</span><input required type="password" minLength={8} maxLength={64} autoComplete="new-password" value={password.confirmPassword} onChange={event => setPassword({ ...password, confirmPassword: event.target.value })}/></label><div className="profile-actions"><button className="primary"><KeyRound size={17}/>修改密码</button></div></form>
</div>
</div>}
{tab === "social" && <form className="profile-card social-settings-card" onSubmit={saveSocialChannels}>
<div className="profile-card-title"><Share2/><div><h2>社媒渠道</h2><p>配置产品分享入口和全站右侧悬浮联系渠道。</p></div><button type="button" className="social-add" onClick={addSocialChannel}><Plus size={16}/>添加渠道</button></div>
<div className="social-channel-head"><span>平台</span><span>展示名称</span><span>主页或联系地址</span><span>展示位置</span><span>排序</span><span>操作</span></div>
<div className="social-channel-list">
{socialChannels.length === 0 && <div className="social-channel-empty">尚未配置社媒渠道</div>}
{socialChannels.map((channel, index) => <div className="social-channel-row" key={`${channel.platform}-${index}`}>
<select value={channel.platform} onChange={event => updateSocialChannel(index, { platform: event.target.value })}>{SOCIAL_PLATFORMS.map(platform => <option key={platform} value={platform} disabled={socialChannels.some((item, itemIndex) => itemIndex !== index && item.platform === platform)}>{platform}</option>)}</select>
<input required maxLength={100} value={channel.displayName} onChange={event => updateSocialChannel(index, { displayName: event.target.value })}/>
<input required maxLength={1000} type={channel.platform === "EMAIL" ? "email" : "url"} placeholder={channel.platform === "EMAIL" ? "sales@example.com" : "https://..."} value={channel.profileUrl} onChange={event => updateSocialChannel(index, { profileUrl: event.target.value })}/>
<div className="social-channel-flags"><label><input type="checkbox" checked={channel.shareEnabled} onChange={event => updateSocialChannel(index, { shareEnabled: event.target.checked })}/>产品分享</label><label><input type="checkbox" checked={channel.floatingEnabled} onChange={event => updateSocialChannel(index, { floatingEnabled: event.target.checked })}/>右侧悬浮</label><label><input type="checkbox" checked={channel.enabled} onChange={event => updateSocialChannel(index, { enabled: event.target.checked })}/>启用</label></div>
<input className="social-sort" type="number" min={0} max={9999} value={channel.sortNo} onChange={event => updateSocialChannel(index, { sortNo: Number(event.target.value) })}/>
<button type="button" className="social-delete" title="删除渠道" onClick={() => setSocialChannels(current => current.filter((_, itemIndex) => itemIndex !== index))}><Trash2 size={17}/></button>
</div>)}
</div>
<div className="profile-actions"><button className="primary"><Save size={17}/>保存社媒渠道</button></div>
</form>}
</div>;
const titles: Record<SettingsTab, [string, string]> = {
store: ["店铺信息", "维护网站名称、行业和店铺介绍。"],
account: ["账户与安全", "维护登录账户、显示名称和密码。"],
social: ["社媒渠道", "配置产品分享入口和全站右侧悬浮联系渠道。"],
};
return (
<div className="account-settings">
<header>
<div>
<h1>{titles[tab][0]}</h1>
<p>{titles[tab][1]}</p>
</div>
<button className="secondary" onClick={logout}>
<LogOut size={17} />
退出登录
</button>
</header>
{(message || error) && (
<div className={error ? "settings-message error" : "settings-message"}>
{error || message}
</div>
)}
{tab === "store" && (
<div className="settings-layout">
<form className="profile-card" onSubmit={saveStore}>
<div className="profile-card-title">
<Store />
<div>
<h2>店铺信息</h2>
<p>用于运营后台识别当前网站和业务所属行业。</p>
</div>
</div>
<label>
<span>店铺名称</span>
<input
required
maxLength={100}
value={store.storeName}
onChange={(event) =>
setStore({ ...store, storeName: event.target.value })
}
/>
</label>
<label>
<span>所属行业</span>
<input
required
maxLength={100}
value={store.industry}
onChange={(event) =>
setStore({ ...store, industry: event.target.value })
}
placeholder="例如:工业设备"
/>
</label>
<label className="wide">
<span>店铺域名</span>
<input
maxLength={255}
value={store.domain || ""}
onChange={(event) =>
setStore({ ...store, domain: event.target.value })
}
placeholder="www.example.com"
/>
{store.domain && (
<small className="store-domain-preview">
访问地址:https://{store.domain.replace(/^https?:\/\//, "")}
</small>
)}
</label>
<label className="wide">
<span>店铺描述</span>
<textarea
rows={5}
maxLength={1000}
value={store.description || ""}
onChange={(event) =>
setStore({ ...store, description: event.target.value })
}
/>
</label>
<div className="profile-actions">
<button className="primary">
<Save size={17} />
保存店铺信息
</button>
</div>
</form>
</div>
)}
{tab === "account" && (
<div className="settings-layout settings-account-layout">
<div className="settings-side">
<form className="profile-card" onSubmit={saveProfile}>
<div className="profile-card-title">
<UserRound />
<div>
<h2>账户资料</h2>
<p>账户名用于登录,显示名称用于后台识别。</p>
</div>
</div>
<label>
<span>登录账户</span>
<input
required
minLength={4}
maxLength={50}
value={profile.username}
onChange={(event) =>
setProfile({ ...profile, username: event.target.value })
}
/>
</label>
<label>
<span>显示名称</span>
<input
required
maxLength={50}
value={profile.displayName}
onChange={(event) =>
setProfile({ ...profile, displayName: event.target.value })
}
/>
</label>
<div className="profile-actions">
<button className="primary">
<Save size={17} />
保存账户资料
</button>
</div>
</form>
<form className="profile-card" onSubmit={savePassword}>
<div className="profile-card-title">
<KeyRound />
<div>
<h2>修改密码</h2>
<p>新密码需与当前密码不同。</p>
</div>
</div>
<label>
<span>当前密码</span>
<input
required
type="password"
autoComplete="current-password"
value={password.currentPassword}
onChange={(event) =>
setPassword({
...password,
currentPassword: event.target.value,
})
}
/>
</label>
<label>
<span>新密码</span>
<input
required
type="password"
minLength={8}
maxLength={64}
autoComplete="new-password"
value={password.newPassword}
onChange={(event) =>
setPassword({
...password,
newPassword: event.target.value,
})
}
/>
</label>
<label>
<span>确认新密码</span>
<input
required
type="password"
minLength={8}
maxLength={64}
autoComplete="new-password"
value={password.confirmPassword}
onChange={(event) =>
setPassword({
...password,
confirmPassword: event.target.value,
})
}
/>
</label>
<div className="profile-actions">
<button className="primary">
<KeyRound size={17} />
修改密码
</button>
</div>
</form>
</div>
</div>
)}
{tab === "social" && (
<form
className="profile-card social-settings-card"
onSubmit={saveSocialChannels}
>
<div className="profile-card-title">
<Share2 />
<div>
<h2>社媒渠道</h2>
<p>配置产品分享入口和全站右侧悬浮联系渠道。</p>
</div>
<button
type="button"
className="social-add"
onClick={addSocialChannel}
>
<Plus size={16} />
添加渠道
</button>
</div>
<div className="social-channel-head">
<span>平台</span>
<span>展示名称</span>
<span>主页或联系地址</span>
<span>展示位置</span>
<span>排序</span>
<span>操作</span>
</div>
<div className="social-channel-list">
{socialChannels.length === 0 && (
<div className="social-channel-empty">尚未配置社媒渠道</div>
)}
{socialChannels.map((channel, index) => (
<div
className="social-channel-row"
key={`${channel.platform}-${index}`}
>
<select
value={channel.platform}
onChange={(event) =>
updateSocialChannel(index, { platform: event.target.value })
}
>
{SOCIAL_PLATFORMS.map((platform) => (
<option
key={platform}
value={platform}
disabled={socialChannels.some(
(item, itemIndex) =>
itemIndex !== index && item.platform === platform,
)}
>
{platform}
</option>
))}
</select>
<input
required
maxLength={100}
value={channel.displayName}
onChange={(event) =>
updateSocialChannel(index, {
displayName: event.target.value,
})
}
/>
<input
required
maxLength={1000}
type={channel.platform === "EMAIL" ? "email" : "url"}
placeholder={
channel.platform === "EMAIL"
? "sales@example.com"
: "https://..."
}
value={channel.profileUrl}
onChange={(event) =>
updateSocialChannel(index, {
profileUrl: event.target.value,
})
}
/>
<div className="social-channel-flags">
<label>
<input
type="checkbox"
checked={channel.shareEnabled}
onChange={(event) =>
updateSocialChannel(index, {
shareEnabled: event.target.checked,
})
}
/>
产品分享
</label>
<label>
<input
type="checkbox"
checked={channel.floatingEnabled}
onChange={(event) =>
updateSocialChannel(index, {
floatingEnabled: event.target.checked,
})
}
/>
右侧悬浮
</label>
<label>
<input
type="checkbox"
checked={channel.enabled}
onChange={(event) =>
updateSocialChannel(index, {
enabled: event.target.checked,
})
}
/>
启用
</label>
</div>
<input
className="social-sort"
type="number"
min={0}
max={9999}
value={channel.sortNo}
onChange={(event) =>
updateSocialChannel(index, {
sortNo: Number(event.target.value),
})
}
/>
<button
type="button"
className="social-delete"
title="删除渠道"
onClick={() =>
setSocialChannels((current) =>
current.filter((_, itemIndex) => itemIndex !== index),
)
}
>
<Trash2 size={17} />
</button>
</div>
))}
</div>
<div className="profile-actions">
<button className="primary">
<Save size={17} />
保存社媒渠道
</button>
</div>
</form>
)}
</div>
);
}
+224 -81
View File
@@ -46,7 +46,12 @@ import DashboardPage from "./DashboardPage";
import CrmCustomerPage from "./CrmCustomerPage";
import { apiPost } from "./api";
import { statusLabel } from "./statusLabels";
import { ensureCurrentSiteCode, getCurrentSiteCode, setCurrentSiteCode, type SiteOption } from "./siteContext";
import {
ensureCurrentSiteCode,
getCurrentSiteCode,
setCurrentSiteCode,
type SiteOption,
} from "./siteContext";
const SITE_WEB =
window.location.hostname === "admin.steliro.com"
@@ -233,8 +238,11 @@ function App({
const previousCodes = new Set(account.sites.map((site) => site.siteCode));
await apiPost("/sites/create", siteForm);
const result = await apiPost<{ items: SiteOption[] }>("/sites/list", {});
const site = result.items.find((item) => !previousCodes.has(item.siteCode));
if (!site) throw new Error("站点已创建,但未能读取新站点信息,请刷新后重试");
const site = result.items.find(
(item) => !previousCodes.has(item.siteCode),
);
if (!site)
throw new Error("站点已创建,但未能读取新站点信息,请刷新后重试");
setCurrentSiteCode(site.siteCode);
window.location.assign("/");
} catch (cause) {
@@ -261,11 +269,11 @@ function App({
const [editingPage, setEditingPage] = useState<string | null>(
resolvePageRoute,
);
const [productMenuOpen, setProductMenuOpen] = useState(true);
const [contentMenuOpen, setContentMenuOpen] = useState(true);
const [frontSiteMenuOpen, setFrontSiteMenuOpen] = useState(true);
const [systemSettingsOpen, setSystemSettingsOpen] = useState(true);
const [crmMenuOpen, setCrmMenuOpen] = useState(true);
const [productMenuOpen, setProductMenuOpen] = useState(false);
const [contentMenuOpen, setContentMenuOpen] = useState(false);
const [frontSiteMenuOpen, setFrontSiteMenuOpen] = useState(false);
const [systemSettingsOpen, setSystemSettingsOpen] = useState(false);
const [crmMenuOpen, setCrmMenuOpen] = useState(false);
const navigateSection = (next: Section) => {
setEditingProduct(null);
setEditingContent(null);
@@ -288,28 +296,28 @@ function App({
? { items: [] }
: section === "dashboard"
? { items: [] }
: section.startsWith("settings-")
? { items: [] }
: section === "navigation"
: section.startsWith("settings-")
? { items: [] }
: section === "agreements"
: section === "navigation"
? { items: [] }
: section === "about-us"
? { items: [] }
: section === "products"
? await post("/products/list", { siteCode: SITE })
: section === "pages"
? await post("/pages/list", { siteCode: SITE })
: section === "decoration"
? { items: [] }
: section === "inquiries"
? await post("/inquiries/list", { siteCode: SITE })
: section === "inquiry-settings"
: section === "agreements"
? { items: [] }
: section === "about-us"
? { items: [] }
: section === "products"
? await post("/products/list", { siteCode: SITE })
: section === "pages"
? await post("/pages/list", { siteCode: SITE })
: section === "decoration"
? { items: [] }
: await post("/contents/list", {
siteCode: SITE,
contentType: section,
});
: section === "inquiries"
? await post("/inquiries/list", { siteCode: SITE })
: section === "inquiry-settings"
? { items: [] }
: await post("/contents/list", {
siteCode: SITE,
contentType: section,
});
setItems(data.items || []);
} catch (e) {
setError(e instanceof Error ? e.message : "加载失败");
@@ -512,11 +520,21 @@ function App({
</button>
</div>
<nav>
<button className={section === "dashboard" ? "active" : ""} onClick={() => navigateSection("dashboard")}><LayoutDashboard size={18}/>数据概览</button>
<button
className={section === "dashboard" ? "active" : ""}
onClick={() => navigateSection("dashboard")}
>
<LayoutDashboard size={18} />
数据概览
</button>
<div className="nav-group">
<button
className={
["products", "product-categories", "product-templates"].includes(section)
[
"products",
"product-categories",
"product-templates",
].includes(section)
? "group-active"
: ""
}
@@ -553,14 +571,28 @@ function App({
)}
</div>
<div className="nav-group">
<button className={section === "crm-customers" ? "group-active" : ""} onClick={() => setCrmMenuOpen(!crmMenuOpen)}>
<button
className={section === "crm-customers" ? "group-active" : ""}
onClick={() => setCrmMenuOpen(!crmMenuOpen)}
>
<Users size={18} />
CRM 管理
<ChevronDown className={crmMenuOpen ? "expanded" : ""} size={16} />
<ChevronDown
className={crmMenuOpen ? "expanded" : ""}
size={16}
/>
</button>
{crmMenuOpen && <div className="nav-children">
<button className={section === "crm-customers" ? "active" : ""} onClick={() => navigateSection("crm-customers")}><Users size={15}/>客户列表</button>
</div>}
{crmMenuOpen && (
<div className="nav-children">
<button
className={section === "crm-customers" ? "active" : ""}
onClick={() => navigateSection("crm-customers")}
>
<Users size={15} />
客户列表
</button>
</div>
)}
</div>
<div className="nav-group">
<button
@@ -655,14 +687,35 @@ function App({
)}
</div>
<div className="nav-group">
<button className={systemSettingsMenus.some((item) => item.key === section) ? "group-active" : ""} onClick={() => setSystemSettingsOpen(!systemSettingsOpen)}>
<button
className={
systemSettingsMenus.some((item) => item.key === section)
? "group-active"
: ""
}
onClick={() => setSystemSettingsOpen(!systemSettingsOpen)}
>
<Settings size={18} />
系统设置
<ChevronDown className={systemSettingsOpen ? "expanded" : ""} size={16} />
<ChevronDown
className={systemSettingsOpen ? "expanded" : ""}
size={16}
/>
</button>
{systemSettingsOpen && <div className="nav-children">
{systemSettingsMenus.map((item) => <button key={item.key} className={section === item.key ? "active" : ""} onClick={() => navigateSection(item.key)}><item.icon size={15} />{item.label}</button>)}
</div>}
{systemSettingsOpen && (
<div className="nav-children">
{systemSettingsMenus.map((item) => (
<button
key={item.key}
className={section === item.key ? "active" : ""}
onClick={() => navigateSection(item.key)}
>
<item.icon size={15} />
{item.label}
</button>
))}
</div>
)}
</div>
{menus.map((m) => (
<button
@@ -678,15 +731,32 @@ function App({
</aside>
<main>
{section === "dashboard" ? (
<DashboardPage onNavigate={(next) => navigateSection(next as Section)} />
<DashboardPage
onNavigate={(next) => navigateSection(next as Section)}
/>
) : section === "crm-customers" ? (
<CrmCustomerPage />
) : section === "settings-store" ? (
<SettingsPage account={account} onAccount={onAccount} onLogout={onLogout} tab="store" />
<SettingsPage
account={account}
onAccount={onAccount}
onLogout={onLogout}
tab="store"
/>
) : section === "settings-account" ? (
<SettingsPage account={account} onAccount={onAccount} onLogout={onLogout} tab="account" />
<SettingsPage
account={account}
onAccount={onAccount}
onLogout={onLogout}
tab="account"
/>
) : section === "settings-social" ? (
<SettingsPage account={account} onAccount={onAccount} onLogout={onLogout} tab="social" />
<SettingsPage
account={account}
onAccount={onAccount}
onLogout={onLogout}
tab="social"
/>
) : section === "about-us" ? (
<AboutUsSettingsPage />
) : section === "seo-settings" ? (
@@ -737,39 +807,39 @@ function App({
<>
{section !== "inquiry-settings" && (
<header>
<div>
<h1>{title}管理</h1>
</div>
{!["inquiries", "inquiry-settings"].includes(section) && (
<div className="header-actions">
{["NEWS", "CASE", "HELP"].includes(section) && (
<div>
<h1>{title}管理</h1>
</div>
{!["inquiries", "inquiry-settings"].includes(section) && (
<div className="header-actions">
{["NEWS", "CASE", "HELP"].includes(section) && (
<button
className="secondary"
onClick={() =>
setSection(`${section}-categories` as Section)
}
>
<FolderTree size={17} />
管理分类
</button>
)}
<button
className="secondary"
className="primary"
onClick={() =>
setSection(`${section}-categories` as Section)
section === "products"
? openProductEditor()
: ["NEWS", "CASE", "HELP"].includes(section)
? openContentEditor(section as EditorialSection)
: section === "pages"
? openPageEditor()
: setOpen(true)
}
>
<FolderTree size={17} />
管理分类
<Plus size={17} />
新建{title}
</button>
)}
<button
className="primary"
onClick={() =>
section === "products"
? openProductEditor()
: ["NEWS", "CASE", "HELP"].includes(section)
? openContentEditor(section as EditorialSection)
: section === "pages"
? openPageEditor()
: setOpen(true)
}
>
<Plus size={17} />
新建{title}
</button>
</div>
)}
</div>
)}
</header>
)}
{section === "inquiry-settings" ? (
@@ -861,7 +931,8 @@ function App({
>
{item.readStatus === 0
? "未读"
: item.statusLabel || statusLabel(item.status)}
: item.statusLabel ||
statusLabel(item.status)}
</span>
<div className="row-actions">
<button className="link">查看</button>
@@ -1067,24 +1138,93 @@ function App({
)}
{siteDialogOpen && (
<div className="mask" onMouseDown={() => setSiteDialogOpen(false)}>
<section className="dialog site-dialog" onMouseDown={(event) => event.stopPropagation()}>
<section
className="dialog site-dialog"
onMouseDown={(event) => event.stopPropagation()}
>
<div className="dialog-head">
<div>
<h2>新增站点</h2>
<p>创建后将自动切换到新站点。</p>
</div>
<button type="button" aria-label="关闭" onClick={() => setSiteDialogOpen(false)}><X size={19} /></button>
<button
type="button"
aria-label="关闭"
onClick={() => setSiteDialogOpen(false)}
>
<X size={19} />
</button>
</div>
<div className="form-grid">
<label><span>站点名称</span><input autoFocus required maxLength={100} value={siteForm.siteName} onChange={(event) => setSiteForm({ ...siteForm, siteName: event.target.value })} placeholder="例如:Shoplix Global" /></label>
<label><span>所属行业</span><input required maxLength={100} value={siteForm.industry} onChange={(event) => setSiteForm({ ...siteForm, industry: event.target.value })} placeholder="例如:工业设备" /></label>
<label><span>站点时区</span><input required maxLength={50} value={siteForm.timezone} onChange={(event) => setSiteForm({ ...siteForm, timezone: event.target.value })} /></label>
<label className="wide"><span>站点描述</span><textarea rows={4} maxLength={1000} value={siteForm.description} onChange={(event) => setSiteForm({ ...siteForm, description: event.target.value })} /></label>
<label>
<span>站点名称</span>
<input
autoFocus
required
maxLength={100}
value={siteForm.siteName}
onChange={(event) =>
setSiteForm({ ...siteForm, siteName: event.target.value })
}
placeholder="例如:Shoplix Global"
/>
</label>
<label>
<span>所属行业</span>
<input
required
maxLength={100}
value={siteForm.industry}
onChange={(event) =>
setSiteForm({ ...siteForm, industry: event.target.value })
}
placeholder="例如:工业设备"
/>
</label>
<label>
<span>站点时区</span>
<input
required
maxLength={50}
value={siteForm.timezone}
onChange={(event) =>
setSiteForm({ ...siteForm, timezone: event.target.value })
}
/>
</label>
<label className="wide">
<span>站点描述</span>
<textarea
rows={4}
maxLength={1000}
value={siteForm.description}
onChange={(event) =>
setSiteForm({
...siteForm,
description: event.target.value,
})
}
/>
</label>
</div>
{siteError && <div className="site-dialog-error">{siteError}</div>}
<div className="dialog-actions">
<button type="button" onClick={() => setSiteDialogOpen(false)}>取消</button>
<button type="button" className="primary" disabled={siteCreating || !siteForm.siteName.trim() || !siteForm.industry.trim() || !siteForm.timezone.trim()} onClick={createSite}>{siteCreating ? "创建中..." : "创建并切换"}</button>
<button type="button" onClick={() => setSiteDialogOpen(false)}>
取消
</button>
<button
type="button"
className="primary"
disabled={
siteCreating ||
!siteForm.siteName.trim() ||
!siteForm.industry.trim() ||
!siteForm.timezone.trim()
}
onClick={createSite}
>
{siteCreating ? "创建中..." : "创建并切换"}
</button>
</div>
</section>
</div>
@@ -1099,7 +1239,10 @@ function RootApp() {
/** 接收账户信息并保证模块级站点上下文与账户权限一致。 */
const acceptAccount = (value: Account) => {
const previousSiteCode = getCurrentSiteCode();
const currentSiteCode = ensureCurrentSiteCode(value.sites || [], value.siteCode);
const currentSiteCode = ensureCurrentSiteCode(
value.sites || [],
value.siteCode,
);
if (previousSiteCode !== currentSiteCode) {
window.location.reload();
return;
+1
View File
@@ -377,6 +377,7 @@ header p {
}
.site-dialog { width:min(620px,calc(100vw - 32px)); }
.site-dialog-error { margin:0 24px 14px; padding:10px 12px; border:1px solid #e5b7b7; border-radius:5px; background:#fff2f2; color:#a52f2f; font-size:13px; }
.store-domain-preview { color:#718087; font-size:12px; font-weight:400; }
.primary:disabled {
opacity: 0.5;
cursor: not-allowed;