账户登录

This commit is contained in:
张锐 committed 2026-11-22 10:14:44 +08:00
1 parent a0c723cdcc
commit 3b555ae815
37 files changed
+728 -26

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
import React, { useEffect, useMemo, useState } from "react";
import { ChevronDown, ChevronRight, Edit3, Plus, X } from "lucide-react";
import { API } from "./api";
const API = "http://localhost:8081/api/admin/v1";
const SITE = "SIT0000000000001";
type ContentType = "NEWS" | "CASE" | "HELP";
type Category = { categoryCode: string; parentCategoryCode: string; categoryName: string; slug: string; description?: string; sortNo: number; status: string };
+2 -2
View File
@@ -4,8 +4,8 @@ import StarterKit from "@tiptap/starter-kit";
import Link from "@tiptap/extension-link";
import Image from "@tiptap/extension-image";
import { ArrowLeft, Bold, Heading2, Heading3, Image as ImageIcon, Italic, Link as LinkIcon, List, Plus, Redo2, Save, Trash2, Undo2 } from "lucide-react";
import { API, assetUrl } from "./api";
const API = "http://localhost:8081/api/admin/v1";
const SITE = "SIT0000000000001";
type ContentType = "NEWS" | "CASE" | "HELP";
type Heading = { level: number; text: string; sortNo: number };
@@ -69,7 +69,7 @@ export default function ContentEditor({ contentType, contentCode, onBack }: Prop
return <div className="product-editor"><div className="editor-top"><div className="breadcrumb-title"><button className="back" onClick={onBack}><ArrowLeft size={17}/>{meta.label}管理</button><span>/</span><h1>{contentCode ? `编辑${meta.label}` : `新增${meta.label}`}</h1>{notice&&<em>{notice}</em>}</div><div className="editor-actions"><button onClick={onBack}>取消</button><button className="primary" disabled={saving || !form.title || !form.slug} onClick={save}><Save size={16}/>{saving ? "保存中" : "保存"}</button></div></div><div className="editor-layout"><div className="editor-main">
<section className="edit-section"><h2>基础信息</h2><div className="edit-grid"><Field label={`${meta.label}标题 *`}><input value={form.title} onChange={(event) => setForm({ ...form, title: event.target.value })}/></Field><Field label="英文路径 *"><input value={form.slug} onChange={(event) => setForm({ ...form, slug: event.target.value.toLowerCase().replace(/[^a-z0-9-]/g, "-") })}/></Field><Field label="作者"><input value={form.authorName || ""} onChange={(event) => setForm({ ...form, authorName: event.target.value })}/></Field><Field label="来源"><input value={form.sourceName || ""} onChange={(event) => setForm({ ...form, sourceName: event.target.value })}/></Field><Field label="排序"><input type="number" value={form.sortNo} onChange={(event) => setForm({ ...form, sortNo: Number(event.target.value) })}/></Field><Field wide label={`${meta.label}简介 *`}><textarea rows={4} value={form.summary || ""} onChange={(event) => setForm({ ...form, summary: event.target.value })}/></Field></div></section>
<section className="edit-section"><h2>{meta.label}封面</h2><div className="cover-upload">{form.coverMediaUrl ? <img src={`http://localhost:8081${form.coverMediaUrl}`} alt={`${meta.label}封面预览`}/> : <ImageIcon size={42}/>}<label><span>选择图片</span><input type="file" accept="image/jpeg,image/png,image/webp,image/gif" onChange={(event) => upload(event.target.files?.[0])}/></label><p>支持 JPG、PNG、WebP、GIF,单图不超过 10MB</p></div></section>
<section className="edit-section"><h2>{meta.label}封面</h2><div className="cover-upload">{form.coverMediaUrl ? <img src={assetUrl(form.coverMediaUrl)} alt={`${meta.label}封面预览`}/> : <ImageIcon size={42}/>}<label><span>选择图片</span><input type="file" accept="image/jpeg,image/png,image/webp,image/gif" onChange={(event) => upload(event.target.files?.[0])}/></label><p>支持 JPG、PNG、WebP、GIF,单图不超过 10MB</p></div></section>
<section className="edit-section"><h2>{meta.label}详情 *</h2><div className="rich-editor"><div className="rich-toolbar"><Tool title="撤销" onClick={() => editor?.chain().focus().undo().run()}><Undo2/></Tool><Tool title="重做" onClick={() => editor?.chain().focus().redo().run()}><Redo2/></Tool><Tool title="粗体" active={editor?.isActive("bold")} onClick={() => editor?.chain().focus().toggleBold().run()}><Bold/></Tool><Tool title="斜体" active={editor?.isActive("italic")} onClick={() => editor?.chain().focus().toggleItalic().run()}><Italic/></Tool><Tool title="二级标题" active={editor?.isActive("heading", { level: 2 })} onClick={() => editor?.chain().focus().toggleHeading({ level: 2 }).run()}><Heading2/></Tool><Tool title="三级标题" active={editor?.isActive("heading", { level: 3 })} onClick={() => editor?.chain().focus().toggleHeading({ level: 3 }).run()}><Heading3/></Tool><Tool title="项目列表" onClick={() => editor?.chain().focus().toggleBulletList().run()}><List/></Tool><Tool title="链接" onClick={addLink}><LinkIcon/></Tool><Tool title="插入图片" onClick={addImage}><ImageIcon/></Tool></div><EditorContent editor={editor}/></div></section>
</div><aside className="editor-side"><section className="edit-section"><h2>发布</h2><Field label="状态"><select value={form.status} onChange={(event) => setForm({ ...form, status: event.target.value })}><option value="DRAFT">草稿</option><option value="PUBLISHED">上架</option><option value="OFFLINE">下线</option></select></Field><label className="check"><input type="checkbox" checked={form.featured} onChange={(event) => setForm({ ...form, featured: event.target.checked })}/>推荐内容</label></section><section className="edit-section"><h2>搜索引擎优化</h2><Field label="SEO 标题"><input maxLength={70} value={seo.title} onChange={(event) => setSeo({ ...seo, title: event.target.value })}/></Field><Field label="SEO 描述"><textarea maxLength={160} rows={4} value={seo.description} onChange={(event) => setSeo({ ...seo, description: event.target.value })}/></Field><Field label="SEO 关键词"><input value={seo.keywords} onChange={(event) => setSeo({ ...seo, keywords: event.target.value })}/></Field><Field label="H1"><input maxLength={120} value={seo.h1} onChange={(event) => setSeo({ ...seo, h1: event.target.value })}/></Field><Field label="Canonical"><input value={seo.canonicalUrl} placeholder={`/${meta.route}/${form.slug}`} onChange={(event) => setSeo({ ...seo, canonicalUrl: event.target.value })}/></Field><div className="section-head"><h3>H2 / H3 标签</h3><button onClick={() => setHeadings([...headings, { level: 2, text: "", sortNo: headings.length }])}><Plus size={15}/></button></div>{headings.map((heading, index) => <div className="heading-row" key={index}><select value={heading.level} onChange={(event) => setHeadings(headings.map((item, position) => position === index ? { ...item, level: Number(event.target.value) } : item))}><option value={2}>H2</option><option value={3}>H3</option></select><input value={heading.text} onChange={(event) => setHeadings(headings.map((item, position) => position === index ? { ...item, text: event.target.value } : item))}/><button onClick={() => setHeadings(headings.filter((_, position) => position !== index))}><Trash2 size={15}/></button></div>)}</section></aside></div></div>;
}
+1 -1
View File
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import { Code2, Pencil, Plus, Trash2 } from "lucide-react";
import { API } from "./api";
const API = "http://localhost:8081/api/admin/v1";
const SITE = "SIT0000000000001";
type CodeItem = { code:string; siteCode:string; title:string; content:string; locale:string; device:string; position:string; enabled:boolean; sortNo:number };
async function post(path:string, body:unknown) { const r=await fetch(API+path,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(body)}); if(!r.ok) throw new Error("请求失败"); return r.json(); }
+1 -1
View File
@@ -1,7 +1,7 @@
import { useEffect, useMemo, useState } from "react";
import { ChevronDown, ChevronUp, Copy, Eye, EyeOff, GripVertical, Monitor, Plus, Redo2, Save, Smartphone, Tablet, Trash2, Undo2, X, ExternalLink } from "lucide-react";
import { API } from "./api";
const API = "http://localhost:8081/api/admin/v1";
const SITE = "SIT0000000000001";
type Viewport = "desktop" | "tablet" | "mobile";
type SectionType = "ANNOUNCEMENT" | "HEADER" | "HERO" | "RICH_TEXT" | "PRODUCTS" | "CONTENT" | "INQUIRY" | "FOOTER";
+1 -1
View File
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";
import { ArrowLeft, Edit3, Plus, Save, Trash2 } from "lucide-react";
import { API } from "./api";
const API = "http://localhost:8081/api/admin/v1";
const SITE = "SIT0000000000001";
type Field = {
fieldCode?: string;
+39
View File
@@ -0,0 +1,39 @@
import { FormEvent, useState } from "react";
import { Eye, EyeOff, LockKeyhole, UserRound } from "lucide-react";
import { apiPost } from "./api";
export type Account = { userCode: string; siteCode: string; username: string; displayName: string };
export default function LoginPage({ onLogin }: { onLogin: (account: Account) => void }) {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [showPassword, setShowPassword] = useState(false);
const [error, setError] = useState("");
const [submitting, setSubmitting] = useState(false);
const submit = async (event: FormEvent) => {
event.preventDefault();
try {
setSubmitting(true);
setError("");
onLogin(await apiPost<Account>("/auth/login", { username, password }));
} catch (cause) {
setError(cause instanceof Error ? cause.message : "登录失败");
} finally {
setSubmitting(false);
}
};
return <div className="login-page">
<section className="login-panel">
<div className="login-brand"><span>S</span><div><strong>Shoplix</strong><small>运营中心</small></div></div>
<div className="login-copy"><h1>登录运营后台</h1><p>使用管理员账户继续管理网站内容和店铺设置。</p></div>
<form onSubmit={submit}>
<label><span>账户</span><div className="login-input"><UserRound size={18}/><input autoFocus autoComplete="username" value={username} onChange={event => setUsername(event.target.value)} placeholder="请输入账户"/></div></label>
<label><span>密码</span><div className="login-input"><LockKeyhole size={18}/><input type={showPassword ? "text" : "password"} autoComplete="current-password" value={password} onChange={event => setPassword(event.target.value)} placeholder="请输入密码"/><button type="button" aria-label={showPassword ? "隐藏密码" : "显示密码"} onClick={() => setShowPassword(!showPassword)}>{showPassword ? <EyeOff size={18}/> : <Eye size={18}/>}</button></div></label>
{error && <div className="login-error">{error}</div>}
<button className="login-submit" disabled={submitting || !username.trim() || !password}>{submitting ? "登录中..." : "登录"}</button>
</form>
</section>
</div>;
}
+2 -2
View File
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import { ImageOff, Search } from "lucide-react";
import { API, assetUrl } from "./api";
const API = "http://localhost:8081/api/admin/v1";
const SITE = "SIT0000000000001";
type Media = {
@@ -93,7 +93,7 @@ export default function MediaCenter() {
<video src={item.url} controls />
) : (
<img
src={`http://localhost:8081${item.url}`}
src={assetUrl(item.url)}
alt={item.altText || item.originalFileName}
/>
)}
+1 -1
View File
@@ -4,8 +4,8 @@ import StarterKit from "@tiptap/starter-kit";
import Link from "@tiptap/extension-link";
import Image from "@tiptap/extension-image";
import { ArrowLeft, Bold, Heading2, Heading3, Image as ImageIcon, Italic, Link as LinkIcon, List, Plus, Redo2, Save, Trash2, Undo2 } from "lucide-react";
import { API } from "./api";
const API = "http://localhost:8081/api/admin/v1";
const SITE = "SIT0000000000001";
type Heading = { level: number; text: string; sortNo: number };
type Props = { pageCode?: string; onBack: () => void };
+2 -2
View File
@@ -4,8 +4,8 @@ import StarterKit from '@tiptap/starter-kit';
import Link from '@tiptap/extension-link';
import Image from '@tiptap/extension-image';
import {ArrowLeft,Bold,Heading2,Heading3,Image as ImageIcon,Italic,Link as LinkIcon,List,Plus,Save,Trash2,Undo2,Redo2} from 'lucide-react';
import {API,assetUrl} from './api';
const API='http://localhost:8081/api/admin/v1';
const SITE='SIT0000000000001';
async function post(path:string,body:unknown){const r=await fetch(API+path,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});if(!r.ok)throw new Error((await r.json()).message||'请求失败');return r.json()}
type Attribute={attributeCode?:string;attributeName:string;value:string;unit:string;sortNo:number};
@@ -25,7 +25,7 @@ export default function ProductEditor({productCode,onBack}:Props){
const addLink=()=>{const href=window.prompt('请输入链接地址');if(href)editor?.chain().focus().setLink({href}).run()};const addImage=()=>{const src=window.prompt('请输入图片地址');if(src)editor?.chain().focus().setImage({src}).run()};
return <div className="product-editor"><div className="editor-top"><div className="breadcrumb-title"><button className="back" onClick={onBack}><ArrowLeft size={17}/>产品管理</button><span>/</span><h1>{productCode?'编辑产品':'新增产品'}</h1>{notice&&<em>{notice}</em>}</div><div className="editor-actions"><button onClick={onBack}>取消</button><button className="primary" disabled={saving||!form.productName||!form.slug} onClick={save}><Save size={16}/>{saving?'保存中':'保存'}</button></div></div><div className="editor-layout"><div className="editor-main">
<section className="edit-section"><h2>基础信息</h2><div className="edit-grid"><Field label="产品标题 *"><input value={form.productName} onChange={e=>setForm({...form,productName:e.target.value})}/></Field><Field label="英文路径 *"><input value={form.slug} onChange={e=>setForm({...form,slug:e.target.value.toLowerCase().replace(/[^a-z0-9-]/g,'-')})}/></Field><Field label="产品分类"><select value={form.primaryCategoryCode} onChange={e=>setForm({...form,primaryCategoryCode:e.target.value})}><option value="">请选择</option>{categories.map(x=><option key={x.categoryCode} value={x.categoryCode}>{x.categoryName}</option>)}</select></Field><Field label="产品型号"><input value={form.model||''} onChange={e=>setForm({...form,model:e.target.value})}/></Field><Field label="排序"><input type="number" value={form.sortNo} onChange={e=>setForm({...form,sortNo:Number(e.target.value)})}/></Field><Field wide label="产品简介 *"><textarea rows={4} value={form.summary||''} onChange={e=>setForm({...form,summary:e.target.value})}/></Field></div></section>
<section className="edit-section"><h2>产品主图</h2><div className="cover-upload">{form.coverMediaUrl?<img src={`http://localhost:8081${form.coverMediaUrl}`} alt="产品主图预览"/>:<ImageIcon size={42}/>}<label><span>选择图片</span><input type="file" accept="image/jpeg,image/png,image/webp,image/gif" onChange={e=>upload(e.target.files?.[0])}/></label><p>支持 JPG、PNG、WebP、GIF,单图不超过 10MB</p></div></section>
<section className="edit-section"><h2>产品主图</h2><div className="cover-upload">{form.coverMediaUrl?<img src={assetUrl(form.coverMediaUrl)} alt="产品主图预览"/>:<ImageIcon size={42}/>}<label><span>选择图片</span><input type="file" accept="image/jpeg,image/png,image/webp,image/gif" onChange={e=>upload(e.target.files?.[0])}/></label><p>支持 JPG、PNG、WebP、GIF,单图不超过 10MB</p></div></section>
<section className="edit-section"><div className="section-head"><h2>产品属性</h2><button onClick={()=>setAttributes([...attributes,{attributeName:'',value:'',unit:'',sortNo:attributes.length}])}><Plus size={16}/>添加属性</button></div>{attributes.map((a,i)=><div className="repeat-row" key={i}><input placeholder="Attribute name" value={a.attributeName} onChange={e=>setAttributes(attributes.map((x,j)=>j===i?{...x,attributeName:e.target.value}:x))}/><input placeholder="Value" value={a.value} onChange={e=>setAttributes(attributes.map((x,j)=>j===i?{...x,value:e.target.value}:x))}/><input placeholder="Unit" value={a.unit||''} onChange={e=>setAttributes(attributes.map((x,j)=>j===i?{...x,unit:e.target.value}:x))}/><button title="删除属性" onClick={()=>setAttributes(attributes.filter((_,j)=>j!==i))}><Trash2 size={17}/></button></div>)}</section>
<section className="edit-section"><div className="section-head"><h2>弱规格参数</h2><button onClick={()=>setSpecifications([...specifications,{groupName:'',name:'',value:'',unit:'',sortNo:specifications.length}])}><Plus size={16}/>添加规格</button></div>{specifications.map((s,i)=><div className="repeat-row specs-row" key={i}><input placeholder="Group" value={s.groupName||''} onChange={e=>setSpecifications(specifications.map((x,j)=>j===i?{...x,groupName:e.target.value}:x))}/><input placeholder="Name" value={s.name} onChange={e=>setSpecifications(specifications.map((x,j)=>j===i?{...x,name:e.target.value}:x))}/><input placeholder="Value" value={s.value} onChange={e=>setSpecifications(specifications.map((x,j)=>j===i?{...x,value:e.target.value}:x))}/><input placeholder="Unit" value={s.unit||''} onChange={e=>setSpecifications(specifications.map((x,j)=>j===i?{...x,unit:e.target.value}:x))}/><button title="删除规格" onClick={()=>setSpecifications(specifications.filter((_,j)=>j!==i))}><Trash2 size={17}/></button></div>)}</section>
<section className="edit-section"><h2>产品详情 *</h2><div className="rich-editor"><div className="rich-toolbar"><Tool title="撤销" onClick={()=>editor?.chain().focus().undo().run()}><Undo2/></Tool><Tool title="重做" onClick={()=>editor?.chain().focus().redo().run()}><Redo2/></Tool><Tool title="粗体" active={editor?.isActive('bold')} onClick={()=>editor?.chain().focus().toggleBold().run()}><Bold/></Tool><Tool title="斜体" active={editor?.isActive('italic')} onClick={()=>editor?.chain().focus().toggleItalic().run()}><Italic/></Tool><Tool title="二级标题" active={editor?.isActive('heading',{level:2})} onClick={()=>editor?.chain().focus().toggleHeading({level:2}).run()}><Heading2/></Tool><Tool title="三级标题" active={editor?.isActive('heading',{level:3})} onClick={()=>editor?.chain().focus().toggleHeading({level:3}).run()}><Heading3/></Tool><Tool title="项目列表" onClick={()=>editor?.chain().focus().toggleBulletList().run()}><List/></Tool><Tool title="链接" onClick={addLink}><LinkIcon/></Tool><Tool title="插入图片" onClick={addImage}><ImageIcon/></Tool></div><EditorContent editor={editor}/></div></section>
+33
View File
@@ -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<StoreProfile>({ 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<StoreProfile>("/store/detail", { siteCode: account.siteCode }).then(setStore).catch(cause => setError(cause instanceof Error ? cause.message : "加载失败")); }, [account.siteCode]);
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(); }, "");
return <div className="account-settings">
<header><div><h1>系统设置</h1><p>维护店铺资料、登录账户和密码。</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>}
<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 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>
</div>;
}
+25
View File
@@ -0,0 +1,25 @@
export const API = "/api/admin/v1";
export type ApiErrorBody = { message?: string };
/** 统一发送管理后台 JSON 请求,并在会话失效时通知应用返回登录页。 */
export async function apiPost<T = any>(path: string, body: unknown = {}): Promise<T> {
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<T>;
}
/** 将后端返回的相对素材地址转换为当前域名下的可访问地址。 */
export function assetUrl(url?: string): string {
return url || "";
}
+36 -14
View File
@@ -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<Section, string> = {
products: "产品", "product-categories": "产品分类", NEWS: "新闻", "NEWS-categories": "新闻分类",
CASE: "案例", "CASE-categories": "案例分类", HELP: "帮助", "HELP-categories": "帮助分类",
pages: "页面", decoration: "店铺装修", "custom-code": "自定义代码", media: "素材中心", inquiries: "询盘", "inquiry-settings": "询盘设置",
settings: "系统设置",
};
const statusLabels: Record<string, string> = { DRAFT: "草稿", PUBLISHED: "已上架", OFFLINE: "已下架" };
function App() {
function App({ account, onAccount, onLogout }: { account: Account; onAccount: (value: Account) => void; onLogout: () => void }) {
const contentRoutes: Record<EditorialSection, string> = { 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() {
<Settings size={18} />
询盘设置
</button>
<button className={section === "settings" ? "active" : ""} onClick={() => navigateSection("settings")}>
<Settings size={18} />
系统设置
</button>
</div>
</aside>
<main>
{section === "decoration" ? <DecorationEditor onBack={() => navigateSection("pages")}/> : section === "custom-code" ? <CustomCodeManager/> : section === "media" ? <MediaCenter/> : editingProduct !== null ? <ProductEditor productCode={editingProduct || undefined} onBack={closeProductEditor} /> : editingContent !== null ? <ContentEditor contentType={editingContent.contentType} contentCode={editingContent.contentCode || undefined} onBack={closeContentEditor} /> : editingPage !== null ? <PageEditor pageCode={editingPage || undefined} onBack={closePageEditor}/> : <>
{section === "settings" ? <SettingsPage account={account} onAccount={onAccount} onLogout={onLogout}/> : section === "decoration" ? <DecorationEditor onBack={() => navigateSection("pages")}/> : section === "custom-code" ? <CustomCodeManager/> : section === "media" ? <MediaCenter/> : editingProduct !== null ? <ProductEditor productCode={editingProduct || undefined} onBack={closeProductEditor} /> : editingContent !== null ? <ContentEditor contentType={editingContent.contentType} contentCode={editingContent.contentCode || undefined} onBack={closeContentEditor} /> : editingPage !== null ? <PageEditor pageCode={editingPage || undefined} onBack={closePageEditor}/> : <>
{section.endsWith("-categories") ? <CategoryManager contentType={section === "NEWS-categories" ? "NEWS" : section === "CASE-categories" ? "CASE" : section === "HELP-categories" ? "HELP" : undefined}/> : <>
<header>
<div>
@@ -481,8 +483,28 @@ function App() {
</div>
);
}
function RootApp() {
const [account, setAccount] = useState<Account | null>(null);
const [checking, setChecking] = useState(true);
useEffect(() => {
const unauthorized = () => setAccount(null);
window.addEventListener("shoplix:unauthorized", unauthorized);
apiPost<Account>("/auth/me")
.then(setAccount)
.catch(() => setAccount(null))
.finally(() => setChecking(false));
return () => window.removeEventListener("shoplix:unauthorized", unauthorized);
}, []);
if (checking) return <div className="auth-loading"><div className="auth-spinner"/><span>正在验证登录状态</span></div>;
if (!account) return <LoginPage onLogin={setAccount}/>;
return <App account={account} onAccount={setAccount} onLogout={() => setAccount(null)}/>;
}
createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
<RootApp />
</React.StrictMode>,
);
+4
View File
@@ -414,3 +414,7 @@ header p {
.inquiry-editor-layout{grid-template-columns:1fr}.form-field-row{grid-template-columns:1fr}.form-list-row{grid-template-columns:1fr}.forms-heading{align-items:flex-start;gap:12px}
}
.form-field-row{grid-template-columns:repeat(3,minmax(0,1fr)) auto;gap:12px;align-items:end;padding:16px;border:1px solid #e1e6e9;border-radius:5px;background:#fafbfb}.form-field-row>label:not(.field-check){display:grid;gap:6px}.form-field-row>label:not(.field-check)>span{font-size:12px;font-weight:700;color:#52605d}.form-field-row .field-check{display:flex;align-items:center;gap:5px;height:38px;font-size:12px}.inquiry-table{overflow-x:auto}.inquiry-table .thead,.inquiry-table .row{min-width:1120px;grid-template-columns:1.25fr 1.7fr 1.35fr 1fr 1fr .8fr .65fr}.inquiry-table .row>span{min-width:0}.inquiry-table .row>span:nth-child(2){overflow:hidden;text-overflow:ellipsis;white-space:nowrap}@media(max-width:900px){.form-field-row{grid-template-columns:1fr 1fr}}
.auth-loading{min-height:100vh;display:flex;align-items:center;justify-content:center;gap:12px;color:#66737d;background:#f4f6f8}.auth-spinner{width:24px;height:24px;border:2px solid #d4ddda;border-top-color:#176b5b;border-radius:50%;animation:auth-spin .8s linear infinite}@keyframes auth-spin{to{transform:rotate(360deg)}}
.login-page{min-height:100vh;display:grid;place-items:center;padding:24px;background:#eef2f3}.login-panel{width:min(430px,100%);background:#fff;border:1px solid #dfe5e9;border-radius:8px;padding:38px;box-shadow:0 18px 48px rgba(19,37,45,.1)}.login-brand{display:flex;align-items:center;gap:12px;margin-bottom:38px}.login-brand>span{width:48px;height:48px;border-radius:7px;background:#efbd43;display:grid;place-items:center;color:#13202b;font-size:24px;font-weight:700}.login-brand>div{display:grid}.login-brand strong{font-size:23px}.login-brand small{color:#77858e}.login-copy h1{font-size:26px;margin:0 0 9px}.login-copy p{margin:0 0 28px;color:#74818a;line-height:1.6}.login-panel form{display:grid;gap:18px}.login-panel label{display:grid;gap:8px}.login-panel label>span{font-size:13px;font-weight:600}.login-input{height:48px;border:1px solid #d6dde2;border-radius:5px;display:flex;align-items:center;padding:0 13px;gap:10px;color:#7b878f}.login-input:focus-within{border-color:#176b5b;box-shadow:0 0 0 3px rgba(23,107,91,.09)}.login-input input{border:0;outline:0;min-width:0;flex:1;font:inherit}.login-input button{border:0;background:transparent;padding:4px;color:#65727b;display:grid;place-items:center}.login-error{padding:10px 12px;border:1px solid #f0c9c9;background:#fff6f6;color:#a33b3b;border-radius:5px;font-size:13px}.login-submit{height:48px;border:0;border-radius:5px;background:#176b5b;color:#fff;font:inherit;font-weight:600;cursor:pointer}.login-submit:disabled{opacity:.55;cursor:not-allowed}
.account-settings{max-width:1500px;margin:0 auto}.account-settings>header{display:flex;align-items:flex-start;justify-content:space-between;margin-bottom:22px}.account-settings>header h1{margin:0 0 6px;font-size:28px}.account-settings>header p{margin:0;color:#71808a}.account-settings>header button{display:flex;align-items:center;gap:7px;border:1px solid #d8dee3;background:#fff;border-radius:5px;padding:10px 14px}.settings-message{margin-bottom:18px;padding:12px 15px;border:1px solid #bcdcd3;background:#eef8f5;color:#176b5b;border-radius:5px}.settings-message.error{border-color:#efcaca;background:#fff6f6;color:#9c3838}.settings-layout{display:grid;grid-template-columns:minmax(0,1.35fr) minmax(360px,.65fr);gap:20px;align-items:start}.settings-side{display:grid;gap:20px}.profile-card{background:#fff;border:1px solid #dfe5e9;border-radius:6px;padding:24px;display:grid;grid-template-columns:1fr 1fr;gap:18px}.settings-side .profile-card{grid-template-columns:1fr}.profile-card-title{grid-column:1/-1;display:flex;align-items:flex-start;gap:13px;padding-bottom:18px;border-bottom:1px solid #e8ecef}.profile-card-title>svg{color:#176b5b}.profile-card-title h2{font-size:18px;margin:0 0 5px}.profile-card-title p{font-size:13px;color:#77848d;margin:0;line-height:1.5}.profile-card label{display:grid;gap:7px}.profile-card label>span{font-size:13px;font-weight:600}.profile-card input,.profile-card textarea{border:1px solid #d8dee3;border-radius:5px;padding:11px 12px;font:inherit;resize:vertical}.profile-card .wide,.profile-actions{grid-column:1/-1}.profile-actions{display:flex;justify-content:flex-end;padding-top:4px}.profile-actions button{border:0;border-radius:5px;background:#176b5b;color:#fff;padding:10px 15px;display:flex;align-items:center;gap:7px;font:inherit;cursor:pointer}@media(max-width:1000px){.settings-layout{grid-template-columns:1fr}}@media(max-width:620px){.login-panel{padding:28px 22px}.profile-card{grid-template-columns:1fr}.profile-card .wide,.profile-actions{grid-column:auto}.account-settings>header{gap:14px}.account-settings>header p{display:none}}
+1 -1
View File
@@ -1 +1 @@
{"root":["./src/categorymanager.tsx","./src/contenteditor.tsx","./src/customcodemanager.tsx","./src/decorationeditor.tsx","./src/inquirysettingspanel.tsx","./src/pageeditor.tsx","./src/producteditor.tsx","./src/main.tsx","./src/vite-env.d.ts"],"version":"5.7.3"}
{"root":["./src/categorymanager.tsx","./src/contenteditor.tsx","./src/customcodemanager.tsx","./src/decorationeditor.tsx","./src/inquirysettingspanel.tsx","./src/loginpage.tsx","./src/mediacenter.tsx","./src/pageeditor.tsx","./src/producteditor.tsx","./src/settingspage.tsx","./src/api.ts","./src/main.tsx","./src/vite-env.d.ts"],"version":"5.7.3"}
+10
View File
@@ -0,0 +1,10 @@
import { defineConfig } from "vite";
export default defineConfig({
server: {
proxy: {
"/api": "http://localhost:8081",
"/uploads": "http://localhost:8081",
},
},
});