| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729 |
- // src/components/admin/node-configurations/NodeConfigEditModal.tsx
- 'use client';
- import React, { useState, useEffect } from 'react';
- import { toast } from 'react-hot-toast';
- import {
- NodeConfigEntryType,
- NodeConfigurationItem,
- SparseUpdatePayload,
- AppointmentTypeItem,
- PluginConfig,
- } from '@/types';
- import { nodeConfigService } from '@/lib/services/nodeConfigService';
- import AppointmentTypeEditor from './AppointmentTypeEditor';
- interface NodeConfigEditModalProps {
- isOpen: boolean;
- onClose: () => void;
- entryType: NodeConfigEntryType;
- config: NodeConfigurationItem | null;
- onSuccess: () => void;
- }
- export default function NodeConfigEditModal({
- isOpen,
- onClose,
- entryType,
- config,
- onSuccess,
- }: NodeConfigEditModalProps) {
- const [mode, setMode] = useState<'visual' | 'json'>('visual');
- const [saving, setSaving] = useState(false);
- // Visual mode form fields
- const [nodeId, setNodeId] = useState('');
- const [website, setWebsite] = useState('');
- const [proxyCd, setProxyCd] = useState<number | ''>('');
- const [sessionMaxLife, setSessionMaxLife] = useState<number | ''>('');
- const [activeTimeStart, setActiveTimeStart] = useState('');
- const [activeTimeEnd, setActiveTimeEnd] = useState('');
- const [proxyPoolStr, setProxyPoolStr] = useState('');
- // Standalone specifics
- const [orderId, setOrderId] = useState('');
- const [accountUsername, setAccountUsername] = useState('');
- const [accountPassword, setAccountPassword] = useState('');
- const [loginInterval, setLoginInterval] = useState<number | ''>('');
- const [userPreferencesStr, setUserPreferencesStr] = useState('{}');
- // Booker specifics
- const [bookerAccountSource, setBookerAccountSource] = useState('');
- const [bookerAccountPoolId, setBookerAccountPoolId] = useState('');
- const [bookerTargetInstances, setBookerTargetInstances] = useState<number | ''>('');
- const [bookerAccountCd, setBookerAccountCd] = useState<number | ''>('');
- const [bookerCooldown, setBookerCooldown] = useState<number | ''>('');
- const [bookerMaxBookings, setBookerMaxBookings] = useState<number | ''>('');
- // Sentinel specifics
- const [sentinelAccountSource, setSentinelAccountSource] = useState('');
- const [sentinelAccountPoolId, setSentinelAccountPoolId] = useState('');
- const [sentinelTargetInstances, setSentinelTargetInstances] = useState<number | ''>('');
- const [sentinelSignalTtl, setSentinelSignalTtl] = useState<number | ''>('');
- const [queryWaitMode, setQueryWaitMode] = useState<'Random' | 'Fixed'>('Random');
- const [fixedWait, setFixedWait] = useState<number | ''>('');
- const [randomMin, setRandomMin] = useState<number | ''>('');
- const [randomMax, setRandomMax] = useState<number | ''>('');
- // Plugin & Free config & Appointment types
- const [pluginConfig, setPluginConfig] = useState<PluginConfig>({});
- const [appointmentTypes, setAppointmentTypes] = useState<AppointmentTypeItem[]>([]);
- const [freeConfigStr, setFreeConfigStr] = useState('{}');
- // JSON mode payload
- const [rawJsonStr, setRawJsonStr] = useState('{\n "set": {},\n "clear": []\n}');
- useEffect(() => {
- if (config) {
- setNodeId(config.node_id || '');
- setWebsite(config.website || '');
- setProxyCd(config.proxy_cd !== undefined ? config.proxy_cd : '');
- setSessionMaxLife(config.session_max_life !== undefined ? config.session_max_life : '');
- setActiveTimeStart(config.active_time_start || '');
- setActiveTimeEnd(config.active_time_end || '');
- setProxyPoolStr(config.proxy_pool ? config.proxy_pool.join(', ') : '');
- setOrderId(config.order_id || '');
- setAccountUsername(config.account?.username || '');
- setAccountPassword(config.account?.password || '');
- setLoginInterval(config.login_interval !== undefined ? config.login_interval : '');
- setUserPreferencesStr(
- config.user_preferences ? JSON.stringify(config.user_preferences, null, 2) : '{}'
- );
- setBookerAccountSource(config.booker?.account_source || 'built-in');
- setBookerAccountPoolId(config.booker?.account_pool_id || '');
- setBookerTargetInstances(config.booker?.target_instances !== undefined ? config.booker.target_instances : 1);
- setBookerAccountCd(config.booker?.account_cd !== undefined ? config.booker.account_cd : '');
- setBookerCooldown(config.booker?.booking_cooldown !== undefined ? config.booker.booking_cooldown : '');
- setBookerMaxBookings(config.booker?.max_bookings_per_account !== undefined ? config.booker.max_bookings_per_account : '');
- setSentinelAccountSource(config.sentinel?.account_source || 'built-in');
- setSentinelAccountPoolId(config.sentinel?.account_pool_id || '');
- setSentinelTargetInstances(config.sentinel?.target_instances !== undefined ? config.sentinel.target_instances : 1);
- setSentinelSignalTtl(config.sentinel?.signal_ttl !== undefined ? config.sentinel.signal_ttl : '');
- const qw = config.sentinel?.query_wait || config.query_wait;
- if (qw) {
- setQueryWaitMode((qw.mode as any) || 'Random');
- setFixedWait(qw.fixed_wait !== undefined ? qw.fixed_wait : '');
- setRandomMin(qw.random_min !== undefined ? qw.random_min : '');
- setRandomMax(qw.random_max !== undefined ? qw.random_max : '');
- } else {
- setQueryWaitMode('Random');
- setFixedWait('');
- setRandomMin('');
- setRandomMax('');
- }
- setPluginConfig(config.plugin_config || {});
- setAppointmentTypes(config.appointment_types || []);
- setFreeConfigStr(config.free_config ? JSON.stringify(config.free_config, null, 2) : '{}');
- setRawJsonStr(
- JSON.stringify(
- {
- set: {},
- clear: [],
- },
- null,
- 2
- )
- );
- }
- }, [config, isOpen]);
- if (!isOpen || !config) return null;
- const calculateSparsePayload = (): SparseUpdatePayload => {
- const setObj: Record<string, any> = {};
- const clearArr: string[] = [];
- if (nodeId.trim() && nodeId.trim() !== (config.node_id || '')) {
- setObj['node_id'] = nodeId.trim();
- }
- if (website !== (config.website || '')) {
- if (website === '') clearArr.push('website');
- else setObj['website'] = website;
- }
- if (proxyCd !== '' && proxyCd !== config.proxy_cd) {
- setObj['proxy_cd'] = Number(proxyCd);
- }
- if (sessionMaxLife !== '' && sessionMaxLife !== config.session_max_life) {
- setObj['session_max_life'] = Number(sessionMaxLife);
- }
- if (activeTimeStart !== (config.active_time_start || '')) setObj['active_time_start'] = activeTimeStart;
- if (activeTimeEnd !== (config.active_time_end || '')) setObj['active_time_end'] = activeTimeEnd;
- const newProxyList = proxyPoolStr.split(',').map((s) => s.trim()).filter(Boolean);
- const oldProxyList = config.proxy_pool || [];
- if (JSON.stringify(newProxyList) !== JSON.stringify(oldProxyList)) {
- setObj['proxy_pool'] = newProxyList;
- }
- if (entryType === 'booker') {
- if (bookerAccountSource !== (config.booker?.account_source || '')) setObj['booker.account_source'] = bookerAccountSource;
- if (bookerAccountPoolId !== (config.booker?.account_pool_id || '')) setObj['booker.account_pool_id'] = bookerAccountPoolId;
- if (bookerTargetInstances !== '' && bookerTargetInstances !== config.booker?.target_instances) {
- setObj['booker.target_instances'] = Number(bookerTargetInstances);
- }
- if (bookerAccountCd !== '' && bookerAccountCd !== config.booker?.account_cd) {
- setObj['booker.account_cd'] = Number(bookerAccountCd);
- }
- if (bookerCooldown !== '' && bookerCooldown !== config.booker?.booking_cooldown) {
- setObj['booker.booking_cooldown'] = Number(bookerCooldown);
- }
- if (bookerMaxBookings !== '' && bookerMaxBookings !== config.booker?.max_bookings_per_account) {
- setObj['booker.max_bookings_per_account'] = Number(bookerMaxBookings);
- }
- }
- if (entryType === 'sentinel') {
- if (sentinelAccountSource !== (config.sentinel?.account_source || '')) setObj['sentinel.account_source'] = sentinelAccountSource;
- if (sentinelAccountPoolId !== (config.sentinel?.account_pool_id || '')) setObj['sentinel.account_pool_id'] = sentinelAccountPoolId;
- if (sentinelTargetInstances !== '' && sentinelTargetInstances !== config.sentinel?.target_instances) {
- setObj['sentinel.target_instances'] = Number(sentinelTargetInstances);
- }
- if (sentinelSignalTtl !== '' && sentinelSignalTtl !== config.sentinel?.signal_ttl) {
- setObj['sentinel.signal_ttl'] = Number(sentinelSignalTtl);
- }
- if (queryWaitMode !== (config.sentinel?.query_wait?.mode || 'Random')) {
- setObj['sentinel.query_wait.mode'] = queryWaitMode;
- }
- if (queryWaitMode === 'Fixed' && fixedWait !== '' && fixedWait !== config.sentinel?.query_wait?.fixed_wait) {
- setObj['sentinel.query_wait.fixed_wait'] = Number(fixedWait);
- }
- if (queryWaitMode === 'Random') {
- if (randomMin !== '' && randomMin !== config.sentinel?.query_wait?.random_min) {
- setObj['sentinel.query_wait.random_min'] = Number(randomMin);
- }
- if (randomMax !== '' && randomMax !== config.sentinel?.query_wait?.random_max) {
- setObj['sentinel.query_wait.random_max'] = Number(randomMax);
- }
- }
- }
- if (entryType === 'standalone') {
- if (orderId !== (config.order_id || '')) setObj['order_id'] = orderId;
- if (accountUsername !== (config.account?.username || '')) setObj['account.username'] = accountUsername;
- if (accountPassword !== (config.account?.password || '')) setObj['account.password'] = accountPassword;
- if (loginInterval !== '' && loginInterval !== config.login_interval) setObj['login_interval'] = Number(loginInterval);
- try {
- const parsedUserPref = userPreferencesStr.trim() ? JSON.parse(userPreferencesStr) : {};
- if (JSON.stringify(parsedUserPref) !== JSON.stringify(config.user_preferences || {})) {
- setObj['user_preferences'] = parsedUserPref;
- }
- } catch {}
- }
- if (JSON.stringify(pluginConfig) !== JSON.stringify(config.plugin_config || {})) {
- setObj['plugin_config'] = pluginConfig;
- }
- if (JSON.stringify(appointmentTypes) !== JSON.stringify(config.appointment_types || [])) {
- setObj['appointment_types'] = appointmentTypes;
- }
- try {
- const parsedFree = freeConfigStr.trim() ? JSON.parse(freeConfigStr) : {};
- if (JSON.stringify(parsedFree) !== JSON.stringify(config.free_config || {})) {
- setObj['free_config'] = parsedFree;
- }
- } catch {}
- return {
- set: Object.keys(setObj).length > 0 ? setObj : undefined,
- clear: clearArr.length > 0 ? clearArr : undefined,
- };
- };
- const handleFormatJson = () => {
- try {
- const parsed = JSON.parse(rawJsonStr);
- setRawJsonStr(JSON.stringify(parsed, null, 2));
- toast.success('JSON 已格式化');
- } catch {
- toast.error('JSON 语法错误,无法格式化');
- }
- };
- const handleCopyJson = () => {
- navigator.clipboard.writeText(rawJsonStr);
- toast.success('已复制到剪贴板');
- };
- const handleSubmit = async (e: React.FormEvent) => {
- e.preventDefault();
- setSaving(true);
- try {
- let payload: SparseUpdatePayload;
- if (mode === 'json') {
- try {
- payload = JSON.parse(rawJsonStr);
- } catch {
- toast.error('JSON 格式错误,请检查语法');
- setSaving(false);
- return;
- }
- } else {
- if (entryType === 'standalone') {
- try {
- if (userPreferencesStr.trim()) {
- JSON.parse(userPreferencesStr);
- }
- } catch {
- toast.error('用户偏好 (user_preferences) JSON 格式错误,请检查语法');
- setSaving(false);
- return;
- }
- }
- payload = calculateSparsePayload();
- if (!payload.set && (!payload.clear || payload.clear.length === 0)) {
- toast('未检测到任何字段变更', { icon: 'ℹ️' });
- onClose();
- setSaving(false);
- return;
- }
- }
- const res = await nodeConfigService.sparseUpdate(entryType, config.id, payload);
- if (res.code === 0) {
- toast.success(`配置更新成功 (版本已升至 v${res.data?.version || config.version + 1})`);
- onSuccess();
- onClose();
- } else {
- toast.error(res.message || '更新失败');
- }
- } catch (err: any) {
- console.error('Update config error:', err);
- toast.error(err?.response?.data?.message || err.message || '更新异常');
- } finally {
- setSaving(false);
- }
- };
- return (
- <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-grayscale p-4 font-mono">
- <div className="bg-neutral-50 border-2 border-black shadow-[8px_8px_0px_#000] w-full max-w-4xl max-h-[92vh] flex flex-col overflow-hidden animate-in zoom-in-95 duration-150">
- {/* Header */}
- <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-2">
- <span className="w-2.5 h-2.5 bg-amber-300 border border-black inline-block" />
- <div>
- <h3 className="font-black text-black text-xs md:text-sm uppercase tracking-wider">
- [ EDIT {entryType.toUpperCase()} CONFIG // 稀疏编辑: {config.node_id} / {config.identifier} (v{config.version}) ]
- </h3>
- </div>
- </div>
- {/* Mode Switcher */}
- <div className="flex items-center gap-2">
- <div className="flex border-2 border-black bg-white p-0.5 gap-1">
- <button
- type="button"
- onClick={() => setMode('visual')}
- className={`px-3 py-1 text-xs font-mono uppercase transition border ${
- mode === 'visual'
- ? 'bg-amber-300 text-black font-black border-black shadow-[1px_1px_0px_#000]'
- : 'text-neutral-700 font-bold border-transparent hover:bg-neutral-100'
- }`}
- >
- [ 可视化表单 ]
- </button>
- <button
- type="button"
- onClick={() => setMode('json')}
- className={`px-3 py-1 text-xs font-mono uppercase transition border ${
- mode === 'json'
- ? 'bg-amber-300 text-black font-black border-black shadow-[1px_1px_0px_#000]'
- : 'text-neutral-700 font-bold border-transparent hover:bg-neutral-100'
- }`}
- >
- [ JSON 稀疏模式 ]
- </button>
- </div>
- <button
- type="button"
- onClick={onClose}
- className="w-6 h-6 bg-white hover:bg-amber-300 border border-black flex items-center justify-center font-black text-xs transition shadow-[1px_1px_0px_#000] active:translate-x-0.5 active:translate-y-0.5 ml-2"
- >
- ✕
- </button>
- </div>
- </div>
- {/* Body */}
- <form onSubmit={handleSubmit} className="flex-1 overflow-y-auto p-5 space-y-5 bg-white text-xs">
- {mode === 'visual' ? (
- <div className="space-y-5">
- {/* Base & Network */}
- <div className="border-2 border-black bg-neutral-100 p-4 shadow-[2px_2px_0px_#000] space-y-3">
- <div className="flex items-center gap-2 border-b-2 border-black pb-1.5">
- <span className="w-2 h-2 bg-black inline-block" />
- <span className="font-black text-black uppercase">[ 01 // 节点与网络参数 ]</span>
- </div>
- <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
- <div className="md:col-span-2">
- <label className="block text-[11px] font-bold text-black mb-1">
- 目标计算节点 (node_id) <span className="text-rose-600 font-bold">*</span>
- </label>
- <input
- type="text"
- required
- value={nodeId}
- onChange={(e) => setNodeId(e.target.value)}
- placeholder="default, node01, node02..."
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div className="md:col-span-2">
- <label className="block text-[11px] font-bold text-black mb-1">使馆/登录网址 (website)</label>
- <input
- type="text"
- value={website}
- onChange={(e) => setWebsite(e.target.value)}
- placeholder="https://visa.vfsglobal.com/..."
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">代理冷却时间 (proxy_cd / 秒)</label>
- <input
- type="number"
- value={proxyCd}
- onChange={(e) => setProxyCd(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">Session 最长存活时间 (秒)</label>
- <input
- type="number"
- value={sessionMaxLife}
- onChange={(e) => setSessionMaxLife(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div className="md:col-span-2">
- <label className="block text-[11px] font-bold text-black mb-1">网络代理池标签列表 (proxy_pool, 逗号分隔)</label>
- <input
- type="text"
- value={proxyPoolStr}
- onChange={(e) => setProxyPoolStr(e.target.value)}
- placeholder="proxy-cheap, proxy-fast"
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- </div>
- </div>
- {/* Booker fields */}
- {entryType === 'booker' && (
- <div className="border-2 border-black bg-neutral-100 p-4 shadow-[2px_2px_0px_#000] space-y-3">
- <div className="flex items-center gap-2 border-b-2 border-black pb-1.5">
- <span className="w-2 h-2 bg-black inline-block" />
- <span className="font-black text-black uppercase">[ 02 // Booker 调度与池参数 ]</span>
- </div>
- <div className="grid grid-cols-1 md:grid-cols-3 gap-3">
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">使馆账号池 ID (account_pool_id)</label>
- <input
- type="text"
- value={bookerAccountPoolId}
- onChange={(e) => setBookerAccountPoolId(e.target.value)}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">目标并发实例 (target_instances)</label>
- <input
- type="number"
- min={1}
- value={bookerTargetInstances}
- onChange={(e) => setBookerTargetInstances(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">账号冷却 CD (account_cd / 秒)</label>
- <input
- type="number"
- value={bookerAccountCd}
- onChange={(e) => setBookerAccountCd(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">下单冷却 (booking_cooldown / 秒)</label>
- <input
- type="number"
- value={bookerCooldown}
- onChange={(e) => setBookerCooldown(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">单号最大占位次数</label>
- <input
- type="number"
- value={bookerMaxBookings}
- onChange={(e) => setBookerMaxBookings(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- </div>
- </div>
- )}
- {/* Sentinel fields */}
- {entryType === 'sentinel' && (
- <div className="border-2 border-black bg-neutral-100 p-4 shadow-[2px_2px_0px_#000] space-y-3">
- <div className="flex items-center gap-2 border-b-2 border-black pb-1.5">
- <span className="w-2 h-2 bg-black inline-block" />
- <span className="font-black text-black uppercase">[ 02 // Sentinel 扫位与信号策略 ]</span>
- </div>
- <div className="grid grid-cols-1 md:grid-cols-3 gap-3">
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">账号池 ID (account_pool_id)</label>
- <input
- type="text"
- value={sentinelAccountPoolId}
- onChange={(e) => setSentinelAccountPoolId(e.target.value)}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">并发实例数 (target_instances)</label>
- <input
- type="number"
- min={1}
- value={sentinelTargetInstances}
- onChange={(e) => setSentinelTargetInstances(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">信号 TTL 持续 (秒)</label>
- <input
- type="number"
- value={sentinelSignalTtl}
- onChange={(e) => setSentinelSignalTtl(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">扫位轮询模式 (query_wait.mode)</label>
- <select
- value={queryWaitMode}
- onChange={(e) => setQueryWaitMode(e.target.value as any)}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 text-xs font-bold text-black outline-none shadow-[2px_2px_0px_#000]"
- >
- <option value="Random">Random (随机等待)</option>
- <option value="Fixed">Fixed (固定等待)</option>
- </select>
- </div>
- {queryWaitMode === 'Fixed' ? (
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">固定等待 (秒)</label>
- <input
- type="number"
- value={fixedWait}
- onChange={(e) => setFixedWait(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- ) : (
- <>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">随机最小等待 (秒)</label>
- <input
- type="number"
- value={randomMin}
- onChange={(e) => setRandomMin(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">随机最大等待 (秒)</label>
- <input
- type="number"
- value={randomMax}
- onChange={(e) => setRandomMax(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- </>
- )}
- </div>
- </div>
- )}
- {/* Standalone fields */}
- {entryType === 'standalone' && (
- <div className="border-2 border-black bg-neutral-100 p-4 shadow-[2px_2px_0px_#000] space-y-3">
- <div className="flex items-center gap-2 border-b-2 border-black pb-1.5">
- <span className="w-2 h-2 bg-black inline-block" />
- <span className="font-black text-black uppercase">[ 02 // Standalone 偏好与凭证 ]</span>
- </div>
- <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">关联订单号 (order_id)</label>
- <input
- type="text"
- value={orderId}
- onChange={(e) => setOrderId(e.target.value)}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">登录重试间隔 (秒)</label>
- <input
- type="number"
- value={loginInterval}
- onChange={(e) => setLoginInterval(e.target.value === '' ? '' : Number(e.target.value))}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">抢签账号 (username)</label>
- <input
- type="text"
- value={accountUsername}
- onChange={(e) => setAccountUsername(e.target.value)}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- <div>
- <label className="block text-[11px] font-bold text-black mb-1">抢签密码 (password)</label>
- <input
- type="text"
- placeholder="输入抢签密码"
- value={accountPassword}
- onChange={(e) => setAccountPassword(e.target.value)}
- className="w-full px-3 py-2 border-2 border-black bg-neutral-50 focus:bg-white text-xs font-mono text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- </div>
- <div className="pt-2 border-t border-black/20 space-y-1.5">
- <div className="flex items-center justify-between">
- <label className="block text-[11px] font-bold text-black">用户偏好 (user_preferences JSON)</label>
- <span className="text-[10px] text-neutral-500 font-mono">支持自定义键值与可变结构</span>
- </div>
- <textarea
- rows={3}
- value={userPreferencesStr}
- onChange={(e) => setUserPreferencesStr(e.target.value)}
- placeholder="{}"
- className="w-full p-2.5 font-mono text-xs border-2 border-black bg-neutral-50 focus:bg-white text-black outline-none shadow-[2px_2px_0px_#000]"
- />
- </div>
- </div>
- )}
- {/* Appointment Types */}
- <AppointmentTypeEditor
- items={appointmentTypes}
- onChange={setAppointmentTypes}
- />
- {/* Free Config */}
- <div className="border-2 border-black bg-neutral-100 p-4 shadow-[2px_2px_0px_#000] space-y-2">
- <div className="flex items-center gap-2 border-b-2 border-black pb-1.5">
- <span className="w-2 h-2 bg-black inline-block" />
- <span className="font-black text-black uppercase">[ 03 // 自定义扩展 (FREE_CONFIG) ]</span>
- </div>
- <textarea
- rows={3}
- value={freeConfigStr}
- onChange={(e) => setFreeConfigStr(e.target.value)}
- className="w-full p-2.5 font-mono text-xs leading-relaxed outline-none bg-neutral-900 text-neutral-100 border-2 border-black shadow-[2px_2px_0px_#000]"
- />
- </div>
- </div>
- ) : (
- /* JSON Sparse Mode */
- <div className="w-full font-mono text-xs select-none space-y-3">
- <div className="flex items-center justify-between px-3 py-2 bg-neutral-200 border-2 border-black">
- <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">[ SPARSE JSON TERMINAL // 稀疏更新视窗 ]</span>
- </div>
- <div className="flex items-center gap-1">
- <button
- type="button"
- onClick={handleFormatJson}
- className="px-2 py-1 bg-white hover:bg-neutral-100 text-black border border-black text-[11px] font-bold shadow-[1px_1px_0px_#000] active:translate-x-0.5 active:translate-y-0.5 uppercase"
- >
- [ 格式化 ]
- </button>
- <button
- type="button"
- onClick={handleCopyJson}
- className="px-2 py-1 bg-white hover:bg-neutral-100 text-black border border-black text-[11px] font-bold shadow-[1px_1px_0px_#000] active:translate-x-0.5 active:translate-y-0.5 uppercase"
- >
- [ 复制 ]
- </button>
- </div>
- </div>
- <div className="border-2 border-black shadow-[4px_4px_0px_#000]">
- <textarea
- rows={14}
- value={rawJsonStr}
- onChange={(e) => setRawJsonStr(e.target.value)}
- placeholder='{\n "set": {},\n "clear": []\n}'
- className="w-full p-4 font-mono text-xs leading-relaxed outline-none bg-neutral-900 text-amber-300 resize-y"
- />
- </div>
- </div>
- )}
- </form>
- {/* Footer */}
- <div className="px-5 py-3 bg-neutral-200 border-t-2 border-black flex justify-between items-center shrink-0">
- <div className="text-[11px] text-neutral-600 font-bold">
- {mode === 'visual' ? '前端将在提交时自动比对生成 set / clear 稀疏负载' : '直接提交 JSON 负载'}
- </div>
- <div className="flex items-center gap-2">
- <button
- type="button"
- onClick={onClose}
- className="px-4 py-1.5 bg-white hover:bg-neutral-100 text-black border-2 border-black text-xs font-bold uppercase shadow-[2px_2px_0px_#000] active:translate-x-0.5 active:translate-y-0.5 transition"
- >
- [ 取消 ]
- </button>
- <button
- type="button"
- onClick={handleSubmit}
- disabled={saving}
- className="px-5 py-1.5 bg-amber-300 hover:bg-amber-400 text-black border-2 border-black text-xs font-black uppercase shadow-[2px_2px_0px_#000] active:translate-x-0.5 active:translate-y-0.5 transition disabled:opacity-50"
- >
- {saving ? '[ 保存中... ]' : '[ 保存更新 ]'}
- </button>
- </div>
- </div>
- </div>
- </div>
- );
- }
|