diff --git a/app/(admin)/settings/style-pro/style-pro-settings-client.tsx b/app/(admin)/settings/style-pro/style-pro-settings-client.tsx index 773e33a83..5e9025928 100644 --- a/app/(admin)/settings/style-pro/style-pro-settings-client.tsx +++ b/app/(admin)/settings/style-pro/style-pro-settings-client.tsx @@ -31,6 +31,8 @@ import { normalizeStyleProConfig, type StyleProCategory, type StyleProConfig, + type StyleProCustomField, + type StyleProCustomFieldType, type StyleProOption, } from "@/lib/style-pro/config"; @@ -66,6 +68,7 @@ function reindexCategories(categories: StyleProCategory[]) { return categories.map((category, index) => ({ ...category, order: (index + 1) * 10, + customFields: reindexCustomFields(category.customFields || []), options: category.options.map((option, optionIndex) => ({ ...option, order: (optionIndex + 1) * 10, @@ -73,6 +76,13 @@ function reindexCategories(categories: StyleProCategory[]) { })); } +function reindexCustomFields(fields: StyleProCustomField[]) { + return fields.map((field, index) => ({ + ...field, + order: (index + 1) * 10, + })); +} + function createCategory(): StyleProCategory { const id = getId("category"); return { @@ -84,10 +94,27 @@ function createCategory(): StyleProCategory { maxSelections: 1, enabled: true, order: 999, + customFields: [], options: [createOption(id)], }; } +function createCustomField(prefix = "custom"): StyleProCustomField { + return { + id: getId(`${prefix}-field`), + label: "自定义要求", + description: "", + type: "text", + placeholder: "请输入自定义要求...", + defaultValue: "", + promptTemplate: "{{fieldLabel}}:{{value}}", + required: false, + enabled: true, + order: 999, + maxLength: 160, + }; +} + function createOption(categoryId: string): StyleProOption { return { id: getId("option"), @@ -147,6 +174,153 @@ function ColorSettingField({ ); } +function CustomFieldEditor({ + field, + onChange, + onRemove, +}: { + field: StyleProCustomField; + onChange: (updates: Partial) => void; + onRemove: () => void; +}) { + const fieldTypeOptions: Array<{ value: StyleProCustomFieldType; label: string }> = [ + { value: "text", label: "单行文本" }, + { value: "textarea", label: "多行文本" }, + { value: "color", label: "颜色选择" }, + ]; + + return ( +
+
+
+
{field.label || "未命名自定义项"}
+
+ {field.type === "color" + ? "颜色选择" + : field.type === "textarea" + ? "多行文本" + : "单行文本"} +
+
+
+ onChange({ enabled })} + /> + +
+
+
+
+ + onChange({ label: event.target.value })} + value={field.label} + /> +
+
+ + onChange({ id: event.target.value })} + value={field.id} + /> +
+
+ + +
+
+ + + onChange({ maxLength: Number(event.target.value) || 160 }) + } + type="number" + value={field.maxLength || (field.type === "textarea" ? 800 : 160)} + /> +
+
+ +
+ {field.type === "color" ? ( + onChange({ defaultValue: event.target.value })} + type="color" + value={ + /^#[0-9a-fA-F]{6}$/.test(field.defaultValue || "") + ? field.defaultValue + : "#ffffff" + } + /> + ) : null} + onChange({ defaultValue: event.target.value })} + placeholder={field.type === "color" ? "#FFFFFF" : "可留空"} + value={field.defaultValue || ""} + /> +
+
+
+ + onChange({ placeholder: event.target.value })} + placeholder="请输入自定义要求..." + value={field.placeholder || ""} + /> +
+
+ + onChange({ description: event.target.value })} + value={field.description || ""} + /> +
+
+ +