|
|
@@ -17,13 +17,14 @@ import {
|
|
|
Columns,
|
|
|
Sparkles,
|
|
|
Layers,
|
|
|
- HelpCircle,
|
|
|
Braces,
|
|
|
Minimize2,
|
|
|
AlertCircle
|
|
|
} from 'lucide-react';
|
|
|
import Editor from '@monaco-editor/react';
|
|
|
import { toast } from 'react-hot-toast';
|
|
|
+import { retroConfirm } from '@/lib/dialog';
|
|
|
+import JsonEditor from '@/components/common/JsonEditor';
|
|
|
import { SchemaItem } from '@/types';
|
|
|
|
|
|
interface SchemaManagerProps {
|
|
|
@@ -31,7 +32,6 @@ interface SchemaManagerProps {
|
|
|
onClose: () => void;
|
|
|
}
|
|
|
|
|
|
-// 常用 Schema 预设模板
|
|
|
const SCHEMA_TEMPLATES = [
|
|
|
{
|
|
|
name: '标准签证申请人材料模板',
|
|
|
@@ -59,56 +59,25 @@ const SCHEMA_TEMPLATES = [
|
|
|
default: 'China',
|
|
|
enum: ['China', 'Hong Kong', 'Taiwan', 'Other'],
|
|
|
},
|
|
|
- birthday: {
|
|
|
+ birth_date: {
|
|
|
type: 'string',
|
|
|
format: 'date',
|
|
|
title: '出生日期',
|
|
|
- placeholder: 'YYYY-MM-DD',
|
|
|
},
|
|
|
visa_center: {
|
|
|
type: 'string',
|
|
|
- title: '递签签证中心',
|
|
|
+ title: '递签中心',
|
|
|
enum: ['Beijing', 'Shanghai', 'Guangzhou', 'Chengdu', 'Wuhan', 'Shenyang'],
|
|
|
},
|
|
|
- slot_routing_key: {
|
|
|
+ expected_date_start: {
|
|
|
type: 'string',
|
|
|
- title: '意向自动化槽位标识 (选填)',
|
|
|
- placeholder: '例如: fr_tls_shanghai_bot',
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- null,
|
|
|
- 2
|
|
|
- ),
|
|
|
- },
|
|
|
- {
|
|
|
- name: '联系人与寄送信息模板',
|
|
|
- description: '包含联系电话、电子邮箱、寄送地址',
|
|
|
- schema_json: JSON.stringify(
|
|
|
- {
|
|
|
- type: 'object',
|
|
|
- title: '联系与交付信息',
|
|
|
- required: ['contact_name', 'phone_number', 'email'],
|
|
|
- properties: {
|
|
|
- contact_name: {
|
|
|
- type: 'string',
|
|
|
- title: '联系人姓名',
|
|
|
- placeholder: '中文姓名',
|
|
|
- },
|
|
|
- phone_number: {
|
|
|
- type: 'string',
|
|
|
- title: '手机号码',
|
|
|
- placeholder: '用于接收进度短信通知',
|
|
|
- },
|
|
|
- email: {
|
|
|
- type: 'string',
|
|
|
- title: '电子邮箱',
|
|
|
- placeholder: '用于接收确认函与文件',
|
|
|
+ format: 'date',
|
|
|
+ title: '期望最早出发/预约日期',
|
|
|
},
|
|
|
- delivery_address: {
|
|
|
+ remarks: {
|
|
|
type: 'string',
|
|
|
- title: '回邮收件地址 (选填)',
|
|
|
- placeholder: '省/市/区/详细地址',
|
|
|
+ title: '备注说明 / 特殊诉求',
|
|
|
+ placeholder: '如有同行人或特殊加急需求可填写',
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -117,28 +86,23 @@ const SCHEMA_TEMPLATES = [
|
|
|
),
|
|
|
},
|
|
|
{
|
|
|
- name: '极简预约说明模板',
|
|
|
- description: '仅包含预约日期期望与备注文档',
|
|
|
+ name: '极简预约信息模板 (仅核心两项)',
|
|
|
+ description: '仅收集护照号和目标城市,适合快捷抢单',
|
|
|
schema_json: JSON.stringify(
|
|
|
{
|
|
|
type: 'object',
|
|
|
- title: '预约偏好设置',
|
|
|
- required: ['preferred_start_date'],
|
|
|
+ title: '极速抢单关键参数',
|
|
|
+ required: ['passport_number', 'city'],
|
|
|
properties: {
|
|
|
- preferred_start_date: {
|
|
|
- type: 'string',
|
|
|
- format: 'date',
|
|
|
- title: '最早期望预约日期',
|
|
|
- },
|
|
|
- preferred_end_date: {
|
|
|
+ passport_number: {
|
|
|
type: 'string',
|
|
|
- format: 'date',
|
|
|
- title: '最晚期望预约日期',
|
|
|
+ title: '护照号码',
|
|
|
+ placeholder: 'E12345678',
|
|
|
},
|
|
|
- notes: {
|
|
|
+ city: {
|
|
|
type: 'string',
|
|
|
- title: '特殊说明与备注',
|
|
|
- placeholder: '如有同行人或特定时间段要求请注明',
|
|
|
+ title: '意向递签城市',
|
|
|
+ placeholder: 'Paris / London / Rome',
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -152,28 +116,24 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
const [schemas, setSchemas] = useState<SchemaItem[]>([]);
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
const [saving, setSaving] = useState(false);
|
|
|
- const [searchKey, setSearchKey] = useState('');
|
|
|
-
|
|
|
- // 移动端 Tab: 'list' | 'editor'
|
|
|
- const [mobileTab, setMobileTab] = useState<'list' | 'editor'>('list');
|
|
|
-
|
|
|
- // 桌面端视图模式: 'split' | 'code' | 'preview'
|
|
|
- const [viewMode, setViewMode] = useState<'split' | 'code' | 'preview'>('split');
|
|
|
|
|
|
- // 编辑模式状态
|
|
|
const [editingId, setEditingId] = useState<number | null>(null);
|
|
|
const [formData, setFormData] = useState({
|
|
|
name: '',
|
|
|
description: '',
|
|
|
- schema_json: SCHEMA_TEMPLATES[0].schema_json,
|
|
|
+ schema_json: '{}',
|
|
|
});
|
|
|
|
|
|
+ const [searchKey, setSearchKey] = useState('');
|
|
|
+ const [viewMode, setViewMode] = useState<'split' | 'code' | 'preview'>('split');
|
|
|
+ const [previewTab, setPreviewTab] = useState<'form' | 'tree' | 'raw'>('form');
|
|
|
+ const [mobileTab, setMobileTab] = useState<'list' | 'editor'>('list');
|
|
|
const [copied, setCopied] = useState(false);
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (isOpen) {
|
|
|
fetchSchemas();
|
|
|
- setMobileTab('list');
|
|
|
+ handleCreateNew();
|
|
|
}
|
|
|
}, [isOpen]);
|
|
|
|
|
|
@@ -183,47 +143,13 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
const res = await api.get('/api/vas/schema/list');
|
|
|
const list = Array.isArray(res.data?.data) ? res.data.data : [];
|
|
|
setSchemas(list);
|
|
|
- // 如果没有正在编辑的对象,且列表有数据,默认不强行选中,保持清晰新建态
|
|
|
- } catch (e) {
|
|
|
- toast.error('加载 Schema 列表失败');
|
|
|
+ } catch {
|
|
|
setSchemas([]);
|
|
|
} finally {
|
|
|
setLoading(false);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- const handleSelectSchema = async (item: SchemaItem) => {
|
|
|
- setEditingId(item.id);
|
|
|
- setMobileTab('editor');
|
|
|
-
|
|
|
- // 尝试拉取完整详情获取完整的 schema_json
|
|
|
- try {
|
|
|
- const res = await api.get('/api/vas/schema/detail', {
|
|
|
- params: { schema_id: item.id, id: item.id },
|
|
|
- });
|
|
|
- const detail = res.data?.data || res.data || item;
|
|
|
- const rawJson = detail.schema_json || detail.content;
|
|
|
- setFormData({
|
|
|
- name: detail.name || item.name,
|
|
|
- description: detail.description || item.description || '',
|
|
|
- schema_json:
|
|
|
- typeof rawJson === 'string'
|
|
|
- ? rawJson
|
|
|
- : JSON.stringify(rawJson || {}, null, 2),
|
|
|
- });
|
|
|
- } catch (e) {
|
|
|
- const rawJson = item.schema_json || item.content;
|
|
|
- setFormData({
|
|
|
- name: item.name,
|
|
|
- description: item.description || '',
|
|
|
- schema_json:
|
|
|
- typeof rawJson === 'string'
|
|
|
- ? rawJson
|
|
|
- : JSON.stringify(rawJson || {}, null, 2),
|
|
|
- });
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
const handleCreateNew = () => {
|
|
|
setEditingId(null);
|
|
|
setFormData({
|
|
|
@@ -234,38 +160,59 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
setMobileTab('editor');
|
|
|
};
|
|
|
|
|
|
- const handleApplyTemplate = (template: typeof SCHEMA_TEMPLATES[0]) => {
|
|
|
- if (!formData.name) {
|
|
|
- setFormData({
|
|
|
- name: template.name,
|
|
|
- description: template.description,
|
|
|
- schema_json: template.schema_json,
|
|
|
- });
|
|
|
- } else {
|
|
|
- setFormData((prev) => ({
|
|
|
- ...prev,
|
|
|
- schema_json: template.schema_json,
|
|
|
- }));
|
|
|
+ const handleSelectSchema = (schema: SchemaItem) => {
|
|
|
+ setEditingId(schema.id);
|
|
|
+ let jsonStr = '{}';
|
|
|
+ if (typeof schema.schema_json === 'string') {
|
|
|
+ try {
|
|
|
+ jsonStr = JSON.stringify(JSON.parse(schema.schema_json), null, 2);
|
|
|
+ } catch {
|
|
|
+ jsonStr = schema.schema_json;
|
|
|
+ }
|
|
|
+ } else if (typeof schema.schema_json === 'object' && schema.schema_json !== null) {
|
|
|
+ jsonStr = JSON.stringify(schema.schema_json, null, 2);
|
|
|
}
|
|
|
- toast.success(`已插入模板: ${template.name}`);
|
|
|
+
|
|
|
+ setFormData({
|
|
|
+ name: schema.name || '',
|
|
|
+ description: schema.description || '',
|
|
|
+ schema_json: jsonStr,
|
|
|
+ });
|
|
|
+ setMobileTab('editor');
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleApplyTemplate = (tmpl: (typeof SCHEMA_TEMPLATES)[0]) => {
|
|
|
+ setFormData((prev) => ({
|
|
|
+ ...prev,
|
|
|
+ name: prev.name || tmpl.name,
|
|
|
+ description: prev.description || tmpl.description,
|
|
|
+ schema_json: tmpl.schema_json,
|
|
|
+ }));
|
|
|
+ toast.success(`已注入模板: ${tmpl.name}`);
|
|
|
};
|
|
|
|
|
|
const handleFormatJson = () => {
|
|
|
try {
|
|
|
const parsed = JSON.parse(formData.schema_json);
|
|
|
- setFormData((prev) => ({ ...prev, schema_json: JSON.stringify(parsed, null, 2) }));
|
|
|
- toast.success('JSON 已格式化');
|
|
|
- } catch (e: any) {
|
|
|
- toast.error('JSON 语法错误,无法格式化: ' + e.message);
|
|
|
+ setFormData((prev) => ({
|
|
|
+ ...prev,
|
|
|
+ schema_json: JSON.stringify(parsed, null, 2),
|
|
|
+ }));
|
|
|
+ toast.success('JSON 格式化成功');
|
|
|
+ } catch {
|
|
|
+ toast.error('JSON 语法错误,无法格式化');
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const handleCompactJson = () => {
|
|
|
try {
|
|
|
const parsed = JSON.parse(formData.schema_json);
|
|
|
- setFormData((prev) => ({ ...prev, schema_json: JSON.stringify(parsed) }));
|
|
|
+ setFormData((prev) => ({
|
|
|
+ ...prev,
|
|
|
+ schema_json: JSON.stringify(parsed),
|
|
|
+ }));
|
|
|
toast.success('JSON 已压缩');
|
|
|
- } catch (e: any) {
|
|
|
+ } catch {
|
|
|
toast.error('JSON 语法错误,无法压缩');
|
|
|
}
|
|
|
};
|
|
|
@@ -273,35 +220,45 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
const handleCopyJson = () => {
|
|
|
navigator.clipboard.writeText(formData.schema_json);
|
|
|
setCopied(true);
|
|
|
- toast.success('已复制 Schema JSON');
|
|
|
- setTimeout(() => setCopied(false), 1500);
|
|
|
+ toast.success('Schema JSON 已复制到剪贴板');
|
|
|
+ setTimeout(() => setCopied(false), 2000);
|
|
|
};
|
|
|
|
|
|
const handleSave = async () => {
|
|
|
- if (!formData.name.trim()) {
|
|
|
- toast.error('请填写 Schema 模板名称');
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (!formData.name.trim()) return toast.error('请输入 Schema 名称');
|
|
|
|
|
|
- let parsed: any;
|
|
|
+ let parsedSchema: any = {};
|
|
|
try {
|
|
|
- parsed = JSON.parse(formData.schema_json);
|
|
|
+ parsedSchema = JSON.parse(formData.schema_json);
|
|
|
+ if (typeof parsedSchema !== 'object' || parsedSchema === null) {
|
|
|
+ throw new Error('Schema 必须是 JSON 对象');
|
|
|
+ }
|
|
|
} catch (e: any) {
|
|
|
- toast.error('JSON 语法格式有误,请先修复语法错误');
|
|
|
- return;
|
|
|
+ return toast.error('JSON Schema 语法无效: ' + e.message);
|
|
|
}
|
|
|
|
|
|
setSaving(true);
|
|
|
try {
|
|
|
if (editingId) {
|
|
|
- await api.post('/api/vas/schema/update', formData, { params: { id: editingId } });
|
|
|
+ await api.post(
|
|
|
+ '/api/vas/schema/update',
|
|
|
+ {
|
|
|
+ name: formData.name,
|
|
|
+ description: formData.description,
|
|
|
+ schema_json: parsedSchema,
|
|
|
+ },
|
|
|
+ { params: { id: editingId } }
|
|
|
+ );
|
|
|
toast.success(`Schema #${editingId} 更新成功`);
|
|
|
} else {
|
|
|
- const res = await api.post('/api/vas/schema/create', formData);
|
|
|
- toast.success('新 Schema 创建成功');
|
|
|
- if (res.data?.data?.id) {
|
|
|
- setEditingId(res.data.data.id);
|
|
|
- }
|
|
|
+ const res = await api.post('/api/vas/schema/create', {
|
|
|
+ name: formData.name,
|
|
|
+ description: formData.description,
|
|
|
+ schema_json: parsedSchema,
|
|
|
+ });
|
|
|
+ const createdId = res.data?.data?.id;
|
|
|
+ toast.success('新建表单 Schema 成功');
|
|
|
+ if (createdId) setEditingId(createdId);
|
|
|
}
|
|
|
fetchSchemas();
|
|
|
} catch (e: any) {
|
|
|
@@ -312,44 +269,43 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
};
|
|
|
|
|
|
const handleDelete = async (id: number) => {
|
|
|
- if (!confirm('删除 Schema 可能导致关联商品下单异常,确定删除吗?')) return;
|
|
|
+ const ok = await retroConfirm({
|
|
|
+ title: '[ CONFIRM // 删除表单定义 ]',
|
|
|
+ message: `确定要永久删除该 Schema #${id} 吗?此操作不可撤销!`,
|
|
|
+ type: 'danger',
|
|
|
+ confirmText: '[ 确认删除 ]',
|
|
|
+ });
|
|
|
+ if (!ok) return;
|
|
|
try {
|
|
|
- await api.delete('/api/vas/schema/delete', { params: { id: id } });
|
|
|
+ await api.delete('/api/vas/schema/delete', { params: { id } });
|
|
|
toast.success('Schema 已删除');
|
|
|
+ if (editingId === id) handleCreateNew();
|
|
|
fetchSchemas();
|
|
|
- if (editingId === id) {
|
|
|
- handleCreateNew();
|
|
|
- }
|
|
|
- } catch (e) {
|
|
|
+ } catch {
|
|
|
toast.error('删除失败');
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- // 解析当前编辑中的 Schema 用于实时渲染
|
|
|
const parsedPreview = useMemo(() => {
|
|
|
try {
|
|
|
const obj = JSON.parse(formData.schema_json);
|
|
|
- return {
|
|
|
- valid: true,
|
|
|
- data: obj,
|
|
|
- properties: obj.properties || {},
|
|
|
- required: Array.isArray(obj.required) ? obj.required : [],
|
|
|
- title: obj.title || formData.name || '动态表单实时预览',
|
|
|
- description: obj.description || formData.description,
|
|
|
- };
|
|
|
- } catch (e) {
|
|
|
+ const title = obj.title || formData.name || '动态收集表单';
|
|
|
+ const description = obj.description || formData.description || '';
|
|
|
+ const properties = obj.properties || {};
|
|
|
+ const required = Array.isArray(obj.required) ? obj.required : [];
|
|
|
+ return { valid: true, title, description, properties, required, error: null };
|
|
|
+ } catch (e: any) {
|
|
|
return {
|
|
|
valid: false,
|
|
|
- error: (e as Error).message,
|
|
|
- properties: {},
|
|
|
- required: [],
|
|
|
title: '',
|
|
|
description: '',
|
|
|
+ properties: {},
|
|
|
+ required: [],
|
|
|
+ error: e.message,
|
|
|
};
|
|
|
}
|
|
|
}, [formData.schema_json, formData.name, formData.description]);
|
|
|
|
|
|
- // 过滤 Schema 列表
|
|
|
const filteredSchemas = useMemo(() => {
|
|
|
if (!searchKey.trim()) return schemas;
|
|
|
const lower = searchKey.trim().toLowerCase();
|
|
|
@@ -364,101 +320,88 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
if (!isOpen) return null;
|
|
|
|
|
|
return (
|
|
|
- <div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-0 md:p-4 animate-in fade-in duration-200">
|
|
|
- <div className="bg-white w-full h-full md:w-full md:max-w-6xl md:h-[90vh] md:rounded-2xl shadow-2xl flex flex-col overflow-hidden border border-slate-200">
|
|
|
+ <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-grayscale p-0 md:p-4 font-mono">
|
|
|
+ <div className="bg-neutral-50 w-full h-full md:w-full md:max-w-6xl md:h-[90vh] border-2 border-black shadow-[8px_8px_0px_#000] flex flex-col overflow-hidden animate-in zoom-in-95 duration-200">
|
|
|
|
|
|
{/* Header */}
|
|
|
- <div className="px-5 py-3.5 border-b border-slate-200 flex justify-between items-center bg-slate-50 flex-shrink-0">
|
|
|
+ <div className="px-5 py-3.5 border-b-2 border-black flex justify-between items-center bg-neutral-200 text-black select-none shrink-0">
|
|
|
<div className="flex items-center gap-3">
|
|
|
- <div className="p-2 bg-purple-50 text-purple-600 rounded-xl border border-purple-100 hidden sm:block">
|
|
|
- <FileJson size={22} />
|
|
|
- </div>
|
|
|
+ <span className="w-2.5 h-2.5 bg-amber-300 border border-black inline-block" />
|
|
|
<div>
|
|
|
<div className="flex items-center gap-2">
|
|
|
- <h3 className="font-extrabold text-slate-900 text-base md:text-lg">
|
|
|
- 表单 Schema 定义中心
|
|
|
+ <h3 className="font-black text-black text-xs md:text-sm uppercase tracking-wider">
|
|
|
+ [ SCHEMA DEFINITION IDE // 动态表单定义中心 ]
|
|
|
</h3>
|
|
|
- <span className="px-2 py-0.5 rounded-full text-xs font-semibold bg-purple-100 text-purple-800">
|
|
|
- JSON Schema IDE
|
|
|
+ <span className="font-bold text-[10px] text-black bg-amber-300 border border-black px-1.5 py-0.2">
|
|
|
+ JSON SCHEMA
|
|
|
</span>
|
|
|
</div>
|
|
|
- <p className="text-xs text-slate-500">
|
|
|
+ <p className="text-[10px] text-neutral-500 mt-0.5">
|
|
|
定义前台用户下单时的动态字段采集规范与表单交互逻辑
|
|
|
</p>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
- <div className="flex items-center gap-2">
|
|
|
- <button
|
|
|
- onClick={onClose}
|
|
|
- className="p-1.5 text-slate-400 hover:text-slate-700 rounded-lg hover:bg-slate-200 transition"
|
|
|
- >
|
|
|
- <X size={20} />
|
|
|
- </button>
|
|
|
- </div>
|
|
|
+ <button
|
|
|
+ onClick={onClose}
|
|
|
+ className="w-6 h-6 bg-white hover:bg-amber-300 border border-black flex items-center justify-center font-bold text-xs transition"
|
|
|
+ >
|
|
|
+ ✕
|
|
|
+ </button>
|
|
|
</div>
|
|
|
|
|
|
{/* Mobile Tabs */}
|
|
|
- <div className="flex md:hidden border-b border-slate-200 flex-shrink-0 bg-slate-50 text-xs font-bold">
|
|
|
+ <div className="flex md:hidden border-b-2 border-black bg-neutral-100 text-xs font-bold uppercase">
|
|
|
<button
|
|
|
onClick={() => setMobileTab('list')}
|
|
|
- className={`flex-1 py-2.5 flex items-center justify-center gap-1.5 ${
|
|
|
- mobileTab === 'list'
|
|
|
- ? 'text-purple-700 border-b-2 border-purple-600 bg-white'
|
|
|
- : 'text-slate-500'
|
|
|
+ className={`flex-1 py-2.5 ${
|
|
|
+ mobileTab === 'list' ? 'bg-amber-300 text-black border-b-2 border-black' : 'text-neutral-600'
|
|
|
}`}
|
|
|
>
|
|
|
- <Layers size={14} /> 模板列表 ({schemas.length})
|
|
|
+ 模板列表 ({schemas.length})
|
|
|
</button>
|
|
|
<button
|
|
|
onClick={() => setMobileTab('editor')}
|
|
|
- className={`flex-1 py-2.5 flex items-center justify-center gap-1.5 ${
|
|
|
- mobileTab === 'editor'
|
|
|
- ? 'text-purple-700 border-b-2 border-purple-600 bg-white'
|
|
|
- : 'text-slate-500'
|
|
|
+ className={`flex-1 py-2.5 ${
|
|
|
+ mobileTab === 'editor' ? 'bg-amber-300 text-black border-b-2 border-black' : 'text-neutral-600'
|
|
|
}`}
|
|
|
>
|
|
|
- <Code2 size={14} /> {editingId ? `编辑 #${editingId}` : '新建 Schema'}
|
|
|
+ {editingId ? `编辑 #${editingId}` : '+ 新建 SCHEMA'}
|
|
|
</button>
|
|
|
</div>
|
|
|
|
|
|
{/* Content Body */}
|
|
|
<div className="flex flex-1 overflow-hidden">
|
|
|
|
|
|
- {/* ======================= */}
|
|
|
{/* 左侧:Schema 列表检索栏 */}
|
|
|
- {/* ======================= */}
|
|
|
<div
|
|
|
- className={`flex-col bg-slate-50/80 border-r border-slate-200 overflow-y-auto p-4 ${
|
|
|
+ className={`flex-col bg-neutral-100 border-r-2 border-black overflow-y-auto p-4 ${
|
|
|
mobileTab === 'list' ? 'flex w-full' : 'hidden'
|
|
|
- } md:flex md:w-80 lg:w-96 flex-shrink-0`}
|
|
|
+ } md:flex md:w-80 lg:w-96 shrink-0 space-y-3`}
|
|
|
>
|
|
|
- {/* 新建按钮 */}
|
|
|
<button
|
|
|
onClick={handleCreateNew}
|
|
|
- className="w-full mb-3.5 py-2.5 px-4 bg-purple-600 hover:bg-purple-700 text-white rounded-xl flex items-center justify-center gap-2 font-bold text-xs shadow-sm transition active:scale-98"
|
|
|
+ className="w-full py-2 px-3 bg-amber-300 hover:bg-amber-400 text-black border-2 border-black font-black text-xs shadow-[2px_2px_0px_#000] uppercase transition active:translate-x-0.5 active:translate-y-0.5 flex items-center justify-center gap-1.5"
|
|
|
>
|
|
|
- <Plus size={16} /> 新建 Schema 模板
|
|
|
+ <Plus size={14} /> <span>[ 新建 SCHEMA 模板 ]</span>
|
|
|
</button>
|
|
|
|
|
|
- {/* 搜索框 */}
|
|
|
- <div className="relative mb-3">
|
|
|
+ <div className="relative">
|
|
|
<input
|
|
|
type="text"
|
|
|
placeholder="搜索 Schema 名称 / ID..."
|
|
|
- className="w-full pl-8 pr-3 py-1.5 border border-slate-300 rounded-lg text-xs outline-none focus:ring-2 focus:ring-purple-500 bg-white"
|
|
|
+ className="w-full pl-8 pr-3 py-1.5 border-2 border-black bg-white text-xs font-mono outline-none shadow-[2px_2px_0px_#000] text-black"
|
|
|
value={searchKey}
|
|
|
onChange={(e) => setSearchKey(e.target.value)}
|
|
|
/>
|
|
|
- <Search size={14} className="absolute left-2.5 top-2 text-slate-400" />
|
|
|
+ <Search size={13} className="absolute left-2.5 top-2 text-black pointer-events-none" />
|
|
|
</div>
|
|
|
|
|
|
- {/* 列表流 */}
|
|
|
- <div className="space-y-2 flex-1 overflow-y-auto pr-0.5">
|
|
|
+ <div className="space-y-2 flex-1 overflow-y-auto">
|
|
|
{loading ? (
|
|
|
- <div className="py-12 text-center text-xs text-slate-400">
|
|
|
- <div className="inline-block animate-spin rounded-full h-5 w-5 border-2 border-slate-300 border-t-purple-600 mb-2" />
|
|
|
- <div>加载 Schema 列表中...</div>
|
|
|
+ <div className="py-8 text-center text-xs text-neutral-500">
|
|
|
+ <Loader2 size={16} className="animate-spin text-black mx-auto mb-1" />
|
|
|
+ <span>[ 加载列表中... ]</span>
|
|
|
</div>
|
|
|
) : filteredSchemas.length > 0 ? (
|
|
|
filteredSchemas.map((s) => {
|
|
|
@@ -467,20 +410,18 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
<div
|
|
|
key={s.id}
|
|
|
onClick={() => handleSelectSchema(s)}
|
|
|
- className={`p-3 rounded-xl border transition cursor-pointer text-xs relative ${
|
|
|
- isSelected
|
|
|
- ? 'bg-purple-50 border-purple-300 ring-1 ring-purple-300 shadow-sm'
|
|
|
- : 'bg-white border-slate-200 hover:border-slate-300 hover:bg-slate-50'
|
|
|
+ className={`p-2.5 border-2 border-black cursor-pointer text-xs transition bg-white space-y-1 ${
|
|
|
+ isSelected ? 'bg-amber-200 shadow-[3px_3px_0px_#000]' : 'shadow-[1px_1px_0px_#000] hover:bg-neutral-50'
|
|
|
}`}
|
|
|
>
|
|
|
- <div className="flex items-start justify-between gap-2">
|
|
|
- <span className="font-bold text-slate-900 line-clamp-1">{s.name}</span>
|
|
|
- <span className="font-mono text-[10px] text-purple-700 bg-purple-100/80 px-1.5 py-0.2 rounded shrink-0">
|
|
|
+ <div className="flex items-start justify-between gap-1.5">
|
|
|
+ <span className="font-bold text-black truncate font-sans">{s.name}</span>
|
|
|
+ <span className="font-mono text-[10px] font-bold text-black bg-neutral-100 border border-black px-1 shrink-0">
|
|
|
#{s.id}
|
|
|
</span>
|
|
|
</div>
|
|
|
{s.description && (
|
|
|
- <p className="text-slate-500 text-[11px] line-clamp-1 mt-1">
|
|
|
+ <p className="text-neutral-500 font-sans text-[10px] truncate">
|
|
|
{s.description}
|
|
|
</p>
|
|
|
)}
|
|
|
@@ -488,64 +429,53 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
);
|
|
|
})
|
|
|
) : (
|
|
|
- <div className="py-8 text-center text-xs text-slate-400 bg-white rounded-lg border border-dashed border-slate-200">
|
|
|
- 暂无匹配的 Schema
|
|
|
+ <div className="py-6 text-center text-xs text-neutral-400 bg-white border border-dashed border-neutral-300">
|
|
|
+ [ 暂无匹配的 Schema ]
|
|
|
</div>
|
|
|
)}
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
- {/* ======================= */}
|
|
|
- {/* 右侧:工作区 (表单 + 编辑器 + 实时预览) */}
|
|
|
- {/* ======================= */}
|
|
|
+ {/* 右侧:工作区 */}
|
|
|
<div
|
|
|
className={`flex-1 flex-col overflow-y-auto bg-white ${
|
|
|
mobileTab === 'editor' ? 'flex' : 'hidden'
|
|
|
} md:flex`}
|
|
|
>
|
|
|
{/* 工作区顶部属性区 */}
|
|
|
- <div className="p-4 bg-slate-50/60 border-b border-slate-200 space-y-3 flex-shrink-0">
|
|
|
- <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
|
|
|
- <div className="flex items-center gap-2">
|
|
|
- <span className="font-mono text-xs font-bold text-purple-700 bg-purple-100 px-2 py-0.5 rounded">
|
|
|
- {editingId ? `编辑中 #${editingId}` : '创建新 Schema'}
|
|
|
+ <div className="p-4 bg-neutral-50 border-b-2 border-black space-y-3 shrink-0">
|
|
|
+ <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
|
|
|
+ <div className="flex items-center gap-2 text-xs">
|
|
|
+ <span className="font-mono font-black text-black bg-amber-300 border border-black px-1.5 py-0.2">
|
|
|
+ {editingId ? `[ 编辑中 #${editingId} ]` : '[ 新建 SCHEMA ]'}
|
|
|
</span>
|
|
|
- <span className="text-xs text-slate-400 font-medium">|</span>
|
|
|
- <span className="text-xs text-slate-500">
|
|
|
- 字段数: <strong className="text-purple-700">{Object.keys(parsedPreview.properties).length}</strong>
|
|
|
+ <span className="text-neutral-500">
|
|
|
+ 字段数: <strong className="text-black font-mono">{Object.keys(parsedPreview.properties).length}</strong>
|
|
|
</span>
|
|
|
</div>
|
|
|
|
|
|
- {/* 视图切换按钮 & 操作 */}
|
|
|
<div className="flex items-center gap-2">
|
|
|
- {/* 桌面端视图切换 */}
|
|
|
- <div className="hidden lg:flex bg-slate-200/80 p-0.5 rounded-lg text-xs font-semibold text-slate-600">
|
|
|
+ <div className="hidden lg:flex border-2 border-black bg-neutral-100 text-xs font-bold uppercase">
|
|
|
<button
|
|
|
type="button"
|
|
|
onClick={() => setViewMode('split')}
|
|
|
- className={`px-2.5 py-1 rounded-md flex items-center gap-1 transition ${
|
|
|
- viewMode === 'split' ? 'bg-white text-purple-700 shadow-sm' : 'hover:text-slate-900'
|
|
|
- }`}
|
|
|
+ className={`px-2 py-1 ${viewMode === 'split' ? 'bg-amber-300 text-black border-r-2 border-black' : 'text-neutral-700'}`}
|
|
|
>
|
|
|
- <Columns size={13} /> 双栏对照
|
|
|
+ 双栏对照
|
|
|
</button>
|
|
|
<button
|
|
|
type="button"
|
|
|
onClick={() => setViewMode('code')}
|
|
|
- className={`px-2.5 py-1 rounded-md flex items-center gap-1 transition ${
|
|
|
- viewMode === 'code' ? 'bg-white text-purple-700 shadow-sm' : 'hover:text-slate-900'
|
|
|
- }`}
|
|
|
+ className={`px-2 py-1 ${viewMode === 'code' ? 'bg-amber-300 text-black border-r-2 border-black' : 'text-neutral-700'}`}
|
|
|
>
|
|
|
- <Code2 size={13} /> 仅代码
|
|
|
+ 仅代码
|
|
|
</button>
|
|
|
<button
|
|
|
type="button"
|
|
|
onClick={() => setViewMode('preview')}
|
|
|
- className={`px-2.5 py-1 rounded-md flex items-center gap-1 transition ${
|
|
|
- viewMode === 'preview' ? 'bg-white text-purple-700 shadow-sm' : 'hover:text-slate-900'
|
|
|
- }`}
|
|
|
+ className={`px-2 py-1 ${viewMode === 'preview' ? 'bg-amber-300 text-black' : 'text-neutral-700'}`}
|
|
|
>
|
|
|
- <Eye size={13} /> 仅表单预览
|
|
|
+ 表单预览
|
|
|
</button>
|
|
|
</div>
|
|
|
|
|
|
@@ -553,9 +483,9 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
<button
|
|
|
type="button"
|
|
|
onClick={() => handleDelete(editingId)}
|
|
|
- className="px-2.5 py-1.5 text-rose-600 hover:bg-rose-50 border border-rose-200 rounded-lg text-xs font-semibold transition flex items-center gap-1"
|
|
|
+ className="px-2 py-1 text-rose-800 bg-rose-100 hover:bg-rose-200 border border-black text-xs font-bold uppercase shadow-[1px_1px_0px_#000]"
|
|
|
>
|
|
|
- <Trash2 size={13} /> 删除
|
|
|
+ 删除
|
|
|
</button>
|
|
|
)}
|
|
|
|
|
|
@@ -563,37 +493,37 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
type="button"
|
|
|
onClick={handleSave}
|
|
|
disabled={saving}
|
|
|
- className="px-4 py-1.5 bg-purple-600 hover:bg-purple-700 text-white rounded-lg text-xs font-bold shadow-sm transition flex items-center gap-1.5 disabled:opacity-50"
|
|
|
+ className="px-4 py-1 bg-amber-300 hover:bg-amber-400 text-black border-2 border-black text-xs font-black shadow-[2px_2px_0px_#000] uppercase transition active:translate-x-0.5 active:translate-y-0.5 flex items-center gap-1 disabled:opacity-50"
|
|
|
>
|
|
|
- {saving ? <Loader2 size={14} className="animate-spin" /> : <Save size={14} />}
|
|
|
- 保存 Schema
|
|
|
+ {saving ? <Loader2 size={13} className="animate-spin" /> : <Save size={13} />}
|
|
|
+ <span>[ 保存 SCHEMA ]</span>
|
|
|
</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
{/* 基础信息输入 */}
|
|
|
- <div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
|
|
- <div>
|
|
|
- <label className="block text-[11px] font-bold text-slate-500 uppercase mb-1">
|
|
|
- Schema 名称 <span className="text-red-500">*</span>
|
|
|
+ <div className="grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs">
|
|
|
+ <div className="space-y-1">
|
|
|
+ <label className="font-bold text-black uppercase block">
|
|
|
+ Schema 名称 <span className="text-black">*</span>
|
|
|
</label>
|
|
|
<input
|
|
|
type="text"
|
|
|
required
|
|
|
placeholder="如:法国申根签证采集表单"
|
|
|
- className="w-full border border-slate-300 rounded-lg px-3 py-1.5 text-xs text-slate-800 focus:ring-2 focus:ring-purple-500 outline-none bg-white"
|
|
|
+ className="w-full border-2 border-black bg-white px-3 py-1.5 text-xs text-black focus:bg-amber-50 outline-none shadow-[2px_2px_0px_#000]"
|
|
|
value={formData.name}
|
|
|
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
|
|
/>
|
|
|
</div>
|
|
|
- <div>
|
|
|
- <label className="block text-[11px] font-bold text-slate-500 uppercase mb-1">
|
|
|
+ <div className="space-y-1">
|
|
|
+ <label className="font-bold text-black uppercase block">
|
|
|
表单功能描述
|
|
|
</label>
|
|
|
<input
|
|
|
type="text"
|
|
|
placeholder="简述该 Schema 的适用场景或所需材料..."
|
|
|
- className="w-full border border-slate-300 rounded-lg px-3 py-1.5 text-xs text-slate-800 focus:ring-2 focus:ring-purple-500 outline-none bg-white"
|
|
|
+ className="w-full border-2 border-black bg-white px-3 py-1.5 text-xs text-black focus:bg-amber-50 outline-none shadow-[2px_2px_0px_#000]"
|
|
|
value={formData.description}
|
|
|
onChange={(e) => setFormData({ ...formData, description: e.target.value })}
|
|
|
/>
|
|
|
@@ -601,16 +531,16 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
</div>
|
|
|
|
|
|
{/* 快速预设模板注入器 */}
|
|
|
- <div className="pt-2 border-t border-slate-200/80 flex flex-wrap items-center gap-2">
|
|
|
- <span className="text-[11px] text-slate-400 font-bold flex items-center gap-1">
|
|
|
- <Sparkles size={12} className="text-amber-500" /> 快速注入模板:
|
|
|
+ <div className="pt-2 border-t border-dashed border-neutral-300 flex flex-wrap items-center gap-1.5 text-xs">
|
|
|
+ <span className="text-[10px] text-neutral-500 font-bold uppercase">
|
|
|
+ [ 快速注入模板 ]:
|
|
|
</span>
|
|
|
{SCHEMA_TEMPLATES.map((tmpl, idx) => (
|
|
|
<button
|
|
|
key={idx}
|
|
|
type="button"
|
|
|
onClick={() => handleApplyTemplate(tmpl)}
|
|
|
- className="px-2.5 py-1 bg-white hover:bg-purple-50 text-slate-700 hover:text-purple-700 border border-slate-200 hover:border-purple-200 rounded-md text-[11px] font-medium transition"
|
|
|
+ className="px-2 py-0.5 bg-white hover:bg-amber-300 text-black border border-black text-[10px] font-bold uppercase transition shadow-[1px_1px_0px_#000]"
|
|
|
>
|
|
|
{tmpl.name}
|
|
|
</button>
|
|
|
@@ -621,44 +551,47 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
{/* 编辑与预览主体区 */}
|
|
|
<div className="flex-1 flex overflow-hidden min-h-[350px]">
|
|
|
|
|
|
- {/* CODE 编辑器 (Monaco) */}
|
|
|
+ {/* CODE 编辑器 */}
|
|
|
{(viewMode === 'split' || viewMode === 'code') && (
|
|
|
<div
|
|
|
- className={`flex flex-col border-r border-slate-200 ${
|
|
|
+ className={`flex flex-col border-r-2 border-black ${
|
|
|
viewMode === 'split' ? 'w-full lg:w-1/2' : 'w-full'
|
|
|
}`}
|
|
|
>
|
|
|
- {/* Monaco 工具栏 */}
|
|
|
- <div className="px-3 py-1.5 bg-slate-900 text-slate-400 text-xs flex items-center justify-between border-b border-slate-800">
|
|
|
- <span className="font-mono text-[11px] text-purple-300 flex items-center gap-1.5">
|
|
|
- <Code2 size={13} /> JSON Schema Source
|
|
|
- </span>
|
|
|
- <div className="flex items-center gap-1.5">
|
|
|
+ {/* Terminal Header */}
|
|
|
+ <div className="px-3 py-2 bg-neutral-200 border-b-2 border-black text-xs flex items-center justify-between select-none">
|
|
|
+ <div className="flex items-center gap-2">
|
|
|
+ <span className="w-2.5 h-2.5 bg-amber-300 border border-black inline-block" />
|
|
|
+ <span className="font-mono text-xs text-black uppercase font-black tracking-wider">
|
|
|
+ [ 01 // JSON SCHEMA DEFINITION // 结构源码 ]
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ <div className="flex items-center gap-1">
|
|
|
<button
|
|
|
type="button"
|
|
|
onClick={handleFormatJson}
|
|
|
- className="px-2 py-0.5 rounded bg-slate-800 hover:bg-slate-700 text-slate-300 text-[11px] flex items-center gap-1 font-medium transition"
|
|
|
+ className="px-2 py-1 bg-white hover:bg-neutral-100 text-black text-[11px] border border-black uppercase font-bold shadow-[1px_1px_0px_#000] active:translate-x-0.5 active:translate-y-0.5"
|
|
|
>
|
|
|
- <Braces size={12} /> 格式化
|
|
|
+ [ 格式化 ]
|
|
|
</button>
|
|
|
<button
|
|
|
type="button"
|
|
|
onClick={handleCompactJson}
|
|
|
- className="px-2 py-0.5 rounded bg-slate-800 hover:bg-slate-700 text-slate-300 text-[11px] flex items-center gap-1 font-medium transition"
|
|
|
+ className="px-2 py-1 bg-white hover:bg-neutral-100 text-black text-[11px] border border-black uppercase font-bold shadow-[1px_1px_0px_#000] active:translate-x-0.5 active:translate-y-0.5"
|
|
|
>
|
|
|
- <Minimize2 size={12} /> 压缩
|
|
|
+ [ 压缩 ]
|
|
|
</button>
|
|
|
<button
|
|
|
type="button"
|
|
|
onClick={handleCopyJson}
|
|
|
- className="px-2 py-0.5 rounded bg-slate-800 hover:bg-slate-700 text-slate-300 text-[11px] flex items-center gap-1 font-medium transition"
|
|
|
+ className="px-2 py-1 bg-white hover:bg-neutral-100 text-black text-[11px] border border-black uppercase font-bold shadow-[1px_1px_0px_#000] active:translate-x-0.5 active:translate-y-0.5"
|
|
|
>
|
|
|
- {copied ? <Check size={12} className="text-emerald-400" /> : <Copy size={12} />} 复制
|
|
|
+ {copied ? '[ 已复制 ]' : '[ 复制 ]'}
|
|
|
</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
- <div className="flex-1 min-h-[300px]">
|
|
|
+ <div className="flex-1 min-h-[300px] bg-neutral-900">
|
|
|
<Editor
|
|
|
height="100%"
|
|
|
language="json"
|
|
|
@@ -672,112 +605,230 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
scrollBeyondLastLine: false,
|
|
|
automaticLayout: true,
|
|
|
tabSize: 2,
|
|
|
+ fontFamily: "'JetBrains Mono', 'Fira Code', Consolas, monospace",
|
|
|
}}
|
|
|
/>
|
|
|
</div>
|
|
|
</div>
|
|
|
)}
|
|
|
|
|
|
- {/* LIVE FORM 实时表单渲染预览 */}
|
|
|
+ {/* 实时多维预览区 (LIVE PREVIEW: Form / Dossier / Raw) */}
|
|
|
{(viewMode === 'split' || viewMode === 'preview') && (
|
|
|
<div
|
|
|
- className={`flex flex-col bg-slate-50/50 overflow-y-auto ${
|
|
|
+ className={`flex flex-col bg-neutral-100 overflow-hidden ${
|
|
|
viewMode === 'split' ? 'hidden lg:flex lg:w-1/2' : 'w-full'
|
|
|
}`}
|
|
|
>
|
|
|
- <div className="px-4 py-2 bg-slate-100/80 border-b border-slate-200 flex items-center justify-between text-xs text-slate-600 font-bold">
|
|
|
- <span className="flex items-center gap-1.5 text-indigo-700">
|
|
|
- <Eye size={14} /> 交互式表单渲染预览 (所见即所得)
|
|
|
- </span>
|
|
|
- <span className="text-[11px] font-normal text-slate-400">
|
|
|
- 模拟前台下单填写效果
|
|
|
- </span>
|
|
|
+ {/* 预览子选项卡导航 */}
|
|
|
+ <div className="px-3 py-2 bg-neutral-200 border-b-2 border-black flex items-center justify-between text-xs shrink-0 select-none">
|
|
|
+ <div className="flex items-center gap-2">
|
|
|
+ <span className="w-2.5 h-2.5 bg-amber-300 border border-black inline-block" />
|
|
|
+ <span className="font-black text-black uppercase tracking-wider">
|
|
|
+ [ 02 // SCHEMA INSPECTOR // 结构剖析与渲染 ]
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="flex border border-black bg-white text-[11px] font-bold uppercase">
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ onClick={() => setPreviewTab('form')}
|
|
|
+ className={`px-2 py-0.5 transition ${
|
|
|
+ previewTab === 'form'
|
|
|
+ ? 'bg-amber-300 text-black font-black border-r border-black'
|
|
|
+ : 'text-neutral-600 hover:text-black border-r border-black'
|
|
|
+ }`}
|
|
|
+ >
|
|
|
+ 表单渲染
|
|
|
+ </button>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ onClick={() => setPreviewTab('tree')}
|
|
|
+ className={`px-2 py-0.5 transition ${
|
|
|
+ previewTab === 'tree'
|
|
|
+ ? 'bg-amber-300 text-black font-black border-r border-black'
|
|
|
+ : 'text-neutral-600 hover:text-black border-r border-black'
|
|
|
+ }`}
|
|
|
+ >
|
|
|
+ 字段结构
|
|
|
+ </button>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ onClick={() => setPreviewTab('raw')}
|
|
|
+ className={`px-2 py-0.5 transition ${
|
|
|
+ previewTab === 'raw'
|
|
|
+ ? 'bg-amber-300 text-black font-black'
|
|
|
+ : 'text-neutral-600 hover:text-black'
|
|
|
+ }`}
|
|
|
+ >
|
|
|
+ JSON 终端
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
|
|
|
- <div className="p-5 overflow-y-auto space-y-4">
|
|
|
+ {/* 预览主体内容 */}
|
|
|
+ <div className="p-4 overflow-y-auto flex-1 space-y-3 text-xs bg-neutral-50 font-mono">
|
|
|
{parsedPreview.valid ? (
|
|
|
- <div className="bg-white p-5 rounded-xl border border-slate-200 shadow-sm space-y-4">
|
|
|
- <div className="border-b border-slate-100 pb-3">
|
|
|
- <h4 className="font-bold text-slate-900 text-sm">
|
|
|
- {parsedPreview.title}
|
|
|
- </h4>
|
|
|
- {parsedPreview.description && (
|
|
|
- <p className="text-xs text-slate-500 mt-0.5">
|
|
|
- {parsedPreview.description}
|
|
|
- </p>
|
|
|
- )}
|
|
|
- </div>
|
|
|
-
|
|
|
- {Object.keys(parsedPreview.properties).length > 0 ? (
|
|
|
- <div className="space-y-4">
|
|
|
- {Object.entries(parsedPreview.properties).map(([fieldKey, prop]: [string, any]) => {
|
|
|
- const isRequired = parsedPreview.required.includes(fieldKey);
|
|
|
- const fieldTitle = prop.title || fieldKey;
|
|
|
- const placeholder = prop.placeholder || `请输入${fieldTitle}`;
|
|
|
-
|
|
|
- return (
|
|
|
- <div key={fieldKey} className="space-y-1">
|
|
|
- <label className="block text-xs font-bold text-slate-700">
|
|
|
- {fieldTitle}{' '}
|
|
|
- {isRequired && <span className="text-rose-500">*</span>}
|
|
|
- <span className="ml-1.5 font-mono text-[10px] font-normal text-slate-400">
|
|
|
- ({fieldKey})
|
|
|
- </span>
|
|
|
- </label>
|
|
|
-
|
|
|
- {/* 下拉选择 */}
|
|
|
- {prop.enum && Array.isArray(prop.enum) ? (
|
|
|
- <select className="w-full border border-slate-300 rounded-lg px-3 py-2 text-xs bg-white text-slate-700 outline-none focus:ring-2 focus:ring-indigo-500 shadow-sm">
|
|
|
- <option value="">-- 请选择 {fieldTitle} --</option>
|
|
|
- {prop.enum.map((opt: string) => (
|
|
|
- <option key={opt} value={opt}>
|
|
|
- {opt}
|
|
|
- </option>
|
|
|
- ))}
|
|
|
- </select>
|
|
|
- ) : prop.format === 'date' ? (
|
|
|
- /* 日期选择器 */
|
|
|
- <input
|
|
|
- type="date"
|
|
|
- className="w-full border border-slate-300 rounded-lg px-3 py-2 text-xs bg-white text-slate-700 outline-none focus:ring-2 focus:ring-indigo-500 shadow-sm"
|
|
|
- />
|
|
|
- ) : prop.type === 'number' || prop.type === 'integer' ? (
|
|
|
- /* 数字输入框 */
|
|
|
- <input
|
|
|
- type="number"
|
|
|
- placeholder={placeholder}
|
|
|
- className="w-full border border-slate-300 rounded-lg px-3 py-2 text-xs bg-white text-slate-700 outline-none focus:ring-2 focus:ring-indigo-500 shadow-sm"
|
|
|
- />
|
|
|
- ) : (
|
|
|
- /* 标准文本输入框 */
|
|
|
- <input
|
|
|
- type="text"
|
|
|
- placeholder={placeholder}
|
|
|
- className="w-full border border-slate-300 rounded-lg px-3 py-2 text-xs bg-white text-slate-700 outline-none focus:ring-2 focus:ring-indigo-500 shadow-sm"
|
|
|
- />
|
|
|
- )}
|
|
|
-
|
|
|
- {prop.description && (
|
|
|
- <p className="text-[11px] text-slate-400 mt-0.5">
|
|
|
- {prop.description}
|
|
|
- </p>
|
|
|
- )}
|
|
|
- </div>
|
|
|
- );
|
|
|
- })}
|
|
|
+ <>
|
|
|
+ {/* 1. 表单 UI 实时渲染 */}
|
|
|
+ {previewTab === 'form' && (
|
|
|
+ <div className="bg-white p-4 border-2 border-black shadow-[4px_4px_0px_#000] space-y-3">
|
|
|
+ <div className="border-b-2 border-black pb-2">
|
|
|
+ <h4 className="font-black text-black text-sm uppercase">
|
|
|
+ [ {parsedPreview.title} ]
|
|
|
+ </h4>
|
|
|
+ {parsedPreview.description && (
|
|
|
+ <p className="text-neutral-600 font-sans text-xs mt-0.5">
|
|
|
+ {parsedPreview.description}
|
|
|
+ </p>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {Object.keys(parsedPreview.properties).length > 0 ? (
|
|
|
+ <div className="space-y-3">
|
|
|
+ {Object.entries(parsedPreview.properties).map(([fieldKey, prop]: [string, any]) => {
|
|
|
+ const isRequired = parsedPreview.required.includes(fieldKey);
|
|
|
+ const fieldTitle = prop.title || fieldKey;
|
|
|
+ const placeholder = prop.placeholder || `请输入 ${fieldTitle}`;
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div key={fieldKey} className="space-y-1">
|
|
|
+ <label className="font-bold text-black uppercase block">
|
|
|
+ {fieldTitle}{' '}
|
|
|
+ {isRequired && <span className="text-black font-black">*</span>}
|
|
|
+ <span className="ml-1 text-[10px] text-neutral-400 font-mono">
|
|
|
+ ({fieldKey})
|
|
|
+ </span>
|
|
|
+ </label>
|
|
|
+
|
|
|
+ {prop.enum && Array.isArray(prop.enum) ? (
|
|
|
+ <select className="w-full border-2 border-black px-3 py-1.5 text-xs bg-white text-black outline-none shadow-[2px_2px_0px_#000]">
|
|
|
+ <option value="">-- 请选择 {fieldTitle} --</option>
|
|
|
+ {prop.enum.map((opt: string) => (
|
|
|
+ <option key={opt} value={opt}>
|
|
|
+ {opt}
|
|
|
+ </option>
|
|
|
+ ))}
|
|
|
+ </select>
|
|
|
+ ) : prop.format === 'date' ? (
|
|
|
+ <input
|
|
|
+ type="date"
|
|
|
+ className="w-full border-2 border-black px-3 py-1.5 text-xs bg-white text-black outline-none shadow-[2px_2px_0px_#000]"
|
|
|
+ />
|
|
|
+ ) : prop.type === 'number' || prop.type === 'integer' ? (
|
|
|
+ <input
|
|
|
+ type="number"
|
|
|
+ placeholder={placeholder}
|
|
|
+ className="w-full border-2 border-black px-3 py-1.5 text-xs bg-white text-black outline-none shadow-[2px_2px_0px_#000]"
|
|
|
+ />
|
|
|
+ ) : (
|
|
|
+ <input
|
|
|
+ type="text"
|
|
|
+ placeholder={placeholder}
|
|
|
+ className="w-full border-2 border-black px-3 py-1.5 text-xs bg-white text-black outline-none shadow-[2px_2px_0px_#000]"
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </div>
|
|
|
+ ) : (
|
|
|
+ <div className="py-6 text-center text-xs text-neutral-400 bg-neutral-50 border-2 border-dashed border-neutral-300">
|
|
|
+ [ Schema 中未定义任何 properties 字段 ]
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
</div>
|
|
|
- ) : (
|
|
|
- <div className="py-8 text-center text-xs text-slate-400 bg-slate-50 rounded-lg border border-dashed border-slate-200">
|
|
|
- Schema 中未定义任何 properties 字段
|
|
|
+ )}
|
|
|
+
|
|
|
+ {/* 2. 字段结构列表 (SCHEMA DOSSIER) */}
|
|
|
+ {previewTab === 'tree' && (
|
|
|
+ <div className="space-y-2.5">
|
|
|
+ <div className="flex items-center justify-between pb-1 border-b-2 border-black text-xs">
|
|
|
+ <span className="font-black uppercase text-black">
|
|
|
+ [ PROPERTIES MANIFEST // 字段属性清单 ({Object.keys(parsedPreview.properties).length}) ]
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {Object.keys(parsedPreview.properties).length > 0 ? (
|
|
|
+ Object.entries(parsedPreview.properties).map(([key, prop]: [string, any]) => {
|
|
|
+ const isReq = parsedPreview.required.includes(key);
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ key={key}
|
|
|
+ className="p-3 bg-white border-2 border-black shadow-[3px_3px_0px_#000] space-y-1.5"
|
|
|
+ >
|
|
|
+ <div className="flex items-start justify-between gap-2">
|
|
|
+ <div className="flex items-center gap-2 flex-wrap">
|
|
|
+ <span className="font-bold text-black text-xs font-sans">
|
|
|
+ {prop.title || key}
|
|
|
+ </span>
|
|
|
+ <span className="font-mono text-[10px] text-neutral-500 font-bold bg-neutral-100 border border-black px-1.5">
|
|
|
+ {key}
|
|
|
+ </span>
|
|
|
+ {isReq ? (
|
|
|
+ <span className="px-1.5 py-0.2 border border-black text-[9px] font-black uppercase bg-amber-300 text-black">
|
|
|
+ REQUIRED
|
|
|
+ </span>
|
|
|
+ ) : (
|
|
|
+ <span className="px-1.5 py-0.2 border border-black text-[9px] font-bold uppercase bg-neutral-100 text-neutral-600">
|
|
|
+ OPTIONAL
|
|
|
+ </span>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ <span className="px-1.5 py-0.2 bg-black text-white text-[10px] font-mono font-bold uppercase">
|
|
|
+ {prop.type || 'any'}
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {prop.description && (
|
|
|
+ <p className="text-[11px] text-neutral-600 font-sans">
|
|
|
+ {prop.description}
|
|
|
+ </p>
|
|
|
+ )}
|
|
|
+
|
|
|
+ {prop.enum && (
|
|
|
+ <div className="pt-1 flex flex-wrap gap-1 items-center">
|
|
|
+ <span className="text-[10px] text-neutral-400 font-bold uppercase">枚举值:</span>
|
|
|
+ {prop.enum.map((opt: string) => (
|
|
|
+ <span
|
|
|
+ key={opt}
|
|
|
+ className="px-1.5 py-0.2 bg-neutral-50 border border-black text-[10px] font-mono"
|
|
|
+ >
|
|
|
+ {opt}
|
|
|
+ </span>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ })
|
|
|
+ ) : (
|
|
|
+ <div className="py-6 text-center text-xs text-neutral-400 bg-white border-2 border-dashed border-neutral-300">
|
|
|
+ [ 暂无结构化字段属性 ]
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
</div>
|
|
|
)}
|
|
|
- </div>
|
|
|
+
|
|
|
+ {/* 3. JSON 格式化源码终端 (RAW JSON TERMINAL) */}
|
|
|
+ {previewTab === 'raw' && (
|
|
|
+ <JsonEditor
|
|
|
+ label="PARSED SCHEMA SOURCE // JSON 结构体源码"
|
|
|
+ value={formData.schema_json}
|
|
|
+ readOnly={true}
|
|
|
+ height="h-96"
|
|
|
+ theme="dark"
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </>
|
|
|
) : (
|
|
|
- <div className="p-4 bg-rose-50 border border-rose-200 rounded-xl text-xs text-rose-700 space-y-1">
|
|
|
- <div className="font-bold flex items-center gap-1">
|
|
|
- <AlertCircle size={14} /> JSON 解析错误
|
|
|
+ <div className="p-4 bg-rose-100 border-2 border-black text-rose-950 text-xs shadow-[3px_3px_0px_#000] space-y-1">
|
|
|
+ <div className="font-black flex items-center gap-1.5">
|
|
|
+ <AlertCircle size={14} className="text-rose-800" />
|
|
|
+ <span>[ SCHEMA JSON 语法解析错误 ]</span>
|
|
|
</div>
|
|
|
- <p className="font-mono text-[11px]">{parsedPreview.error}</p>
|
|
|
+ <p className="font-mono text-[11px] bg-white p-2 border border-black mt-1">
|
|
|
+ {parsedPreview.error}
|
|
|
+ </p>
|
|
|
</div>
|
|
|
)}
|
|
|
</div>
|