@guo514360255/antd-lib 1.4.12 → 1.4.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.
- package/dist/CustomDetailModal/index.js +2 -1
- package/dist/CustomFormModal/formModal.d.ts +6 -0
- package/dist/CustomFormModal/index.js +49 -38
- package/dist/CustomTable/index.js +4 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.js +8 -0
- package/dist/store/useFormData.d.ts +23 -0
- package/dist/store/useFormData.js +27 -0
- package/dist/utils/util.js +3 -1
- package/package.json +5 -3
|
@@ -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
|
|
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) {
|
|
@@ -5,7 +5,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
|
5
5
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
6
6
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
7
7
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
8
|
-
var _excluded = ["type", "onSubmit", "columns", "formColumns", "saveRequest", "updateRequest", "detailRequest", "handleData", "title", "tableActionRef", "formList"];
|
|
8
|
+
var _excluded = ["type", "onSubmit", "columns", "formColumns", "saveRequest", "updateRequest", "detailRequest", "handleData", "title", "tableActionRef", "formList", "handleModalData"];
|
|
9
9
|
/*
|
|
10
10
|
* @Author: 郭郭
|
|
11
11
|
* @Date: 2025/8/15
|
|
@@ -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";
|
|
@@ -32,24 +34,24 @@ var CustomFormModal = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
32
34
|
tableActionRef = props.tableActionRef,
|
|
33
35
|
_props$formList = props.formList,
|
|
34
36
|
formList = _props$formList === void 0 ? {} : _props$formList,
|
|
37
|
+
handleModalData = props.handleModalData,
|
|
35
38
|
other = _objectWithoutProperties(props, _excluded);
|
|
39
|
+
var _useFormData = useFormData(),
|
|
40
|
+
formValues = _useFormData.formValues,
|
|
41
|
+
setFieldValues = _useFormData.setFieldValues;
|
|
36
42
|
var formRef = useRef();
|
|
37
|
-
var _useState = useState(
|
|
43
|
+
var _useState = useState(false),
|
|
38
44
|
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
open = _useState2[0],
|
|
46
|
+
setOpen = _useState2[1];
|
|
41
47
|
var _useState3 = useState(false),
|
|
42
48
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
loading = _useState4[0],
|
|
50
|
+
setLoading = _useState4[1];
|
|
45
51
|
var _useState5 = useState(false),
|
|
46
52
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
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 =
|
|
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
|
-
|
|
113
|
-
setValues(data || {});
|
|
114
|
+
setFieldValues(handleModalData(data || {}));
|
|
114
115
|
return _context.abrupt("return");
|
|
115
|
-
case
|
|
116
|
-
_context.prev =
|
|
116
|
+
case 12:
|
|
117
|
+
_context.prev = 12;
|
|
117
118
|
_context.t0 = _context["catch"](3);
|
|
118
119
|
console.warn(_context.t0);
|
|
119
|
-
case
|
|
120
|
-
_context.prev =
|
|
120
|
+
case 15:
|
|
121
|
+
_context.prev = 15;
|
|
121
122
|
setDetailLoading(false);
|
|
122
|
-
return _context.finish(
|
|
123
|
-
case
|
|
123
|
+
return _context.finish(15);
|
|
124
|
+
case 18:
|
|
124
125
|
setTimeout(function () {
|
|
125
|
-
|
|
126
|
-
formRef === null || formRef === void 0 || (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setFieldsValue(values || {});
|
|
127
|
-
setValues(values || {});
|
|
126
|
+
setFieldValues(handleModalData(values || {}));
|
|
128
127
|
}, 0);
|
|
129
|
-
case
|
|
128
|
+
case 19:
|
|
130
129
|
case "end":
|
|
131
130
|
return _context.stop();
|
|
132
131
|
}
|
|
133
|
-
}, _callee, null, [[3,
|
|
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$
|
|
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$
|
|
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({},
|
|
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 (!
|
|
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$
|
|
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$
|
|
208
|
+
var _formRef$current3;
|
|
210
209
|
setOpen(false);
|
|
211
|
-
(_formRef$
|
|
210
|
+
(_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 || _formRef$current3.resetFields();
|
|
212
211
|
if (onSubmit) {
|
|
213
212
|
onSubmit();
|
|
214
213
|
}
|
|
@@ -225,8 +224,19 @@ var CustomFormModal = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
225
224
|
onClick: submitEvent
|
|
226
225
|
}, "\u63D0\u4EA4")];
|
|
227
226
|
var getPlaceholder = function getPlaceholder(type, title) {
|
|
228
|
-
return "\u8BF7".concat(placeholder[type || 'input'] ||
|
|
227
|
+
return "\u8BF7".concat(placeholder[type || 'input'] || '选择').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(!!
|
|
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
|
|
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";
|
|
@@ -171,7 +172,7 @@ var CustomTable = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
171
172
|
var _formModalRef$current;
|
|
172
173
|
var record = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
173
174
|
// @ts-ignore
|
|
174
|
-
(_formModalRef$current = formModalRef.current) === null || _formModalRef$current === void 0 || _formModalRef$current.open(
|
|
175
|
+
(_formModalRef$current = formModalRef.current) === null || _formModalRef$current === void 0 || _formModalRef$current.open(record);
|
|
175
176
|
};
|
|
176
177
|
useImperativeHandle(ref, function () {
|
|
177
178
|
return {
|
|
@@ -416,6 +417,7 @@ var CustomTable = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
416
417
|
saveRequest: saveRequest,
|
|
417
418
|
updateRequest: updateRequest,
|
|
418
419
|
detailRequest: detailRequest,
|
|
420
|
+
handleModalData: handleModalData,
|
|
419
421
|
columns: columns.filter(function (item) {
|
|
420
422
|
return !item.hideInForm && item.dataIndex !== 'operation' && item.valueType !== 'option';
|
|
421
423
|
})
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -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
|
+
});
|
package/dist/utils/util.js
CHANGED
|
@@ -6,8 +6,10 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
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.
|
|
3
|
+
"version": "1.4.14",
|
|
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.
|
|
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",
|