-
产品主图
{form.coverMediaUrl?

:
}支持 JPG、PNG、WebP、GIF,单图不超过 10MB
+
产品主图
{form.coverMediaUrl?
})
:
}支持 JPG、PNG、WebP、GIF,单图不超过 10MB
产品属性
{attributes.map((a,i)=>setAttributes(attributes.map((x,j)=>j===i?{...x,attributeName:e.target.value}:x))}/>setAttributes(attributes.map((x,j)=>j===i?{...x,value:e.target.value}:x))}/>setAttributes(attributes.map((x,j)=>j===i?{...x,unit:e.target.value}:x))}/>
)}
弱规格参数
{specifications.map((s,i)=>setSpecifications(specifications.map((x,j)=>j===i?{...x,groupName:e.target.value}:x))}/>setSpecifications(specifications.map((x,j)=>j===i?{...x,name:e.target.value}:x))}/>setSpecifications(specifications.map((x,j)=>j===i?{...x,value:e.target.value}:x))}/>setSpecifications(specifications.map((x,j)=>j===i?{...x,unit:e.target.value}:x))}/>
)}
产品详情 *
editor?.chain().focus().undo().run()}>editor?.chain().focus().redo().run()}>editor?.chain().focus().toggleBold().run()}>editor?.chain().focus().toggleItalic().run()}>editor?.chain().focus().toggleHeading({level:2}).run()}>editor?.chain().focus().toggleHeading({level:3}).run()}>editor?.chain().focus().toggleBulletList().run()}>
diff --git a/web-admin/src/SettingsPage.tsx b/web-admin/src/SettingsPage.tsx
new file mode 100644
index 0000000..641f5ac
--- /dev/null
+++ b/web-admin/src/SettingsPage.tsx
@@ -0,0 +1,33 @@
+import { FormEvent, useEffect, useState } from "react";
+import { KeyRound, LogOut, Save, Store, UserRound } from "lucide-react";
+import { apiPost } from "./api";
+import type { Account } from "./LoginPage";
+
+type StoreProfile = { siteCode: string; storeName: string; description: string; industry: string };
+
+export default function SettingsPage({ account, onAccount, onLogout }: { account: Account; onAccount: (value: Account) => void; onLogout: () => void }) {
+ const [store, setStore] = useState
({ siteCode: account.siteCode, storeName: "", description: "", industry: "" });
+ const [profile, setProfile] = useState({ username: account.username, displayName: account.displayName });
+ const [password, setPassword] = useState({ currentPassword: "", newPassword: "", confirmPassword: "" });
+ const [message, setMessage] = useState("");
+ const [error, setError] = useState("");
+
+ useEffect(() => { apiPost("/store/detail", { siteCode: account.siteCode }).then(setStore).catch(cause => setError(cause instanceof Error ? cause.message : "加载失败")); }, [account.siteCode]);
+ const run = async (operation: () => Promise, 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(); }, "");
+
+ return
+
+ {(message || error) &&
{error || message}
}
+
+
;
+}
diff --git a/web-admin/src/api.ts b/web-admin/src/api.ts
new file mode 100644
index 0000000..5ac5631
--- /dev/null
+++ b/web-admin/src/api.ts
@@ -0,0 +1,25 @@
+export const API = "/api/admin/v1";
+
+export type ApiErrorBody = { message?: string };
+
+/** 统一发送管理后台 JSON 请求,并在会话失效时通知应用返回登录页。 */
+export async function apiPost(path: string, body: unknown = {}): Promise {
+ const response = await fetch(API + path, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(body),
+ });
+ if (response.status === 401) {
+ window.dispatchEvent(new Event("shoplix:unauthorized"));
+ }
+ if (!response.ok) {
+ const error = (await response.json().catch(() => ({}))) as ApiErrorBody;
+ throw new Error(error.message || "请求失败");
+ }
+ return response.json() as Promise;
+}
+
+/** 将后端返回的相对素材地址转换为当前域名下的可访问地址。 */
+export function assetUrl(url?: string): string {
+ return url || "";
+}
diff --git a/web-admin/src/main.tsx b/web-admin/src/main.tsx
index 94e5521..6027eb9 100644
--- a/web-admin/src/main.tsx
+++ b/web-admin/src/main.tsx
@@ -27,11 +27,13 @@ import PageEditor from "./PageEditor";
import DecorationEditor from "./DecorationEditor";
import CustomCodeManager from "./CustomCodeManager";
import MediaCenter from "./MediaCenter";
+import LoginPage, { type Account } from "./LoginPage";
+import SettingsPage from "./SettingsPage";
+import { apiPost } from "./api";
-const API = "http://localhost:8081/api/admin/v1";
-const SITE_WEB = "http://localhost:5174";
+const SITE_WEB = window.location.hostname === "admin.steliro.com" ? "https://site.steliro.com" : "http://localhost:5174";
const SITE = "SIT0000000000001";
-type Section = "products" | "product-categories" | "NEWS" | "NEWS-categories" | "CASE" | "CASE-categories" | "HELP" | "HELP-categories" | "pages" | "decoration" | "custom-code" | "media" | "inquiries" | "inquiry-settings";
+type Section = "products" | "product-categories" | "NEWS" | "NEWS-categories" | "CASE" | "CASE-categories" | "HELP" | "HELP-categories" | "pages" | "decoration" | "custom-code" | "media" | "inquiries" | "inquiry-settings" | "settings";
type EditorialSection = "NEWS" | "CASE" | "HELP";
type ContentEditorState = { contentType: EditorialSection; contentCode: string };
type Item = {
@@ -62,14 +64,7 @@ type Item = {
};
async function post(path: string, body: unknown) {
- const response = await fetch(API + path, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify(body),
- });
- if (!response.ok)
- throw new Error((await response.json()).message || "请求失败");
- return response.json();
+ return apiPost(path, body);
}
const menus = [
@@ -83,10 +78,11 @@ const sectionLabels: Record = {
products: "产品", "product-categories": "产品分类", NEWS: "新闻", "NEWS-categories": "新闻分类",
CASE: "案例", "CASE-categories": "案例分类", HELP: "帮助", "HELP-categories": "帮助分类",
pages: "页面", decoration: "店铺装修", "custom-code": "自定义代码", media: "素材中心", inquiries: "询盘", "inquiry-settings": "询盘设置",
+ settings: "系统设置",
};
const statusLabels: Record = { DRAFT: "草稿", PUBLISHED: "已上架", OFFLINE: "已下架" };
-function App() {
+function App({ account, onAccount, onLogout }: { account: Account; onAccount: (value: Account) => void; onLogout: () => void }) {
const contentRoutes: Record = { NEWS: "news", CASE: "cases", HELP: "help" };
const resolveContentRoute = (): ContentEditorState | null => {
const match = window.location.pathname.match(/^\/(news|cases|help)\/(new|([^/]+)\/edit)$/);
@@ -136,6 +132,8 @@ function App() {
setError("");
const data =
section.endsWith("-categories")
+ ? { items: [] }
+ : section === "settings"
? { items: [] }
: section === "products"
? await post("/products/list", { siteCode: SITE })
@@ -322,10 +320,14 @@ function App() {
询盘设置
+