whistle.mock-plugins 1.2.2-beta.4 → 1.2.2-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -95,6 +95,9 @@ const InterfaceManagement = () => {
95
95
  // 数据管理显示模式
96
96
  const [displayMode, setDisplayMode] = useState('modal');
97
97
 
98
+ // 接口表单显示模式
99
+ const [interfaceFormDisplayMode, setInterfaceFormDisplayMode] = useState('modal');
100
+
98
101
  // 表单实例
99
102
  const [form] = Form.useForm();
100
103
 
@@ -165,6 +168,29 @@ const InterfaceManagement = () => {
165
168
  };
166
169
  }, []);
167
170
 
171
+ // 监听接口表单显示模式变化
172
+ useEffect(() => {
173
+ // 初始化时从 localStorage 读取配置
174
+ const savedMode = localStorage.getItem('interfaceFormDisplayMode');
175
+ if (savedMode) {
176
+ setInterfaceFormDisplayMode(savedMode);
177
+ }
178
+
179
+ // 监听 storage 事件,实现设置立即生效
180
+ const handleStorageChange = () => {
181
+ const newMode = localStorage.getItem('interfaceFormDisplayMode');
182
+ if (newMode) {
183
+ setInterfaceFormDisplayMode(newMode);
184
+ }
185
+ };
186
+
187
+ window.addEventListener('storage', handleStorageChange);
188
+
189
+ return () => {
190
+ window.removeEventListener('storage', handleStorageChange);
191
+ };
192
+ }, []);
193
+
168
194
  // 获取当前选中的功能模块
169
195
  const selectedFeature = features.find(f => f.id === selectedFeatureId);
170
196
 
@@ -1543,63 +1569,70 @@ const InterfaceManagement = () => {
1543
1569
  </div>
1544
1570
  </Card>
1545
1571
 
1546
- {/* 接口编辑/创建模态框 */}
1547
- <Modal
1548
- title={
1549
- <div style={{
1550
- fontSize: '18px',
1551
- fontWeight: 600,
1552
- color: '#262626',
1553
- display: 'flex',
1554
- alignItems: 'center',
1555
- gap: '8px'
1556
- }}>
1557
- <span>{editingInterface ? '编辑接口' : (isDuplicateMode ? '复制新增接口' : '添加接口')}</span>
1558
- <Badge
1559
- count="配置向导"
1560
- style={{
1561
- backgroundColor: '#f0f9ff',
1562
- color: '#1677ff',
1563
- fontSize: '11px',
1564
- fontWeight: 'normal'
1565
- }}
1566
- />
1567
- </div>
1568
- }
1569
- open={modalVisible}
1570
- onOk={handleSubmit}
1571
- onCancel={handleCancel}
1572
- width={1200}
1573
- destroyOnClose
1574
- okText={editingInterface ? '保存' : '创建'}
1575
- cancelText="取消"
1576
- bodyStyle={{
1577
- maxHeight: '75vh',
1578
- overflow: 'auto',
1579
- padding: '0',
1580
- background: '#fafafa'
1581
- }}
1582
- className="interface-modal"
1583
- >
1584
- <div style={{ padding: '24px' }}>
1585
- <Form
1586
- form={form}
1587
- layout="vertical"
1588
- initialValues={{
1589
- name: '',
1590
- group: '',
1591
- pattern: '',
1592
- proxyType: 'response',
1593
- statusCode: '200',
1594
- contentType: 'application/json; charset=utf-8',
1595
- responses: [],
1596
- httpMethod: 'ALL',
1597
- targetUrl: '',
1598
- headerItems: [],
1599
- paramMatchers: [],
1600
- responseDelay: '0'
1601
- }}
1602
- >
1572
+ {/* 接口编辑/创建模态框/抽屉 */}
1573
+ {interfaceFormDisplayMode === 'drawer' ? (
1574
+ <Drawer
1575
+ title={
1576
+ <div style={{
1577
+ fontSize: '18px',
1578
+ fontWeight: 600,
1579
+ color: '#262626',
1580
+ display: 'flex',
1581
+ alignItems: 'center',
1582
+ gap: '8px'
1583
+ }}>
1584
+ <span>{editingInterface ? '编辑接口' : (isDuplicateMode ? '复制新增接口' : '添加接口')}</span>
1585
+ <Badge
1586
+ count="配置向导"
1587
+ style={{
1588
+ backgroundColor: '#f0f9ff',
1589
+ color: '#1677ff',
1590
+ fontSize: '11px',
1591
+ fontWeight: 'normal'
1592
+ }}
1593
+ />
1594
+ </div>
1595
+ }
1596
+ placement="right"
1597
+ width={1040}
1598
+ open={modalVisible}
1599
+ onClose={handleCancel}
1600
+ destroyOnClose
1601
+ bodyStyle={{
1602
+ padding: '0',
1603
+ background: '#fafafa'
1604
+ }}
1605
+ footer={
1606
+ <div style={{ textAlign: 'right' }}>
1607
+ <Space>
1608
+ <Button onClick={handleCancel}>取消</Button>
1609
+ <Button type="primary" onClick={handleSubmit}>
1610
+ {editingInterface ? '保存' : '创建'}
1611
+ </Button>
1612
+ </Space>
1613
+ </div>
1614
+ }
1615
+ className="interface-drawer"
1616
+ >
1617
+ <div style={{ padding: '24px' }}>
1618
+ <Form
1619
+ form={form}
1620
+ layout="vertical"
1621
+ initialValues={{
1622
+ name: '',
1623
+ group: '',
1624
+ pattern: '',
1625
+ proxyType: 'response',
1626
+ statusCode: '200',
1627
+ contentType: 'application/json; charset=utf-8',
1628
+ responses: [],
1629
+ httpMethod: 'ALL',
1630
+ targetUrl: '',
1631
+ headerItems: [],
1632
+ paramMatchers: [],
1633
+ responseDelay: '0'
1634
+ }}
1635
+ >
1603
1636
  <Collapse
1604
1637
  defaultActiveKey={
1605
1638
  editingInterface && editingInterface.proxyType === 'response'
@@ -2106,7 +2139,538 @@ const InterfaceManagement = () => {
2106
2139
  </Collapse>
2107
2140
  </Form>
2108
2141
  </div>
2109
- </Modal>
2142
+ </Drawer>
2143
+ ) : (
2144
+ <Modal
2145
+ title={
2146
+ <div style={{
2147
+ fontSize: '18px',
2148
+ fontWeight: 600,
2149
+ color: '#262626',
2150
+ display: 'flex',
2151
+ alignItems: 'center',
2152
+ gap: '8px'
2153
+ }}>
2154
+ <span>{editingInterface ? '编辑接口' : (isDuplicateMode ? '复制新增接口' : '添加接口')}</span>
2155
+ <Badge
2156
+ count="配置向导"
2157
+ style={{
2158
+ backgroundColor: '#f0f9ff',
2159
+ color: '#1677ff',
2160
+ fontSize: '11px',
2161
+ fontWeight: 'normal'
2162
+ }}
2163
+ />
2164
+ </div>
2165
+ }
2166
+ open={modalVisible}
2167
+ onCancel={handleCancel}
2168
+ onOk={handleSubmit}
2169
+ width={1040}
2170
+ destroyOnClose
2171
+ okText={editingInterface ? '保存' : '创建'}
2172
+ cancelText="取消"
2173
+ bodyStyle={{
2174
+ maxHeight: '70vh',
2175
+ overflow: 'auto',
2176
+ background: '#fafafa'
2177
+ }}
2178
+ >
2179
+ <div style={{ padding: '0' }}>
2180
+ <Form
2181
+ form={form}
2182
+ layout="vertical"
2183
+ initialValues={{
2184
+ name: '',
2185
+ group: '',
2186
+ pattern: '',
2187
+ proxyType: 'response',
2188
+ statusCode: '200',
2189
+ contentType: 'application/json; charset=utf-8',
2190
+ responses: [],
2191
+ httpMethod: 'ALL',
2192
+ targetUrl: '',
2193
+ headerItems: [],
2194
+ paramMatchers: [],
2195
+ responseDelay: '0'
2196
+ }}
2197
+ >
2198
+ {/* Modal 模式下使用相同的表单内容,但去掉 Collapse 包装 */}
2199
+ <div style={{ padding: '24px' }}>
2200
+ {/* 基础信息 */}
2201
+ <div style={{ marginBottom: '24px' }}>
2202
+ <div style={{ fontSize: '16px', fontWeight: 600, marginBottom: '16px', display: 'flex', alignItems: 'center', gap: '8px' }}>
2203
+ <Badge count="1" style={{ backgroundColor: '#1677ff' }} />
2204
+ <span>基础信息</span>
2205
+ </div>
2206
+ <div style={{ display: 'flex', flexDirection: 'row', gap: '16px' }}>
2207
+ <div style={{ flex: 1 }}>
2208
+ <Form.Item
2209
+ name="name"
2210
+ label="接口名称"
2211
+ rules={[{ required: true, message: '请输入接口名称' }]}
2212
+ >
2213
+ <Input placeholder="请输入接口名称" />
2214
+ </Form.Item>
2215
+ </div>
2216
+ <div style={{ flex: 1 }}>
2217
+ <Form.Item
2218
+ name="group"
2219
+ label="分组"
2220
+ tooltip="为接口设置分组,便于管理和批量操作"
2221
+ >
2222
+ <Select
2223
+ placeholder="选择或创建分组"
2224
+ showSearch
2225
+ allowClear
2226
+ style={{ width: '100%' }}
2227
+ mode="tags"
2228
+ maxTagCount="responsive"
2229
+ maxTagTextLength={10}
2230
+ onChange={(value) => {
2231
+ if (Array.isArray(value) && value.length > 0) {
2232
+ const groupValue = value[0] === '' ? undefined : value[0];
2233
+ form.setFieldsValue({ group: groupValue });
2234
+ }
2235
+ }}
2236
+ onInputKeyDown={(e) => {
2237
+ if (e.key === 'Enter') {
2238
+ e.stopPropagation();
2239
+ }
2240
+ }}
2241
+ >
2242
+ {Array.from(new Set(interfaces.map(item => item.group).filter(Boolean))).map(group => (
2243
+ <Option key={group} value={group}>{group}</Option>
2244
+ ))}
2245
+ </Select>
2246
+ </Form.Item>
2247
+ </div>
2248
+ </div>
2249
+ </div>
2250
+
2251
+ {/* URL配置 */}
2252
+ <div style={{ marginBottom: '24px' }}>
2253
+ <div style={{ fontSize: '16px', fontWeight: 600, marginBottom: '16px', display: 'flex', alignItems: 'center', gap: '8px' }}>
2254
+ <Badge count="2" style={{ backgroundColor: '#1677ff' }} />
2255
+ <span>URL配置</span>
2256
+ </div>
2257
+ <div style={{ display: 'flex', flexDirection: 'row', gap: '16px' }}>
2258
+ <div style={{ flex: 1 }}>
2259
+ <Form.Item
2260
+ name="pattern"
2261
+ label="URL匹配规则"
2262
+ rules={[
2263
+ { required: true, message: '请输入URL匹配规则' },
2264
+ ({ getFieldValue }) => ({
2265
+ validator(_, value) {
2266
+ const proxyType = getFieldValue('proxyType');
2267
+ if (!value) return Promise.resolve();
2268
+
2269
+ if (proxyType === 'url_redirect') {
2270
+ try {
2271
+ new URL(value);
2272
+ return Promise.resolve();
2273
+ } catch (e) {
2274
+ return Promise.reject(new Error('URL重定向模式下,URL匹配规则必须是完整的URL(包括http://或https://)'));
2275
+ }
2276
+ }
2277
+
2278
+ if (proxyType === 'redirect') {
2279
+ if (value.startsWith('http://') || value.startsWith('https://')) {
2280
+ return Promise.resolve();
2281
+ }
2282
+ return Promise.reject(new Error('重定向模式下,URL匹配规则必须以http://或https://开头'));
2283
+ }
2284
+
2285
+ if (proxyType === 'response') {
2286
+ if (value.startsWith('/') && value.endsWith('/')) {
2287
+ try {
2288
+ new RegExp(value.slice(1, -1));
2289
+ return Promise.resolve();
2290
+ } catch (e) {
2291
+ return Promise.reject(new Error('无效的正则表达式格式'));
2292
+ }
2293
+ }
2294
+
2295
+ if (value.includes('*')) {
2296
+ if (/^[a-zA-Z0-9\-_/.*]+$/.test(value)) {
2297
+ return Promise.resolve();
2298
+ }
2299
+ return Promise.reject(new Error('通配符URL格式不正确'));
2300
+ }
2301
+
2302
+ if (/^[a-zA-Z0-9\-_/]+$/.test(value)) {
2303
+ return Promise.resolve();
2304
+ }
2305
+ return Promise.reject(new Error('URL路径格式不正确'));
2306
+ }
2307
+
2308
+ return Promise.resolve();
2309
+ },
2310
+ }),
2311
+ ]}
2312
+ tooltip={{
2313
+ title: (
2314
+ <>
2315
+ <div>不同处理方式下URL匹配规则要求:</div>
2316
+ <ul style={{margin: '5px 0 0 15px', padding: 0}}>
2317
+ <li><b>模拟响应:</b> 支持路径格式如 /api/users,通配符如 /api/*,正则如 /\/api\/\d+/</li>
2318
+ <li><b>重定向:</b> 必须以http://或https://开头,例如:https://example.com/api</li>
2319
+ <li><b>URL重定向:</b> 必须是完整URL,包括http://或https://,例如:https://example.com/api/users</li>
2320
+ </ul>
2321
+ </>
2322
+ ),
2323
+ overlayStyle: { maxWidth: '450px' }
2324
+ }}
2325
+ >
2326
+ <Input
2327
+ placeholder="根据选择的处理方式输入相应格式的URL"
2328
+ />
2329
+ </Form.Item>
2330
+ </div>
2331
+ <div style={{ flex: 1 }}>
2332
+ <Form.Item
2333
+ name="proxyType"
2334
+ label="处理方式"
2335
+ rules={[{ required: true, message: '请选择处理方式' }]}
2336
+ tooltip={{
2337
+ title: (
2338
+ <>
2339
+ <div>不同处理方式的规则说明:</div>
2340
+ <ul style={{margin: '5px 0 0 15px', padding: 0}}>
2341
+ <li><b>模拟响应:</b> 返回您定义的响应内容</li>
2342
+ <li><b>重定向:</b> 将请求重定向到其他URL,URL匹配规则必须以http://或https://开头</li>
2343
+ <li><b>URL重定向:</b> 完全匹配URL时重定向,URL匹配规则必须是完整URL</li>
2344
+ </ul>
2345
+ </>
2346
+ ),
2347
+ overlayStyle: { maxWidth: '450px' }
2348
+ }}
2349
+ >
2350
+ <Select onChange={(value) => {
2351
+ form.setFieldsValue({ pattern: '' });
2352
+ const patternInput = document.querySelector('input[placeholder="根据选择的处理方式输入相应格式的URL"]');
2353
+ if (patternInput) {
2354
+ if (value === 'response') {
2355
+ patternInput.placeholder = "例如:/api/users,/api/users/*,/api\\/users\\/\\d+/";
2356
+ } else if (value === 'redirect') {
2357
+ patternInput.placeholder = "例如:https://example.com/api";
2358
+ } else if (value === 'url_redirect') {
2359
+ patternInput.placeholder = "例如:https://example.com/api/users";
2360
+ }
2361
+ }
2362
+ }}>
2363
+ {proxyTypes.map(item => (
2364
+ <Option key={item.value} value={item.value}>{item.label}</Option>
2365
+ ))}
2366
+ </Select>
2367
+ </Form.Item>
2368
+ </div>
2369
+ </div>
2370
+
2371
+ <div style={{ display: 'flex', flexDirection: 'row', gap: '16px' }}>
2372
+ <div style={{ flex: 1 }}>
2373
+ <Form.Item
2374
+ name="httpMethod"
2375
+ label="请求方法"
2376
+ rules={[{ required: true, message: '请选择请求方法' }]}
2377
+ >
2378
+ <Select>
2379
+ {httpMethods.map(item => (
2380
+ <Option key={item.value} value={item.value}>{item.label}</Option>
2381
+ ))}
2382
+ </Select>
2383
+ </Form.Item>
2384
+ </div>
2385
+ <div style={{ flex: 1 }}>
2386
+ {/* 这里可以留空或添加其他字段 */}
2387
+ </div>
2388
+ </div>
2389
+ </div>
2390
+
2391
+ {/* 高级配置 */}
2392
+ <div style={{ marginBottom: '24px' }}>
2393
+ <div style={{ fontSize: '16px', fontWeight: 600, marginBottom: '16px', display: 'flex', alignItems: 'center', gap: '8px' }}>
2394
+ <Badge count="3" style={{ backgroundColor: '#1677ff' }} />
2395
+ <span>高级配置</span>
2396
+ </div>
2397
+
2398
+ {/* 根据proxyType显示不同的表单项 */}
2399
+ <Form.Item noStyle shouldUpdate={(prevValues, currentValues) => prevValues.proxyType !== currentValues.proxyType}>
2400
+ {({ getFieldValue }) => {
2401
+ const proxyType = getFieldValue('proxyType');
2402
+
2403
+ if (proxyType === 'response') {
2404
+ return (
2405
+ <>
2406
+ <div style={{ display: 'flex', flexDirection: 'row', gap: '16px' }}>
2407
+ <div style={{ flex: 1 }}>
2408
+ <Form.Item
2409
+ name="statusCode"
2410
+ label="状态码"
2411
+ rules={[{ required: true, message: '请选择状态码' }]}
2412
+ >
2413
+ <Select>
2414
+ {statusCodes.map(item => (
2415
+ <Option key={item.value} value={item.value}>{item.label}</Option>
2416
+ ))}
2417
+ </Select>
2418
+ </Form.Item>
2419
+ </div>
2420
+ <div style={{ flex: 1 }}>
2421
+ <Form.Item
2422
+ name="contentType"
2423
+ label="内容类型"
2424
+ rules={[{ required: true, message: '请选择内容类型' }]}
2425
+ >
2426
+ <Select>
2427
+ {contentTypes.map(item => (
2428
+ <Option key={item.value} value={item.value}>{item.label}</Option>
2429
+ ))}
2430
+ </Select>
2431
+ </Form.Item>
2432
+ </div>
2433
+ <div style={{ flex: 1 }}>
2434
+ <Form.Item
2435
+ name="responseDelay"
2436
+ label="延迟响应(毫秒)"
2437
+ tooltip="设置接口响应延迟时间,单位为毫秒"
2438
+ rules={[
2439
+ {
2440
+ pattern: /^\d*$/,
2441
+ message: '请输入有效的数字'
2442
+ },
2443
+ {
2444
+ validator: (_, value) => {
2445
+ if (!value || parseInt(value, 10) <= 60000) {
2446
+ return Promise.resolve();
2447
+ }
2448
+ return Promise.reject(new Error('延迟时间不能超过60秒(60000毫秒)'));
2449
+ }
2450
+ }
2451
+ ]}
2452
+ >
2453
+ <Input placeholder="例如:500" />
2454
+ </Form.Item>
2455
+ </div>
2456
+ </div>
2457
+
2458
+ {/* 请求入参匹配设置 */}
2459
+ <Form.Item
2460
+ label="请求入参匹配"
2461
+ tooltip="设置请求参数的匹配条件,只有当请求参数满足条件时才返回对应的响应。支持嵌套属性路径,如:a.b.c"
2462
+ >
2463
+ <Form.List name="paramMatchers">
2464
+ {(fields, { add, remove }) => (
2465
+ <>
2466
+ {fields.map(({ key, name, ...restField }) => (
2467
+ <div key={key} style={{ display: 'flex', gap: '8px', alignItems: 'center', marginBottom: '8px' }}>
2468
+ <Form.Item
2469
+ {...restField}
2470
+ name={[name, 'paramPath']}
2471
+ rules={[
2472
+ { required: true, message: '请输入参数路径' },
2473
+ {
2474
+ pattern: /^[a-zA-Z_$][a-zA-Z0-9_$.]*$/,
2475
+ message: '请输入有效的参数路径,如:userId 或 data.user.id'
2476
+ }
2477
+ ]}
2478
+ style={{ flex: 1, margin: 0 }}
2479
+ >
2480
+ <Input placeholder="参数路径(如:userId 或 data.user.id)" />
2481
+ </Form.Item>
2482
+ <Form.Item
2483
+ {...restField}
2484
+ name={[name, 'paramValue']}
2485
+ rules={[{ required: true, message: '请输入期望值' }]}
2486
+ style={{ flex: 1, margin: 0 }}
2487
+ >
2488
+ <Input placeholder="期望值(如:123 或 admin)" />
2489
+ </Form.Item>
2490
+ <Form.Item
2491
+ {...restField}
2492
+ name={[name, 'matchType']}
2493
+ style={{ width: 100, margin: 0 }}
2494
+ initialValue="exact"
2495
+ >
2496
+ <Select placeholder="匹配类型">
2497
+ <Option value="exact">精确匹配</Option>
2498
+ <Option value="contains">包含</Option>
2499
+ <Option value="regex">正则</Option>
2500
+ </Select>
2501
+ </Form.Item>
2502
+ <Button
2503
+ type="text"
2504
+ danger
2505
+ icon={<DeleteOutlined />}
2506
+ onClick={() => remove(name)}
2507
+ />
2508
+ </div>
2509
+ ))}
2510
+ <div style={{ display: 'flex', alignItems: 'center', gap: '8px', marginTop: '8px' }}>
2511
+ <Button
2512
+ type="dashed"
2513
+ onClick={() => add()}
2514
+ icon={<PlusOutlined />}
2515
+ style={{ flex: 1 }}
2516
+ >
2517
+ 添加参数匹配规则
2518
+ </Button>
2519
+ <Popover
2520
+ content={
2521
+ <div style={{ maxWidth: '300px' }}>
2522
+ <div style={{ marginBottom: '8px', fontWeight: 'bold' }}>匹配规则说明:</div>
2523
+ <div style={{ lineHeight: '1.6' }}>
2524
+ <div>• <strong>精确匹配</strong>:参数值完全相等</div>
2525
+ <div>• <strong>包含</strong>:参数值包含指定内容</div>
2526
+ <div>• <strong>正则</strong>:参数值符合正则表达式</div>
2527
+ <div>• <strong>嵌套路径</strong>:使用点号分隔,如 data.user.id</div>
2528
+ </div>
2529
+ </div>
2530
+ }
2531
+ title="参数匹配规则"
2532
+ trigger="click"
2533
+ placement="top"
2534
+ >
2535
+ <Button
2536
+ type="text"
2537
+ icon={<QuestionCircleOutlined />}
2538
+ style={{
2539
+ color: '#999',
2540
+ padding: '4px'
2541
+ }}
2542
+ size="small"
2543
+ />
2544
+ </Popover>
2545
+ </div>
2546
+ </>
2547
+ )}
2548
+ </Form.List>
2549
+ </Form.Item>
2550
+
2551
+ {/* 隐藏的表单字段用于存储响应数据 */}
2552
+ <Form.Item
2553
+ name="responses"
2554
+ initialValue={[]}
2555
+ hidden
2556
+ >
2557
+ <Input />
2558
+ </Form.Item>
2559
+ <Form.Item name="activeResponseId" hidden>
2560
+ <Input />
2561
+ </Form.Item>
2562
+
2563
+ {/* 使用新的合并组件 */}
2564
+ <Form.Item noStyle shouldUpdate>
2565
+ {({ getFieldValue }) => {
2566
+ let responses = getFieldValue('responses') || [];
2567
+ const activeResponseId = getFieldValue('activeResponseId');
2568
+
2569
+ if (!Array.isArray(responses)) {
2570
+ try {
2571
+ if (typeof responses === 'string') {
2572
+ responses = JSON.parse(responses);
2573
+ }
2574
+ } catch (e) {
2575
+ responses = [];
2576
+ }
2577
+ }
2578
+
2579
+ return (
2580
+ <ResponseContentEditor
2581
+ form={form}
2582
+ responses={responses}
2583
+ activeResponseId={activeResponseId}
2584
+ onPreview={handlePreview}
2585
+ />
2586
+ );
2587
+ }}
2588
+ </Form.Item>
2589
+ </>
2590
+ );
2591
+ } else if (proxyType === 'redirect' || proxyType === 'url_redirect') {
2592
+ return (
2593
+ <>
2594
+ <Form.Item
2595
+ name="targetUrl"
2596
+ label="重定向目标URL"
2597
+ rules={[
2598
+ { required: true, message: '请输入重定向目标URL' },
2599
+ {
2600
+ validator(_, value) {
2601
+ if (!value) return Promise.resolve();
2602
+ try {
2603
+ new URL(value);
2604
+ return Promise.resolve();
2605
+ } catch (e) {
2606
+ return Promise.reject(new Error('请输入有效的URL格式(包括http://或https://)'));
2607
+ }
2608
+ }
2609
+ }
2610
+ ]}
2611
+ tooltip="重定向的目标URL,必须是完整的URL格式"
2612
+ >
2613
+ <Input
2614
+ placeholder="例如:https://api.example.com/users"
2615
+ />
2616
+ </Form.Item>
2617
+
2618
+ {/* 自定义请求头设置 */}
2619
+ <Form.Item label="自定义请求头">
2620
+ <Form.List name="headerItems">
2621
+ {(fields, { add, remove }) => (
2622
+ <>
2623
+ {fields.map(({ key, name, ...restField }) => (
2624
+ <div key={key} style={{ display: 'flex', gap: '8px', alignItems: 'center', marginBottom: '8px' }}>
2625
+ <Form.Item
2626
+ {...restField}
2627
+ name={[name, 'headerName']}
2628
+ rules={[{ required: true, message: '请输入请求头名称' }]}
2629
+ style={{ flex: 1, margin: 0 }}
2630
+ >
2631
+ <Input placeholder="请求头名称(如:Authorization)" />
2632
+ </Form.Item>
2633
+ <Form.Item
2634
+ {...restField}
2635
+ name={[name, 'headerValue']}
2636
+ rules={[{ required: true, message: '请输入请求头值' }]}
2637
+ style={{ flex: 1, margin: 0 }}
2638
+ >
2639
+ <Input placeholder="请求头值(如:Bearer token123)" />
2640
+ </Form.Item>
2641
+ <Button
2642
+ type="text"
2643
+ danger
2644
+ icon={<DeleteOutlined />}
2645
+ onClick={() => remove(name)}
2646
+ />
2647
+ </div>
2648
+ ))}
2649
+ <Button
2650
+ type="dashed"
2651
+ onClick={() => add()}
2652
+ icon={<PlusOutlined />}
2653
+ style={{ width: '100%', marginTop: '8px' }}
2654
+ >
2655
+ 添加请求头
2656
+ </Button>
2657
+ </>
2658
+ )}
2659
+ </Form.List>
2660
+ </Form.Item>
2661
+ </>
2662
+ );
2663
+ }
2664
+
2665
+ return null;
2666
+ }}
2667
+ </Form.Item>
2668
+ </div>
2669
+ </div>
2670
+ </Form>
2671
+ </div>
2672
+ </Modal>
2673
+ )}
2110
2674
 
2111
2675
  {/* 使用拆分后的预览模态框组件 */}
2112
2676
  <PreviewModal