NodeConfigEditModal.tsx 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. // src/components/admin/node-configurations/NodeConfigEditModal.tsx
  2. 'use client';
  3. import React, { useState, useEffect } from 'react';
  4. import { toast } from 'react-hot-toast';
  5. import {
  6. NodeConfigEntryType,
  7. NodeConfigurationItem,
  8. SparseUpdatePayload,
  9. AppointmentTypeItem,
  10. PluginConfig,
  11. } from '@/types';
  12. import { nodeConfigService } from '@/lib/services/nodeConfigService';
  13. import AppointmentTypeEditor from './AppointmentTypeEditor';
  14. interface NodeConfigEditModalProps {
  15. isOpen: boolean;
  16. onClose: () => void;
  17. entryType: NodeConfigEntryType;
  18. config: NodeConfigurationItem | null;
  19. onSuccess: () => void;
  20. }
  21. export default function NodeConfigEditModal({
  22. isOpen,
  23. onClose,
  24. entryType,
  25. config,
  26. onSuccess,
  27. }: NodeConfigEditModalProps) {
  28. const [mode, setMode] = useState<'visual' | 'json'>('visual');
  29. const [saving, setSaving] = useState(false);
  30. // Visual mode form fields
  31. const [nodeId, setNodeId] = useState('');
  32. const [website, setWebsite] = useState('');
  33. const [proxyCd, setProxyCd] = useState<number | ''>('');
  34. const [sessionMaxLife, setSessionMaxLife] = useState<number | ''>('');
  35. const [activeTimeStart, setActiveTimeStart] = useState('');
  36. const [activeTimeEnd, setActiveTimeEnd] = useState('');
  37. const [proxyPoolStr, setProxyPoolStr] = useState('');
  38. // Standalone specifics
  39. const [orderId, setOrderId] = useState('');
  40. const [accountUsername, setAccountUsername] = useState('');
  41. const [accountPassword, setAccountPassword] = useState('');
  42. const [loginInterval, setLoginInterval] = useState<number | ''>('');
  43. const [userPreferencesStr, setUserPreferencesStr] = useState('{}');
  44. // Booker specifics
  45. const [bookerAccountSource, setBookerAccountSource] = useState('');
  46. const [bookerAccountPoolId, setBookerAccountPoolId] = useState('');
  47. const [bookerTargetInstances, setBookerTargetInstances] = useState<number | ''>('');
  48. const [bookerAccountCd, setBookerAccountCd] = useState<number | ''>('');
  49. const [bookerCooldown, setBookerCooldown] = useState<number | ''>('');
  50. const [bookerMaxBookings, setBookerMaxBookings] = useState<number | ''>('');
  51. // Sentinel specifics
  52. const [sentinelAccountSource, setSentinelAccountSource] = useState('');
  53. const [sentinelAccountPoolId, setSentinelAccountPoolId] = useState('');
  54. const [sentinelTargetInstances, setSentinelTargetInstances] = useState<number | ''>('');
  55. const [sentinelSignalTtl, setSentinelSignalTtl] = useState<number | ''>('');
  56. const [queryWaitMode, setQueryWaitMode] = useState<'Random' | 'Fixed'>('Random');
  57. const [fixedWait, setFixedWait] = useState<number | ''>('');
  58. const [randomMin, setRandomMin] = useState<number | ''>('');
  59. const [randomMax, setRandomMax] = useState<number | ''>('');
  60. // Plugin & Free config & Appointment types
  61. const [pluginConfig, setPluginConfig] = useState<PluginConfig>({});
  62. const [appointmentTypes, setAppointmentTypes] = useState<AppointmentTypeItem[]>([]);
  63. const [freeConfigStr, setFreeConfigStr] = useState('{}');
  64. // JSON mode payload
  65. const [rawJsonStr, setRawJsonStr] = useState('{\n "set": {},\n "clear": []\n}');
  66. useEffect(() => {
  67. if (config) {
  68. setNodeId(config.node_id || '');
  69. setWebsite(config.website || '');
  70. setProxyCd(config.proxy_cd !== undefined ? config.proxy_cd : '');
  71. setSessionMaxLife(config.session_max_life !== undefined ? config.session_max_life : '');
  72. setActiveTimeStart(config.active_time_start || '');
  73. setActiveTimeEnd(config.active_time_end || '');
  74. setProxyPoolStr(config.proxy_pool ? config.proxy_pool.join(', ') : '');
  75. setOrderId(config.order_id || '');
  76. setAccountUsername(config.account?.username || '');
  77. setAccountPassword(config.account?.password || '');
  78. setLoginInterval(config.login_interval !== undefined ? config.login_interval : '');
  79. setUserPreferencesStr(
  80. config.user_preferences ? JSON.stringify(config.user_preferences, null, 2) : '{}'
  81. );
  82. setBookerAccountSource(config.booker?.account_source || 'built-in');
  83. setBookerAccountPoolId(config.booker?.account_pool_id || '');
  84. setBookerTargetInstances(config.booker?.target_instances !== undefined ? config.booker.target_instances : 1);
  85. setBookerAccountCd(config.booker?.account_cd !== undefined ? config.booker.account_cd : '');
  86. setBookerCooldown(config.booker?.booking_cooldown !== undefined ? config.booker.booking_cooldown : '');
  87. setBookerMaxBookings(config.booker?.max_bookings_per_account !== undefined ? config.booker.max_bookings_per_account : '');
  88. setSentinelAccountSource(config.sentinel?.account_source || 'built-in');
  89. setSentinelAccountPoolId(config.sentinel?.account_pool_id || '');
  90. setSentinelTargetInstances(config.sentinel?.target_instances !== undefined ? config.sentinel.target_instances : 1);
  91. setSentinelSignalTtl(config.sentinel?.signal_ttl !== undefined ? config.sentinel.signal_ttl : '');
  92. const qw = config.sentinel?.query_wait || config.query_wait;
  93. if (qw) {
  94. setQueryWaitMode((qw.mode as any) || 'Random');
  95. setFixedWait(qw.fixed_wait !== undefined ? qw.fixed_wait : '');
  96. setRandomMin(qw.random_min !== undefined ? qw.random_min : '');
  97. setRandomMax(qw.random_max !== undefined ? qw.random_max : '');
  98. } else {
  99. setQueryWaitMode('Random');
  100. setFixedWait('');
  101. setRandomMin('');
  102. setRandomMax('');
  103. }
  104. setPluginConfig(config.plugin_config || {});
  105. setAppointmentTypes(config.appointment_types || []);
  106. setFreeConfigStr(config.free_config ? JSON.stringify(config.free_config, null, 2) : '{}');
  107. setRawJsonStr(
  108. JSON.stringify(
  109. {
  110. set: {},
  111. clear: [],
  112. },
  113. null,
  114. 2
  115. )
  116. );
  117. }
  118. }, [config, isOpen]);
  119. if (!isOpen || !config) return null;
  120. const calculateSparsePayload = (): SparseUpdatePayload => {
  121. const setObj: Record<string, any> = {};
  122. const clearArr: string[] = [];
  123. if (nodeId.trim() && nodeId.trim() !== (config.node_id || '')) {
  124. setObj['node_id'] = nodeId.trim();
  125. }
  126. if (website !== (config.website || '')) {
  127. if (website === '') clearArr.push('website');
  128. else setObj['website'] = website;
  129. }
  130. if (proxyCd !== '' && proxyCd !== config.proxy_cd) {
  131. setObj['proxy_cd'] = Number(proxyCd);
  132. }
  133. if (sessionMaxLife !== '' && sessionMaxLife !== config.session_max_life) {
  134. setObj['session_max_life'] = Number(sessionMaxLife);
  135. }
  136. if (activeTimeStart !== (config.active_time_start || '')) setObj['active_time_start'] = activeTimeStart;
  137. if (activeTimeEnd !== (config.active_time_end || '')) setObj['active_time_end'] = activeTimeEnd;
  138. const newProxyList = proxyPoolStr.split(',').map((s) => s.trim()).filter(Boolean);
  139. const oldProxyList = config.proxy_pool || [];
  140. if (JSON.stringify(newProxyList) !== JSON.stringify(oldProxyList)) {
  141. setObj['proxy_pool'] = newProxyList;
  142. }
  143. if (entryType === 'booker') {
  144. if (bookerAccountSource !== (config.booker?.account_source || '')) setObj['booker.account_source'] = bookerAccountSource;
  145. if (bookerAccountPoolId !== (config.booker?.account_pool_id || '')) setObj['booker.account_pool_id'] = bookerAccountPoolId;
  146. if (bookerTargetInstances !== '' && bookerTargetInstances !== config.booker?.target_instances) {
  147. setObj['booker.target_instances'] = Number(bookerTargetInstances);
  148. }
  149. if (bookerAccountCd !== '' && bookerAccountCd !== config.booker?.account_cd) {
  150. setObj['booker.account_cd'] = Number(bookerAccountCd);
  151. }
  152. if (bookerCooldown !== '' && bookerCooldown !== config.booker?.booking_cooldown) {
  153. setObj['booker.booking_cooldown'] = Number(bookerCooldown);
  154. }
  155. if (bookerMaxBookings !== '' && bookerMaxBookings !== config.booker?.max_bookings_per_account) {
  156. setObj['booker.max_bookings_per_account'] = Number(bookerMaxBookings);
  157. }
  158. }
  159. if (entryType === 'sentinel') {
  160. if (sentinelAccountSource !== (config.sentinel?.account_source || '')) setObj['sentinel.account_source'] = sentinelAccountSource;
  161. if (sentinelAccountPoolId !== (config.sentinel?.account_pool_id || '')) setObj['sentinel.account_pool_id'] = sentinelAccountPoolId;
  162. if (sentinelTargetInstances !== '' && sentinelTargetInstances !== config.sentinel?.target_instances) {
  163. setObj['sentinel.target_instances'] = Number(sentinelTargetInstances);
  164. }
  165. if (sentinelSignalTtl !== '' && sentinelSignalTtl !== config.sentinel?.signal_ttl) {
  166. setObj['sentinel.signal_ttl'] = Number(sentinelSignalTtl);
  167. }
  168. if (queryWaitMode !== (config.sentinel?.query_wait?.mode || 'Random')) {
  169. setObj['sentinel.query_wait.mode'] = queryWaitMode;
  170. }
  171. if (queryWaitMode === 'Fixed' && fixedWait !== '' && fixedWait !== config.sentinel?.query_wait?.fixed_wait) {
  172. setObj['sentinel.query_wait.fixed_wait'] = Number(fixedWait);
  173. }
  174. if (queryWaitMode === 'Random') {
  175. if (randomMin !== '' && randomMin !== config.sentinel?.query_wait?.random_min) {
  176. setObj['sentinel.query_wait.random_min'] = Number(randomMin);
  177. }
  178. if (randomMax !== '' && randomMax !== config.sentinel?.query_wait?.random_max) {
  179. setObj['sentinel.query_wait.random_max'] = Number(randomMax);
  180. }
  181. }
  182. }
  183. if (entryType === 'standalone') {
  184. if (orderId !== (config.order_id || '')) setObj['order_id'] = orderId;
  185. if (accountUsername !== (config.account?.username || '')) setObj['account.username'] = accountUsername;
  186. if (accountPassword !== (config.account?.password || '')) setObj['account.password'] = accountPassword;
  187. if (loginInterval !== '' && loginInterval !== config.login_interval) setObj['login_interval'] = Number(loginInterval);
  188. try {
  189. const parsedUserPref = userPreferencesStr.trim() ? JSON.parse(userPreferencesStr) : {};
  190. if (JSON.stringify(parsedUserPref) !== JSON.stringify(config.user_preferences || {})) {
  191. setObj['user_preferences'] = parsedUserPref;
  192. }
  193. } catch {}
  194. }
  195. if (JSON.stringify(pluginConfig) !== JSON.stringify(config.plugin_config || {})) {
  196. setObj['plugin_config'] = pluginConfig;
  197. }
  198. if (JSON.stringify(appointmentTypes) !== JSON.stringify(config.appointment_types || [])) {
  199. setObj['appointment_types'] = appointmentTypes;
  200. }
  201. try {
  202. const parsedFree = freeConfigStr.trim() ? JSON.parse(freeConfigStr) : {};
  203. if (JSON.stringify(parsedFree) !== JSON.stringify(config.free_config || {})) {
  204. setObj['free_config'] = parsedFree;
  205. }
  206. } catch {}
  207. return {
  208. set: Object.keys(setObj).length > 0 ? setObj : undefined,
  209. clear: clearArr.length > 0 ? clearArr : undefined,
  210. };
  211. };
  212. const handleFormatJson = () => {
  213. try {
  214. const parsed = JSON.parse(rawJsonStr);
  215. setRawJsonStr(JSON.stringify(parsed, null, 2));
  216. toast.success('JSON 已格式化');
  217. } catch {
  218. toast.error('JSON 语法错误,无法格式化');
  219. }
  220. };
  221. const handleCopyJson = () => {
  222. navigator.clipboard.writeText(rawJsonStr);
  223. toast.success('已复制到剪贴板');
  224. };
  225. const handleSubmit = async (e: React.FormEvent) => {
  226. e.preventDefault();
  227. setSaving(true);
  228. try {
  229. let payload: SparseUpdatePayload;
  230. if (mode === 'json') {
  231. try {
  232. payload = JSON.parse(rawJsonStr);
  233. } catch {
  234. toast.error('JSON 格式错误,请检查语法');
  235. setSaving(false);
  236. return;
  237. }
  238. } else {
  239. if (entryType === 'standalone') {
  240. try {
  241. if (userPreferencesStr.trim()) {
  242. JSON.parse(userPreferencesStr);
  243. }
  244. } catch {
  245. toast.error('用户偏好 (user_preferences) JSON 格式错误,请检查语法');
  246. setSaving(false);
  247. return;
  248. }
  249. }
  250. payload = calculateSparsePayload();
  251. if (!payload.set && (!payload.clear || payload.clear.length === 0)) {
  252. toast('未检测到任何字段变更', { icon: 'ℹ️' });
  253. onClose();
  254. setSaving(false);
  255. return;
  256. }
  257. }
  258. const res = await nodeConfigService.sparseUpdate(entryType, config.id, payload);
  259. if (res.code === 0) {
  260. toast.success(`配置更新成功 (版本已升至 v${res.data?.version || config.version + 1})`);
  261. onSuccess();
  262. onClose();
  263. } else {
  264. toast.error(res.message || '更新失败');
  265. }
  266. } catch (err: any) {
  267. console.error('Update config error:', err);
  268. toast.error(err?.response?.data?.message || err.message || '更新异常');
  269. } finally {
  270. setSaving(false);
  271. }
  272. };
  273. return (
  274. <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-grayscale p-4 font-mono">
  275. <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">
  276. {/* Header */}
  277. <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">
  278. <div className="flex items-center gap-2">
  279. <span className="w-2.5 h-2.5 bg-amber-300 border border-black inline-block" />
  280. <div>
  281. <h3 className="font-black text-black text-xs md:text-sm uppercase tracking-wider">
  282. [ EDIT {entryType.toUpperCase()} CONFIG // 稀疏编辑: {config.node_id} / {config.identifier} (v{config.version}) ]
  283. </h3>
  284. </div>
  285. </div>
  286. {/* Mode Switcher */}
  287. <div className="flex items-center gap-2">
  288. <div className="flex border-2 border-black bg-white p-0.5 gap-1">
  289. <button
  290. type="button"
  291. onClick={() => setMode('visual')}
  292. className={`px-3 py-1 text-xs font-mono uppercase transition border ${
  293. mode === 'visual'
  294. ? 'bg-amber-300 text-black font-black border-black shadow-[1px_1px_0px_#000]'
  295. : 'text-neutral-700 font-bold border-transparent hover:bg-neutral-100'
  296. }`}
  297. >
  298. [ 可视化表单 ]
  299. </button>
  300. <button
  301. type="button"
  302. onClick={() => setMode('json')}
  303. className={`px-3 py-1 text-xs font-mono uppercase transition border ${
  304. mode === 'json'
  305. ? 'bg-amber-300 text-black font-black border-black shadow-[1px_1px_0px_#000]'
  306. : 'text-neutral-700 font-bold border-transparent hover:bg-neutral-100'
  307. }`}
  308. >
  309. [ JSON 稀疏模式 ]
  310. </button>
  311. </div>
  312. <button
  313. type="button"
  314. onClick={onClose}
  315. 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"
  316. >
  317. ✕
  318. </button>
  319. </div>
  320. </div>
  321. {/* Body */}
  322. <form onSubmit={handleSubmit} className="flex-1 overflow-y-auto p-5 space-y-5 bg-white text-xs">
  323. {mode === 'visual' ? (
  324. <div className="space-y-5">
  325. {/* Base & Network */}
  326. <div className="border-2 border-black bg-neutral-100 p-4 shadow-[2px_2px_0px_#000] space-y-3">
  327. <div className="flex items-center gap-2 border-b-2 border-black pb-1.5">
  328. <span className="w-2 h-2 bg-black inline-block" />
  329. <span className="font-black text-black uppercase">[ 01 // 节点与网络参数 ]</span>
  330. </div>
  331. <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
  332. <div className="md:col-span-2">
  333. <label className="block text-[11px] font-bold text-black mb-1">
  334. 目标计算节点 (node_id) <span className="text-rose-600 font-bold">*</span>
  335. </label>
  336. <input
  337. type="text"
  338. required
  339. value={nodeId}
  340. onChange={(e) => setNodeId(e.target.value)}
  341. placeholder="default, node01, node02..."
  342. 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]"
  343. />
  344. </div>
  345. <div className="md:col-span-2">
  346. <label className="block text-[11px] font-bold text-black mb-1">使馆/登录网址 (website)</label>
  347. <input
  348. type="text"
  349. value={website}
  350. onChange={(e) => setWebsite(e.target.value)}
  351. placeholder="https://visa.vfsglobal.com/..."
  352. 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]"
  353. />
  354. </div>
  355. <div>
  356. <label className="block text-[11px] font-bold text-black mb-1">代理冷却时间 (proxy_cd / 秒)</label>
  357. <input
  358. type="number"
  359. value={proxyCd}
  360. onChange={(e) => setProxyCd(e.target.value === '' ? '' : Number(e.target.value))}
  361. 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]"
  362. />
  363. </div>
  364. <div>
  365. <label className="block text-[11px] font-bold text-black mb-1">Session 最长存活时间 (秒)</label>
  366. <input
  367. type="number"
  368. value={sessionMaxLife}
  369. onChange={(e) => setSessionMaxLife(e.target.value === '' ? '' : Number(e.target.value))}
  370. 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]"
  371. />
  372. </div>
  373. <div className="md:col-span-2">
  374. <label className="block text-[11px] font-bold text-black mb-1">网络代理池标签列表 (proxy_pool, 逗号分隔)</label>
  375. <input
  376. type="text"
  377. value={proxyPoolStr}
  378. onChange={(e) => setProxyPoolStr(e.target.value)}
  379. placeholder="proxy-cheap, proxy-fast"
  380. 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]"
  381. />
  382. </div>
  383. </div>
  384. </div>
  385. {/* Booker fields */}
  386. {entryType === 'booker' && (
  387. <div className="border-2 border-black bg-neutral-100 p-4 shadow-[2px_2px_0px_#000] space-y-3">
  388. <div className="flex items-center gap-2 border-b-2 border-black pb-1.5">
  389. <span className="w-2 h-2 bg-black inline-block" />
  390. <span className="font-black text-black uppercase">[ 02 // Booker 调度与池参数 ]</span>
  391. </div>
  392. <div className="grid grid-cols-1 md:grid-cols-3 gap-3">
  393. <div>
  394. <label className="block text-[11px] font-bold text-black mb-1">使馆账号池 ID (account_pool_id)</label>
  395. <input
  396. type="text"
  397. value={bookerAccountPoolId}
  398. onChange={(e) => setBookerAccountPoolId(e.target.value)}
  399. 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]"
  400. />
  401. </div>
  402. <div>
  403. <label className="block text-[11px] font-bold text-black mb-1">目标并发实例 (target_instances)</label>
  404. <input
  405. type="number"
  406. min={1}
  407. value={bookerTargetInstances}
  408. onChange={(e) => setBookerTargetInstances(e.target.value === '' ? '' : Number(e.target.value))}
  409. 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]"
  410. />
  411. </div>
  412. <div>
  413. <label className="block text-[11px] font-bold text-black mb-1">账号冷却 CD (account_cd / 秒)</label>
  414. <input
  415. type="number"
  416. value={bookerAccountCd}
  417. onChange={(e) => setBookerAccountCd(e.target.value === '' ? '' : Number(e.target.value))}
  418. 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]"
  419. />
  420. </div>
  421. <div>
  422. <label className="block text-[11px] font-bold text-black mb-1">下单冷却 (booking_cooldown / 秒)</label>
  423. <input
  424. type="number"
  425. value={bookerCooldown}
  426. onChange={(e) => setBookerCooldown(e.target.value === '' ? '' : Number(e.target.value))}
  427. 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]"
  428. />
  429. </div>
  430. <div>
  431. <label className="block text-[11px] font-bold text-black mb-1">单号最大占位次数</label>
  432. <input
  433. type="number"
  434. value={bookerMaxBookings}
  435. onChange={(e) => setBookerMaxBookings(e.target.value === '' ? '' : Number(e.target.value))}
  436. 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]"
  437. />
  438. </div>
  439. </div>
  440. </div>
  441. )}
  442. {/* Sentinel fields */}
  443. {entryType === 'sentinel' && (
  444. <div className="border-2 border-black bg-neutral-100 p-4 shadow-[2px_2px_0px_#000] space-y-3">
  445. <div className="flex items-center gap-2 border-b-2 border-black pb-1.5">
  446. <span className="w-2 h-2 bg-black inline-block" />
  447. <span className="font-black text-black uppercase">[ 02 // Sentinel 扫位与信号策略 ]</span>
  448. </div>
  449. <div className="grid grid-cols-1 md:grid-cols-3 gap-3">
  450. <div>
  451. <label className="block text-[11px] font-bold text-black mb-1">账号池 ID (account_pool_id)</label>
  452. <input
  453. type="text"
  454. value={sentinelAccountPoolId}
  455. onChange={(e) => setSentinelAccountPoolId(e.target.value)}
  456. 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]"
  457. />
  458. </div>
  459. <div>
  460. <label className="block text-[11px] font-bold text-black mb-1">并发实例数 (target_instances)</label>
  461. <input
  462. type="number"
  463. min={1}
  464. value={sentinelTargetInstances}
  465. onChange={(e) => setSentinelTargetInstances(e.target.value === '' ? '' : Number(e.target.value))}
  466. 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]"
  467. />
  468. </div>
  469. <div>
  470. <label className="block text-[11px] font-bold text-black mb-1">信号 TTL 持续 (秒)</label>
  471. <input
  472. type="number"
  473. value={sentinelSignalTtl}
  474. onChange={(e) => setSentinelSignalTtl(e.target.value === '' ? '' : Number(e.target.value))}
  475. 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]"
  476. />
  477. </div>
  478. <div>
  479. <label className="block text-[11px] font-bold text-black mb-1">扫位轮询模式 (query_wait.mode)</label>
  480. <select
  481. value={queryWaitMode}
  482. onChange={(e) => setQueryWaitMode(e.target.value as any)}
  483. 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]"
  484. >
  485. <option value="Random">Random (随机等待)</option>
  486. <option value="Fixed">Fixed (固定等待)</option>
  487. </select>
  488. </div>
  489. {queryWaitMode === 'Fixed' ? (
  490. <div>
  491. <label className="block text-[11px] font-bold text-black mb-1">固定等待 (秒)</label>
  492. <input
  493. type="number"
  494. value={fixedWait}
  495. onChange={(e) => setFixedWait(e.target.value === '' ? '' : Number(e.target.value))}
  496. 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]"
  497. />
  498. </div>
  499. ) : (
  500. <>
  501. <div>
  502. <label className="block text-[11px] font-bold text-black mb-1">随机最小等待 (秒)</label>
  503. <input
  504. type="number"
  505. value={randomMin}
  506. onChange={(e) => setRandomMin(e.target.value === '' ? '' : Number(e.target.value))}
  507. 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]"
  508. />
  509. </div>
  510. <div>
  511. <label className="block text-[11px] font-bold text-black mb-1">随机最大等待 (秒)</label>
  512. <input
  513. type="number"
  514. value={randomMax}
  515. onChange={(e) => setRandomMax(e.target.value === '' ? '' : Number(e.target.value))}
  516. 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]"
  517. />
  518. </div>
  519. </>
  520. )}
  521. </div>
  522. </div>
  523. )}
  524. {/* Standalone fields */}
  525. {entryType === 'standalone' && (
  526. <div className="border-2 border-black bg-neutral-100 p-4 shadow-[2px_2px_0px_#000] space-y-3">
  527. <div className="flex items-center gap-2 border-b-2 border-black pb-1.5">
  528. <span className="w-2 h-2 bg-black inline-block" />
  529. <span className="font-black text-black uppercase">[ 02 // Standalone 偏好与凭证 ]</span>
  530. </div>
  531. <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
  532. <div>
  533. <label className="block text-[11px] font-bold text-black mb-1">关联订单号 (order_id)</label>
  534. <input
  535. type="text"
  536. value={orderId}
  537. onChange={(e) => setOrderId(e.target.value)}
  538. 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]"
  539. />
  540. </div>
  541. <div>
  542. <label className="block text-[11px] font-bold text-black mb-1">登录重试间隔 (秒)</label>
  543. <input
  544. type="number"
  545. value={loginInterval}
  546. onChange={(e) => setLoginInterval(e.target.value === '' ? '' : Number(e.target.value))}
  547. 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]"
  548. />
  549. </div>
  550. <div>
  551. <label className="block text-[11px] font-bold text-black mb-1">抢签账号 (username)</label>
  552. <input
  553. type="text"
  554. value={accountUsername}
  555. onChange={(e) => setAccountUsername(e.target.value)}
  556. 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]"
  557. />
  558. </div>
  559. <div>
  560. <label className="block text-[11px] font-bold text-black mb-1">抢签密码 (password)</label>
  561. <input
  562. type="text"
  563. placeholder="输入抢签密码"
  564. value={accountPassword}
  565. onChange={(e) => setAccountPassword(e.target.value)}
  566. 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]"
  567. />
  568. </div>
  569. </div>
  570. <div className="pt-2 border-t border-black/20 space-y-1.5">
  571. <div className="flex items-center justify-between">
  572. <label className="block text-[11px] font-bold text-black">用户偏好 (user_preferences JSON)</label>
  573. <span className="text-[10px] text-neutral-500 font-mono">支持自定义键值与可变结构</span>
  574. </div>
  575. <textarea
  576. rows={3}
  577. value={userPreferencesStr}
  578. onChange={(e) => setUserPreferencesStr(e.target.value)}
  579. placeholder="{}"
  580. 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]"
  581. />
  582. </div>
  583. </div>
  584. )}
  585. {/* Appointment Types */}
  586. <AppointmentTypeEditor
  587. items={appointmentTypes}
  588. onChange={setAppointmentTypes}
  589. />
  590. {/* Free Config */}
  591. <div className="border-2 border-black bg-neutral-100 p-4 shadow-[2px_2px_0px_#000] space-y-2">
  592. <div className="flex items-center gap-2 border-b-2 border-black pb-1.5">
  593. <span className="w-2 h-2 bg-black inline-block" />
  594. <span className="font-black text-black uppercase">[ 03 // 自定义扩展 (FREE_CONFIG) ]</span>
  595. </div>
  596. <textarea
  597. rows={3}
  598. value={freeConfigStr}
  599. onChange={(e) => setFreeConfigStr(e.target.value)}
  600. 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]"
  601. />
  602. </div>
  603. </div>
  604. ) : (
  605. /* JSON Sparse Mode */
  606. <div className="w-full font-mono text-xs select-none space-y-3">
  607. <div className="flex items-center justify-between px-3 py-2 bg-neutral-200 border-2 border-black">
  608. <div className="flex items-center gap-2">
  609. <span className="w-2.5 h-2.5 bg-amber-300 border border-black inline-block" />
  610. <span className="font-black text-black uppercase">[ SPARSE JSON TERMINAL // 稀疏更新视窗 ]</span>
  611. </div>
  612. <div className="flex items-center gap-1">
  613. <button
  614. type="button"
  615. onClick={handleFormatJson}
  616. 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"
  617. >
  618. [ 格式化 ]
  619. </button>
  620. <button
  621. type="button"
  622. onClick={handleCopyJson}
  623. 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"
  624. >
  625. [ 复制 ]
  626. </button>
  627. </div>
  628. </div>
  629. <div className="border-2 border-black shadow-[4px_4px_0px_#000]">
  630. <textarea
  631. rows={14}
  632. value={rawJsonStr}
  633. onChange={(e) => setRawJsonStr(e.target.value)}
  634. placeholder='{\n "set": {},\n "clear": []\n}'
  635. className="w-full p-4 font-mono text-xs leading-relaxed outline-none bg-neutral-900 text-amber-300 resize-y"
  636. />
  637. </div>
  638. </div>
  639. )}
  640. </form>
  641. {/* Footer */}
  642. <div className="px-5 py-3 bg-neutral-200 border-t-2 border-black flex justify-between items-center shrink-0">
  643. <div className="text-[11px] text-neutral-600 font-bold">
  644. {mode === 'visual' ? '前端将在提交时自动比对生成 set / clear 稀疏负载' : '直接提交 JSON 负载'}
  645. </div>
  646. <div className="flex items-center gap-2">
  647. <button
  648. type="button"
  649. onClick={onClose}
  650. 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"
  651. >
  652. [ 取消 ]
  653. </button>
  654. <button
  655. type="button"
  656. onClick={handleSubmit}
  657. disabled={saving}
  658. 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"
  659. >
  660. {saving ? '[ 保存中... ]' : '[ 保存更新 ]'}
  661. </button>
  662. </div>
  663. </div>
  664. </div>
  665. </div>
  666. );
  667. }