@guo514360255/antd-lib 1.4.12 → 1.4.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.
@@ -13,8 +13,9 @@ var _excluded = ["type", "columns", "detailRequest", "handleDetailData", "title"
13
13
 
14
14
  import { findTreeNodeByKey, isEmptyValue } from "../utils/util";
15
15
  import { Descriptions, Drawer, Image, Modal, Spin } from 'antd';
16
- import { isNumber, isString } from 'lodash';
16
+ import isNumber from 'lodash/isNumber';
17
17
  import isObject from 'lodash/isObject';
18
+ import isString from 'lodash/isString';
18
19
  import React, { forwardRef, useImperativeHandle, useState } from 'react';
19
20
  import "./index.less";
20
21
  var CustomModal = /*#__PURE__*/forwardRef(function (props, ref) {
@@ -13,9 +13,11 @@ var _excluded = ["type", "onSubmit", "columns", "formColumns", "saveRequest", "u
13
13
  */
14
14
 
15
15
  import { DeleteOutlined } from '@ant-design/icons';
16
+ import { useFormData } from "../store/useFormData";
16
17
  import { Button, Drawer, Form, message, Modal, Spin } from 'antd';
17
18
  import cloneDeep from 'lodash/cloneDeep';
18
- import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
19
+ import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
20
+ import useDeepCompareEffect from 'use-deep-compare-effect';
19
21
  import CustomUpload from "../CustomUpload";
20
22
  import FormItem from "../FormItem";
21
23
  import "./index.less";
@@ -33,23 +35,23 @@ var CustomFormModal = /*#__PURE__*/forwardRef(function (props, ref) {
33
35
  _props$formList = props.formList,
34
36
  formList = _props$formList === void 0 ? {} : _props$formList,
35
37
  other = _objectWithoutProperties(props, _excluded);
38
+ var _useFormData = useFormData(),
39
+ formValues = _useFormData.formValues,
40
+ setFieldValues = _useFormData.setFieldValues;
36
41
  var formRef = useRef();
37
- var _useState = useState({}),
42
+ // const [values, setValues] = useState<any>({});
43
+ var _useState = useState(false),
38
44
  _useState2 = _slicedToArray(_useState, 2),
39
- values = _useState2[0],
40
- setValues = _useState2[1];
45
+ open = _useState2[0],
46
+ setOpen = _useState2[1];
41
47
  var _useState3 = useState(false),
42
48
  _useState4 = _slicedToArray(_useState3, 2),
43
- open = _useState4[0],
44
- setOpen = _useState4[1];
49
+ loading = _useState4[0],
50
+ setLoading = _useState4[1];
45
51
  var _useState5 = useState(false),
46
52
  _useState6 = _slicedToArray(_useState5, 2),
47
- loading = _useState6[0],
48
- setLoading = _useState6[1];
49
- var _useState7 = useState(false),
50
- _useState8 = _slicedToArray(_useState7, 2),
51
- detailLoading = _useState8[0],
52
- setDetailLoading = _useState8[1];
53
+ detailLoading = _useState6[0],
54
+ setDetailLoading = _useState6[1];
53
55
  var _message$useMessage = message.useMessage(),
54
56
  _message$useMessage2 = _slicedToArray(_message$useMessage, 2),
55
57
  messageApi = _message$useMessage2[0],
@@ -89,13 +91,13 @@ var CustomFormModal = /*#__PURE__*/forwardRef(function (props, ref) {
89
91
  return {
90
92
  open: function open(values) {
91
93
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
92
- var _formRef$current, data;
94
+ var data;
93
95
  return _regeneratorRuntime().wrap(function _callee$(_context) {
94
96
  while (1) switch (_context.prev = _context.next) {
95
97
  case 0:
96
98
  setOpen(true);
97
99
  if (!(values !== null && values !== void 0 && values.id && detailRequest)) {
98
- _context.next = 19;
100
+ _context.next = 18;
99
101
  break;
100
102
  }
101
103
  setDetailLoading(true);
@@ -109,45 +111,42 @@ var CustomFormModal = /*#__PURE__*/forwardRef(function (props, ref) {
109
111
  data["".concat(item.dataIndex).concat(formKey)] = data[item.dataIndex];
110
112
  }
111
113
  });
112
- formRef === null || formRef === void 0 || (_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setFieldsValue(data || {});
113
- setValues(data || {});
114
+ setFieldValues(data || {});
114
115
  return _context.abrupt("return");
115
- case 13:
116
- _context.prev = 13;
116
+ case 12:
117
+ _context.prev = 12;
117
118
  _context.t0 = _context["catch"](3);
118
119
  console.warn(_context.t0);
119
- case 16:
120
- _context.prev = 16;
120
+ case 15:
121
+ _context.prev = 15;
121
122
  setDetailLoading(false);
122
- return _context.finish(16);
123
- case 19:
123
+ return _context.finish(15);
124
+ case 18:
124
125
  setTimeout(function () {
125
- var _formRef$current2;
126
- formRef === null || formRef === void 0 || (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setFieldsValue(values || {});
127
- setValues(values || {});
126
+ setFieldValues(values || {});
128
127
  }, 0);
129
- case 20:
128
+ case 19:
130
129
  case "end":
131
130
  return _context.stop();
132
131
  }
133
- }, _callee, null, [[3, 13, 16, 19]]);
132
+ }, _callee, null, [[3, 12, 15, 18]]);
134
133
  }))();
135
134
  }
136
135
  };
137
136
  });
138
137
  var submitEvent = /*#__PURE__*/function () {
139
138
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
140
- var _formRef$current3, _formRef$current4, _tableActionRef$curre, formData, data, result, _key2;
139
+ var _formRef$current, _formRef$current2, _tableActionRef$curre, formData, data, result, _key2;
141
140
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
142
141
  while (1) switch (_context2.prev = _context2.next) {
143
142
  case 0:
144
143
  setLoading(true);
145
144
  _context2.prev = 1;
146
145
  _context2.next = 4;
147
- return (_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 ? void 0 : _formRef$current3.validateFields();
146
+ return (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.validateFields();
148
147
  case 4:
149
148
  formData = _context2.sent;
150
- data = _objectSpread(_objectSpread({}, values), formData);
149
+ data = _objectSpread(_objectSpread({}, formValues), formData);
151
150
  result = {};
152
151
  for (_key2 in data) {
153
152
  if (new RegExp(formKey).test(_key2)) {
@@ -159,7 +158,7 @@ var CustomFormModal = /*#__PURE__*/forwardRef(function (props, ref) {
159
158
  if (handleData) {
160
159
  result = handleData(result);
161
160
  }
162
- if (!values.id) {
161
+ if (!formValues.id) {
163
162
  _context2.next = 15;
164
163
  break;
165
164
  }
@@ -181,7 +180,7 @@ var CustomFormModal = /*#__PURE__*/forwardRef(function (props, ref) {
181
180
  return saveRequest(result);
182
181
  case 18:
183
182
  setOpen(false);
184
- (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 || _formRef$current4.resetFields();
183
+ (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.resetFields();
185
184
  if (onSubmit) {
186
185
  onSubmit();
187
186
  }
@@ -206,9 +205,9 @@ var CustomFormModal = /*#__PURE__*/forwardRef(function (props, ref) {
206
205
  };
207
206
  }();
208
207
  var close = function close() {
209
- var _formRef$current5;
208
+ var _formRef$current3;
210
209
  setOpen(false);
211
- (_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 || _formRef$current5.resetFields();
210
+ (_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 || _formRef$current3.resetFields();
212
211
  if (onSubmit) {
213
212
  onSubmit();
214
213
  }
@@ -227,6 +226,17 @@ var CustomFormModal = /*#__PURE__*/forwardRef(function (props, ref) {
227
226
  var getPlaceholder = function getPlaceholder(type, title) {
228
227
  return "\u8BF7".concat(placeholder[type || 'input'] || placeholder.default).concat(title ? title : '');
229
228
  };
229
+
230
+ // 深度监听form数据
231
+ useDeepCompareEffect(function () {
232
+ var _formRef$current4;
233
+ (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 || _formRef$current4.setFieldsValue(formValues || {});
234
+ }, [formValues]);
235
+ useEffect(function () {
236
+ return function () {
237
+ setFieldValues({});
238
+ };
239
+ }, []);
230
240
  return /*#__PURE__*/React.createElement("div", {
231
241
  className: "custom-modal-container"
232
242
  }, messageHolder, /*#__PURE__*/React.createElement(Spin, {
@@ -236,7 +246,7 @@ var CustomFormModal = /*#__PURE__*/forwardRef(function (props, ref) {
236
246
  }), /*#__PURE__*/React.createElement(Component, _extends({
237
247
  width: other.width || 600,
238
248
  footer: footer,
239
- title: "".concat(!!values.id ? '编辑' : '新增').concat(title || '')
249
+ title: "".concat(!!formValues.id ? '编辑' : '新增').concat(title || '')
240
250
  }, other, {
241
251
  open: open,
242
252
  onClose: close,
@@ -245,7 +255,8 @@ var CustomFormModal = /*#__PURE__*/forwardRef(function (props, ref) {
245
255
  size: "large",
246
256
  layout: "vertical",
247
257
  autoComplete: "off",
248
- ref: formRef
258
+ ref: formRef,
259
+ clearOnDestroy: true
249
260
  }, handleColumns(Array.isArray(formColumns) && formColumns.length ? formColumns : columns || []).map(function (item) {
250
261
  var defaultPlaceholder = getPlaceholder(item.type, item.title);
251
262
  return item.type === 'list' ? /*#__PURE__*/React.createElement(Form.List, {
@@ -16,7 +16,8 @@ var _excluded = ["isIndex", "isDelete", "isUpdateState", "isDetail", "isUpdate",
16
16
  import { ProTable } from '@ant-design/pro-table';
17
17
  import CustomFormModal from "../CustomFormModal";
18
18
  import { Button, message, Popconfirm, Progress } from 'antd';
19
- import { cloneDeep, debounce } from 'lodash';
19
+ import cloneDeep from 'lodash/cloneDeep';
20
+ import debounce from 'lodash/debounce';
20
21
  import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
21
22
  import CustomDetailModal from "../CustomDetailModal";
22
23
  import "./index.less";
package/dist/index.d.ts CHANGED
@@ -10,4 +10,5 @@ export { default as CustomUpload } from './CustomUpload';
10
10
  export { default as DynamicIcon } from './DynamicIcon';
11
11
  export { default as FormItem } from './FormItem';
12
12
  export * from './hooks';
13
+ export * from './store';
13
14
  export * from './utils';
package/dist/index.js CHANGED
@@ -6,4 +6,5 @@ export { default as CustomUpload } from "./CustomUpload";
6
6
  export { default as DynamicIcon } from "./DynamicIcon";
7
7
  export { default as FormItem } from "./FormItem";
8
8
  export * from "./hooks";
9
+ export * from "./store";
9
10
  export * from "./utils";
@@ -0,0 +1,2 @@
1
+ import { useFormData } from './useFormData';
2
+ export { useFormData };
@@ -0,0 +1,8 @@
1
+ /*
2
+ * @Author: 郭郭
3
+ * @Date: 2025/12/19
4
+ * @Description:
5
+ */
6
+
7
+ import { useFormData } from "./useFormData";
8
+ export { useFormData };
@@ -0,0 +1,23 @@
1
+ export interface FormValues {
2
+ /**
3
+ * 表单数据
4
+ */
5
+ formValues: {
6
+ [key: string]: any;
7
+ };
8
+ /**
9
+ * 设置表单数据
10
+ * @param data
11
+ */
12
+ setFieldValues: (data: {
13
+ [key: string]: any;
14
+ }) => void;
15
+ /**
16
+ * 设置表单单个数据
17
+ * @param data
18
+ */
19
+ setFieldValue: (data: {
20
+ [key: string]: any;
21
+ }) => void;
22
+ }
23
+ export declare const useFormData: import("zustand").UseBoundStore<import("zustand").StoreApi<FormValues>>;
@@ -0,0 +1,27 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ /*
3
+ * @Author: 郭郭
4
+ * @Date: 2025/12/19
5
+ * @Description:
6
+ */
7
+
8
+ import { create } from 'zustand';
9
+ export var useFormData = create(function (set) {
10
+ return {
11
+ formValues: {},
12
+ setFieldValues: function setFieldValues(values) {
13
+ return set(function () {
14
+ return {
15
+ formValues: values
16
+ };
17
+ });
18
+ },
19
+ setFieldValue: function setFieldValue(values) {
20
+ return set(function (state) {
21
+ return {
22
+ formValues: _objectSpread(_objectSpread({}, state.formValues), values)
23
+ };
24
+ });
25
+ }
26
+ };
27
+ });
@@ -6,8 +6,10 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
6
  * @Description:
7
7
  */
8
8
 
9
- import { isEmpty, isNil, isString } from 'lodash';
9
+ import isEmpty from 'lodash/isEmpty';
10
10
  import isFinite from 'lodash/isFinite';
11
+ import isNil from 'lodash/isNil';
12
+ import isString from 'lodash/isString';
11
13
  /**
12
14
  * 本地文件转为base64
13
15
  * @param file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guo514360255/antd-lib",
3
- "version": "1.4.12",
3
+ "version": "1.4.13",
4
4
  "description": "react design 5 lib",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -49,11 +49,13 @@
49
49
  "@ant-design/pro-components": "^2.8.10",
50
50
  "@babel/runtime": "^7.28.4",
51
51
  "@types/lodash": "^4.17.20",
52
- "antd": "^5.28.0",
52
+ "antd": "^5.x",
53
53
  "antd-img-crop": "^4.27.0",
54
54
  "crypto-js": "^4.2.0",
55
55
  "js-cookie": "^3.0.5",
56
- "lodash": "^4.17.21"
56
+ "lodash": "^4.17.21",
57
+ "use-deep-compare-effect": "^1.8.1",
58
+ "zustand": "^5.0.9"
57
59
  },
58
60
  "devDependencies": {
59
61
  "@commitlint/cli": "^17.1.2",