whistle.mock-plugins 1.0.6-beta.20 → 1.0.6-beta.21

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whistle.mock-plugins",
3
- "version": "1.0.6-beta.20",
3
+ "version": "1.0.6-beta.21",
4
4
  "description": "Whistle 插件,用于快速创建 API 模拟数据",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import { Card, Button, Space, Badge, Row, Col, Input, Select, Tooltip, message } from 'antd';
1
+ import React, { useState } from 'react';
2
+ import { Card, Button, Space, Badge, Row, Col, Input, Select, Tooltip, message, AutoComplete } from 'antd';
3
3
  import {
4
4
  CodeOutlined,
5
5
  EyeOutlined,
@@ -7,7 +7,8 @@ import {
7
7
  FileTextOutlined,
8
8
  PlusCircleOutlined,
9
9
  DeleteOutlined,
10
- CheckCircleOutlined
10
+ CheckCircleOutlined,
11
+ EditOutlined
11
12
  } from '@ant-design/icons';
12
13
  import { generateResponseId } from './utils';
13
14
 
@@ -21,6 +22,8 @@ const ResponseContentEditor = ({
21
22
  onPreview
22
23
  }) => {
23
24
  const { getFieldValue, setFieldsValue } = form;
25
+ const [isEditing, setIsEditing] = useState(false);
26
+ const [editingName, setEditingName] = useState('');
24
27
 
25
28
  // 查找激活的响应
26
29
  const activeResponseIndex = responses.findIndex(r => r.id === activeResponseId);
@@ -88,15 +91,34 @@ const ResponseContentEditor = ({
88
91
  // 切换响应
89
92
  const handleResponseSelect = (responseId) => {
90
93
  setFieldsValue({ activeResponseId: responseId });
94
+ setIsEditing(false);
91
95
  };
92
96
 
93
- // 更新响应名称
94
- const handleNameChange = (responseId, name) => {
95
- const currentResponses = getFieldValue('responses') || [];
96
- const updatedResponses = currentResponses.map(resp =>
97
- resp.id === responseId ? { ...resp, name } : resp
98
- );
99
- setFieldsValue({ responses: updatedResponses });
97
+ // 开始编辑响应名称
98
+ const handleStartEdit = () => {
99
+ if (activeResponse) {
100
+ setEditingName(activeResponse.name || '');
101
+ setIsEditing(true);
102
+ }
103
+ };
104
+
105
+ // 完成编辑响应名称
106
+ const handleFinishEdit = () => {
107
+ if (activeResponseId && editingName.trim()) {
108
+ const currentResponses = getFieldValue('responses') || [];
109
+ const updatedResponses = currentResponses.map(resp =>
110
+ resp.id === activeResponseId ? { ...resp, name: editingName.trim() } : resp
111
+ );
112
+ setFieldsValue({ responses: updatedResponses });
113
+ }
114
+ setIsEditing(false);
115
+ setEditingName('');
116
+ };
117
+
118
+ // 取消编辑
119
+ const handleCancelEdit = () => {
120
+ setIsEditing(false);
121
+ setEditingName('');
100
122
  };
101
123
 
102
124
  // 更新响应内容
@@ -219,73 +241,95 @@ const ResponseContentEditor = ({
219
241
  style={{ marginBottom: 16 }}
220
242
  bodyStyle={{ padding: '16px' }}
221
243
  >
222
- {/* 响应选择和名称编辑 */}
244
+ {/* 响应选择和名称编辑合并区域 */}
223
245
  <div style={{ marginBottom: '16px' }}>
224
246
  <Row gutter={12} align="middle">
225
- <Col span={10}>
247
+ <Col span={20}>
226
248
  <div style={{ marginBottom: '8px' }}>
227
249
  <label style={{
228
250
  fontSize: '12px',
229
251
  color: '#666',
230
252
  fontWeight: 'bold'
231
253
  }}>
232
- 选择响应
254
+ 选择响应 / 编辑名称
233
255
  </label>
234
256
  </div>
235
- <Select
236
- style={{ width: '100%' }}
237
- placeholder="选择要编辑的响应"
238
- value={activeResponseId}
239
- onChange={handleResponseSelect}
240
- optionLabelProp="label"
241
- >
242
- {responses.map((resp, index) => (
243
- <Option
244
- key={resp.id}
245
- value={resp.id}
246
- label={
247
- <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
248
- <CheckCircleOutlined style={{ color: '#52c41a' }} />
249
- <span>{resp.name || `响应 ${index + 1}`}</span>
250
- </div>
251
- }
252
- >
253
- <div style={{ padding: '4px 0' }}>
254
- <div style={{
255
- display: 'flex',
256
- alignItems: 'center',
257
- justifyContent: 'space-between',
258
- marginBottom: '4px'
259
- }}>
260
- <span style={{ fontWeight: 'bold' }}>
261
- {resp.name || `响应 ${index + 1}`}
262
- </span>
263
- {resp.id === activeResponseId && (
264
- <Badge status="processing" text="当前选中" />
265
- )}
266
- </div>
267
- </div>
268
- </Option>
269
- ))}
270
- </Select>
271
- </Col>
272
-
273
- <Col span={10}>
274
- <div style={{ marginBottom: '8px' }}>
275
- <label style={{
276
- fontSize: '12px',
277
- color: '#666',
278
- fontWeight: 'bold'
279
- }}>
280
- 响应名称
281
- </label>
257
+
258
+ <div style={{ position: 'relative' }}>
259
+ {isEditing ? (
260
+ // 编辑模式:显示输入框
261
+ <Input.Group compact>
262
+ <Input
263
+ style={{ width: 'calc(100% - 80px)' }}
264
+ value={editingName}
265
+ onChange={(e) => setEditingName(e.target.value)}
266
+ onPressEnter={handleFinishEdit}
267
+ onBlur={handleFinishEdit}
268
+ placeholder="输入响应名称"
269
+ autoFocus
270
+ />
271
+ <Button
272
+ style={{ width: '40px' }}
273
+ type="primary"
274
+ icon={<CheckCircleOutlined />}
275
+ onClick={handleFinishEdit}
276
+ />
277
+ <Button
278
+ style={{ width: '40px' }}
279
+ icon={<DeleteOutlined />}
280
+ onClick={handleCancelEdit}
281
+ />
282
+ </Input.Group>
283
+ ) : (
284
+ // 选择模式:显示下拉选择器
285
+ <Input.Group compact>
286
+ <Select
287
+ style={{ width: 'calc(100% - 40px)' }}
288
+ placeholder="选择要编辑的响应"
289
+ value={activeResponseId}
290
+ onChange={handleResponseSelect}
291
+ optionLabelProp="label"
292
+ >
293
+ {responses.map((resp, index) => (
294
+ <Option
295
+ key={resp.id}
296
+ value={resp.id}
297
+ label={
298
+ <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
299
+ <CheckCircleOutlined style={{ color: '#52c41a' }} />
300
+ <span>{resp.name || `响应 ${index + 1}`}</span>
301
+ </div>
302
+ }
303
+ >
304
+ <div style={{ padding: '4px 0' }}>
305
+ <div style={{
306
+ display: 'flex',
307
+ alignItems: 'center',
308
+ justifyContent: 'space-between',
309
+ marginBottom: '4px'
310
+ }}>
311
+ <span style={{ fontWeight: 'bold' }}>
312
+ {resp.name || `响应 ${index + 1}`}
313
+ </span>
314
+ {resp.id === activeResponseId && (
315
+ <Badge status="processing" text="当前选中" />
316
+ )}
317
+ </div>
318
+ </div>
319
+ </Option>
320
+ ))}
321
+ </Select>
322
+ <Tooltip title="编辑响应名称">
323
+ <Button
324
+ style={{ width: '40px' }}
325
+ icon={<EditOutlined />}
326
+ onClick={handleStartEdit}
327
+ disabled={!activeResponse}
328
+ />
329
+ </Tooltip>
330
+ </Input.Group>
331
+ )}
282
332
  </div>
283
- <Input
284
- placeholder="响应名称"
285
- value={activeResponse?.name || ''}
286
- onChange={(e) => activeResponseId && handleNameChange(activeResponseId, e.target.value)}
287
- disabled={!activeResponse}
288
- />
289
333
  </Col>
290
334
 
291
335
  <Col span={4}>