功能迭代
This commit is contained in:
1 parent
ed890edb85
commit
d1844ce9a2
80 files changed
+1799
-75
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import PageEditor from "./PageEditor";
|
||||
import { apiPost } from "./api";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
|
||||
/** 关于我们固定页面设置入口。 */
|
||||
export default function AboutUsSettingsPage() {
|
||||
|
||||
@@ -4,8 +4,9 @@ import { EditorContent, useEditor } from "@tiptap/react";
|
||||
import StarterKit from "@tiptap/starter-kit";
|
||||
import Link from "@tiptap/extension-link";
|
||||
import { apiPost } from "./api";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
const AGREEMENT_PUBLISH_STATUS = "PUBLISHED";
|
||||
type AgreementKey = "COOKIE_POLICY" | "PRIVACY_POLICY" | "TERMS_OF_SERVICE";
|
||||
type AgreementTab = { key: AgreementKey; label: string; pageName: string; slug: string; seoDescription:string; robots:string };
|
||||
|
||||
@@ -9,8 +9,9 @@ import {
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { API } from "./api";
|
||||
import { statusLabel } from "./statusLabels";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
type ContentType = "NEWS" | "CASE" | "HELP";
|
||||
type Category = {
|
||||
categoryCode: string;
|
||||
|
||||
@@ -22,8 +22,9 @@ import {
|
||||
X,
|
||||
} from "lucide-react";
|
||||
import { API, assetUrl } from "./api";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
type ContentType = "NEWS" | "CASE" | "HELP";
|
||||
type Heading = { level: number; text: string; sortNo: number };
|
||||
type MediaItem = {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
.crm-page{max-width:1500px;margin:auto}.crm-actions{display:flex;gap:9px}.crm-actions .secondary,.crm-import{height:40px;border:1px solid #d5dce2;background:#fff;color:#34424d;border-radius:6px;padding:0 14px;display:inline-flex;align-items:center;gap:7px;font-weight:600;cursor:pointer}.crm-import input{display:none}.crm-toolbar{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px}.crm-toolbar form{width:min(540px,60vw);height:42px;display:flex;align-items:center;gap:8px;border:1px solid #d9e0e5;background:#fff;border-radius:6px;padding-left:12px}.crm-toolbar input{min-width:0;flex:1;border:0;outline:0}.crm-toolbar button{height:100%;border:0;border-left:1px solid #e1e6e9;background:#f8faf9;padding:0 18px}.crm-toolbar>span{color:#718087}.crm-table{background:#fff;border:1px solid #dfe5e9;border-radius:6px;overflow:hidden}.crm-row{display:grid;grid-template-columns:1.35fr 1.35fr .7fr 1.2fr .5fr .6fr;gap:16px;align-items:center;min-height:72px;padding:12px 18px;border-bottom:1px solid #edf0f2}.crm-row:last-child{border:0}.crm-head{min-height:44px;background:#f8fafb;color:#6d7983;font-size:12px;font-weight:600}.crm-row>div{min-width:0;display:grid;gap:4px}.crm-row strong,.crm-row small,.crm-row span{overflow:hidden;text-overflow:ellipsis}.crm-row small{color:#839099}.crm-social{display:flex!important;grid-auto-flow:column;justify-content:start}.crm-social a{width:30px;height:30px;display:grid;place-items:center;border:1px solid #dce3e0;border-radius:4px;color:#176b5b}.crm-social svg{width:15px}.crm-tags{display:flex!important;flex-wrap:wrap;gap:5px}.crm-tags span{border:1px solid;border-radius:12px;padding:2px 7px;font-size:11px}.crm-empty{padding:70px;text-align:center;color:#839099}.crm-pages{display:flex;justify-content:center;align-items:center;gap:12px;margin-top:18px}.crm-pages button{border:1px solid #d5ddda;background:#fff;padding:8px 14px;border-radius:4px}.crm-dialog{width:min(850px,100%)}.crm-tag-dialog{width:min(520px,100%)}.crm-tag-options{border:1px solid #d9dee5;border-radius:5px;padding:12px;display:flex!important;flex-wrap:wrap;gap:12px!important}.crm-tag-options legend{font-size:13px;font-weight:600;padding:0 5px}.crm-tag-options label{display:flex!important;align-items:center;gap:6px}.crm-tag-options input{width:16px;height:16px}.crm-tag-options span{font-weight:500!important}@media(max-width:900px){.crm-row{grid-template-columns:1fr 1fr}.crm-head{display:none}.crm-actions{flex-wrap:wrap}.crm-toolbar{align-items:flex-start;gap:10px}.crm-toolbar form{width:100%}}
|
||||
@@ -0,0 +1,490 @@
|
||||
import { FormEvent, useEffect, useState } from "react";
|
||||
import {
|
||||
Facebook,
|
||||
Globe2,
|
||||
Instagram,
|
||||
Linkedin,
|
||||
Plus,
|
||||
Search,
|
||||
Tags,
|
||||
Upload,
|
||||
X,
|
||||
} from "lucide-react";
|
||||
import { apiPost } from "./api";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
import "./CrmCustomerPage.css";
|
||||
|
||||
type Tag = { tagCode: string; tagName: string; color: string };
|
||||
type Customer = {
|
||||
customerCode: string;
|
||||
companyName: string;
|
||||
contactName: string;
|
||||
website: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
country: string;
|
||||
facebookUrl: string;
|
||||
instagramUrl: string;
|
||||
linkedinUrl: string;
|
||||
whatsapp: string;
|
||||
remark: string;
|
||||
source: string;
|
||||
status: string;
|
||||
tags: Tag[];
|
||||
createTime: string;
|
||||
};
|
||||
const SITE = getCurrentSiteCode();
|
||||
const emptyForm = {
|
||||
customerCode: "",
|
||||
companyName: "",
|
||||
contactName: "",
|
||||
website: "",
|
||||
email: "",
|
||||
phone: "",
|
||||
country: "",
|
||||
facebookUrl: "",
|
||||
instagramUrl: "",
|
||||
linkedinUrl: "",
|
||||
whatsapp: "",
|
||||
remark: "",
|
||||
tagCodes: [] as string[],
|
||||
};
|
||||
|
||||
/** 解析支持引号转义的 CSV 文本。 */
|
||||
function parseCsv(text: string): string[][] {
|
||||
const rows: string[][] = [];
|
||||
let row: string[] = [];
|
||||
let value = "";
|
||||
let quoted = false;
|
||||
for (let index = 0; index < text.length; index += 1) {
|
||||
const char = text[index];
|
||||
if (char === '"' && quoted && text[index + 1] === '"') {
|
||||
value += '"';
|
||||
index += 1;
|
||||
} else if (char === '"') quoted = !quoted;
|
||||
else if (char === "," && !quoted) {
|
||||
row.push(value.trim());
|
||||
value = "";
|
||||
} else if ((char === "\n" || char === "\r") && !quoted) {
|
||||
if (char === "\r" && text[index + 1] === "\n") index += 1;
|
||||
row.push(value.trim());
|
||||
if (row.some(Boolean)) rows.push(row);
|
||||
row = [];
|
||||
value = "";
|
||||
} else value += char;
|
||||
}
|
||||
row.push(value.trim());
|
||||
if (row.some(Boolean)) rows.push(row);
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** CRM 客户管理页面。 */
|
||||
export default function CrmCustomerPage() {
|
||||
const [items, setItems] = useState<Customer[]>([]);
|
||||
const [tags, setTags] = useState<Tag[]>([]);
|
||||
const [query, setQuery] = useState("");
|
||||
const [pageNo, setPageNo] = useState(1);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [totalPages, setTotalPages] = useState(0);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState("");
|
||||
const [dialog, setDialog] = useState(false);
|
||||
const [form, setForm] = useState(emptyForm);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [tagDialog, setTagDialog] = useState(false);
|
||||
const [tagForm, setTagForm] = useState({ tagName: "", color: "#176b5b" });
|
||||
const [importing, setImporting] = useState(false);
|
||||
/** 加载客户分页。 */ const load = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
const data = await apiPost<{
|
||||
items: Customer[];
|
||||
total: number;
|
||||
totalPages: number;
|
||||
tags: Tag[];
|
||||
}>("/crm/customers/page", {
|
||||
siteCode: SITE,
|
||||
keyword: query.trim(),
|
||||
pageNo,
|
||||
pageSize: 20,
|
||||
});
|
||||
setItems(data.items);
|
||||
setTags(data.tags);
|
||||
setTotal(data.total);
|
||||
setTotalPages(data.totalPages);
|
||||
} catch (reason) {
|
||||
setError(reason instanceof Error ? reason.message : "客户加载失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [pageNo]);
|
||||
/** 打开新增或编辑客户弹窗。 */ const edit = (customer?: Customer) => {
|
||||
setForm(
|
||||
customer
|
||||
? { ...customer, tagCodes: customer.tags.map((tag) => tag.tagCode) }
|
||||
: emptyForm,
|
||||
);
|
||||
setDialog(true);
|
||||
};
|
||||
/** 保存客户资料。 */ const save = async (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
try {
|
||||
setSaving(true);
|
||||
setError("");
|
||||
await apiPost("/crm/customers/save", { siteCode: SITE, ...form });
|
||||
setDialog(false);
|
||||
await load();
|
||||
} catch (reason) {
|
||||
setError(reason instanceof Error ? reason.message : "客户保存失败");
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
/** 创建客户标签。 */ const createTag = async (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
try {
|
||||
await apiPost("/crm/customers/tags/create", {
|
||||
siteCode: SITE,
|
||||
...tagForm,
|
||||
});
|
||||
setTagDialog(false);
|
||||
setTagForm({ tagName: "", color: "#176b5b" });
|
||||
await load();
|
||||
} catch (reason) {
|
||||
setError(reason instanceof Error ? reason.message : "标签创建失败");
|
||||
}
|
||||
};
|
||||
/** 导入 CSV 客户文件。 */ const importCsv = async (file?: File) => {
|
||||
if (!file) return;
|
||||
try {
|
||||
setImporting(true);
|
||||
setError("");
|
||||
const rows = parseCsv(await file.text());
|
||||
if (rows.length < 2) throw new Error("CSV 文件没有客户数据");
|
||||
const headers = rows[0].map((value) => value.toLowerCase());
|
||||
const field = (row: string[], name: string) =>
|
||||
row[headers.indexOf(name)] || "";
|
||||
const imported = rows
|
||||
.slice(1)
|
||||
.map((row) => ({
|
||||
companyName: field(row, "companyname"),
|
||||
contactName: field(row, "contactname"),
|
||||
website: field(row, "website"),
|
||||
email: field(row, "email"),
|
||||
phone: field(row, "phone"),
|
||||
country: field(row, "country"),
|
||||
facebookUrl: field(row, "facebookurl"),
|
||||
instagramUrl: field(row, "instagramurl"),
|
||||
linkedinUrl: field(row, "linkedinurl"),
|
||||
whatsapp: field(row, "whatsapp"),
|
||||
remark: field(row, "remark"),
|
||||
}));
|
||||
await apiPost("/crm/customers/import", {
|
||||
siteCode: SITE,
|
||||
items: imported,
|
||||
});
|
||||
setPageNo(1);
|
||||
await load();
|
||||
} catch (reason) {
|
||||
setError(reason instanceof Error ? reason.message : "客户导入失败");
|
||||
} finally {
|
||||
setImporting(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="crm-page">
|
||||
<header>
|
||||
<div>
|
||||
<h1>客户列表</h1>
|
||||
<p>集中管理公司资料、联系人、社媒账号和客户标签</p>
|
||||
</div>
|
||||
<div className="crm-actions">
|
||||
<button className="secondary" onClick={() => setTagDialog(true)}>
|
||||
<Tags size={16} />
|
||||
新建标签
|
||||
</button>
|
||||
<label className="secondary crm-import">
|
||||
<Upload size={16} />
|
||||
{importing ? "导入中" : "导入客户"}
|
||||
<input
|
||||
type="file"
|
||||
accept=".csv,text/csv"
|
||||
disabled={importing}
|
||||
onChange={(event) => {
|
||||
void importCsv(event.target.files?.[0]);
|
||||
event.target.value = "";
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<button className="primary" onClick={() => edit()}>
|
||||
<Plus size={16} />
|
||||
新增客户
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
<div className="crm-toolbar">
|
||||
<form
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
setPageNo(1);
|
||||
void load();
|
||||
}}
|
||||
>
|
||||
<Search size={17} />
|
||||
<input
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder="搜索公司、联系人或邮箱"
|
||||
/>
|
||||
<button>搜索</button>
|
||||
</form>
|
||||
<span>共 {total} 个客户</span>
|
||||
</div>
|
||||
{error && <div className="notice">{error}</div>}
|
||||
<section className="crm-table">
|
||||
<div className="crm-row crm-head">
|
||||
<span>客户</span>
|
||||
<span>联系方式</span>
|
||||
<span>社媒</span>
|
||||
<span>标签</span>
|
||||
<span>来源</span>
|
||||
<span>操作</span>
|
||||
</div>
|
||||
{loading ? (
|
||||
<div className="crm-empty">正在加载客户</div>
|
||||
) : items.length === 0 ? (
|
||||
<div className="crm-empty">暂无客户,可新增或导入 CSV</div>
|
||||
) : (
|
||||
items.map((item) => (
|
||||
<div className="crm-row" key={item.customerCode}>
|
||||
<div>
|
||||
<strong>{item.companyName}</strong>
|
||||
<small>
|
||||
{item.contactName || item.country || item.customerCode}
|
||||
</small>
|
||||
</div>
|
||||
<div>
|
||||
<span>{item.email || "--"}</span>
|
||||
<small>{item.phone || item.website || "未填写联系方式"}</small>
|
||||
</div>
|
||||
<div className="crm-social">
|
||||
{item.website && (
|
||||
<a href={item.website} target="_blank" title="网站">
|
||||
<Globe2 />
|
||||
</a>
|
||||
)}
|
||||
{item.facebookUrl && (
|
||||
<a href={item.facebookUrl} target="_blank" title="Facebook">
|
||||
<Facebook />
|
||||
</a>
|
||||
)}
|
||||
{item.instagramUrl && (
|
||||
<a href={item.instagramUrl} target="_blank" title="Instagram">
|
||||
<Instagram />
|
||||
</a>
|
||||
)}
|
||||
{item.linkedinUrl && (
|
||||
<a href={item.linkedinUrl} target="_blank" title="LinkedIn">
|
||||
<Linkedin />
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
<div className="crm-tags">
|
||||
{item.tags.length ? (
|
||||
item.tags.map((tag) => (
|
||||
<span
|
||||
key={tag.tagCode}
|
||||
style={{ borderColor: tag.color, color: tag.color }}
|
||||
>
|
||||
{tag.tagName}
|
||||
</span>
|
||||
))
|
||||
) : (
|
||||
<small>未打标</small>
|
||||
)}
|
||||
</div>
|
||||
<span>{item.source === "IMPORT" ? "导入" : "手工新增"}</span>
|
||||
<button className="link" onClick={() => edit(item)}>
|
||||
查看 / 编辑
|
||||
</button>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</section>
|
||||
{totalPages > 1 && (
|
||||
<div className="crm-pages">
|
||||
<button disabled={pageNo === 1} onClick={() => setPageNo(pageNo - 1)}>
|
||||
上一页
|
||||
</button>
|
||||
<span>
|
||||
{pageNo} / {totalPages}
|
||||
</span>
|
||||
<button
|
||||
disabled={pageNo === totalPages}
|
||||
onClick={() => setPageNo(pageNo + 1)}
|
||||
>
|
||||
下一页
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{dialog && (
|
||||
<div className="mask">
|
||||
<form className="dialog crm-dialog" onSubmit={save}>
|
||||
<div className="dialog-head">
|
||||
<div>
|
||||
<h2>{form.customerCode ? "编辑客户" : "新增客户"}</h2>
|
||||
<p>维护公司、联系人和社媒触达信息</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="icon"
|
||||
onClick={() => setDialog(false)}
|
||||
>
|
||||
<X />
|
||||
</button>
|
||||
</div>
|
||||
<div className="form-grid">
|
||||
<label>
|
||||
<span>公司名称</span>
|
||||
<input
|
||||
maxLength={200}
|
||||
value={form.companyName}
|
||||
onChange={(event) =>
|
||||
setForm({ ...form, companyName: event.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<span>联系人</span>
|
||||
<input
|
||||
maxLength={100}
|
||||
value={form.contactName}
|
||||
onChange={(event) =>
|
||||
setForm({ ...form, contactName: event.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
{(
|
||||
[
|
||||
["email", "邮箱"],
|
||||
["phone", "电话"],
|
||||
["country", "国家/地区"],
|
||||
["website", "公司网站"],
|
||||
["facebookUrl", "Facebook"],
|
||||
["instagramUrl", "Instagram"],
|
||||
["linkedinUrl", "LinkedIn"],
|
||||
["whatsapp", "WhatsApp"],
|
||||
] as const
|
||||
).map(([key, label]) => (
|
||||
<label key={key}>
|
||||
<span>{label}</span>
|
||||
<input
|
||||
type={key === "email" ? "email" : "text"}
|
||||
value={form[key]}
|
||||
onChange={(event) =>
|
||||
setForm({ ...form, [key]: event.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
<fieldset className="wide crm-tag-options">
|
||||
<legend>客户标签</legend>
|
||||
{tags.map((tag) => (
|
||||
<label key={tag.tagCode}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.tagCodes.includes(tag.tagCode)}
|
||||
onChange={() =>
|
||||
setForm({
|
||||
...form,
|
||||
tagCodes: form.tagCodes.includes(tag.tagCode)
|
||||
? form.tagCodes.filter(
|
||||
(code) => code !== tag.tagCode,
|
||||
)
|
||||
: [...form.tagCodes, tag.tagCode],
|
||||
})
|
||||
}
|
||||
/>
|
||||
<span style={{ color: tag.color }}>{tag.tagName}</span>
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
<label className="wide">
|
||||
<span>备注</span>
|
||||
<textarea
|
||||
rows={4}
|
||||
maxLength={2000}
|
||||
value={form.remark}
|
||||
onChange={(event) =>
|
||||
setForm({ ...form, remark: event.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className="dialog-actions">
|
||||
<button type="button" onClick={() => setDialog(false)}>
|
||||
取消
|
||||
</button>
|
||||
<button className="primary" disabled={saving}>
|
||||
{saving ? "保存中" : "保存客户"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
)}
|
||||
{tagDialog && (
|
||||
<div className="mask">
|
||||
<form className="dialog crm-tag-dialog" onSubmit={createTag}>
|
||||
<div className="dialog-head">
|
||||
<div>
|
||||
<h2>新建客户标签</h2>
|
||||
<p>标签创建后可用于客户分类</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="icon"
|
||||
onClick={() => setTagDialog(false)}
|
||||
>
|
||||
<X />
|
||||
</button>
|
||||
</div>
|
||||
<div className="form-grid">
|
||||
<label>
|
||||
<span>标签名称</span>
|
||||
<input
|
||||
autoFocus
|
||||
required
|
||||
maxLength={50}
|
||||
value={tagForm.tagName}
|
||||
onChange={(event) =>
|
||||
setTagForm({ ...tagForm, tagName: event.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<span>标签颜色</span>
|
||||
<input
|
||||
type="color"
|
||||
value={tagForm.color}
|
||||
onChange={(event) =>
|
||||
setTagForm({ ...tagForm, color: event.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className="dialog-actions">
|
||||
<button type="button" onClick={() => setTagDialog(false)}>
|
||||
取消
|
||||
</button>
|
||||
<button className="primary">创建标签</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Code2, Pencil, Plus, Trash2 } from "lucide-react";
|
||||
import { API } from "./api";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
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,8 +1,9 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Activity, ArrowUpRight, Clock3, Eye, FileCheck2, Mail, Monitor, RefreshCw, Users } from "lucide-react";
|
||||
import { apiPost } from "./api";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
type Trend = { date: string; pageViews: number; visitors: number };
|
||||
type ContentStat = { type: string; label: string; total: number; published: number };
|
||||
type TopPage = { path: string; title: string; pageViews: number; visitors: number };
|
||||
|
||||
@@ -20,8 +20,9 @@ import {
|
||||
} from "lucide-react";
|
||||
import { API } from "./api";
|
||||
import { statusLabel } from "./statusLabels";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
type Viewport = "desktop" | "tablet" | "mobile";
|
||||
type HeroHeight = "30" | "50" | "80" | "100";
|
||||
type SectionType =
|
||||
|
||||
@@ -2,8 +2,9 @@ import React, { useEffect, useState } from "react";
|
||||
import { ArrowLeft, Edit3, Plus, Save, Trash2, X } from "lucide-react";
|
||||
import { API } from "./api";
|
||||
import { statusLabel } from "./statusLabels";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
type Field = {
|
||||
fieldCode?: string;
|
||||
fieldKey: string;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { FormEvent, useState } from "react";
|
||||
import { Eye, EyeOff, LockKeyhole, UserRound } from "lucide-react";
|
||||
import { apiPost } from "./api";
|
||||
import type { SiteOption } from "./siteContext";
|
||||
|
||||
export type Account = { userCode: string; siteCode: string; username: string; displayName: string };
|
||||
export type Account = { userCode: string; siteCode: string; username: string; displayName: string; sites: SiteOption[] };
|
||||
|
||||
export default function LoginPage({ onLogin }: { onLogin: (account: Account) => void }) {
|
||||
const [username, setUsername] = useState("");
|
||||
|
||||
@@ -9,18 +9,84 @@
|
||||
min-height: 30px;
|
||||
}
|
||||
|
||||
.media-card {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.media-card.selected {
|
||||
border-color: #176b5b;
|
||||
box-shadow: 0 0 0 1px #176b5b;
|
||||
}
|
||||
|
||||
.media-card-selector {
|
||||
position: absolute;
|
||||
top: 18px;
|
||||
left: 18px;
|
||||
z-index: 2;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 4px;
|
||||
background: rgba(255, 255, 255, 0.92);
|
||||
box-shadow: 0 1px 5px rgba(20, 35, 32, 0.22);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.media-card-selector input,
|
||||
.media-selection-tools input {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
margin: 0;
|
||||
accent-color: #176b5b;
|
||||
}
|
||||
|
||||
.media-selection-tools {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.media-selection-tools > label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
color: #34424d;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.media-batch-delete {
|
||||
height: 34px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 0 11px;
|
||||
border: 1px solid #d9a7a7;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
color: #a53b3b;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.media-delete {
|
||||
width: 30px;
|
||||
min-width: 62px;
|
||||
height: 30px;
|
||||
border: 1px solid #ead3d3;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
color: #a53b3b;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.media-result-summary { gap: 12px; }
|
||||
.media-selection-tools { flex-wrap: wrap; }
|
||||
}
|
||||
|
||||
.media-delete:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: wait;
|
||||
|
||||
@@ -12,8 +12,9 @@ import {
|
||||
} from "lucide-react";
|
||||
import { API, apiPost, assetUrl } from "./api";
|
||||
import "./MediaCenter.css";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
|
||||
type Media = {
|
||||
/** 素材业务编号。 */ mediaCode: string;
|
||||
@@ -53,6 +54,8 @@ export default function MediaCenter() {
|
||||
const [tagValue, setTagValue] = useState("");
|
||||
const [savingTag, setSavingTag] = useState(false);
|
||||
const [deletingCode, setDeletingCode] = useState("");
|
||||
const [selectedCodes, setSelectedCodes] = useState<Set<string>>(new Set());
|
||||
const [batchDeleting, setBatchDeleting] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setTimeout(() => setDebouncedQuery(query.trim()), 300);
|
||||
@@ -158,6 +161,11 @@ export default function MediaCenter() {
|
||||
siteCode: SITE,
|
||||
mediaCode: item.mediaCode,
|
||||
});
|
||||
setSelectedCodes((current) => {
|
||||
const next = new Set(current);
|
||||
next.delete(item.mediaCode);
|
||||
return next;
|
||||
});
|
||||
if (items.length === 1 && pageNo > 1) {
|
||||
setPageNo((current) => current - 1);
|
||||
} else {
|
||||
@@ -170,6 +178,49 @@ export default function MediaCenter() {
|
||||
}
|
||||
};
|
||||
|
||||
/** 选择或取消选择指定素材。 */
|
||||
const toggleSelected = (mediaCode: string) => {
|
||||
setSelectedCodes((current) => {
|
||||
const next = new Set(current);
|
||||
if (next.has(mediaCode)) next.delete(mediaCode);
|
||||
else next.add(mediaCode);
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
/** 全选或取消选择当前页素材。 */
|
||||
const toggleCurrentPage = () => {
|
||||
const currentCodes = items.map((item) => item.mediaCode);
|
||||
const allSelected = currentCodes.every((code) => selectedCodes.has(code));
|
||||
setSelectedCodes((current) => {
|
||||
const next = new Set(current);
|
||||
currentCodes.forEach((code) => allSelected ? next.delete(code) : next.add(code));
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
/** 批量删除已选择的素材。 */
|
||||
const batchDeleteMedia = async () => {
|
||||
const mediaCodes = Array.from(selectedCodes);
|
||||
if (mediaCodes.length === 0) return;
|
||||
if (!window.confirm(`确认删除已选择的 ${mediaCodes.length} 个素材吗?已发布页面中的文件仍会保留。`)) return;
|
||||
try {
|
||||
setBatchDeleting(true);
|
||||
setError("");
|
||||
await apiPost("/media/batch-delete", { siteCode: SITE, mediaCodes });
|
||||
setSelectedCodes(new Set());
|
||||
if (items.every((item) => selectedCodes.has(item.mediaCode)) && pageNo > 1) {
|
||||
setPageNo((current) => current - 1);
|
||||
} else {
|
||||
await load();
|
||||
}
|
||||
} catch (reason) {
|
||||
setError(reason instanceof Error ? reason.message : "素材批量删除失败");
|
||||
} finally {
|
||||
setBatchDeleting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const pages = pageNumbers(pageNo, totalPages);
|
||||
|
||||
return (
|
||||
@@ -234,7 +285,18 @@ export default function MediaCenter() {
|
||||
{error && <div className="notice">{error}</div>}
|
||||
<section className="media-panel">
|
||||
<div className="media-result-summary">
|
||||
<span>共 {total} 个素材</span>
|
||||
<div className="media-selection-tools">
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={items.length > 0 && items.every((item) => selectedCodes.has(item.mediaCode))}
|
||||
onChange={toggleCurrentPage}
|
||||
/>
|
||||
全选当前页
|
||||
</label>
|
||||
<span>共 {total} 个素材{selectedCodes.size > 0 ? `,已选 ${selectedCodes.size} 个` : ""}</span>
|
||||
{selectedCodes.size > 0 && <button type="button" className="media-batch-delete" disabled={batchDeleting} onClick={() => void batchDeleteMedia()}><Trash2 size={15}/>{batchDeleting ? "删除中" : "批量删除"}</button>}
|
||||
</div>
|
||||
<label>
|
||||
每页
|
||||
<select
|
||||
@@ -269,7 +331,10 @@ export default function MediaCenter() {
|
||||
) : (
|
||||
<div className="media-grid">
|
||||
{items.map((item) => (
|
||||
<article className="media-card" key={item.mediaCode}>
|
||||
<article className={`media-card${selectedCodes.has(item.mediaCode) ? " selected" : ""}`} key={item.mediaCode}>
|
||||
<label className="media-card-selector" title="选择素材">
|
||||
<input type="checkbox" checked={selectedCodes.has(item.mediaCode)} onChange={() => toggleSelected(item.mediaCode)} />
|
||||
</label>
|
||||
{item.mediaType === "VIDEO" ? (
|
||||
<video src={item.url} controls />
|
||||
) : (
|
||||
@@ -336,6 +401,7 @@ export default function MediaCenter() {
|
||||
onClick={() => void deleteMedia(item)}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
<span>删除</span>
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
@@ -10,8 +10,9 @@ import {
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { apiPost } from "./api";
|
||||
import { statusLabel } from "./statusLabels";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE_CODE = "SIT0000000000001";
|
||||
const SITE_CODE = getCurrentSiteCode();
|
||||
|
||||
type NavigationSummary = {
|
||||
navigationCode: string;
|
||||
|
||||
@@ -19,8 +19,9 @@ import {
|
||||
Undo2,
|
||||
} from "lucide-react";
|
||||
import { API } from "./api";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
type Heading = { level: number; text: string; sortNo: number };
|
||||
type Props = {
|
||||
pageCode?: string;
|
||||
|
||||
@@ -24,8 +24,9 @@ import {
|
||||
X,
|
||||
} from "lucide-react";
|
||||
import { API, assetUrl } from "./api";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
async function post(path: string, body: unknown) {
|
||||
const r = await fetch(API + path, {
|
||||
method: "POST",
|
||||
|
||||
@@ -21,8 +21,9 @@ import {
|
||||
} from "lucide-react";
|
||||
import { apiPost, assetUrl } from "./api";
|
||||
import { statusLabel } from "./statusLabels";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
|
||||
type ProductTemplate = {
|
||||
/** 模板业务编号。 */ templateCode: string;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Save } from "lucide-react";
|
||||
import { apiPost } from "./api";
|
||||
import { getCurrentSiteCode } from "./siteContext";
|
||||
|
||||
/** 当前后台维护的站点业务编号。 */
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
|
||||
/** 固定页面 SEO 类型定义。 */
|
||||
type SeoPageOption = {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { FormEvent, useEffect, useState } from "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 };
|
||||
@@ -9,7 +10,8 @@ type SettingsTab = "store" | "account" | "social";
|
||||
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 }) {
|
||||
const [store, setStore] = useState<StoreProfile>({ siteCode: account.siteCode, storeName: "", description: "", industry: "" });
|
||||
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 [socialChannels, setSocialChannels] = useState<SocialChannel[]>([]);
|
||||
@@ -17,9 +19,9 @@ export default function SettingsPage({ account, onAccount, onLogout, tab }: { ac
|
||||
const [error, setError] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
apiPost<StoreProfile>("/store/detail", { siteCode: account.siteCode }).then(setStore).catch(cause => setError(cause instanceof Error ? cause.message : "加载失败"));
|
||||
if (tab === "social") apiPost<{ items: SocialChannel[] }>("/social-channels/list", { siteCode: account.siteCode }).then(data => setSocialChannels(data.items || [])).catch(cause => setError(cause instanceof Error ? cause.message : "社媒渠道加载失败"));
|
||||
}, [account.siteCode, tab]);
|
||||
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)), "账户资料已更新"); };
|
||||
@@ -34,7 +36,7 @@ export default function SettingsPage({ account, onAccount, onLogout, tab }: { ac
|
||||
/** 更新指定社媒渠道。 */
|
||||
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: account.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">
|
||||
|
||||
+114
-17
@@ -43,14 +43,16 @@ import NavigationManager from "./NavigationManager";
|
||||
import AgreementSettingsPage from "./AgreementSettingsPage";
|
||||
import AboutUsSettingsPage from "./AboutUsSettingsPage";
|
||||
import DashboardPage from "./DashboardPage";
|
||||
import CrmCustomerPage from "./CrmCustomerPage";
|
||||
import { apiPost } from "./api";
|
||||
import { statusLabel } from "./statusLabels";
|
||||
import { ensureCurrentSiteCode, getCurrentSiteCode, setCurrentSiteCode, type SiteOption } from "./siteContext";
|
||||
|
||||
const SITE_WEB =
|
||||
window.location.hostname === "admin.steliro.com"
|
||||
? "https://site.steliro.com"
|
||||
: "http://localhost:5174";
|
||||
const SITE = "SIT0000000000001";
|
||||
const SITE = getCurrentSiteCode();
|
||||
type Section =
|
||||
| "dashboard"
|
||||
| "products"
|
||||
@@ -74,7 +76,8 @@ type Section =
|
||||
| "inquiry-settings"
|
||||
| "settings-store"
|
||||
| "settings-account"
|
||||
| "settings-social";
|
||||
| "settings-social"
|
||||
| "crm-customers";
|
||||
type EditorialSection = "NEWS" | "CASE" | "HELP";
|
||||
type ContentEditorState = {
|
||||
contentType: EditorialSection;
|
||||
@@ -141,6 +144,7 @@ const systemSettingsMenus = [
|
||||
{ key: "settings-store" as Section, label: "店铺信息", icon: Store },
|
||||
{ key: "settings-account" as Section, label: "账户与安全", icon: UserRound },
|
||||
{ key: "settings-social" as Section, label: "社媒渠道", icon: Share2 },
|
||||
{ key: "inquiry-settings" as Section, label: "询盘设置", icon: Settings },
|
||||
];
|
||||
const sectionLabels: Record<Section, string> = {
|
||||
dashboard: "数据概览",
|
||||
@@ -166,6 +170,7 @@ const sectionLabels: Record<Section, string> = {
|
||||
"settings-store": "店铺信息",
|
||||
"settings-account": "账户与安全",
|
||||
"settings-social": "社媒渠道",
|
||||
"crm-customers": "客户列表",
|
||||
};
|
||||
function App({
|
||||
account,
|
||||
@@ -204,6 +209,40 @@ function App({
|
||||
const [query, setQuery] = useState("");
|
||||
const [open, setOpen] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [siteDialogOpen, setSiteDialogOpen] = useState(false);
|
||||
const [siteCreating, setSiteCreating] = useState(false);
|
||||
const [siteError, setSiteError] = useState("");
|
||||
const [siteForm, setSiteForm] = useState({
|
||||
siteName: "",
|
||||
industry: "",
|
||||
description: "",
|
||||
timezone: "Asia/Shanghai",
|
||||
});
|
||||
const currentSiteCode = getCurrentSiteCode();
|
||||
/** 切换当前站点并重新加载所有站点级数据。 */
|
||||
const switchSite = (siteCode: string) => {
|
||||
if (siteCode === currentSiteCode) return;
|
||||
setCurrentSiteCode(siteCode);
|
||||
window.location.assign("/");
|
||||
};
|
||||
/** 创建站点并自动切换到新站点。 */
|
||||
const createSite = async () => {
|
||||
try {
|
||||
setSiteCreating(true);
|
||||
setSiteError("");
|
||||
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("站点已创建,但未能读取新站点信息,请刷新后重试");
|
||||
setCurrentSiteCode(site.siteCode);
|
||||
window.location.assign("/");
|
||||
} catch (cause) {
|
||||
setSiteError(cause instanceof Error ? cause.message : "站点创建失败");
|
||||
} finally {
|
||||
setSiteCreating(false);
|
||||
}
|
||||
};
|
||||
const resolveProductRoute = () => {
|
||||
if (window.location.pathname === "/products/new") return "";
|
||||
const match = window.location.pathname.match(/^\/products\/([^/]+)\/edit$/);
|
||||
@@ -226,6 +265,7 @@ function App({
|
||||
const [contentMenuOpen, setContentMenuOpen] = useState(true);
|
||||
const [frontSiteMenuOpen, setFrontSiteMenuOpen] = useState(true);
|
||||
const [systemSettingsOpen, setSystemSettingsOpen] = useState(true);
|
||||
const [crmMenuOpen, setCrmMenuOpen] = useState(true);
|
||||
const navigateSection = (next: Section) => {
|
||||
setEditingProduct(null);
|
||||
setEditingContent(null);
|
||||
@@ -447,6 +487,30 @@ function App({
|
||||
Shoplix<small>运营中心</small>
|
||||
</div>
|
||||
</div>
|
||||
<div className="site-switcher">
|
||||
<div>
|
||||
<Globe2 size={15} />
|
||||
<select
|
||||
aria-label="当前站点"
|
||||
value={currentSiteCode}
|
||||
onChange={(event) => switchSite(event.target.value)}
|
||||
>
|
||||
{account.sites.map((site) => (
|
||||
<option key={site.siteCode} value={site.siteCode}>
|
||||
{site.siteName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
title="新增站点"
|
||||
aria-label="新增站点"
|
||||
onClick={() => setSiteDialogOpen(true)}
|
||||
>
|
||||
<Plus size={16} />
|
||||
</button>
|
||||
</div>
|
||||
<nav>
|
||||
<button className={section === "dashboard" ? "active" : ""} onClick={() => navigateSection("dashboard")}><LayoutDashboard size={18}/>数据概览</button>
|
||||
<div className="nav-group">
|
||||
@@ -488,6 +552,16 @@ function App({
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="nav-group">
|
||||
<button className={section === "crm-customers" ? "group-active" : ""} onClick={() => setCrmMenuOpen(!crmMenuOpen)}>
|
||||
<Users size={18} />
|
||||
CRM 管理
|
||||
<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>}
|
||||
</div>
|
||||
<div className="nav-group">
|
||||
<button
|
||||
className={
|
||||
@@ -601,23 +675,12 @@ function App({
|
||||
</button>
|
||||
))}
|
||||
</nav>
|
||||
<div className="aside-bottom">
|
||||
<button>
|
||||
<Users size={18} />
|
||||
CRM 客户
|
||||
</button>
|
||||
<button
|
||||
className={section === "inquiry-settings" ? "active" : ""}
|
||||
onClick={() => navigateSection("inquiry-settings")}
|
||||
>
|
||||
<Settings size={18} />
|
||||
询盘设置
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
<main>
|
||||
{section === "dashboard" ? (
|
||||
<DashboardPage onNavigate={(next) => navigateSection(next as Section)} />
|
||||
) : section === "crm-customers" ? (
|
||||
<CrmCustomerPage />
|
||||
) : section === "settings-store" ? (
|
||||
<SettingsPage account={account} onAccount={onAccount} onLogout={onLogout} tab="store" />
|
||||
) : section === "settings-account" ? (
|
||||
@@ -1002,6 +1065,30 @@ function App({
|
||||
</section>
|
||||
</div>
|
||||
)}
|
||||
{siteDialogOpen && (
|
||||
<div className="mask" onMouseDown={() => setSiteDialogOpen(false)}>
|
||||
<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>
|
||||
</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>
|
||||
</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>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1009,12 +1096,22 @@ function App({
|
||||
function RootApp() {
|
||||
const [account, setAccount] = useState<Account | null>(null);
|
||||
const [checking, setChecking] = useState(true);
|
||||
/** 接收账户信息并保证模块级站点上下文与账户权限一致。 */
|
||||
const acceptAccount = (value: Account) => {
|
||||
const previousSiteCode = getCurrentSiteCode();
|
||||
const currentSiteCode = ensureCurrentSiteCode(value.sites || [], value.siteCode);
|
||||
if (previousSiteCode !== currentSiteCode) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
setAccount(value);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const unauthorized = () => setAccount(null);
|
||||
window.addEventListener("shoplix:unauthorized", unauthorized);
|
||||
apiPost<Account>("/auth/me")
|
||||
.then(setAccount)
|
||||
.then(acceptAccount)
|
||||
.catch(() => setAccount(null))
|
||||
.finally(() => setChecking(false));
|
||||
return () =>
|
||||
@@ -1028,7 +1125,7 @@ function RootApp() {
|
||||
<span>正在验证登录状态</span>
|
||||
</div>
|
||||
);
|
||||
if (!account) return <LoginPage onLogin={setAccount} />;
|
||||
if (!account) return <LoginPage onLogin={acceptAccount} />;
|
||||
return (
|
||||
<App
|
||||
account={account}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/** 后台可切换站点选项。 */
|
||||
export type SiteOption = {
|
||||
/** 站点业务编号。 */ siteCode: string;
|
||||
/** 站点名称。 */ siteName: string;
|
||||
/** 所属行业。 */ industry: string;
|
||||
/** 当前账户的站点角色值。 */ role: string;
|
||||
/** 当前账户的站点角色文案。 */ roleLabel: string;
|
||||
};
|
||||
|
||||
/** 当前站点本地存储键。 */
|
||||
const CURRENT_SITE_KEY = "shoplix.currentSiteCode";
|
||||
/** 兼容历史版本的默认站点编号。 */
|
||||
const DEFAULT_SITE_CODE = "SIT0000000000001";
|
||||
|
||||
/** 获取当前选中的站点业务编号。 */
|
||||
export function getCurrentSiteCode(): string {
|
||||
return window.localStorage.getItem(CURRENT_SITE_KEY) || DEFAULT_SITE_CODE;
|
||||
}
|
||||
|
||||
/** 保存当前选中的站点业务编号。 */
|
||||
export function setCurrentSiteCode(siteCode: string): void {
|
||||
window.localStorage.setItem(CURRENT_SITE_KEY, siteCode);
|
||||
}
|
||||
|
||||
/** 确保本地当前站点属于登录账户并返回最终站点。 */
|
||||
export function ensureCurrentSiteCode(sites: SiteOption[], defaultSiteCode: string): string {
|
||||
const current = getCurrentSiteCode();
|
||||
if (sites.some((site) => site.siteCode === current)) return current;
|
||||
const fallback = sites.find((site) => site.siteCode === defaultSiteCode)?.siteCode
|
||||
|| sites[0]?.siteCode
|
||||
|| defaultSiteCode;
|
||||
setCurrentSiteCode(fallback);
|
||||
return fallback;
|
||||
}
|
||||
@@ -70,6 +70,12 @@ select {
|
||||
font-weight: 400;
|
||||
margin-top: 2px;
|
||||
}
|
||||
.site-switcher { display:grid; grid-template-columns:minmax(0,1fr) 36px; gap:6px; padding:0 4px 16px; }
|
||||
.site-switcher > div { min-width:0; height:38px; display:flex; align-items:center; gap:7px; padding:0 8px; border:1px solid #344451; border-radius:6px; background:#111a22; color:#93a2ae; }
|
||||
.site-switcher select { min-width:0; width:100%; border:0; outline:0; background:transparent; color:#f0f4f7; font-size:13px; cursor:pointer; }
|
||||
.site-switcher select option { color:#17212b; background:#fff; }
|
||||
.site-switcher > button { width:36px; height:38px; padding:0!important; justify-content:center; border:1px solid #344451!important; background:#111a22!important; }
|
||||
.site-switcher > button:hover { border-color:#e9b949!important; color:#e9b949!important; }
|
||||
nav {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
@@ -369,6 +375,8 @@ header p {
|
||||
background: #176b5b;
|
||||
color: #fff;
|
||||
}
|
||||
.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; }
|
||||
.primary:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"root":["./src/aboutussettingspage.tsx","./src/agreementsettingspage.tsx","./src/categorymanager.tsx","./src/contenteditor.tsx","./src/customcodemanager.tsx","./src/dashboardpage.tsx","./src/decorationeditor.tsx","./src/inquirysettingspanel.tsx","./src/loginpage.tsx","./src/mediacenter.tsx","./src/navigationmanager.tsx","./src/pageeditor.tsx","./src/producteditor.tsx","./src/seosettingspage.tsx","./src/settingspage.tsx","./src/api.ts","./src/main.tsx","./src/statuslabels.ts","./src/vite-env.d.ts"],"version":"5.7.3"}
|
||||
{"root":["./src/aboutussettingspage.tsx","./src/agreementsettingspage.tsx","./src/categorymanager.tsx","./src/contenteditor.tsx","./src/crmcustomerpage.tsx","./src/customcodemanager.tsx","./src/dashboardpage.tsx","./src/decorationeditor.tsx","./src/inquirysettingspanel.tsx","./src/loginpage.tsx","./src/mediacenter.tsx","./src/navigationmanager.tsx","./src/pageeditor.tsx","./src/producteditor.tsx","./src/producttemplatemanager.tsx","./src/seosettingspage.tsx","./src/settingspage.tsx","./src/api.ts","./src/main.tsx","./src/sitecontext.ts","./src/statuslabels.ts","./src/vite-env.d.ts"],"version":"5.7.3"}
|
||||
Reference in new issue
Block a user