whistle.mock-plugins 1.2.2-beta.2 → 1.2.2-beta.23

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.
@@ -221,7 +221,7 @@ const MockData = () => {
221
221
  };
222
222
 
223
223
  const viewInterfaces = (feature) => {
224
- // 导航到该功能的接口列表页面
224
+ localStorage.setItem('selectedFeatureId', feature.id);
225
225
  history.push(`/interface/${feature.id}`);
226
226
  };
227
227
 
@@ -1,11 +1,123 @@
1
- import React from 'react';
1
+ import React, { useState, useEffect } from 'react';
2
2
  import AppLayout from '../components/AppLayout';
3
- import { Card, Typography, Empty } from 'antd';
3
+ import { Card, Typography, Switch, Space, Modal, Button } from 'antd';
4
+ import { QuestionCircleOutlined } from '@ant-design/icons';
5
+ import axios from 'axios';
4
6
  import '../styles/settings.css';
5
7
 
6
- const { Title, Text, Paragraph } = Typography;
8
+ const { Text } = Typography;
9
+
10
+ const syncSettingsToBackend = (patch) => {
11
+ axios.put('/cgi-bin/settings', patch).catch(() => {});
12
+ };
7
13
 
8
14
  const Settings = () => {
15
+ const [displayMode, setDisplayMode] = useState('modal');
16
+ const [interfaceFormDisplayMode, setInterfaceFormDisplayMode] = useState('modal');
17
+ const [interfaceParamMatcherEnabled, setInterfaceParamMatcherEnabled] = useState(true);
18
+ const [responseParamMatcherEnabled, setResponseParamMatcherEnabled] = useState(true);
19
+
20
+ useEffect(() => {
21
+ const savedMode = localStorage.getItem('dataManagementDisplayMode');
22
+ if (savedMode) setDisplayMode(savedMode);
23
+
24
+ const savedInterfaceFormMode = localStorage.getItem('interfaceFormDisplayMode');
25
+ if (savedInterfaceFormMode) setInterfaceFormDisplayMode(savedInterfaceFormMode);
26
+
27
+ // 优先从后端读取入参匹配开关,保持前后端一致
28
+ axios.get('/cgi-bin/settings').then(({ data }) => {
29
+ const ipm = data.interfaceParamMatcherEnabled !== false;
30
+ const rpm = data.responseParamMatcherEnabled !== false;
31
+ setInterfaceParamMatcherEnabled(ipm);
32
+ setResponseParamMatcherEnabled(rpm);
33
+ localStorage.setItem('interfaceParamMatcherEnabled', String(ipm));
34
+ localStorage.setItem('responseParamMatcherEnabled', String(rpm));
35
+ window.dispatchEvent(new Event('storage'));
36
+ }).catch(() => {
37
+ const savedInterfaceParamMatcher = localStorage.getItem('interfaceParamMatcherEnabled');
38
+ if (savedInterfaceParamMatcher !== null) setInterfaceParamMatcherEnabled(savedInterfaceParamMatcher !== 'false');
39
+ const savedResponseParamMatcher = localStorage.getItem('responseParamMatcherEnabled');
40
+ if (savedResponseParamMatcher !== null) setResponseParamMatcherEnabled(savedResponseParamMatcher !== 'false');
41
+ });
42
+ }, []);
43
+
44
+ const handleDisplayModeChange = (checked) => {
45
+ const newMode = checked ? 'drawer' : 'modal';
46
+ setDisplayMode(newMode);
47
+ localStorage.setItem('dataManagementDisplayMode', newMode);
48
+ window.dispatchEvent(new Event('storage'));
49
+ };
50
+
51
+ const handleInterfaceFormDisplayModeChange = (checked) => {
52
+ const newMode = checked ? 'drawer' : 'modal';
53
+ setInterfaceFormDisplayMode(newMode);
54
+ localStorage.setItem('interfaceFormDisplayMode', newMode);
55
+ window.dispatchEvent(new Event('storage'));
56
+ };
57
+
58
+ const handleInterfaceParamMatcherChange = (checked) => {
59
+ setInterfaceParamMatcherEnabled(checked);
60
+ localStorage.setItem('interfaceParamMatcherEnabled', String(checked));
61
+ syncSettingsToBackend({ interfaceParamMatcherEnabled: checked });
62
+ window.dispatchEvent(new Event('storage'));
63
+ };
64
+
65
+ const handleResponseParamMatcherChange = (checked) => {
66
+ setResponseParamMatcherEnabled(checked);
67
+ localStorage.setItem('responseParamMatcherEnabled', String(checked));
68
+ syncSettingsToBackend({ responseParamMatcherEnabled: checked });
69
+ window.dispatchEvent(new Event('storage'));
70
+ };
71
+
72
+ const showMatcherRuleModal = (type) => {
73
+ if (type === 'interface') {
74
+ Modal.info({
75
+ title: '接口入参匹配规则说明',
76
+ width: 560,
77
+ content: (
78
+ <div>
79
+ <p>用于区分同一 URL 下的不同接口定义(接口级匹配)。</p>
80
+ <p>执行顺序与优先级:</p>
81
+ <ul>
82
+ <li>先进行 URL 匹配,命中多个接口时,按接口匹配条件顺序查找第一条命中规则。</li>
83
+ <li>若命中规则且配置了目标响应,则直接返回该响应(最高优先级)。</li>
84
+ <li>若命中规则但未配置目标响应,则进入“响应入参匹配”阶段继续判断。</li>
85
+ <li>若本开关关闭,则跳过接口级匹配,直接走“响应入参匹配”(若开启)。</li>
86
+ </ul>
87
+ <p>兜底逻辑:</p>
88
+ <ul>
89
+ <li>若最终没有任何入参规则命中,系统返回默认响应。</li>
90
+ <li>支持嵌套参数路径,例如:data.user.id。</li>
91
+ </ul>
92
+ </div>
93
+ )
94
+ });
95
+ return;
96
+ }
97
+
98
+ Modal.info({
99
+ title: '响应入参匹配规则说明',
100
+ width: 560,
101
+ content: (
102
+ <div>
103
+ <p>用于在同一接口内,根据请求参数选择具体响应(响应级匹配)。</p>
104
+ <p>执行顺序与优先级:</p>
105
+ <ul>
106
+ <li>仅在“接口入参匹配”未直接确定目标响应时才会执行。</li>
107
+ <li>按响应配置顺序匹配,命中第一条规则即返回对应响应。</li>
108
+ <li>支持精确匹配、包含匹配、正则匹配。</li>
109
+ <li>若本开关关闭,则跳过响应级匹配,直接使用默认响应。</li>
110
+ </ul>
111
+ <p>兜底逻辑:</p>
112
+ <ul>
113
+ <li>开启但未命中任一规则时,使用默认响应。</li>
114
+ <li>与接口级都关闭时,请求将直接返回默认响应。</li>
115
+ </ul>
116
+ </div>
117
+ )
118
+ });
119
+ };
120
+
9
121
  return (
10
122
  <AppLayout>
11
123
  <div className="page-container">
@@ -19,14 +131,107 @@ const Settings = () => {
19
131
  </div>
20
132
 
21
133
  <Card title="界面设置" className="settings-card">
22
- <Empty
23
- description="暂无可配置项"
24
- style={{ padding: '40px 0' }}
25
- />
134
+ <div className="settings-item">
135
+ <div className="settings-item-header">
136
+ <div>
137
+ <div className="settings-item-title">数据管理交互</div>
138
+ <div className="settings-item-description">
139
+ 选择数据管理的显示方式
140
+ </div>
141
+ </div>
142
+ <Space>
143
+ <Text type="secondary">
144
+ {displayMode === 'drawer' ? '抽屉模式' : '弹窗模式'}
145
+ </Text>
146
+ <Switch
147
+ checked={displayMode === 'drawer'}
148
+ onChange={handleDisplayModeChange}
149
+ />
150
+ </Space>
151
+ </div>
152
+ </div>
153
+
154
+ <div className="settings-item">
155
+ <div className="settings-item-header">
156
+ <div>
157
+ <div className="settings-item-title">接口表单交互</div>
158
+ <div className="settings-item-description">
159
+ 选择添加/编辑接口的显示方式
160
+ </div>
161
+ </div>
162
+ <Space>
163
+ <Text type="secondary">
164
+ {interfaceFormDisplayMode === 'drawer' ? '抽屉模式' : '弹窗模式'}
165
+ </Text>
166
+ <Switch
167
+ checked={interfaceFormDisplayMode === 'drawer'}
168
+ onChange={handleInterfaceFormDisplayModeChange}
169
+ />
170
+ </Space>
171
+ </div>
172
+ </div>
173
+
174
+ <div className="settings-item">
175
+ <div className="settings-item-header">
176
+ <div>
177
+ <div className="settings-item-title">
178
+ 接口入参匹配
179
+ <Button
180
+ type="text"
181
+ size="small"
182
+ className="settings-help-icon"
183
+ icon={<QuestionCircleOutlined />}
184
+ onClick={() => showMatcherRuleModal('interface')}
185
+ />
186
+ </div>
187
+ <div className="settings-item-description">
188
+ 是否在接口编辑表单中显示「接口匹配条件」配置区域
189
+ </div>
190
+ </div>
191
+ <Space>
192
+ <Text type="secondary">
193
+ {interfaceParamMatcherEnabled ? '已开启' : '已关闭'}
194
+ </Text>
195
+ <Switch
196
+ checked={interfaceParamMatcherEnabled}
197
+ onChange={handleInterfaceParamMatcherChange}
198
+ />
199
+ </Space>
200
+ </div>
201
+ </div>
202
+
203
+ <div className="settings-item">
204
+ <div className="settings-item-header">
205
+ <div>
206
+ <div className="settings-item-title">
207
+ 响应入参匹配
208
+ <Button
209
+ type="text"
210
+ size="small"
211
+ className="settings-help-icon"
212
+ icon={<QuestionCircleOutlined />}
213
+ onClick={() => showMatcherRuleModal('response')}
214
+ />
215
+ </div>
216
+ <div className="settings-item-description">
217
+ 是否在响应内容编辑器中显示「入参匹配规则」配置区域
218
+ </div>
219
+ </div>
220
+ <Space>
221
+ <Text type="secondary">
222
+ {responseParamMatcherEnabled ? '已开启' : '已关闭'}
223
+ </Text>
224
+ <Switch
225
+ checked={responseParamMatcherEnabled}
226
+ onChange={handleResponseParamMatcherChange}
227
+ />
228
+ </Space>
229
+ </div>
230
+ </div>
26
231
  </Card>
27
232
  </div>
28
233
  </AppLayout>
29
234
  );
30
235
  };
31
236
 
32
- export default Settings;
237
+ export default Settings;
@@ -294,20 +294,11 @@
294
294
  .interface-table td {
295
295
  padding: 12px 16px !important;
296
296
  white-space: nowrap;
297
- overflow: visible !important;
298
- text-overflow: ellipsis;
299
- }
300
-
301
- /* 确保表格容器不裁剪下拉菜单 */
302
- .interface-list-container {
303
- overflow: visible !important;
304
- }
305
-
306
- .interface-list-container .ant-table-container {
307
- overflow: visible !important;
297
+ overflow: hidden;
308
298
  }
309
299
 
310
- .interface-list-container .ant-table-body {
300
+ /* 当前响应列需要 overflow: visible 以显示完整的下拉菜单 */
301
+ .interface-table td.current-response-cell {
311
302
  overflow: visible !important;
312
303
  }
313
304
 
@@ -33,6 +33,50 @@
33
33
  font-weight: 500;
34
34
  }
35
35
 
36
+ /* 设置项样式 */
37
+ .settings-item {
38
+ padding: 16px 0;
39
+ border-bottom: 1px solid #f0f0f0;
40
+ }
41
+
42
+ .settings-item:last-child {
43
+ border-bottom: none;
44
+ }
45
+
46
+ .settings-item-header {
47
+ display: flex;
48
+ justify-content: space-between;
49
+ align-items: center;
50
+ }
51
+
52
+ .settings-item-title {
53
+ font-size: 14px;
54
+ font-weight: 500;
55
+ color: #262626;
56
+ margin-bottom: 4px;
57
+ display: inline-flex;
58
+ align-items: center;
59
+ gap: 2px;
60
+ }
61
+
62
+ .settings-item-description {
63
+ font-size: 12px;
64
+ color: #8c8c8c;
65
+ line-height: 1.5;
66
+ }
67
+
68
+ .settings-help-icon {
69
+ color: #8c8c8c;
70
+ padding: 0;
71
+ min-width: auto;
72
+ height: auto;
73
+ line-height: 1;
74
+ }
75
+
76
+ .settings-help-icon:hover {
77
+ color: #1677ff;
78
+ }
79
+
36
80
  .settings-section {
37
81
  margin-bottom: 32px;
38
82
  }
@@ -205,4 +249,4 @@ input:checked + .slider:before {
205
249
  width: 100%;
206
250
  margin-bottom: 8px;
207
251
  }
208
- }
252
+ }