@zat-design/sisyphus-react 4.0.13 → 4.0.14

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.
Files changed (41) hide show
  1. package/dist/index.esm.css +1 -1
  2. package/dist/less.esm.css +1 -1
  3. package/es/ProEditLabel/index.js +81 -31
  4. package/es/ProEditLabel/propsType.d.ts +4 -4
  5. package/es/ProForm/components/combination/Group/utils/index.d.ts +17 -17
  6. package/es/ProLayout/components/Layout/Menu/FoldMenu/index.js +42 -9
  7. package/es/ProLayout/components/Layout/Menu/OpenMenu/index.js +9 -8
  8. package/es/ProLayout/components/TabsManager/components/TabItem.js +9 -1
  9. package/es/ProLayout/components/TabsManager/hooks/useTabsState.js +52 -7
  10. package/es/ProLayout/components/TabsManager/index.js +52 -16
  11. package/es/ProLayout/components/TabsManager/propTypes.d.ts +2 -0
  12. package/es/ProLayout/components/TabsManager/style/index.less +115 -3
  13. package/es/ProLayout/index.js +30 -16
  14. package/es/ProLayout/propTypes.d.ts +3 -3
  15. package/es/ProLayout/utils/index.js +85 -21
  16. package/es/ProTable/style/index.less +19 -3
  17. package/es/ProWaterMark/propsType.d.ts +3 -61
  18. package/es/locale/en_US.d.ts +1 -0
  19. package/es/locale/en_US.js +2 -1
  20. package/es/locale/zh_CN.d.ts +1 -0
  21. package/es/locale/zh_CN.js +2 -1
  22. package/lib/ProEditLabel/index.js +81 -31
  23. package/lib/ProEditLabel/propsType.d.ts +4 -4
  24. package/lib/ProForm/components/combination/Group/utils/index.d.ts +17 -17
  25. package/lib/ProLayout/components/Layout/Menu/FoldMenu/index.js +42 -9
  26. package/lib/ProLayout/components/Layout/Menu/OpenMenu/index.js +9 -8
  27. package/lib/ProLayout/components/TabsManager/components/TabItem.js +9 -1
  28. package/lib/ProLayout/components/TabsManager/hooks/useTabsState.js +54 -7
  29. package/lib/ProLayout/components/TabsManager/index.js +52 -16
  30. package/lib/ProLayout/components/TabsManager/propTypes.d.ts +2 -0
  31. package/lib/ProLayout/components/TabsManager/style/index.less +115 -3
  32. package/lib/ProLayout/index.js +30 -16
  33. package/lib/ProLayout/propTypes.d.ts +3 -3
  34. package/lib/ProLayout/utils/index.js +85 -21
  35. package/lib/ProTable/style/index.less +19 -3
  36. package/lib/ProWaterMark/propsType.d.ts +3 -61
  37. package/lib/locale/en_US.d.ts +1 -0
  38. package/lib/locale/en_US.js +2 -1
  39. package/lib/locale/zh_CN.d.ts +1 -0
  40. package/lib/locale/zh_CN.js +2 -1
  41. package/package.json +1 -1
@@ -74,6 +74,11 @@ var ProEditLabel = _ref => {
74
74
  _Form$useForm4 = _slicedToArray(_Form$useForm3, 1),
75
75
  viewForm = _Form$useForm4[0];
76
76
  var inputRef = (0, _react.useRef)(null);
77
+
78
+ // 类型断言:antd FormInstance 确实有这些方法(setFieldsValue, validateFields等)
79
+ // 使用类型断言解决 TypeScript 类型检查问题
80
+ var formInstance = form;
81
+ var viewFormInstance = viewForm;
77
82
  var onPress = e => {
78
83
  var element = e.target;
79
84
  if (e.key === 'Enter') {
@@ -89,9 +94,16 @@ var ProEditLabel = _ref => {
89
94
  if (mode === 'popup') {
90
95
  // 兼容老写法
91
96
  if (!popupProps.columns) {
92
- form.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', confirmValue);
97
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
98
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
99
+ return;
100
+ }
101
+ formInstance.setFieldsValue({
102
+ [popupProps.type]: confirmValue
103
+ });
93
104
  } else {
94
- form.setFieldsValue(confirmValue || {});
105
+ var matchedValue = (0, _utils.matchFormValue)(confirmValue, popupProps.columns);
106
+ formInstance.setFieldsValue(matchedValue || {});
95
107
  }
96
108
  // 弹窗同步最新value数据,解决Popconfirm空白处关闭数据不同步问题
97
109
  setState({
@@ -119,13 +131,21 @@ var ProEditLabel = _ref => {
119
131
  if (mode === 'popup' && props.value) {
120
132
  // 兼容老写法
121
133
  if (!popupProps.columns) {
122
- form.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', props.value);
134
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
135
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
136
+ return;
137
+ }
138
+ formInstance.setFieldsValue({
139
+ [popupProps.type]: props.value
140
+ });
123
141
  // 文本模式初始化赋值
124
- viewForm.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', props.value);
142
+ viewFormInstance.setFieldsValue({
143
+ [popupProps.type]: props.value
144
+ });
125
145
  } else {
126
- form.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
146
+ formInstance.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
127
147
  // 文本模式初始化赋值
128
- viewForm.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
148
+ viewFormInstance.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
129
149
  }
130
150
  }
131
151
  }, [props.value, mode]);
@@ -136,9 +156,15 @@ var ProEditLabel = _ref => {
136
156
  if (mode === 'popup' && confirmValue !== props.value) {
137
157
  // 兼容老写法
138
158
  if (!popupProps.columns) {
139
- viewForm.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', confirmValue);
159
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
160
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
161
+ return;
162
+ }
163
+ viewFormInstance.setFieldsValue({
164
+ [popupProps.type]: confirmValue
165
+ });
140
166
  } else {
141
- viewForm.setFieldsValue((0, _utils.matchFormValue)(confirmValue, popupProps.columns) || {});
167
+ viewFormInstance.setFieldsValue((0, _utils.matchFormValue)(confirmValue, popupProps.columns) || {});
142
168
  }
143
169
  }
144
170
  }, [confirmValue, mode]);
@@ -157,53 +183,71 @@ var ProEditLabel = _ref => {
157
183
  */
158
184
  var onConfirmHandle = /*#__PURE__*/function () {
159
185
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
160
- var res, value;
186
+ var res, value, fieldName;
161
187
  return _regeneratorRuntime().wrap(function _callee$(_context) {
162
188
  while (1) switch (_context.prev = _context.next) {
163
189
  case 0:
164
190
  _context.next = 2;
165
- return form.validateFields();
191
+ return formInstance.validateFields();
166
192
  case 2:
167
193
  res = _context.sent;
168
- // 兼容老写法
169
- if (!popupProps.columns) {
170
- value = res[(popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input'];
194
+ if (popupProps.columns) {
195
+ _context.next = 10;
196
+ break;
197
+ }
198
+ if (popupProps !== null && popupProps !== void 0 && popupProps.type) {
199
+ _context.next = 7;
200
+ break;
171
201
  }
172
- value = res;
173
- _context.prev = 5;
202
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
203
+ return _context.abrupt("return", Promise.reject(new Error('popupProps.type is required')));
204
+ case 7:
205
+ value = res[popupProps.type];
206
+ _context.next = 11;
207
+ break;
208
+ case 10:
209
+ // 新写法:如果只有一个字段,提取单个值;否则使用整个对象
210
+ if (popupProps.columns.length === 1) {
211
+ fieldName = popupProps.columns[0].name || popupProps.columns[0].type;
212
+ value = res[fieldName];
213
+ } else {
214
+ value = res;
215
+ }
216
+ case 11:
217
+ _context.prev = 11;
174
218
  _context.t0 = onFinish;
175
219
  if (!_context.t0) {
176
- _context.next = 10;
220
+ _context.next = 16;
177
221
  break;
178
222
  }
179
- _context.next = 10;
223
+ _context.next = 16;
180
224
  return onFinish(value);
181
- case 10:
225
+ case 16:
182
226
  _context.t1 = onConfirm;
183
227
  if (!_context.t1) {
184
- _context.next = 14;
228
+ _context.next = 20;
185
229
  break;
186
230
  }
187
- _context.next = 14;
231
+ _context.next = 20;
188
232
  return onConfirm(value);
189
- case 14:
190
- _context.next = 16;
233
+ case 20:
234
+ _context.next = 22;
191
235
  return setState({
192
236
  confirmValue: value,
193
237
  popValue: value
194
238
  });
195
- case 16:
196
- _context.next = 21;
239
+ case 22:
240
+ _context.next = 27;
197
241
  break;
198
- case 18:
199
- _context.prev = 18;
200
- _context.t2 = _context["catch"](5);
242
+ case 24:
243
+ _context.prev = 24;
244
+ _context.t2 = _context["catch"](11);
201
245
  return _context.abrupt("return", Promise.reject());
202
- case 21:
246
+ case 27:
203
247
  case "end":
204
248
  return _context.stop();
205
249
  }
206
- }, _callee, null, [[5, 18]]);
250
+ }, _callee, null, [[11, 24]]);
207
251
  }));
208
252
  return function onConfirmHandle() {
209
253
  return _ref2.apply(this, arguments);
@@ -216,9 +260,15 @@ var ProEditLabel = _ref => {
216
260
  var onCancelHandle = () => {
217
261
  // 兼容老写法
218
262
  if (!popupProps.columns) {
219
- form.setFieldValue((popupProps === null || popupProps === void 0 ? void 0 : popupProps.type) || 'Input', props.value);
263
+ if (!(popupProps !== null && popupProps !== void 0 && popupProps.type)) {
264
+ console.warn('ProEditLabel: popupProps.type is required when using old API (without columns)');
265
+ return;
266
+ }
267
+ formInstance.setFieldsValue({
268
+ [popupProps.type]: props.value
269
+ });
220
270
  } else {
221
- form.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
271
+ formInstance.setFieldsValue((0, _utils.matchFormValue)(props.value, popupProps.columns) || {});
222
272
  }
223
273
  setState({
224
274
  popValue: props.value
@@ -2,7 +2,7 @@ import { InputProps } from 'antd/es/input';
2
2
  import { PopconfirmProps } from 'antd/es/popconfirm';
3
3
  import { FormInstance } from 'antd/es/form';
4
4
  import React from 'react';
5
- import type { ProFormColumnType } from '../index';
5
+ import type { ProFormColumnType } from '../ProForm/propsType';
6
6
  export interface ContainerType {
7
7
  /**
8
8
  * @description 触发方式
@@ -77,13 +77,13 @@ export interface PopupType {
77
77
  * @description 列配置
78
78
  * @default -
79
79
  */
80
- columns?: ProFormColumnType;
80
+ columns?: ProFormColumnType[];
81
81
  /**
82
82
  * @description 允许扩展字段
83
83
  */
84
84
  [key: string]: any;
85
85
  }
86
- export interface LabelType extends InputProps {
86
+ export interface LabelType extends Omit<InputProps, 'onChange'> {
87
87
  /**
88
88
  * @description 是否打开
89
89
  * @default false
@@ -98,7 +98,7 @@ export interface LabelType extends InputProps {
98
98
  * @description 值变化回调
99
99
  * @default -
100
100
  */
101
- onChange?: (value: React.ChangeEvent<HTMLInputElement>) => void;
101
+ onChange?: (value: any) => void;
102
102
  /**
103
103
  * @description 是否可编辑
104
104
  * @default false
@@ -76,34 +76,35 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
76
76
  show?: boolean | ReactiveFunction<any, boolean>;
77
77
  component?: React.ReactNode | ReactiveFunction<any, React.ReactNode>;
78
78
  children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
79
- isView?: boolean;
80
- id?: string;
81
- prefixCls?: string;
82
- className?: string;
83
79
  style?: React.CSSProperties;
80
+ className?: string;
84
81
  rootClassName?: string;
82
+ trim?: boolean;
83
+ normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
85
84
  hidden?: boolean;
85
+ layout?: import("antd/es/form/Form").FormItemLayout;
86
+ help?: React.ReactNode;
87
+ vertical?: boolean;
88
+ preserve?: boolean;
89
+ id?: string;
86
90
  onReset?: () => void;
91
+ prefixCls?: string;
92
+ htmlFor?: string;
93
+ trigger?: string;
87
94
  status?: "" | "warning" | "error" | "success" | "validating";
88
- vertical?: boolean;
89
- validateTrigger?: string | false | string[];
90
- getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
91
- desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
92
- valueType?: import("../../../render/propsType").ProFormValueType;
95
+ isView?: boolean;
93
96
  colon?: boolean;
94
- htmlFor?: string;
95
97
  labelAlign?: import("antd/es/form/interface").FormLabelAlign;
96
98
  labelCol?: import("antd").ColProps;
97
99
  getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
98
- normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
99
100
  shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
100
- trigger?: string;
101
+ validateTrigger?: string | false | string[];
101
102
  validateDebounce?: number;
102
103
  valuePropName?: string;
104
+ getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
103
105
  messageVariables?: Record<string, string>;
104
106
  initialValue?: any;
105
107
  onMetaChange?: (meta: import("@rc-component/form/lib/Field").MetaEvent) => void;
106
- preserve?: boolean;
107
108
  isListField?: boolean;
108
109
  isList?: boolean;
109
110
  noStyle?: boolean;
@@ -111,10 +112,9 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
111
112
  icons: import("antd/es/form/FormItem").FeedbackIcons;
112
113
  };
113
114
  validateStatus?: "" | "warning" | "error" | "success" | "validating";
114
- layout?: import("antd/es/form/Form").FormItemLayout;
115
115
  wrapperCol?: import("antd").ColProps;
116
- help?: React.ReactNode;
117
116
  fieldId?: string;
117
+ valueType?: import("../../../render/propsType").ProFormValueType;
118
118
  switchValue?: [any, any];
119
119
  viewRender?: (value: any, record: any, { form, index, namePath, }: {
120
120
  [key: string]: any;
@@ -122,11 +122,11 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
122
122
  index?: number;
123
123
  }) => string | React.ReactElement<any, any>;
124
124
  viewType?: import("../../../render/propsType").ViewType;
125
- trim?: boolean;
126
125
  upperCase?: boolean;
127
126
  toISOString?: boolean;
128
127
  toCSTString?: boolean;
129
128
  clearNotShow?: boolean;
129
+ desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
130
130
  name: any;
131
131
  dependencies: any[];
132
132
  tooltip: string | {
@@ -141,7 +141,7 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
141
141
  * 创建组件属性
142
142
  */
143
143
  export declare const createComponentProps: (column: FlexibleGroupColumnType, formItemProps: any) => {
144
- componentProps: import("lodash").Omit<any, "precision" | "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow">;
144
+ componentProps: import("lodash").Omit<any, "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow" | "precision">;
145
145
  formItemTransform: {
146
146
  getValueProps: any;
147
147
  normalize: any;
@@ -114,13 +114,25 @@ var FoldMenu = props => {
114
114
  var menuItem = (0, _utils.findMenuItemByKey)(menus, String(id));
115
115
  var menuKeyPath = menuItem !== null && menuItem !== void 0 && menuItem.keyIdPath ? menuItem.keyIdPath.map(id => String(id)) : [String(id)];
116
116
 
117
- // 调用用户传入的onMenuClick回调
117
+ // 调用用户传入的onMenuClick回调,获取返回值(是否应该激活菜单)
118
+ var shouldActivate = true;
118
119
  if (onMenuClick) {
119
- onMenuClick({
120
+ var result = onMenuClick({
120
121
  item: menuItem,
121
122
  key: String(id),
122
123
  keyPath: menuKeyPath
123
124
  });
125
+ // 如果返回 false,表示不应该激活菜单
126
+ if (result === false) {
127
+ shouldActivate = false;
128
+ }
129
+ }
130
+
131
+ // 只有在 shouldActivate 为 true 时才设置选中状态
132
+ if (shouldActivate) {
133
+ onSelected({
134
+ selectedPath: toPath
135
+ });
124
136
  }
125
137
  },
126
138
  children: LiNode
@@ -134,17 +146,26 @@ var FoldMenu = props => {
134
146
  var menuItem = (0, _utils.findMenuItemByKey)(menus, String(id));
135
147
  var menuKeyPath = menuItem !== null && menuItem !== void 0 && menuItem.keyIdPath ? menuItem.keyIdPath.map(id => String(id)) : [String(id)];
136
148
 
137
- // 调用用户传入的onMenuClick回调
149
+ // 调用用户传入的onMenuClick回调,获取返回值(是否应该激活菜单)
150
+ var shouldActivate = true;
138
151
  if (onMenuClick) {
139
- onMenuClick({
152
+ var result = onMenuClick({
140
153
  item: menuItem,
141
154
  key: String(id),
142
155
  keyPath: menuKeyPath
143
156
  });
157
+ // 如果返回 false,表示不应该激活菜单
158
+ if (result === false) {
159
+ shouldActivate = false;
160
+ }
161
+ }
162
+
163
+ // 只有在 shouldActivate 为 true 时才设置选中状态
164
+ if (shouldActivate) {
165
+ onSelected({
166
+ selectedPath: toPath
167
+ });
144
168
  }
145
- onSelected({
146
- selectedPath: toPath
147
- });
148
169
  },
149
170
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Link, {
150
171
  to: toPath,
@@ -157,13 +178,25 @@ var FoldMenu = props => {
157
178
  var menuItem = (0, _utils.findMenuItemByKey)(menus, String(id));
158
179
  var menuKeyPath = menuItem !== null && menuItem !== void 0 && menuItem.keyIdPath ? menuItem.keyIdPath.map(id => String(id)) : [String(id)];
159
180
 
160
- // 调用用户传入的onMenuClick回调
181
+ // 调用用户传入的onMenuClick回调,获取返回值(是否应该激活菜单)
182
+ var shouldActivate = true;
161
183
  if (onMenuClick) {
162
- onMenuClick({
184
+ var result = onMenuClick({
163
185
  item: menuItem,
164
186
  key: String(id),
165
187
  keyPath: menuKeyPath
166
188
  });
189
+ // 如果返回 false,表示不应该激活菜单
190
+ if (result === false) {
191
+ shouldActivate = false;
192
+ }
193
+ }
194
+
195
+ // 只有在 shouldActivate 为 true 时才设置选中状态
196
+ if (shouldActivate) {
197
+ onSelected({
198
+ selectedPath: toPath
199
+ });
167
200
  }
168
201
  },
169
202
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Link, {
@@ -161,26 +161,27 @@ var OpenMenu = props => {
161
161
  keyPath = _ref2.keyPath,
162
162
  key = _ref2.key,
163
163
  domEvent = _ref2.domEvent;
164
- // console.log('item', item);
165
- // console.log('keyPath', keyPath);
166
- // console.log('key', key);
167
- // console.log('domEvent', domEvent);
168
-
169
164
  // 查找完整的菜单项数据
170
165
  var menuItem = (0, _utils.findMenuItemByKey)(menus, key);
171
166
  var menuKeyPath = menuItem !== null && menuItem !== void 0 && menuItem.keyIdPath ? menuItem.keyIdPath.map(id => String(id)) : keyPath;
172
167
 
173
- // 调用用户传入的onMenuClick回调
168
+ // 调用用户传入的onMenuClick回调,获取返回值(是否应该激活菜单)
169
+ var shouldActivate = true;
174
170
  if (onMenuClick) {
175
- onMenuClick({
171
+ var result = onMenuClick({
176
172
  item: menuItem,
177
173
  key,
178
174
  keyPath: menuKeyPath
179
175
  });
176
+ // 如果返回 false,表示不应该激活菜单
177
+ if (result === false) {
178
+ shouldActivate = false;
179
+ }
180
180
  }
181
181
 
182
182
  // 只有最后一级菜单(叶子节点)才设置选中状态和路径
183
- if (menuItem && (0, _utils2.isLeafMenuItem)(menuItem)) {
183
+ // 并且只有在 shouldActivate true 时才设置
184
+ if (menuItem && (0, _utils2.isLeafMenuItem)(menuItem) && shouldActivate) {
184
185
  var _item$props, _item$props2;
185
186
  setState({
186
187
  selectedKeys: keyPath,
@@ -28,6 +28,14 @@ var TabItemComponent = _ref => {
28
28
  e.stopPropagation();
29
29
  _onClose();
30
30
  };
31
+
32
+ // 作为 antd Tabs label 使用时,不需要阻止事件冒泡
33
+ // antd Tabs 会通过 onChange 处理切换,我们的 onClick 作为备用
34
+ var handleLabelClick = e => {
35
+ // 不阻止冒泡,让 antd Tabs 处理切换
36
+ // 但我们也调用 onClick 以确保状态同步
37
+ onClick();
38
+ };
31
39
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_TabContextMenu.TabContextMenu, {
32
40
  tabId: tab.id,
33
41
  closable: tab.closable,
@@ -41,7 +49,7 @@ var TabItemComponent = _ref => {
41
49
  tabMenuClick: tabMenuClick,
42
50
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
43
51
  className: `pro-layout-tab-item ${active ? 'active' : ''} ${tab.closable ? 'closable' : ''}`,
44
- onClick: onClick,
52
+ onClick: handleLabelClick,
45
53
  "data-testid": `tab-${tab.id}`,
46
54
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
47
55
  className: "pro-layout-tab-content",
@@ -5,9 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useTabsState = void 0;
7
7
  var _react = require("react");
8
+ var _antd = require("antd");
8
9
  var _propTypes = require("../propTypes");
9
10
  var _useTabsCache2 = require("./useTabsCache");
11
+ var _locale = _interopRequireWildcard(require("../../../../locale"));
10
12
  var _utils = require("../utils");
13
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
14
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
15
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
16
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
17
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -111,12 +115,50 @@ var useTabsState = options => {
111
115
  }, [state, saveToCache, finalConfig, isInitialized]);
112
116
 
113
117
  /**
114
- * 添加标签页
118
+ * 检查是否可以添加标签页(用于在菜单点击时判断是否应该激活菜单)
115
119
  */
116
- var addTab = (0, _react.useCallback)((menuItem, options) => {
120
+ var canAddTab = (0, _react.useCallback)((menuItem, options) => {
117
121
  var _ref = options || {},
118
122
  _ref$forceNew = _ref.forceNew,
119
123
  forceNew = _ref$forceNew === void 0 ? false : _ref$forceNew;
124
+
125
+ // 只有最后一级菜单(叶子节点)才能添加标签页
126
+ if (!(0, _utils.isLeafMenuItem)(menuItem)) {
127
+ return false;
128
+ }
129
+
130
+ // 检查是否需要外部跳转
131
+ if ((0, _utils.shouldOpenExternal)(menuItem)) {
132
+ return false;
133
+ }
134
+
135
+ // 如果 forceNew = false(默认),检查是否已存在相同的标签页
136
+ if (!forceNew) {
137
+ var existingTab = state.tabsList.find(tab => {
138
+ var _tab$menuItem;
139
+ return ((_tab$menuItem = tab.menuItem) === null || _tab$menuItem === void 0 ? void 0 : _tab$menuItem.code) === menuItem.code || tab.url === menuItem.url;
140
+ });
141
+ if (existingTab) {
142
+ // 如果已存在,可以添加(会切换到已存在的标签页)
143
+ return true;
144
+ }
145
+ }
146
+
147
+ // 检查是否超出限制(只有在需要创建新标签页时才检查)
148
+ if ((0, _utils.checkTabLimit)(state.tabsList, finalConfig.max)) {
149
+ // 达到最大值时,不能添加新标签页
150
+ return false;
151
+ }
152
+ return true;
153
+ }, [state.tabsList, finalConfig]);
154
+
155
+ /**
156
+ * 添加标签页
157
+ */
158
+ var addTab = (0, _react.useCallback)((menuItem, options) => {
159
+ var _ref2 = options || {},
160
+ _ref2$forceNew = _ref2.forceNew,
161
+ forceNew = _ref2$forceNew === void 0 ? false : _ref2$forceNew;
120
162
  setState(prevState => {
121
163
  // 只有最后一级菜单(叶子节点)才能添加标签页
122
164
  if (!(0, _utils.isLeafMenuItem)(menuItem)) {
@@ -134,8 +176,8 @@ var useTabsState = options => {
134
176
  // 如果 forceNew = false(默认),检查是否已存在相同的标签页
135
177
  if (!forceNew) {
136
178
  var existingTab = prevState.tabsList.find(tab => {
137
- var _tab$menuItem;
138
- return ((_tab$menuItem = tab.menuItem) === null || _tab$menuItem === void 0 ? void 0 : _tab$menuItem.code) === menuItem.code || tab.url === menuItem.url;
179
+ var _tab$menuItem2;
180
+ return ((_tab$menuItem2 = tab.menuItem) === null || _tab$menuItem2 === void 0 ? void 0 : _tab$menuItem2.code) === menuItem.code || tab.url === menuItem.url;
139
181
  });
140
182
  if (existingTab) {
141
183
  var _existingTab$menuItem;
@@ -151,7 +193,11 @@ var useTabsState = options => {
151
193
 
152
194
  // 检查是否超出限制
153
195
  if ((0, _utils.checkTabLimit)(prevState.tabsList, finalConfig.max)) {
154
- // 达到最大值时,不添加新标签页,直接返回
196
+ // 达到最大值时,不添加新标签页,显示提示信息
197
+ var messageText = (0, _locale.formatMessage)(_locale.default.ProLayout.tabMaxLimitMessage, {
198
+ max: finalConfig.max
199
+ });
200
+ _antd.message.info(messageText);
155
201
  return prevState;
156
202
  }
157
203
 
@@ -342,8 +388,8 @@ var useTabsState = options => {
342
388
 
343
389
  // 检查是否已在 Tabs 中
344
390
  var existingTab = state.tabsList.find(tab => {
345
- var _tab$menuItem2;
346
- return ((_tab$menuItem2 = tab.menuItem) === null || _tab$menuItem2 === void 0 ? void 0 : _tab$menuItem2.code) === targetMenu.code || tab.url === targetMenu.url;
391
+ var _tab$menuItem3;
392
+ return ((_tab$menuItem3 = tab.menuItem) === null || _tab$menuItem3 === void 0 ? void 0 : _tab$menuItem3.code) === targetMenu.code || tab.url === targetMenu.url;
347
393
  });
348
394
  if (existingTab) {
349
395
  // 如果已存在,切换到该 Tab
@@ -359,6 +405,7 @@ var useTabsState = options => {
359
405
  return {
360
406
  state,
361
407
  addTab,
408
+ canAddTab,
362
409
  removeTab,
363
410
  switchTab,
364
411
  closeOtherTabs,
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _react = require("react");
8
+ var _antd = require("antd");
8
9
  var _useTabsState2 = require("./hooks/useTabsState");
9
10
  var _TabItem = require("./components/TabItem");
10
11
  var _TabsContext = require("./components/TabsContext");
@@ -34,6 +35,7 @@ var TabsManager = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
34
35
  }),
35
36
  state = _useTabsState.state,
36
37
  _addTab = _useTabsState.addTab,
38
+ canAddTab = _useTabsState.canAddTab,
37
39
  removeTab = _useTabsState.removeTab,
38
40
  switchTab = _useTabsState.switchTab,
39
41
  closeOtherTabs = _useTabsState.closeOtherTabs,
@@ -99,25 +101,58 @@ var TabsManager = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
99
101
  })
100
102
  }), [_addTab, removeTab, state.tabsList, state.activeKey, state.activeComponent]);
101
103
 
104
+ // 处理标签切换
105
+ var handleTabChange = (0, _react.useCallback)(activeKey => {
106
+ switchTab(activeKey);
107
+ }, [switchTab]);
108
+
109
+ // 处理标签关闭
110
+ var handleTabEdit = (0, _react.useCallback)((targetKey, action) => {
111
+ if (action === 'remove') {
112
+ removeTab(targetKey);
113
+ }
114
+ }, [removeTab]);
115
+
116
+ // 构建 Tabs items
117
+ var tabsItems = (0, _react.useMemo)(() => {
118
+ if (state.tabsList.length === 0) return [];
119
+ return state.tabsList.map(tab => ({
120
+ key: tab.id,
121
+ label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TabItem.TabItemComponent, {
122
+ tab: tab,
123
+ active: tab.id === state.activeKey,
124
+ onClick: () => switchTab(tab.id),
125
+ onClose: () => removeTab(tab.id),
126
+ onCloseOthers: () => closeOtherTabs(tab.id),
127
+ onCloseRight: () => closeRightTabs(tab.id),
128
+ onCloseAll: closeAllTabs,
129
+ tabsList: state.tabsList,
130
+ menuItems: config === null || config === void 0 ? void 0 : config.menuItems,
131
+ tabMenuClick: config === null || config === void 0 ? void 0 : config.tabMenuClick
132
+ }),
133
+ closable: tab.closable,
134
+ children: null // 内容在 renderContent() 中渲染
135
+ }));
136
+ }, [state.tabsList, state.activeKey, config === null || config === void 0 ? void 0 : config.menuItems, config === null || config === void 0 ? void 0 : config.tabMenuClick, switchTab, removeTab, closeOtherTabs, closeRightTabs, closeAllTabs]);
137
+
102
138
  // 渲染标签页列表
103
139
  var renderTabList = () => {
104
140
  if (state.tabsList.length === 0) return null;
105
141
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
106
142
  className: "pro-layout-tabs-header",
107
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
108
- className: "pro-layout-tab-list",
109
- children: state.tabsList.map(tab => /*#__PURE__*/(0, _jsxRuntime.jsx)(_TabItem.TabItemComponent, {
110
- tab: tab,
111
- active: tab.id === state.activeKey,
112
- onClick: () => switchTab(tab.id),
113
- onClose: () => removeTab(tab.id),
114
- onCloseOthers: () => closeOtherTabs(tab.id),
115
- onCloseRight: () => closeRightTabs(tab.id),
116
- onCloseAll: closeAllTabs,
117
- tabsList: state.tabsList,
118
- menuItems: config === null || config === void 0 ? void 0 : config.menuItems,
119
- tabMenuClick: config === null || config === void 0 ? void 0 : config.tabMenuClick
120
- }, tab.id))
143
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.Tabs, {
144
+ activeKey: state.activeKey || undefined,
145
+ onChange: handleTabChange,
146
+ onEdit: handleTabEdit,
147
+ type: "editable-card",
148
+ hideAdd: true,
149
+ items: tabsItems,
150
+ className: "pro-layout-tabs-antd",
151
+ classNames: {
152
+ popup: {
153
+ root: 'pro-layout-tabs-dropdown-menu'
154
+ }
155
+ }
121
156
  })
122
157
  });
123
158
  };
@@ -167,8 +202,9 @@ var TabsManager = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
167
202
 
168
203
  // 暴露方法给父组件
169
204
  (0, _react.useImperativeHandle)(ref, () => ({
170
- handleMenuClick
171
- }), [handleMenuClick]);
205
+ handleMenuClick,
206
+ canAddTab
207
+ }), [handleMenuClick, canAddTab]);
172
208
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_TabsContext.TabsContext.Provider, {
173
209
  value: tabsInstance,
174
210
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {