whistle.mock-plugins 1.2.0-beta.11 → 1.2.0-beta.13

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.2.0-beta.11",
3
+ "version": "1.2.0-beta.13",
4
4
  "description": "Whistle 插件,用于快速创建 API 模拟数据",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -385,8 +385,9 @@ const InterfaceManagement = () => {
385
385
 
386
386
  const handleSubmit = async () => {
387
387
  try {
388
- // 表单验证
389
- const values = await form.validateFields();
388
+ // 表单验证 - 先验证所有字段,再获取所有字段值(包括折叠的)
389
+ await form.validateFields();
390
+ const values = form.getFieldsValue(true); // true表示获取所有字段,包括未渲染的
390
391
  console.log('表单提交数据:', values);
391
392
 
392
393
  // 处理自定义请求头
@@ -405,19 +406,19 @@ const InterfaceManagement = () => {
405
406
  groupValue = groupValue.length > 0 ? groupValue[0] : '';
406
407
  }
407
408
 
408
- // 构建接口数据
409
+ // 构建接口数据 - 在编辑模式下,确保关键字段不丢失
409
410
  const interfaceData = {
410
- name: values.name,
411
- group: groupValue || '', // 确保group不为undefined
412
- urlPattern: values.pattern,
413
- proxyType: values.proxyType,
411
+ name: values.name || (editingInterface ? editingInterface.name : ''),
412
+ group: groupValue || (editingInterface ? editingInterface.group : '') || '', // 确保group不为undefined
413
+ urlPattern: values.pattern || (editingInterface ? editingInterface.urlPattern : ''),
414
+ proxyType: values.proxyType || (editingInterface ? editingInterface.proxyType : 'response'),
414
415
  featureId: selectedFeatureId,
415
- responses: values.responses,
416
- activeResponseId: values.activeResponseId,
417
- httpStatus: parseInt(values.statusCode, 10), // 转换为数字
418
- contentType: values.contentType,
419
- responseDelay: parseInt(values.responseDelay, 10) || 0,
420
- httpMethod: values.httpMethod,
416
+ responses: values.responses || (editingInterface ? editingInterface.responses : []),
417
+ activeResponseId: values.activeResponseId || (editingInterface ? editingInterface.activeResponseId : null),
418
+ httpStatus: parseInt(values.statusCode, 10) || (editingInterface ? editingInterface.httpStatus : 200), // 转换为数字
419
+ contentType: values.contentType || (editingInterface ? editingInterface.contentType : 'application/json; charset=utf-8'),
420
+ responseDelay: parseInt(values.responseDelay, 10) || (editingInterface ? editingInterface.responseDelay : 0) || 0,
421
+ httpMethod: values.httpMethod || (editingInterface ? editingInterface.httpMethod : 'ALL'),
421
422
  active: true
422
423
  };
423
424
 
@@ -391,8 +391,9 @@ const InterfaceManagement = () => {
391
391
 
392
392
  const handleSubmit = async () => {
393
393
  try {
394
- // 表单验证
395
- const values = await form.validateFields();
394
+ // 表单验证 - 先验证所有字段,再获取所有字段值(包括折叠的)
395
+ await form.validateFields();
396
+ const values = form.getFieldsValue(true); // true表示获取所有字段,包括未渲染的
396
397
  console.log('表单提交数据:', values);
397
398
 
398
399
  // 处理自定义请求头
@@ -411,19 +412,19 @@ const InterfaceManagement = () => {
411
412
  groupValue = groupValue.length > 0 ? groupValue[0] : '';
412
413
  }
413
414
 
414
- // 构建接口数据
415
+ // 构建接口数据 - 在编辑模式下,确保关键字段不丢失
415
416
  const interfaceData = {
416
- name: values.name,
417
- group: groupValue || '', // 确保group不为undefined
418
- urlPattern: values.pattern,
419
- proxyType: values.proxyType,
417
+ name: values.name || (editingInterface ? editingInterface.name : ''),
418
+ group: groupValue || (editingInterface ? editingInterface.group : '') || '', // 确保group不为undefined
419
+ urlPattern: values.pattern || (editingInterface ? editingInterface.urlPattern : ''),
420
+ proxyType: values.proxyType || (editingInterface ? editingInterface.proxyType : 'response'),
420
421
  featureId: selectedFeatureId,
421
- responses: values.responses,
422
- activeResponseId: values.activeResponseId,
423
- httpStatus: parseInt(values.statusCode, 10), // 转换为数字
424
- contentType: values.contentType,
425
- responseDelay: parseInt(values.responseDelay, 10) || 0,
426
- httpMethod: values.httpMethod,
422
+ responses: values.responses || (editingInterface ? editingInterface.responses : []),
423
+ activeResponseId: values.activeResponseId || (editingInterface ? editingInterface.activeResponseId : null),
424
+ httpStatus: parseInt(values.statusCode, 10) || (editingInterface ? editingInterface.httpStatus : 200), // 转换为数字
425
+ contentType: values.contentType || (editingInterface ? editingInterface.contentType : 'application/json; charset=utf-8'),
426
+ responseDelay: parseInt(values.responseDelay, 10) || (editingInterface ? editingInterface.responseDelay : 0) || 0,
427
+ httpMethod: values.httpMethod || (editingInterface ? editingInterface.httpMethod : 'ALL'),
427
428
  active: true
428
429
  };
429
430
 
@@ -1318,7 +1319,11 @@ const InterfaceManagement = () => {
1318
1319
  }}
1319
1320
  >
1320
1321
  <Collapse
1321
- defaultActiveKey={['1', '2', '3']}
1322
+ defaultActiveKey={
1323
+ editingInterface && editingInterface.proxyType === 'response'
1324
+ ? ['3'] // mock代理场景:只展开第3步(高级配置)
1325
+ : ['1', '2', '3'] // 其他场景:展开所有步骤
1326
+ }
1322
1327
  style={{ marginBottom: '16px' }}
1323
1328
  ghost
1324
1329
  >