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

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.1",
3
+ "version": "1.2.2-beta.2",
4
4
  "description": "Whistle 插件,用于快速创建 API 模拟数据",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -39,6 +39,7 @@
39
39
  "jest": "^29.7.0",
40
40
  "react": "^18.2.0",
41
41
  "react-dom": "^18.2.0",
42
+ "react-resizable": "^3.0.5",
42
43
  "react-sortablejs": "^6.1.4",
43
44
  "sortablejs": "^1.15.3",
44
45
  "react-markdown": "^8.0.7",
@@ -15,6 +15,7 @@ import {
15
15
  FileTextOutlined, PlusCircleOutlined, SettingOutlined,
16
16
  SearchOutlined, FilterOutlined, ReloadOutlined, DownOutlined, QuestionCircleOutlined, CopyOutlined
17
17
  } from '@ant-design/icons';
18
+ // 移除 react-resizable,改用原生实现
18
19
  import '../styles/interface-management.css';
19
20
  import axios from 'axios';
20
21
 
@@ -97,13 +98,27 @@ const InterfaceManagement = () => {
97
98
  const [tableConfig, setTableConfig] = useState(() => {
98
99
  const cached = localStorage.getItem('interface-table-config');
99
100
  const defaultVisibleColumns = COLUMN_CONFIG.map(col => col.key);
100
- return cached ? JSON.parse(cached) : {
101
+ const defaultConfig = {
101
102
  sortOrder: null,
102
103
  sortField: null,
103
104
  pageSize: 10,
104
105
  current: 1,
105
- visibleColumns: defaultVisibleColumns
106
+ visibleColumns: defaultVisibleColumns,
107
+ columnWidths: {
108
+ currentResponse: 180
109
+ }
106
110
  };
111
+
112
+ if (cached) {
113
+ const parsedConfig = JSON.parse(cached);
114
+ // 确保 columnWidths 存在
115
+ if (!parsedConfig.columnWidths) {
116
+ parsedConfig.columnWidths = { currentResponse: 180 };
117
+ }
118
+ return parsedConfig;
119
+ }
120
+
121
+ return defaultConfig;
107
122
  });
108
123
 
109
124
  // 保存表格配置到localStorage
@@ -675,7 +690,12 @@ const InterfaceManagement = () => {
675
690
  // 重置列配置
676
691
  const handleResetColumns = () => {
677
692
  const defaultColumns = COLUMN_CONFIG.map(col => col.key);
678
- saveTableConfig({ visibleColumns: defaultColumns });
693
+ saveTableConfig({
694
+ visibleColumns: defaultColumns,
695
+ columnWidths: {
696
+ currentResponse: 180
697
+ }
698
+ });
679
699
  };
680
700
 
681
701
  // 切换列配置面板显示
@@ -706,6 +726,61 @@ const InterfaceManagement = () => {
706
726
  message.success('数据已刷新');
707
727
  };
708
728
 
729
+ // 可调整大小的表头组件(使用原生实现)
730
+ const ResizableTitle = (props) => {
731
+ const { onResize, width, columnKey, ...restProps } = props;
732
+
733
+ if (!width || !onResize) {
734
+ return <th {...restProps} />;
735
+ }
736
+
737
+ const handleMouseDown = (e) => {
738
+ e.preventDefault();
739
+ e.stopPropagation();
740
+
741
+ const startX = e.clientX;
742
+ const startWidth = width;
743
+
744
+ const handleMouseMove = (moveEvent) => {
745
+ const deltaX = moveEvent.clientX - startX;
746
+ const newWidth = Math.max(50, startWidth + deltaX); // 最小宽度 50px
747
+ onResize(columnKey, newWidth);
748
+ };
749
+
750
+ const handleMouseUp = () => {
751
+ document.removeEventListener('mousemove', handleMouseMove);
752
+ document.removeEventListener('mouseup', handleMouseUp);
753
+ document.body.style.cursor = '';
754
+ document.body.style.userSelect = '';
755
+ };
756
+
757
+ document.addEventListener('mousemove', handleMouseMove);
758
+ document.addEventListener('mouseup', handleMouseUp);
759
+ document.body.style.cursor = 'col-resize';
760
+ document.body.style.userSelect = 'none';
761
+ };
762
+
763
+ return (
764
+ <th {...restProps} style={{ ...restProps.style, position: 'relative' }}>
765
+ {restProps.children}
766
+ <span
767
+ className="column-resize-handle"
768
+ onMouseDown={handleMouseDown}
769
+ onClick={(e) => e.stopPropagation()}
770
+ />
771
+ </th>
772
+ );
773
+ };
774
+
775
+ // 处理列宽调整
776
+ const handleResize = (columnKey, newWidth) => {
777
+ const newColumnWidths = {
778
+ ...tableConfig.columnWidths,
779
+ [columnKey]: newWidth
780
+ };
781
+ saveTableConfig({ columnWidths: newColumnWidths });
782
+ };
783
+
709
784
  // 批量操作接口状态
710
785
  const handleBatchOperation = async (active) => {
711
786
  if (!selectedRowKeys || selectedRowKeys.length === 0) {
@@ -803,7 +878,12 @@ const InterfaceManagement = () => {
803
878
  title: '当前响应',
804
879
  dataIndex: 'activeResponseId',
805
880
  key: 'currentResponse',
806
- width: 180,
881
+ width: tableConfig.columnWidths?.currentResponse || 180,
882
+ onHeaderCell: (column) => ({
883
+ width: column.width,
884
+ columnKey: 'currentResponse',
885
+ onResize: handleResize,
886
+ }),
807
887
  render: (activeResponseId, record) => {
808
888
  // 如果没有响应数据,返回空
809
889
  if (!record.responses || !Array.isArray(record.responses) || record.responses.length === 0) {
@@ -822,6 +902,7 @@ const InterfaceManagement = () => {
822
902
  style={{ width: '100%' }}
823
903
  onChange={(value) => handleResponseSwitch(record.id, value)}
824
904
  disabled={record.proxyType !== 'response'}
905
+ getPopupContainer={(trigger) => trigger.parentNode}
825
906
  >
826
907
  {record.responses.map(resp => (
827
908
  <Option key={resp.id} value={resp.id}>
@@ -1333,6 +1414,11 @@ const InterfaceManagement = () => {
1333
1414
  selectedRowKeys,
1334
1415
  onChange: onSelectChange,
1335
1416
  }}
1417
+ components={{
1418
+ header: {
1419
+ cell: ResizableTitle,
1420
+ },
1421
+ }}
1336
1422
  size="middle"
1337
1423
  pagination={{
1338
1424
  current: tableConfig.current,
@@ -294,10 +294,23 @@
294
294
  .interface-table td {
295
295
  padding: 12px 16px !important;
296
296
  white-space: nowrap;
297
- overflow: hidden;
297
+ overflow: visible !important;
298
298
  text-overflow: ellipsis;
299
299
  }
300
300
 
301
+ /* 确保表格容器不裁剪下拉菜单 */
302
+ .interface-list-container {
303
+ overflow: visible !important;
304
+ }
305
+
306
+ .interface-list-container .ant-table-container {
307
+ overflow: visible !important;
308
+ }
309
+
310
+ .interface-list-container .ant-table-body {
311
+ overflow: visible !important;
312
+ }
313
+
301
314
  /* 卡片视图样式 */
302
315
  .interface-card-view {
303
316
  padding-bottom: 20px;
@@ -1283,3 +1296,35 @@
1283
1296
  .interface-table .ant-pagination-options {
1284
1297
  margin-right: 16px;
1285
1298
  }
1299
+
1300
+ /* 可调整列宽样式 */
1301
+ .column-resize-handle {
1302
+ position: absolute;
1303
+ right: -5px;
1304
+ top: 0;
1305
+ bottom: 0;
1306
+ width: 10px;
1307
+ cursor: col-resize;
1308
+ z-index: 1;
1309
+ user-select: none;
1310
+ }
1311
+
1312
+ .column-resize-handle:hover {
1313
+ background-color: rgba(24, 144, 255, 0.2);
1314
+ }
1315
+
1316
+ .column-resize-handle::after {
1317
+ content: '';
1318
+ position: absolute;
1319
+ right: 4px;
1320
+ top: 50%;
1321
+ transform: translateY(-50%);
1322
+ width: 2px;
1323
+ height: 20px;
1324
+ background-color: #d9d9d9;
1325
+ transition: background-color 0.3s;
1326
+ }
1327
+
1328
+ .column-resize-handle:hover::after {
1329
+ background-color: #1890ff;
1330
+ }