|
|
@@ -1,7 +1,6 @@
|
|
|
'use client';
|
|
|
|
|
|
import { useState, useEffect, useMemo } from 'react';
|
|
|
-import api from '@/lib/api';
|
|
|
import {
|
|
|
Loader2,
|
|
|
Plus,
|
|
|
@@ -24,60 +23,120 @@ import {
|
|
|
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 {
|
|
|
- isOpen: boolean;
|
|
|
- onClose: () => void;
|
|
|
-}
|
|
|
+import DynamicOrderSchemaForm from '@/components/admin/orders/DynamicOrderSchemaForm';
|
|
|
+import JsonEditor from '@/components/common/JsonEditor';
|
|
|
+import { productService } from '@/lib/services';
|
|
|
|
|
|
const SCHEMA_TEMPLATES = [
|
|
|
{
|
|
|
- name: '标准签证申请人材料模板',
|
|
|
- description: '包含姓名、护照号、出生日期、签证中心等常用字段',
|
|
|
+ name: '申根签证通用表单 (完整版)',
|
|
|
+ description: '标准申根国签证基础申请表,包含护照、联系方式、出行目的等标准字段。',
|
|
|
schema_json: JSON.stringify(
|
|
|
{
|
|
|
+ title: '申根签证申请基础资料',
|
|
|
+ description: '请如实填写申请人的护照与基本身份信息,带 * 为必填项。',
|
|
|
type: 'object',
|
|
|
- title: '签证申请人基础资料',
|
|
|
- description: '请准确填写申请人护照信息与预约需求',
|
|
|
- required: ['applicant_name', 'passport_number', 'nationality', 'visa_center'],
|
|
|
+ required: [
|
|
|
+ 'surname',
|
|
|
+ 'name',
|
|
|
+ 'birthday',
|
|
|
+ 'passport_no',
|
|
|
+ 'passport_expire_date',
|
|
|
+ 'phone',
|
|
|
+ 'email',
|
|
|
+ ],
|
|
|
+ 'ui:order': [
|
|
|
+ 'surname',
|
|
|
+ 'name',
|
|
|
+ 'birthday',
|
|
|
+ 'nationality',
|
|
|
+ 'passport_no',
|
|
|
+ 'passport_expire_date',
|
|
|
+ 'phone_code',
|
|
|
+ 'phone',
|
|
|
+ 'email',
|
|
|
+ 'visa_center',
|
|
|
+ 'category',
|
|
|
+ 'subcategory',
|
|
|
+ 'notes',
|
|
|
+ ],
|
|
|
properties: {
|
|
|
- applicant_name: {
|
|
|
+ surname: {
|
|
|
type: 'string',
|
|
|
- title: '申请人全名 (拼音)',
|
|
|
- placeholder: '如: ZHANG SAN',
|
|
|
+ title: '姓氏 (Surname / Pinyin)',
|
|
|
+ description: '例如: WANG',
|
|
|
+ 'x-order': 1,
|
|
|
},
|
|
|
- passport_number: {
|
|
|
+ name: {
|
|
|
type: 'string',
|
|
|
- title: '护照号码',
|
|
|
- placeholder: '如: E12345678',
|
|
|
+ title: '名字 (Given Name / Pinyin)',
|
|
|
+ description: '例如: XIAOMING',
|
|
|
+ 'x-order': 2,
|
|
|
+ },
|
|
|
+ birthday: {
|
|
|
+ type: 'string',
|
|
|
+ title: '出生日期',
|
|
|
+ format: 'date',
|
|
|
+ 'x-order': 3,
|
|
|
},
|
|
|
nationality: {
|
|
|
type: 'string',
|
|
|
title: '国籍',
|
|
|
- default: 'China',
|
|
|
- enum: ['China', 'Hong Kong', 'Taiwan', 'Other'],
|
|
|
+ default: 'CHN',
|
|
|
+ 'x-order': 4,
|
|
|
+ },
|
|
|
+ passport_no: {
|
|
|
+ type: 'string',
|
|
|
+ title: '护照号码',
|
|
|
+ description: '如: E12345678',
|
|
|
+ 'x-order': 5,
|
|
|
},
|
|
|
- birth_date: {
|
|
|
+ passport_expire_date: {
|
|
|
type: 'string',
|
|
|
+ title: '护照有效期至',
|
|
|
format: 'date',
|
|
|
- title: '出生日期',
|
|
|
+ 'x-order': 6,
|
|
|
+ },
|
|
|
+ phone_code: {
|
|
|
+ type: 'string',
|
|
|
+ title: '国家区号',
|
|
|
+ default: '+86',
|
|
|
+ 'x-order': 7,
|
|
|
+ },
|
|
|
+ phone: {
|
|
|
+ type: 'string',
|
|
|
+ title: '联系手机号',
|
|
|
+ 'x-order': 8,
|
|
|
+ },
|
|
|
+ email: {
|
|
|
+ type: 'string',
|
|
|
+ title: '电子邮箱 (用于接收预约确认信)',
|
|
|
+ format: 'email',
|
|
|
+ 'x-order': 9,
|
|
|
},
|
|
|
visa_center: {
|
|
|
type: 'string',
|
|
|
title: '递签中心',
|
|
|
enum: ['Beijing', 'Shanghai', 'Guangzhou', 'Chengdu', 'Wuhan', 'Shenyang'],
|
|
|
+ 'x-order': 10,
|
|
|
},
|
|
|
- expected_date_start: {
|
|
|
+ category: {
|
|
|
type: 'string',
|
|
|
- format: 'date',
|
|
|
- title: '期望最早出发/预约日期',
|
|
|
+ title: '大类 (Category)',
|
|
|
+ default: 'Short Stay',
|
|
|
+ 'x-order': 11,
|
|
|
+ },
|
|
|
+ subcategory: {
|
|
|
+ type: 'string',
|
|
|
+ title: '子类别 (Subcategory)',
|
|
|
+ default: 'Tourism',
|
|
|
+ 'x-order': 12,
|
|
|
},
|
|
|
- remarks: {
|
|
|
+ notes: {
|
|
|
type: 'string',
|
|
|
- title: '备注说明 / 特殊诉求',
|
|
|
- placeholder: '如有同行人或特殊加急需求可填写',
|
|
|
+ title: '特殊备注 / 出行计划简要',
|
|
|
+ 'x-order': 13,
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -86,23 +145,49 @@ const SCHEMA_TEMPLATES = [
|
|
|
),
|
|
|
},
|
|
|
{
|
|
|
- name: '极简预约信息模板 (仅核心两项)',
|
|
|
- description: '仅收集护照号和目标城市,适合快捷抢单',
|
|
|
+ name: '抢号监控简化表单 (仅预约关键信息)',
|
|
|
+ description: '适用于极速抢位或自动监控,仅收集账号密码及中心代码。',
|
|
|
schema_json: JSON.stringify(
|
|
|
{
|
|
|
+ title: '自动化抢位关键配置',
|
|
|
type: 'object',
|
|
|
- title: '极速抢单关键参数',
|
|
|
- required: ['passport_number', 'city'],
|
|
|
+ required: ['target_center', 'preferred_date_start', 'preferred_date_end'],
|
|
|
+ 'ui:order': [
|
|
|
+ 'target_center',
|
|
|
+ 'preferred_date_start',
|
|
|
+ 'preferred_date_end',
|
|
|
+ 'vfs_login_email',
|
|
|
+ 'auto_pay',
|
|
|
+ ],
|
|
|
properties: {
|
|
|
- passport_number: {
|
|
|
+ target_center: {
|
|
|
type: 'string',
|
|
|
- title: '护照号码',
|
|
|
- placeholder: 'E12345678',
|
|
|
+ title: '目标签证中心代码',
|
|
|
+ enum: ['FRA-SHA', 'FRA-BJS', 'ITA-SHA', 'ESP-CAN'],
|
|
|
+ 'x-order': 1,
|
|
|
},
|
|
|
- city: {
|
|
|
+ preferred_date_start: {
|
|
|
type: 'string',
|
|
|
- title: '意向递签城市',
|
|
|
- placeholder: 'Paris / London / Rome',
|
|
|
+ title: '期望预约开始日期',
|
|
|
+ format: 'date',
|
|
|
+ 'x-order': 2,
|
|
|
+ },
|
|
|
+ preferred_date_end: {
|
|
|
+ type: 'string',
|
|
|
+ title: '期望预约截止日期',
|
|
|
+ format: 'date',
|
|
|
+ 'x-order': 3,
|
|
|
+ },
|
|
|
+ vfs_login_email: {
|
|
|
+ type: 'string',
|
|
|
+ title: '官方申请账号 (选填)',
|
|
|
+ 'x-order': 4,
|
|
|
+ },
|
|
|
+ auto_pay: {
|
|
|
+ type: 'boolean',
|
|
|
+ title: '刷出名额后是否自动锁定 (默认是)',
|
|
|
+ default: true,
|
|
|
+ 'x-order': 5,
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -112,19 +197,24 @@ const SCHEMA_TEMPLATES = [
|
|
|
},
|
|
|
];
|
|
|
|
|
|
+interface SchemaManagerProps {
|
|
|
+ isOpen: boolean;
|
|
|
+ onClose: () => void;
|
|
|
+}
|
|
|
+
|
|
|
export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
const [schemas, setSchemas] = useState<SchemaItem[]>([]);
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
const [saving, setSaving] = useState(false);
|
|
|
+ const [keyword, setKeyword] = useState('');
|
|
|
|
|
|
const [editingId, setEditingId] = useState<number | null>(null);
|
|
|
const [formData, setFormData] = useState({
|
|
|
name: '',
|
|
|
description: '',
|
|
|
- schema_json: '{}',
|
|
|
+ schema_json: SCHEMA_TEMPLATES[0].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');
|
|
|
@@ -140,8 +230,8 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
const fetchSchemas = async () => {
|
|
|
setLoading(true);
|
|
|
try {
|
|
|
- const res = await api.get('/api/vas/schema/list');
|
|
|
- const list = Array.isArray(res.data?.data) ? res.data.data : [];
|
|
|
+ const res = await productService.listSchemas();
|
|
|
+ const list = Array.isArray(res?.data) ? res.data : [];
|
|
|
setSchemas(list);
|
|
|
} catch {
|
|
|
setSchemas([]);
|
|
|
@@ -240,23 +330,19 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
setSaving(true);
|
|
|
try {
|
|
|
if (editingId) {
|
|
|
- await api.post(
|
|
|
- '/api/vas/schema/update',
|
|
|
- {
|
|
|
- name: formData.name,
|
|
|
- description: formData.description,
|
|
|
- schema_json: parsedSchema,
|
|
|
- },
|
|
|
- { params: { id: editingId } }
|
|
|
- );
|
|
|
+ await productService.updateSchema(editingId, {
|
|
|
+ name: formData.name,
|
|
|
+ description: formData.description,
|
|
|
+ schema_json: parsedSchema,
|
|
|
+ });
|
|
|
toast.success(`Schema #${editingId} 更新成功`);
|
|
|
} else {
|
|
|
- const res = await api.post('/api/vas/schema/create', {
|
|
|
+ const res = await productService.createSchema({
|
|
|
name: formData.name,
|
|
|
description: formData.description,
|
|
|
schema_json: parsedSchema,
|
|
|
});
|
|
|
- const createdId = res.data?.data?.id;
|
|
|
+ const createdId = res?.data?.id || res?.id;
|
|
|
toast.success('新建表单 Schema 成功');
|
|
|
if (createdId) setEditingId(createdId);
|
|
|
}
|
|
|
@@ -277,7 +363,7 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
});
|
|
|
if (!ok) return;
|
|
|
try {
|
|
|
- await api.delete('/api/vas/schema/delete', { params: { id } });
|
|
|
+ await productService.deleteSchema(id);
|
|
|
toast.success('Schema 已删除');
|
|
|
if (editingId === id) handleCreateNew();
|
|
|
fetchSchemas();
|
|
|
@@ -307,15 +393,15 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
}, [formData.schema_json, formData.name, formData.description]);
|
|
|
|
|
|
const filteredSchemas = useMemo(() => {
|
|
|
- if (!searchKey.trim()) return schemas;
|
|
|
- const lower = searchKey.trim().toLowerCase();
|
|
|
+ if (!keyword.trim()) return schemas;
|
|
|
+ const lower = keyword.trim().toLowerCase();
|
|
|
return schemas.filter(
|
|
|
(s) =>
|
|
|
s.name.toLowerCase().includes(lower) ||
|
|
|
(s.description || '').toLowerCase().includes(lower) ||
|
|
|
String(s.id).includes(lower)
|
|
|
);
|
|
|
- }, [schemas, searchKey]);
|
|
|
+ }, [schemas, keyword]);
|
|
|
|
|
|
if (!isOpen) return null;
|
|
|
|
|
|
@@ -391,8 +477,8 @@ export default function SchemaManager({ isOpen, onClose }: SchemaManagerProps) {
|
|
|
type="text"
|
|
|
placeholder="搜索 Schema 名称 / ID..."
|
|
|
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)}
|
|
|
+ value={keyword}
|
|
|
+ onChange={(e) => setKeyword(e.target.value)}
|
|
|
/>
|
|
|
<Search size={13} className="absolute left-2.5 top-2 text-black pointer-events-none" />
|
|
|
</div>
|