refactor: align inquiry storage structure
This commit is contained in:
1 parent
3fdec5a549
commit
a0c723cdcc
13 files changed
+659
-32
No files matched your search
@@ -3,35 +3,634 @@ import { ArrowLeft, Edit3, Plus, Save, Trash2 } from "lucide-react";
|
||||
|
||||
const API = "http://localhost:8081/api/admin/v1";
|
||||
const SITE = "SIT0000000000001";
|
||||
type Field = { fieldCode?: string; fieldKey: string; label: string; fieldType: string; placeholder: string; helpText: string; maxLength?: number | null; required: boolean; systemField: boolean; optionsJson: string; widthType: string; sortNo: number };
|
||||
type Form = { formCode?: string; formName: string; scene: string; submitButtonText: string; successMessage: string; privacyPageCode: string; status: string; sortNo: number; fields: Field[] };
|
||||
const emptyField = (): Field => ({ fieldKey: "", label: "", fieldType: "TEXT", placeholder: "", helpText: "", maxLength: null, required: false, systemField: false, optionsJson: "", widthType: "FULL", sortNo: 0 });
|
||||
const emptyForm = (): Form => ({ formName: "", scene: "PRODUCT", submitButtonText: "Submit Inquiry", successMessage: "Thank you. We will contact you soon.", privacyPageCode: "", status: "DRAFT", sortNo: 30, fields: [emptyField()] });
|
||||
const sceneLabels: Record<string, string> = { PRODUCT: "产品详情页按钮", GENERAL: "网站右下角悬浮按钮", CONTACT: "联系页面", CONTENT: "新闻、案例和帮助详情页", PAGE: "固定或自定义页面" };
|
||||
type Field = {
|
||||
fieldCode?: string;
|
||||
fieldKey: string;
|
||||
label: string;
|
||||
fieldType: string;
|
||||
placeholder: string;
|
||||
helpText: string;
|
||||
maxLength?: number | null;
|
||||
required: boolean;
|
||||
systemField: boolean;
|
||||
optionsJson: string;
|
||||
widthType: string;
|
||||
sortNo: number;
|
||||
};
|
||||
type Form = {
|
||||
formCode?: string;
|
||||
defaultInquiry: boolean;
|
||||
formName: string;
|
||||
description: string;
|
||||
scene: string;
|
||||
submitButtonText: string;
|
||||
successMessage: string;
|
||||
privacyPageCode: string;
|
||||
status: string;
|
||||
sortNo: number;
|
||||
fields: Field[];
|
||||
};
|
||||
const emptyField = (): Field => ({
|
||||
fieldKey: "",
|
||||
label: "",
|
||||
fieldType: "TEXT",
|
||||
placeholder: "",
|
||||
helpText: "",
|
||||
maxLength: null,
|
||||
required: false,
|
||||
systemField: false,
|
||||
optionsJson: "",
|
||||
widthType: "FULL",
|
||||
sortNo: 0,
|
||||
});
|
||||
const emptyForm = (): Form => ({
|
||||
defaultInquiry: false,
|
||||
formName: "",
|
||||
description: "",
|
||||
scene: "PRODUCT",
|
||||
submitButtonText: "Submit Inquiry",
|
||||
successMessage: "Thank you. We will contact you soon.",
|
||||
privacyPageCode: "",
|
||||
status: "DRAFT",
|
||||
sortNo: 30,
|
||||
fields: [emptyField()],
|
||||
});
|
||||
const sceneLabels: Record<string, string> = {
|
||||
PRODUCT: "产品详情页按钮",
|
||||
GENERAL: "网站右下角悬浮按钮",
|
||||
CONTACT: "联系页面",
|
||||
CONTENT: "新闻、案例和帮助详情页",
|
||||
PAGE: "固定或自定义页面",
|
||||
};
|
||||
|
||||
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 || "请求失败");
|
||||
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();
|
||||
}
|
||||
|
||||
/** 询盘基础设置和动态表单管理。 */
|
||||
export default function InquirySettingsPanel() {
|
||||
const [tab, setTab] = useState<"settings" | "forms">("settings");
|
||||
const [settings, setSettings] = useState({ inquiryEnabled: true, captchaEnabled: false, privacyConsentRequired: true, duplicateWindowMinutes: 30, ipHourLimit: 10, emailDayLimit: 20, successAction: "MESSAGE", successPageCode: "", successRedirectUrl: "", notificationEnabled: true, autoReplyEnabled: false, autoReplySubject: "", autoReplyContent: "", dataRetentionDays: 730 });
|
||||
const [settings, setSettings] = useState({
|
||||
inquiryEnabled: true,
|
||||
captchaEnabled: false,
|
||||
privacyConsentRequired: true,
|
||||
duplicateWindowMinutes: 30,
|
||||
ipHourLimit: 10,
|
||||
emailDayLimit: 20,
|
||||
successAction: "MESSAGE",
|
||||
successPageCode: "",
|
||||
successRedirectUrl: "",
|
||||
notificationEnabled: true,
|
||||
autoReplyEnabled: false,
|
||||
autoReplySubject: "",
|
||||
autoReplyContent: "",
|
||||
dataRetentionDays: 730,
|
||||
});
|
||||
const [forms, setForms] = useState<Form[]>([]);
|
||||
const [editing, setEditing] = useState<Form | null>(null);
|
||||
const [notice, setNotice] = useState("");
|
||||
const [saving, setSaving] = useState(false);
|
||||
const loadForms = () => post("/inquiries/forms/list", { siteCode: SITE }).then((data) => setForms(data.items || [])).catch((error) => setNotice(error.message));
|
||||
useEffect(() => { post("/inquiries/settings/detail", { siteCode: SITE }).then(setSettings).catch((error) => setNotice(error.message)); void loadForms(); }, []);
|
||||
const saveSettings = async () => { try { setSaving(true); await post("/inquiries/settings/save", { siteCode: SITE, ...settings }); setNotice("询盘基础设置已保存"); } catch (error) { setNotice(error instanceof Error ? error.message : "保存失败"); } finally { setSaving(false); } };
|
||||
const saveForm = async () => { if (!editing) return; try { setSaving(true); await post("/inquiries/forms/save", { ...editing, siteCode: SITE, fields: editing.fields.map((field, index) => ({ ...field, sortNo: index })) }); setNotice("询盘表单已保存"); setEditing(null); await loadForms(); } catch (error) { setNotice(error instanceof Error ? error.message : "保存失败"); } finally { setSaving(false); } };
|
||||
const updateField = (index: number, value: Partial<Field>) => editing && setEditing({ ...editing, fields: editing.fields.map((field, position) => position === index ? { ...field, ...value } : field) });
|
||||
const loadForms = () =>
|
||||
post("/inquiries/forms/list", { siteCode: SITE })
|
||||
.then((data) => setForms(data.items || []))
|
||||
.catch((error) => setNotice(error.message));
|
||||
useEffect(() => {
|
||||
post("/inquiries/settings/detail", { siteCode: SITE })
|
||||
.then(setSettings)
|
||||
.catch((error) => setNotice(error.message));
|
||||
void loadForms();
|
||||
}, []);
|
||||
const saveSettings = async () => {
|
||||
try {
|
||||
setSaving(true);
|
||||
await post("/inquiries/settings/save", { siteCode: SITE, ...settings });
|
||||
setNotice("询盘基础设置已保存");
|
||||
} catch (error) {
|
||||
setNotice(error instanceof Error ? error.message : "保存失败");
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
const saveForm = async () => {
|
||||
if (!editing) return;
|
||||
try {
|
||||
setSaving(true);
|
||||
await post("/inquiries/forms/save", {
|
||||
...editing,
|
||||
siteCode: SITE,
|
||||
fields: editing.fields.map((field, index) => ({
|
||||
...field,
|
||||
sortNo: index,
|
||||
})),
|
||||
});
|
||||
setNotice("询盘表单已保存");
|
||||
setEditing(null);
|
||||
await loadForms();
|
||||
} catch (error) {
|
||||
setNotice(error instanceof Error ? error.message : "保存失败");
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
const updateField = (index: number, value: Partial<Field>) =>
|
||||
editing &&
|
||||
setEditing({
|
||||
...editing,
|
||||
fields: editing.fields.map((field, position) =>
|
||||
position === index ? { ...field, ...value } : field,
|
||||
),
|
||||
});
|
||||
|
||||
if (editing) return <div className="inquiry-form-editor"><div className="editor-top"><div className="breadcrumb-title"><button className="back" onClick={() => setEditing(null)}><ArrowLeft size={17}/>询盘表单</button><span>/</span><h1>{editing.formCode ? "编辑表单" : "新增表单"}</h1></div><div className="editor-actions"><button onClick={() => setEditing(null)}>取消</button><button className="primary" disabled={saving || !editing.formName || editing.fields.some((field) => !field.fieldKey || !field.label)} onClick={saveForm}><Save size={16}/>{saving ? "保存中" : "保存"}</button></div></div><div className="inquiry-editor-layout"><div className="editor-main"><section className="edit-section"><h2>表单信息</h2><div className="edit-grid"><Field label="表单名称 *"><input value={editing.formName} onChange={(event) => setEditing({ ...editing, formName: event.target.value })}/></Field><Field label="展示到线上网站"><select value={editing.scene} onChange={(event) => setEditing({ ...editing, scene: event.target.value })}>{Object.entries(sceneLabels).map(([value, label]) => <option value={value} key={value}>{label}</option>)}</select></Field><Field wide label="提交成功英文提示"><textarea rows={3} value={editing.successMessage} onChange={(event) => setEditing({ ...editing, successMessage: event.target.value })}/></Field></div></section><section className="edit-section"><div className="section-head"><h2>表单字段</h2><button onClick={() => setEditing({ ...editing, fields: [...editing.fields, { ...emptyField(), sortNo: editing.fields.length }] })}><Plus size={16}/>添加字段</button></div><div className="form-field-list">{editing.fields.map((field, index) => <div className="form-field-row" key={field.fieldCode || index}><Field label="标题 *"><input placeholder="Name" value={field.label} onChange={(event) => updateField(index, { label: event.target.value })}/></Field><Field label="字段键 *"><input placeholder="field_key" value={field.fieldKey} onChange={(event) => updateField(index, { fieldKey: event.target.value.toLowerCase().replace(/[^a-z0-9_]/g, "_") })}/></Field><Field label="类型"><select value={field.fieldType} onChange={(event) => updateField(index, { fieldType: event.target.value })}><option value="TEXT">单行文本</option><option value="TEXTAREA">多行文本</option><option value="EMAIL">邮箱</option><option value="PHONE">电话</option><option value="NUMBER">数字</option><option value="SINGLE_SELECT">下拉单选</option><option value="MULTI_SELECT">下拉多选</option><option value="RADIO">单选框</option><option value="CHECKBOX">复选框</option><option value="FILE">文件</option><option value="IMAGE">图片上传</option><option value="COUNTRY">国家</option></select></Field><Field label="提示"><input placeholder="Help text" value={field.helpText || ""} onChange={(event) => updateField(index, { helpText: event.target.value })}/></Field><Field label="框内提示语"><input placeholder="Placeholder" value={field.placeholder || ""} onChange={(event) => updateField(index, { placeholder: event.target.value })}/></Field><Field label="限制字数"><input type="number" min={1} max={5000} placeholder="不限制" value={field.maxLength || ""} onChange={(event) => updateField(index, { maxLength: event.target.value ? Number(event.target.value) : null })}/></Field><label className="field-check"><input type="checkbox" checked={field.required} onChange={(event) => updateField(index, { required: event.target.checked })}/>必填</label><Field label="展示宽度"><select value={field.widthType} onChange={(event) => updateField(index, { widthType: event.target.value })}><option value="FULL">整行</option><option value="HALF">半行</option></select></Field><button className="field-delete" title="删除字段" onClick={() => setEditing({ ...editing, fields: editing.fields.filter((_, position) => position !== index) })}><Trash2 size={17}/></button></div>)}</div></section><section className="edit-section"><Field label="提交按钮英文文案 *"><input maxLength={100} value={editing.submitButtonText} onChange={(event) => setEditing({ ...editing, submitButtonText: event.target.value })}/></Field></section></div><aside className="editor-side"><section className="edit-section"><h2>发布设置</h2><Field label="状态"><select value={editing.status} onChange={(event) => setEditing({ ...editing, status: event.target.value })}><option value="DRAFT">草稿</option><option value="PUBLISHED">已发布</option><option value="OFFLINE">已下线</option></select></Field><Field label="排序"><input type="number" value={editing.sortNo} onChange={(event) => setEditing({ ...editing, sortNo: Number(event.target.value) })}/></Field></section></aside></div></div>;
|
||||
if (editing)
|
||||
return (
|
||||
<div className="inquiry-form-editor">
|
||||
<div className="editor-top">
|
||||
<div className="breadcrumb-title">
|
||||
<button className="back" onClick={() => setEditing(null)}>
|
||||
<ArrowLeft size={17} />
|
||||
询盘表单
|
||||
</button>
|
||||
<span>/</span>
|
||||
<h1>{editing.formCode ? "编辑表单" : "新增表单"}</h1>
|
||||
</div>
|
||||
<div className="editor-actions">
|
||||
<button onClick={() => setEditing(null)}>取消</button>
|
||||
<button
|
||||
className="primary"
|
||||
disabled={
|
||||
saving ||
|
||||
!editing.formName ||
|
||||
editing.fields.some((field) => !field.fieldKey || !field.label)
|
||||
}
|
||||
onClick={saveForm}
|
||||
>
|
||||
<Save size={16} />
|
||||
{saving ? "保存中" : "保存"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="inquiry-editor-layout">
|
||||
<div className="editor-main">
|
||||
<section className="edit-section">
|
||||
<h2>表单信息</h2>
|
||||
<div className="edit-grid">
|
||||
<Field label="表单名称 *">
|
||||
<input
|
||||
value={editing.formName}
|
||||
onChange={(event) =>
|
||||
setEditing({ ...editing, formName: event.target.value })
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="展示到线上网站">
|
||||
<select
|
||||
value={editing.scene}
|
||||
onChange={(event) =>
|
||||
setEditing({ ...editing, scene: event.target.value })
|
||||
}
|
||||
>
|
||||
{Object.entries(sceneLabels).map(([value, label]) => (
|
||||
<option value={value} key={value}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<Field wide label="表单简介">
|
||||
<textarea
|
||||
rows={3}
|
||||
maxLength={1000}
|
||||
value={editing.description || ""}
|
||||
onChange={(event) =>
|
||||
setEditing({ ...editing, description: event.target.value })
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field wide label="提交成功英文提示">
|
||||
<textarea
|
||||
rows={3}
|
||||
value={editing.successMessage}
|
||||
onChange={(event) =>
|
||||
setEditing({
|
||||
...editing,
|
||||
successMessage: event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
</section>
|
||||
<section className="edit-section">
|
||||
<div className="section-head">
|
||||
<h2>表单字段</h2>
|
||||
<button
|
||||
onClick={() =>
|
||||
setEditing({
|
||||
...editing,
|
||||
fields: [
|
||||
...editing.fields,
|
||||
{ ...emptyField(), sortNo: editing.fields.length },
|
||||
],
|
||||
})
|
||||
}
|
||||
>
|
||||
<Plus size={16} />
|
||||
添加字段
|
||||
</button>
|
||||
</div>
|
||||
<div className="form-field-list">
|
||||
{editing.fields.map((field, index) => (
|
||||
<div
|
||||
className="form-field-row"
|
||||
key={field.fieldCode || index}
|
||||
>
|
||||
<Field label="标题 *">
|
||||
<input
|
||||
placeholder="Name"
|
||||
value={field.label}
|
||||
onChange={(event) =>
|
||||
updateField(index, { label: event.target.value })
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="字段键 *">
|
||||
<input
|
||||
placeholder="field_key"
|
||||
value={field.fieldKey}
|
||||
onChange={(event) =>
|
||||
updateField(index, {
|
||||
fieldKey: event.target.value
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9_]/g, "_"),
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="类型">
|
||||
<select
|
||||
value={field.fieldType}
|
||||
onChange={(event) =>
|
||||
updateField(index, { fieldType: event.target.value })
|
||||
}
|
||||
>
|
||||
<option value="TEXT">单行文本</option>
|
||||
<option value="TEXTAREA">多行文本</option>
|
||||
<option value="EMAIL">邮箱</option>
|
||||
<option value="PHONE">电话</option>
|
||||
<option value="NUMBER">数字</option>
|
||||
<option value="SINGLE_SELECT">下拉单选</option>
|
||||
<option value="MULTI_SELECT">下拉多选</option>
|
||||
<option value="RADIO">单选框</option>
|
||||
<option value="CHECKBOX">复选框</option>
|
||||
<option value="FILE">文件</option>
|
||||
<option value="IMAGE">图片上传</option>
|
||||
<option value="COUNTRY">国家</option>
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="提示">
|
||||
<input
|
||||
placeholder="Help text"
|
||||
value={field.helpText || ""}
|
||||
onChange={(event) =>
|
||||
updateField(index, { helpText: event.target.value })
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="框内提示语">
|
||||
<input
|
||||
placeholder="Placeholder"
|
||||
value={field.placeholder || ""}
|
||||
onChange={(event) =>
|
||||
updateField(index, {
|
||||
placeholder: event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="限制字数">
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={5000}
|
||||
placeholder="不限制"
|
||||
value={field.maxLength || ""}
|
||||
onChange={(event) =>
|
||||
updateField(index, {
|
||||
maxLength: event.target.value
|
||||
? Number(event.target.value)
|
||||
: null,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<label className="field-check">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={field.required}
|
||||
onChange={(event) =>
|
||||
updateField(index, { required: event.target.checked })
|
||||
}
|
||||
/>
|
||||
必填
|
||||
</label>
|
||||
<Field label="展示宽度">
|
||||
<select
|
||||
value={field.widthType}
|
||||
onChange={(event) =>
|
||||
updateField(index, { widthType: event.target.value })
|
||||
}
|
||||
>
|
||||
<option value="FULL">整行</option>
|
||||
<option value="HALF">半行</option>
|
||||
</select>
|
||||
</Field>
|
||||
<button
|
||||
className="field-delete"
|
||||
title="删除字段"
|
||||
onClick={() =>
|
||||
setEditing({
|
||||
...editing,
|
||||
fields: editing.fields.filter(
|
||||
(_, position) => position !== index,
|
||||
),
|
||||
})
|
||||
}
|
||||
>
|
||||
<Trash2 size={17} />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
<section className="edit-section">
|
||||
<Field label="提交按钮英文文案 *">
|
||||
<input
|
||||
maxLength={100}
|
||||
value={editing.submitButtonText}
|
||||
onChange={(event) =>
|
||||
setEditing({
|
||||
...editing,
|
||||
submitButtonText: event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
</section>
|
||||
</div>
|
||||
<aside className="editor-side">
|
||||
<section className="edit-section">
|
||||
<h2>发布设置</h2>
|
||||
<label className="setting-check">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={editing.defaultInquiry}
|
||||
onChange={(event) =>
|
||||
setEditing({ ...editing, defaultInquiry: event.target.checked })
|
||||
}
|
||||
/>
|
||||
<span>设为默认询盘表单</span>
|
||||
</label>
|
||||
<Field label="状态">
|
||||
<select
|
||||
value={editing.status}
|
||||
onChange={(event) =>
|
||||
setEditing({ ...editing, status: event.target.value })
|
||||
}
|
||||
>
|
||||
<option value="DRAFT">草稿</option>
|
||||
<option value="PUBLISHED">已发布</option>
|
||||
<option value="OFFLINE">已下线</option>
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="排序">
|
||||
<input
|
||||
type="number"
|
||||
value={editing.sortNo}
|
||||
onChange={(event) =>
|
||||
setEditing({
|
||||
...editing,
|
||||
sortNo: Number(event.target.value),
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
</section>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return <div className="inquiry-settings"><div className="settings-tabs"><button className={tab === "settings" ? "active" : ""} onClick={() => setTab("settings")}>基础设置</button><button className={tab === "forms" ? "active" : ""} onClick={() => setTab("forms")}>询盘表单</button></div>{notice && <div className="notice">{notice}</div>}{tab === "settings" ? <section className="settings-panel"><h2>提交、风控与邮件</h2><div className="form-grid"><Field label="启用询盘"><input type="checkbox" checked={settings.inquiryEnabled} onChange={(event) => setSettings({ ...settings, inquiryEnabled: event.target.checked })}/></Field><Field label="隐私授权必填"><input type="checkbox" checked={settings.privacyConsentRequired} onChange={(event) => setSettings({ ...settings, privacyConsentRequired: event.target.checked })}/></Field><Field label="IP 每小时上限"><input type="number" value={settings.ipHourLimit} onChange={(event) => setSettings({ ...settings, ipHourLimit: Number(event.target.value) })}/></Field><Field label="邮箱每日上限"><input type="number" value={settings.emailDayLimit} onChange={(event) => setSettings({ ...settings, emailDayLimit: Number(event.target.value) })}/></Field><Field label="重复识别窗口(分钟)"><input type="number" value={settings.duplicateWindowMinutes} onChange={(event) => setSettings({ ...settings, duplicateWindowMinutes: Number(event.target.value) })}/></Field><Field label="数据保留天数"><input type="number" value={settings.dataRetentionDays} onChange={(event) => setSettings({ ...settings, dataRetentionDays: Number(event.target.value) })}/></Field><Field label="启用客户自动回复"><input type="checkbox" checked={settings.autoReplyEnabled} onChange={(event) => setSettings({ ...settings, autoReplyEnabled: event.target.checked })}/></Field><Field wide label="自动回复英文主题"><input value={settings.autoReplySubject || ""} onChange={(event) => setSettings({ ...settings, autoReplySubject: event.target.value })}/></Field><Field wide label="自动回复英文内容"><textarea rows={5} value={settings.autoReplyContent || ""} onChange={(event) => setSettings({ ...settings, autoReplyContent: event.target.value })}/></Field></div><div className="settings-actions"><button className="primary" disabled={saving} onClick={saveSettings}>保存设置</button></div></section> : <><div className="forms-heading"><div><h2>询盘表单</h2><p>配置不同展示位置使用的英文询盘表单。</p></div><button className="primary" onClick={() => setEditing(emptyForm())}><Plus size={17}/>新增表单</button></div><section className="forms-list">{forms.length === 0 ? <div className="empty"><strong>暂无询盘表单</strong><p>创建表单后发布到产品详情、联系页或全站悬浮入口。</p></div> : forms.map((form) => <div className="form-list-row" key={form.formCode}><div><strong>{form.formName}</strong><small>{sceneLabels[form.scene] || form.scene}</small></div><span className={`status ${form.status.toLowerCase()}`}>{form.status === "PUBLISHED" ? "已发布" : form.status === "OFFLINE" ? "已下线" : "草稿"}</span><span>{form.fields.length} 个字段</span><button className="link" onClick={() => setEditing({ ...form, fields: form.fields || [] })}><Edit3 size={15}/>编辑</button></div>)}</section></>}</div>;
|
||||
return (
|
||||
<div className="inquiry-settings">
|
||||
<div className="settings-tabs">
|
||||
<button
|
||||
className={tab === "settings" ? "active" : ""}
|
||||
onClick={() => setTab("settings")}
|
||||
>
|
||||
基础设置
|
||||
</button>
|
||||
<button
|
||||
className={tab === "forms" ? "active" : ""}
|
||||
onClick={() => setTab("forms")}
|
||||
>
|
||||
询盘表单
|
||||
</button>
|
||||
</div>
|
||||
{notice && <div className="notice">{notice}</div>}
|
||||
{tab === "settings" ? (
|
||||
<section className="settings-panel">
|
||||
<h2>提交、风控与邮件</h2>
|
||||
<div className="form-grid">
|
||||
<Field label="启用询盘">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={settings.inquiryEnabled}
|
||||
onChange={(event) =>
|
||||
setSettings({
|
||||
...settings,
|
||||
inquiryEnabled: event.target.checked,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="隐私授权必填">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={settings.privacyConsentRequired}
|
||||
onChange={(event) =>
|
||||
setSettings({
|
||||
...settings,
|
||||
privacyConsentRequired: event.target.checked,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="IP 每小时上限">
|
||||
<input
|
||||
type="number"
|
||||
value={settings.ipHourLimit}
|
||||
onChange={(event) =>
|
||||
setSettings({
|
||||
...settings,
|
||||
ipHourLimit: Number(event.target.value),
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="邮箱每日上限">
|
||||
<input
|
||||
type="number"
|
||||
value={settings.emailDayLimit}
|
||||
onChange={(event) =>
|
||||
setSettings({
|
||||
...settings,
|
||||
emailDayLimit: Number(event.target.value),
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="重复识别窗口(分钟)">
|
||||
<input
|
||||
type="number"
|
||||
value={settings.duplicateWindowMinutes}
|
||||
onChange={(event) =>
|
||||
setSettings({
|
||||
...settings,
|
||||
duplicateWindowMinutes: Number(event.target.value),
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="数据保留天数">
|
||||
<input
|
||||
type="number"
|
||||
value={settings.dataRetentionDays}
|
||||
onChange={(event) =>
|
||||
setSettings({
|
||||
...settings,
|
||||
dataRetentionDays: Number(event.target.value),
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="启用客户自动回复">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={settings.autoReplyEnabled}
|
||||
onChange={(event) =>
|
||||
setSettings({
|
||||
...settings,
|
||||
autoReplyEnabled: event.target.checked,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field wide label="自动回复英文主题">
|
||||
<input
|
||||
value={settings.autoReplySubject || ""}
|
||||
onChange={(event) =>
|
||||
setSettings({
|
||||
...settings,
|
||||
autoReplySubject: event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field wide label="自动回复英文内容">
|
||||
<textarea
|
||||
rows={5}
|
||||
value={settings.autoReplyContent || ""}
|
||||
onChange={(event) =>
|
||||
setSettings({
|
||||
...settings,
|
||||
autoReplyContent: event.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<div className="settings-actions">
|
||||
<button
|
||||
className="primary"
|
||||
disabled={saving}
|
||||
onClick={saveSettings}
|
||||
>
|
||||
保存设置
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
) : (
|
||||
<>
|
||||
<div className="forms-heading">
|
||||
<div>
|
||||
<h2>询盘表单</h2>
|
||||
<p>配置不同展示位置使用的英文询盘表单。</p>
|
||||
</div>
|
||||
<button className="primary" onClick={() => setEditing(emptyForm())}>
|
||||
<Plus size={17} />
|
||||
新增表单
|
||||
</button>
|
||||
</div>
|
||||
<section className="forms-list">
|
||||
{forms.length === 0 ? (
|
||||
<div className="empty">
|
||||
<strong>暂无询盘表单</strong>
|
||||
<p>创建表单后发布到产品详情、联系页或全站悬浮入口。</p>
|
||||
</div>
|
||||
) : (
|
||||
forms.map((form) => (
|
||||
<div className="form-list-row" key={form.formCode}>
|
||||
<div>
|
||||
<strong>{form.formName}</strong>
|
||||
<small>{sceneLabels[form.scene] || form.scene}</small>
|
||||
</div>
|
||||
<span className={`status ${form.status.toLowerCase()}`}>
|
||||
{form.status === "PUBLISHED"
|
||||
? "已发布"
|
||||
: form.status === "OFFLINE"
|
||||
? "已下线"
|
||||
: "草稿"}
|
||||
</span>
|
||||
<span>{form.fields.length} 个字段</span>
|
||||
<button
|
||||
className="link"
|
||||
onClick={() =>
|
||||
setEditing({ ...form, fields: form.fields || [] })
|
||||
}
|
||||
>
|
||||
<Edit3 size={15} />
|
||||
编辑
|
||||
</button>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</section>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Field({ label, wide, children }: { label: string; wide?: boolean; children: React.ReactNode }) { return <label className={wide ? "wide" : ""}><span>{label}</span>{children}</label>; }
|
||||
function Field({
|
||||
label,
|
||||
wide,
|
||||
children,
|
||||
}: {
|
||||
label: string;
|
||||
wide?: boolean;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<label className={wide ? "wide" : ""}>
|
||||
<span>{label}</span>
|
||||
{children}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
@@ -50,7 +50,12 @@ type Item = {
|
||||
customerEmail?: string;
|
||||
companyName?: string;
|
||||
countryCode?: string;
|
||||
countryName?: string;
|
||||
provinceName?: string;
|
||||
cityName?: string;
|
||||
clientIp?: string;
|
||||
readStatus?: number;
|
||||
inquiryTitle?: string;
|
||||
sourceType?: string;
|
||||
statusLabel?: string;
|
||||
createTime?: string;
|
||||
@@ -364,7 +369,7 @@ function App() {
|
||||
item.productCode || item.contentCode || item.pageCode || item.inquiryCode || index
|
||||
}
|
||||
>
|
||||
{section === "inquiries" ? <><span><strong>{item.companyName || item.customerName || "--"}</strong><small>{item.customerName || "--"}</small></span><span>{item.customerEmail || "--"}</span><span>{item.countryCode || "未知"}({item.clientIp || "--"})</span><span>{item.createTime?.replace("T", " ").slice(0, 16) || "--"}</span><span>{item.productName || item.sourceType || "网站询盘"}</span><span className={`status ${item.status.toLowerCase()}`}>{item.statusLabel || item.status}</span><div className="row-actions"><button className="link">查看</button></div></> : <><span><strong>{item.productName || item.title || item.pageName}</strong><small>{item.model || item.productCode || item.contentCode || item.pageCode}</small></span><code>/{item.slug}</code><span className={`status ${item.status.toLowerCase()}`}>{statusLabels[item.status] || item.status}</span><span>{item.publishTime?.replace("T", " ").slice(0, 16) || "--"}</span><div className="row-actions">{["products", "NEWS", "CASE", "HELP"].includes(section) && item.slug && <a className="link" href={`${SITE_WEB}/${section === "products" ? "products" : section === "CASE" ? "cases" : section === "NEWS" ? "news" : "help"}/${encodeURIComponent(item.slug)}`} target="_blank" rel="noreferrer">查看前台</a>}<button className="link" onClick={() => section === "products" && item.productCode ? openProductEditor(item.productCode) : ["NEWS", "CASE", "HELP"].includes(section) && item.contentCode ? openContentEditor(section as EditorialSection, item.contentCode) : section === "pages" && item.pageCode ? openPageEditor(item.pageCode) : undefined}>编辑</button>{["products", "NEWS", "CASE", "HELP"].includes(section) && <><button className="link" onClick={() => void changeItemStatus(item)}>{item.status === "PUBLISHED" ? "下架" : "上架"}</button><button className="link danger" onClick={() => void deleteItem(item)}>删除</button></>}</div></>}
|
||||
{section === "inquiries" ? <><span><strong>{item.companyName || item.customerName || "--"}</strong><small>{item.customerName || "--"}</small></span><span>{item.customerEmail || "--"}</span><span>{item.countryName || item.countryCode || "未知"}({item.clientIp || "--"})</span><span>{item.createTime?.replace("T", " ").slice(0, 16) || "--"}</span><span>{item.productName || item.inquiryTitle || item.sourceType || "网站询盘"}</span><span className={`status ${item.status.toLowerCase()}`}>{item.readStatus === 0 ? "未读" : item.statusLabel || item.status}</span><div className="row-actions"><button className="link">查看</button></div></> : <><span><strong>{item.productName || item.title || item.pageName}</strong><small>{item.model || item.productCode || item.contentCode || item.pageCode}</small></span><code>/{item.slug}</code><span className={`status ${item.status.toLowerCase()}`}>{statusLabels[item.status] || item.status}</span><span>{item.publishTime?.replace("T", " ").slice(0, 16) || "--"}</span><div className="row-actions">{["products", "NEWS", "CASE", "HELP"].includes(section) && item.slug && <a className="link" href={`${SITE_WEB}/${section === "products" ? "products" : section === "CASE" ? "cases" : section === "NEWS" ? "news" : "help"}/${encodeURIComponent(item.slug)}`} target="_blank" rel="noreferrer">查看前台</a>}<button className="link" onClick={() => section === "products" && item.productCode ? openProductEditor(item.productCode) : ["NEWS", "CASE", "HELP"].includes(section) && item.contentCode ? openContentEditor(section as EditorialSection, item.contentCode) : section === "pages" && item.pageCode ? openPageEditor(item.pageCode) : undefined}>编辑</button>{["products", "NEWS", "CASE", "HELP"].includes(section) && <><button className="link" onClick={() => void changeItemStatus(item)}>{item.status === "PUBLISHED" ? "下架" : "上架"}</button><button className="link danger" onClick={() => void deleteItem(item)}>删除</button></>}</div></>}
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user