whistle.mock-plugins 1.0.6-beta.12 → 1.0.6-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/app/cgi-bin/interfaces.js +35 -0
- package/app/public/js/index.js +1 -1
- package/lib/routes/interfaces.js +165 -70
- package/package.json +1 -1
- package/ui/src/pages/InterfaceManagement.js +80 -33
package/lib/routes/interfaces.js
CHANGED
|
@@ -20,60 +20,55 @@ const processInterfaceData = (data) => {
|
|
|
20
20
|
const result = { ...data };
|
|
21
21
|
|
|
22
22
|
// 调试日志
|
|
23
|
-
console.log('
|
|
23
|
+
console.log('=== 开始处理接口数据 ===');
|
|
24
|
+
console.log('原始数据:', JSON.stringify({
|
|
25
|
+
name: result.name,
|
|
24
26
|
hasResponses: !!result.responses,
|
|
27
|
+
responsesType: typeof result.responses,
|
|
25
28
|
responsesLength: result.responses ? result.responses.length : 0,
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
responses: result.responses,
|
|
30
|
+
responseContent: !!result.responseContent,
|
|
31
|
+
activeResponseId: result.activeResponseId
|
|
32
|
+
}, null, 2));
|
|
28
33
|
|
|
29
|
-
//
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
34
|
+
// 处理 responses 数组
|
|
35
|
+
if (result.responses && Array.isArray(result.responses) && result.responses.length > 0) {
|
|
36
|
+
console.log('发现 responses 数组,直接处理多响应数据');
|
|
37
|
+
|
|
38
|
+
// 确保每个响应都有合法的 id, name 和 content
|
|
39
|
+
result.responses = result.responses.map((resp, index) => {
|
|
40
|
+
console.log(`处理响应 ${index}:`, resp);
|
|
41
|
+
|
|
42
|
+
if (!resp.id) {
|
|
43
|
+
resp.id = Math.random().toString(36).substring(2, 15);
|
|
44
|
+
console.log(`为响应 ${index} 添加 ID:`, resp.id);
|
|
45
|
+
}
|
|
46
|
+
if (!resp.name) {
|
|
47
|
+
resp.name = `响应 ${index + 1}`;
|
|
48
|
+
console.log(`为响应 ${index} 添加默认名称:`, resp.name);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const processedResp = {
|
|
52
|
+
id: resp.id,
|
|
53
|
+
name: resp.name,
|
|
54
|
+
description: resp.description || '',
|
|
55
|
+
content: resp.content || '{}'
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
console.log(`处理后的响应 ${index}:`, processedResp);
|
|
59
|
+
return processedResp;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
console.log('处理后的响应数组长度:', result.responses.length);
|
|
63
|
+
console.log('所有处理后的响应:', result.responses);
|
|
64
|
+
|
|
65
|
+
// 如果有响应但没有设置 activeResponseId,默认使用第一个
|
|
66
|
+
if (!result.activeResponseId) {
|
|
67
|
+
result.activeResponseId = result.responses[0].id;
|
|
68
|
+
console.log('设置默认激活响应:', result.activeResponseId);
|
|
60
69
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
name: resp.name,
|
|
64
|
-
description: resp.description || '',
|
|
65
|
-
content: resp.content || '{}'
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// 如果有响应但没有设置 activeResponseId,默认使用第一个
|
|
70
|
-
if (result.responses.length > 0 && !result.activeResponseId) {
|
|
71
|
-
result.activeResponseId = result.responses[0].id;
|
|
72
|
-
console.log('设置默认激活响应:', result.activeResponseId);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 确保 responseContent 字段始终存在(向后兼容)
|
|
76
|
-
if (result.responses.length > 0) {
|
|
70
|
+
|
|
71
|
+
// 确保 responseContent 字段始终存在(向后兼容)
|
|
77
72
|
const activeResponse = result.activeResponseId
|
|
78
73
|
? result.responses.find(r => r.id === result.activeResponseId)
|
|
79
74
|
: result.responses[0];
|
|
@@ -82,14 +77,43 @@ const processInterfaceData = (data) => {
|
|
|
82
77
|
result.responseContent = activeResponse.content;
|
|
83
78
|
console.log('设置 responseContent 为当前激活响应内容');
|
|
84
79
|
}
|
|
80
|
+
|
|
81
|
+
} else if (result.responseContent) {
|
|
82
|
+
// 如果没有提供 responses 但有 responseContent,创建默认响应(向后兼容)
|
|
83
|
+
console.log('创建默认响应,因为没有 responses 数组但有 responseContent');
|
|
84
|
+
result.responses = [{
|
|
85
|
+
id: Math.random().toString(36).substring(2, 15),
|
|
86
|
+
name: '默认响应',
|
|
87
|
+
description: '',
|
|
88
|
+
content: result.responseContent
|
|
89
|
+
}];
|
|
90
|
+
result.activeResponseId = result.responses[0].id;
|
|
91
|
+
console.log('创建的默认响应:', result.responses[0]);
|
|
92
|
+
|
|
93
|
+
} else {
|
|
94
|
+
// 如果既没有 responses 也没有 responseContent,创建一个空的默认响应
|
|
95
|
+
console.log('创建空的默认响应');
|
|
96
|
+
result.responses = [{
|
|
97
|
+
id: Math.random().toString(36).substring(2, 15),
|
|
98
|
+
name: '默认响应',
|
|
99
|
+
description: '',
|
|
100
|
+
content: '{}'
|
|
101
|
+
}];
|
|
102
|
+
result.activeResponseId = result.responses[0].id;
|
|
103
|
+
result.responseContent = '{}';
|
|
104
|
+
console.log('创建的空默认响应:', result.responses[0]);
|
|
85
105
|
}
|
|
86
106
|
|
|
87
107
|
// 最终日志
|
|
88
|
-
console.log('
|
|
108
|
+
console.log('=== 处理后的最终接口数据 ===');
|
|
109
|
+
console.log('最终数据:', JSON.stringify({
|
|
110
|
+
name: result.name,
|
|
89
111
|
responsesLength: result.responses.length,
|
|
112
|
+
responses: result.responses,
|
|
90
113
|
activeResponseId: result.activeResponseId,
|
|
91
114
|
hasResponseContent: !!result.responseContent
|
|
92
|
-
}));
|
|
115
|
+
}, null, 2));
|
|
116
|
+
console.log('=== 接口数据处理完成 ===\n');
|
|
93
117
|
|
|
94
118
|
return result;
|
|
95
119
|
};
|
|
@@ -104,33 +128,69 @@ const initRouter = () => {
|
|
|
104
128
|
// 获取所有接口
|
|
105
129
|
router.get('/interfaces', (req, res) => {
|
|
106
130
|
try {
|
|
131
|
+
const { featureId } = req.query;
|
|
132
|
+
|
|
107
133
|
// 读取所有功能
|
|
108
134
|
const featuresFile = path.join(DATA_DIR, 'features.json');
|
|
109
135
|
if (!fs.existsSync(featuresFile)) {
|
|
110
|
-
return res.json([]);
|
|
136
|
+
return res.json({ code: 0, data: [] });
|
|
111
137
|
}
|
|
112
138
|
|
|
113
139
|
const features = fs.readJsonSync(featuresFile);
|
|
114
140
|
let allInterfaces = [];
|
|
115
141
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const interfacesFile = path.join(DATA_DIR, `interfaces-${
|
|
142
|
+
if (featureId) {
|
|
143
|
+
// 获取特定功能的接口
|
|
144
|
+
const interfacesFile = path.join(DATA_DIR, `interfaces-${featureId}.json`);
|
|
119
145
|
if (fs.existsSync(interfacesFile)) {
|
|
120
146
|
const interfaces = fs.readJsonSync(interfacesFile);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
147
|
+
console.log('=== 获取接口:从文件读取的原始数据 ===');
|
|
148
|
+
console.log(`文件路径: ${interfacesFile}`);
|
|
149
|
+
console.log('原始接口数据:', JSON.stringify(interfaces, null, 2));
|
|
150
|
+
|
|
151
|
+
const processedInterfaces = interfaces.map((item, index) => {
|
|
152
|
+
console.log(`=== 处理接口 ${index}: ${item.name} ===`);
|
|
153
|
+
console.log('处理前的接口数据:', JSON.stringify(item, null, 2));
|
|
154
|
+
|
|
155
|
+
// 确保每个接口都经过数据处理
|
|
156
|
+
const processed = processInterfaceData(item);
|
|
157
|
+
console.log('处理后的接口数据:', JSON.stringify(processed, null, 2));
|
|
158
|
+
|
|
159
|
+
const feature = features.find(f => f.id === featureId);
|
|
160
|
+
const result = {
|
|
161
|
+
...processed,
|
|
162
|
+
featureName: feature ? feature.name : '未知功能'
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
console.log('最终接口数据:', JSON.stringify(result, null, 2));
|
|
166
|
+
return result;
|
|
167
|
+
});
|
|
168
|
+
allInterfaces = processedInterfaces;
|
|
127
169
|
}
|
|
128
|
-
}
|
|
170
|
+
} else {
|
|
171
|
+
// 读取每个功能的接口
|
|
172
|
+
features.forEach(feature => {
|
|
173
|
+
const interfacesFile = path.join(DATA_DIR, `interfaces-${feature.id}.json`);
|
|
174
|
+
if (fs.existsSync(interfacesFile)) {
|
|
175
|
+
const interfaces = fs.readJsonSync(interfacesFile);
|
|
176
|
+
// 确保每个接口都经过数据处理
|
|
177
|
+
const processedInterfaces = interfaces.map(item => {
|
|
178
|
+
const processed = processInterfaceData(item);
|
|
179
|
+
return {
|
|
180
|
+
...processed,
|
|
181
|
+
featureName: feature.name
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
allInterfaces = allInterfaces.concat(processedInterfaces);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
129
188
|
|
|
130
|
-
|
|
189
|
+
console.log(`获取接口列表成功,共 ${allInterfaces.length} 个接口`);
|
|
190
|
+
res.json({ code: 0, data: allInterfaces });
|
|
131
191
|
} catch (err) {
|
|
132
192
|
console.error('获取接口列表失败:', err);
|
|
133
|
-
res.status(500).json({
|
|
193
|
+
res.status(500).json({ code: 1, message: '获取接口列表失败: ' + err.message });
|
|
134
194
|
}
|
|
135
195
|
});
|
|
136
196
|
|
|
@@ -140,7 +200,7 @@ const initRouter = () => {
|
|
|
140
200
|
// 读取所有功能
|
|
141
201
|
const featuresFile = path.join(DATA_DIR, 'features.json');
|
|
142
202
|
if (!fs.existsSync(featuresFile)) {
|
|
143
|
-
return res.status(404).json({
|
|
203
|
+
return res.status(404).json({ code: 1, message: '接口不存在' });
|
|
144
204
|
}
|
|
145
205
|
|
|
146
206
|
const features = fs.readJsonSync(featuresFile);
|
|
@@ -153,8 +213,10 @@ const initRouter = () => {
|
|
|
153
213
|
const interfaces = fs.readJsonSync(interfacesFile);
|
|
154
214
|
const found = interfaces.find(item => item.id === req.params.id);
|
|
155
215
|
if (found) {
|
|
216
|
+
// 确保数据经过处理
|
|
217
|
+
const processed = processInterfaceData(found);
|
|
156
218
|
foundInterface = {
|
|
157
|
-
...
|
|
219
|
+
...processed,
|
|
158
220
|
featureName: feature.name
|
|
159
221
|
};
|
|
160
222
|
break;
|
|
@@ -163,13 +225,14 @@ const initRouter = () => {
|
|
|
163
225
|
}
|
|
164
226
|
|
|
165
227
|
if (!foundInterface) {
|
|
166
|
-
return res.status(404).json({
|
|
228
|
+
return res.status(404).json({ code: 1, message: '接口不存在' });
|
|
167
229
|
}
|
|
168
230
|
|
|
169
|
-
|
|
231
|
+
console.log(`获取接口详情成功: ${foundInterface.name},响应数量: ${foundInterface.responses ? foundInterface.responses.length : 0}`);
|
|
232
|
+
res.json({ code: 0, data: foundInterface });
|
|
170
233
|
} catch (err) {
|
|
171
234
|
console.error('获取接口详情失败:', err);
|
|
172
|
-
res.status(500).json({
|
|
235
|
+
res.status(500).json({ code: 1, message: '获取接口详情失败: ' + err.message });
|
|
173
236
|
}
|
|
174
237
|
});
|
|
175
238
|
|
|
@@ -210,7 +273,10 @@ const initRouter = () => {
|
|
|
210
273
|
: [];
|
|
211
274
|
|
|
212
275
|
// 处理接口数据,确保兼容多响应格式
|
|
276
|
+
console.log('=== 创建接口:开始处理数据 ===');
|
|
277
|
+
console.log('接收到的接口数据:', JSON.stringify(interfaceData, null, 2));
|
|
213
278
|
const processedData = processInterfaceData(interfaceData);
|
|
279
|
+
console.log('处理后的接口数据:', JSON.stringify(processedData, null, 2));
|
|
214
280
|
|
|
215
281
|
// 创建新接口
|
|
216
282
|
const newInterface = {
|
|
@@ -220,10 +286,20 @@ const initRouter = () => {
|
|
|
220
286
|
updatedAt: new Date().toISOString()
|
|
221
287
|
};
|
|
222
288
|
|
|
289
|
+
console.log('=== 创建接口:准备保存的完整接口数据 ===');
|
|
290
|
+
console.log('完整的新接口数据:', JSON.stringify(newInterface, null, 2));
|
|
291
|
+
|
|
223
292
|
interfaces.push(newInterface);
|
|
224
293
|
|
|
225
294
|
// 保存接口列表
|
|
226
295
|
fs.writeJsonSync(interfacesFile, interfaces, { spaces: 2 });
|
|
296
|
+
console.log('接口数据已保存到文件:', interfacesFile);
|
|
297
|
+
|
|
298
|
+
// 验证保存后从文件读取的数据
|
|
299
|
+
const savedInterfaces = fs.readJsonSync(interfacesFile);
|
|
300
|
+
const savedInterface = savedInterfaces.find(item => item.id === newInterface.id);
|
|
301
|
+
console.log('=== 创建接口:验证保存后的数据 ===');
|
|
302
|
+
console.log('从文件读取的保存后数据:', JSON.stringify(savedInterface, null, 2));
|
|
227
303
|
|
|
228
304
|
// 更新功能模块的接口数量
|
|
229
305
|
const featureIndex = features.findIndex(f => f.id === interfaceData.featureId);
|
|
@@ -231,6 +307,9 @@ const initRouter = () => {
|
|
|
231
307
|
features[featureIndex].updatedAt = new Date().toISOString();
|
|
232
308
|
fs.writeJsonSync(featuresFile, features, { spaces: 2 });
|
|
233
309
|
|
|
310
|
+
console.log('=== 创建接口:准备返回的数据 ===');
|
|
311
|
+
console.log('返回给前端的数据:', JSON.stringify(newInterface, null, 2));
|
|
312
|
+
|
|
234
313
|
res.json({
|
|
235
314
|
code: 0,
|
|
236
315
|
message: '接口创建成功',
|
|
@@ -303,7 +382,10 @@ const initRouter = () => {
|
|
|
303
382
|
}
|
|
304
383
|
|
|
305
384
|
// 处理接口数据,确保兼容多响应格式
|
|
385
|
+
console.log('=== 更新接口:开始处理数据 ===');
|
|
386
|
+
console.log('接收到的接口数据:', JSON.stringify(interfaceData, null, 2));
|
|
306
387
|
const processedData = processInterfaceData(interfaceData);
|
|
388
|
+
console.log('处理后的接口数据:', JSON.stringify(processedData, null, 2));
|
|
307
389
|
|
|
308
390
|
// 更新接口
|
|
309
391
|
const updatedInterface = {
|
|
@@ -312,10 +394,23 @@ const initRouter = () => {
|
|
|
312
394
|
updatedAt: new Date().toISOString()
|
|
313
395
|
};
|
|
314
396
|
|
|
397
|
+
console.log('=== 更新接口:准备保存的完整接口数据 ===');
|
|
398
|
+
console.log('完整的更新接口数据:', JSON.stringify(updatedInterface, null, 2));
|
|
399
|
+
|
|
315
400
|
interfaces[index] = updatedInterface;
|
|
316
401
|
|
|
317
402
|
// 保存接口列表
|
|
318
403
|
fs.writeJsonSync(interfacesFile, interfaces, { spaces: 2 });
|
|
404
|
+
console.log('接口数据已保存到文件:', interfacesFile);
|
|
405
|
+
|
|
406
|
+
// 验证保存后从文件读取的数据
|
|
407
|
+
const savedInterfaces = fs.readJsonSync(interfacesFile);
|
|
408
|
+
const savedInterface = savedInterfaces.find(item => item.id === id);
|
|
409
|
+
console.log('=== 更新接口:验证保存后的数据 ===');
|
|
410
|
+
console.log('从文件读取的保存后数据:', JSON.stringify(savedInterface, null, 2));
|
|
411
|
+
|
|
412
|
+
console.log('=== 更新接口:准备返回的数据 ===');
|
|
413
|
+
console.log('返回给前端的数据:', JSON.stringify(updatedInterface, null, 2));
|
|
319
414
|
|
|
320
415
|
res.json({
|
|
321
416
|
code: 0,
|
package/package.json
CHANGED
|
@@ -112,9 +112,38 @@ const InterfaceManagement = () => {
|
|
|
112
112
|
try {
|
|
113
113
|
setInterfacesLoading(true);
|
|
114
114
|
const response = await axios.get(`/cgi-bin/interfaces?featureId=${selectedFeatureId}`);
|
|
115
|
+
|
|
116
|
+
console.log('获取接口列表响应:', response.data);
|
|
117
|
+
|
|
115
118
|
if (response.data && response.data.code === 0 && Array.isArray(response.data.data)) {
|
|
116
|
-
|
|
119
|
+
// 确保每个接口的响应数据格式正确
|
|
120
|
+
const processedInterfaces = response.data.data.map(item => {
|
|
121
|
+
console.log(`处理接口 ${item.name}:`, {
|
|
122
|
+
hasResponses: !!item.responses,
|
|
123
|
+
responsesLength: item.responses ? item.responses.length : 0,
|
|
124
|
+
activeResponseId: item.activeResponseId
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// 确保 responses 是数组
|
|
128
|
+
if (!Array.isArray(item.responses)) {
|
|
129
|
+
item.responses = [];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 确保每个响应都有必要的字段
|
|
133
|
+
item.responses = item.responses.map((resp, index) => ({
|
|
134
|
+
id: resp.id || `resp-${index}-${Date.now()}`,
|
|
135
|
+
name: resp.name || `响应 ${index + 1}`,
|
|
136
|
+
description: resp.description || '',
|
|
137
|
+
content: resp.content || '{}'
|
|
138
|
+
}));
|
|
139
|
+
|
|
140
|
+
return item;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
setInterfaces(processedInterfaces);
|
|
144
|
+
console.log('处理后的接口列表:', processedInterfaces);
|
|
117
145
|
} else {
|
|
146
|
+
console.warn('接口数据格式不正确:', response.data);
|
|
118
147
|
setInterfaces([]);
|
|
119
148
|
message.warning('获取接口配置数据格式不正确');
|
|
120
149
|
}
|
|
@@ -304,14 +333,20 @@ const InterfaceManagement = () => {
|
|
|
304
333
|
const handleSubmit = async () => {
|
|
305
334
|
try {
|
|
306
335
|
const values = await form.validateFields();
|
|
307
|
-
console.log('
|
|
336
|
+
console.log('=== 开始表单提交 ===');
|
|
337
|
+
console.log('表单提交,原始值:', JSON.stringify(values, null, 2));
|
|
308
338
|
|
|
309
339
|
// 获取当前激活的响应ID和所有响应
|
|
310
340
|
const activeResponseId = values.activeResponseId;
|
|
311
341
|
let responses = values.responses || [];
|
|
312
342
|
|
|
343
|
+
console.log('提取的原始响应数据:', responses);
|
|
344
|
+
console.log('响应数据类型:', typeof responses);
|
|
345
|
+
console.log('是否为数组:', Array.isArray(responses));
|
|
346
|
+
|
|
313
347
|
// 确保responses是数组格式
|
|
314
348
|
if (!Array.isArray(responses)) {
|
|
349
|
+
console.log('响应数据不是数组,尝试解析...');
|
|
315
350
|
try {
|
|
316
351
|
if (typeof responses === 'string') {
|
|
317
352
|
responses = JSON.parse(responses);
|
|
@@ -327,18 +362,24 @@ const InterfaceManagement = () => {
|
|
|
327
362
|
}
|
|
328
363
|
}
|
|
329
364
|
|
|
330
|
-
console.log('处理前的响应数据:', responses);
|
|
365
|
+
console.log('处理前的响应数据:', JSON.stringify(responses, null, 2));
|
|
331
366
|
|
|
332
367
|
// 确保每个响应都有名称、描述和内容
|
|
333
|
-
const cleanedResponses = responses.map((resp, index) =>
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
368
|
+
const cleanedResponses = responses.map((resp, index) => {
|
|
369
|
+
console.log(`处理响应 ${index}:`, resp);
|
|
370
|
+
const cleaned = {
|
|
371
|
+
id: resp.id || uuidv4(),
|
|
372
|
+
name: resp.name || `响应 ${index + 1}`,
|
|
373
|
+
description: resp.description || '',
|
|
374
|
+
content: resp.content || '{}'
|
|
375
|
+
};
|
|
376
|
+
console.log(`处理后的响应 ${index}:`, cleaned);
|
|
377
|
+
return cleaned;
|
|
378
|
+
});
|
|
339
379
|
|
|
340
380
|
// 如果没有响应,创建一个默认响应
|
|
341
381
|
if (cleanedResponses.length === 0) {
|
|
382
|
+
console.log('没有响应数据,创建默认响应');
|
|
342
383
|
const defaultId = uuidv4();
|
|
343
384
|
cleanedResponses.push({
|
|
344
385
|
id: defaultId,
|
|
@@ -357,8 +398,10 @@ const InterfaceManagement = () => {
|
|
|
357
398
|
// 获取激活的响应
|
|
358
399
|
const activeResponse = cleanedResponses.find(r => r.id === validActiveResponseId) || cleanedResponses[0];
|
|
359
400
|
|
|
360
|
-
console.log('
|
|
401
|
+
console.log('=== 清理后的响应数据 ===');
|
|
402
|
+
console.log('清理后的响应数据:', JSON.stringify(cleanedResponses, null, 2));
|
|
361
403
|
console.log('激活的响应ID:', validActiveResponseId);
|
|
404
|
+
console.log('激活的响应:', activeResponse);
|
|
362
405
|
|
|
363
406
|
// 检查responseBody是否是有效的JSON
|
|
364
407
|
if (values.proxyType === 'response' && values.contentType.includes('application/json')) {
|
|
@@ -406,18 +449,24 @@ const InterfaceManagement = () => {
|
|
|
406
449
|
active: true
|
|
407
450
|
};
|
|
408
451
|
|
|
409
|
-
console.log('
|
|
452
|
+
console.log('=== 最终提交的接口数据 ===');
|
|
453
|
+
console.log('提交的接口数据:', JSON.stringify(interfaceData, null, 2));
|
|
410
454
|
|
|
411
455
|
let response;
|
|
412
456
|
if (editingInterface) {
|
|
413
457
|
// 更新现有接口
|
|
458
|
+
console.log('执行接口更新,ID:', editingInterface.id);
|
|
414
459
|
response = await axios.put(`/cgi-bin/interfaces?id=${editingInterface.id}`, interfaceData);
|
|
415
460
|
} else {
|
|
416
461
|
// 创建新接口
|
|
462
|
+
console.log('执行接口创建');
|
|
417
463
|
response = await axios.post('/cgi-bin/interfaces', interfaceData);
|
|
418
464
|
}
|
|
419
465
|
|
|
466
|
+
console.log('服务器响应:', response.data);
|
|
467
|
+
|
|
420
468
|
if (response.data && response.data.code === 0) {
|
|
469
|
+
console.log('=== 接口操作成功 ===');
|
|
421
470
|
message.success(editingInterface ? '接口更新成功' : '接口创建成功');
|
|
422
471
|
setModalVisible(false);
|
|
423
472
|
fetchInterfaces();
|
|
@@ -432,6 +481,7 @@ const InterfaceManagement = () => {
|
|
|
432
481
|
// 已经显示了错误信息,不需要再显示
|
|
433
482
|
return;
|
|
434
483
|
}
|
|
484
|
+
console.error('=== 接口操作失败 ===');
|
|
435
485
|
console.error('操作失败:', error);
|
|
436
486
|
message.error(error.response?.data?.message || error.message || '操作失败');
|
|
437
487
|
}
|
|
@@ -1155,7 +1205,7 @@ const InterfaceManagement = () => {
|
|
|
1155
1205
|
|
|
1156
1206
|
{/* 根据proxyType显示不同的表单项 */}
|
|
1157
1207
|
<Form.Item noStyle shouldUpdate={(prevValues, currentValues) => prevValues.proxyType !== currentValues.proxyType}>
|
|
1158
|
-
{({ getFieldValue }) => {
|
|
1208
|
+
{({ getFieldValue, setFieldsValue }) => {
|
|
1159
1209
|
const proxyType = getFieldValue('proxyType');
|
|
1160
1210
|
|
|
1161
1211
|
if (proxyType === 'response') {
|
|
@@ -1240,11 +1290,6 @@ const InterfaceManagement = () => {
|
|
|
1240
1290
|
|
|
1241
1291
|
const activeResponseId = getFieldValue('activeResponseId');
|
|
1242
1292
|
|
|
1243
|
-
// 同步更新响应内容到form.responses字段
|
|
1244
|
-
const updateResponses = (newResponses) => {
|
|
1245
|
-
setFieldsValue({ responses: newResponses });
|
|
1246
|
-
};
|
|
1247
|
-
|
|
1248
1293
|
return (
|
|
1249
1294
|
<List
|
|
1250
1295
|
size="small"
|
|
@@ -1288,14 +1333,15 @@ const InterfaceManagement = () => {
|
|
|
1288
1333
|
placeholder="响应名称"
|
|
1289
1334
|
value={item.name || `响应 ${index + 1}`}
|
|
1290
1335
|
onChange={(e) => {
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
name: e.target.value
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1336
|
+
console.log(`更新响应 ${item.id} 的名称:`, e.target.value);
|
|
1337
|
+
const currentResponses = getFieldValue('responses') || [];
|
|
1338
|
+
const newResponses = currentResponses.map(resp =>
|
|
1339
|
+
resp.id === item.id
|
|
1340
|
+
? { ...resp, name: e.target.value }
|
|
1341
|
+
: resp
|
|
1342
|
+
);
|
|
1343
|
+
console.log('新的响应列表:', newResponses);
|
|
1344
|
+
setFieldsValue({ responses: newResponses });
|
|
1299
1345
|
}}
|
|
1300
1346
|
style={{ width: '100%' }}
|
|
1301
1347
|
/>
|
|
@@ -1304,14 +1350,15 @@ const InterfaceManagement = () => {
|
|
|
1304
1350
|
placeholder="响应描述(可选)"
|
|
1305
1351
|
value={item.description || ''}
|
|
1306
1352
|
onChange={(e) => {
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
description: e.target.value
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1353
|
+
console.log(`更新响应 ${item.id} 的描述:`, e.target.value);
|
|
1354
|
+
const currentResponses = getFieldValue('responses') || [];
|
|
1355
|
+
const newResponses = currentResponses.map(resp =>
|
|
1356
|
+
resp.id === item.id
|
|
1357
|
+
? { ...resp, description: e.target.value }
|
|
1358
|
+
: resp
|
|
1359
|
+
);
|
|
1360
|
+
console.log('新的响应列表:', newResponses);
|
|
1361
|
+
setFieldsValue({ responses: newResponses });
|
|
1315
1362
|
}}
|
|
1316
1363
|
style={{ marginBottom: 8 }}
|
|
1317
1364
|
rows={2}
|