@hw-component/table 1.9.13 → 1.9.15
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/es/DialogTable/Content.d.ts +2 -1
- package/es/DialogTable/Content.js +4 -2
- package/es/DialogTable/DwTable.d.ts +1 -0
- package/es/DialogTable/DwTable.js +10 -4
- package/es/DialogTable/ModalTable.d.ts +1 -0
- package/es/DialogTable/ModalTable.js +9 -3
- package/es/DialogTable/hooks.d.ts +3 -1
- package/es/DialogTable/hooks.js +4 -2
- package/es/Table.d.ts +1 -1
- package/es/Table.js +8 -9
- package/es/hooks/useReq.d.ts +3 -3
- package/es/hooks/useReq.js +82 -19
- package/es/modal.d.ts +3 -1
- package/lib/DialogTable/Content.d.ts +2 -1
- package/lib/DialogTable/Content.js +4 -2
- package/lib/DialogTable/DwTable.d.ts +1 -0
- package/lib/DialogTable/DwTable.js +10 -4
- package/lib/DialogTable/ModalTable.d.ts +1 -0
- package/lib/DialogTable/ModalTable.js +9 -3
- package/lib/DialogTable/hooks.d.ts +3 -1
- package/lib/DialogTable/hooks.js +4 -2
- package/lib/Table.d.ts +1 -1
- package/lib/Table.js +8 -9
- package/lib/hooks/useReq.d.ts +3 -3
- package/lib/hooks/useReq.js +81 -18
- package/lib/modal.d.ts +3 -1
- package/package.json +15 -14
- package/src/components/DialogTable/Content.tsx +2 -0
- package/src/components/DialogTable/DwTable.tsx +10 -2
- package/src/components/DialogTable/ModalTable.tsx +11 -2
- package/src/components/DialogTable/hooks.ts +2 -0
- package/src/components/Table.tsx +7 -5
- package/src/components/hooks/useReq.ts +57 -8
- package/src/components/modal.ts +3 -1
- package/src/pages/DwTable/index.tsx +16 -2
- package/src/pages/ModalTable/index.tsx +14 -2
- package/src/pages/Table/index.tsx +27 -32
package/lib/hooks/useReq.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface IParamsModal {
|
|
|
4
4
|
loading?: boolean;
|
|
5
5
|
error?: Error;
|
|
6
6
|
reload?: (params: any) => Promise<any>;
|
|
7
|
-
dataSource?: any;
|
|
7
|
+
dataSource?: ResultModal | any[];
|
|
8
8
|
manual?: boolean;
|
|
9
9
|
formInitValues?: Record<string, any>;
|
|
10
10
|
}
|
|
@@ -28,8 +28,8 @@ declare const _default: ({ request, loading, error, reload, dataSource, manual,
|
|
|
28
28
|
} | {
|
|
29
29
|
loading: boolean | undefined;
|
|
30
30
|
error: Error | undefined;
|
|
31
|
-
data:
|
|
32
|
-
run: (params?: Record<string, any>) => Promise<
|
|
31
|
+
data: ResultModal;
|
|
32
|
+
run: (params?: Record<string, any>) => Promise<void>;
|
|
33
33
|
saveParams: {
|
|
34
34
|
old: {};
|
|
35
35
|
};
|
package/lib/hooks/useReq.js
CHANGED
|
@@ -10,10 +10,16 @@ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/
|
|
|
10
10
|
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptors');
|
|
11
11
|
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/define-properties');
|
|
12
12
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
|
|
13
|
-
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
14
13
|
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
15
14
|
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
15
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
16
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
16
17
|
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
18
|
+
require('core-js/modules/es.object.to-string.js');
|
|
19
|
+
require('core-js/modules/es.regexp.to-string.js');
|
|
20
|
+
var _Number$parseInt = require('@babel/runtime-corejs3/core-js/number/parse-int');
|
|
21
|
+
var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/slice');
|
|
22
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js/array/is-array');
|
|
17
23
|
var React = require('react');
|
|
18
24
|
var ahooks = require('ahooks');
|
|
19
25
|
|
|
@@ -21,42 +27,99 @@ var _excluded = ["size", "current"],
|
|
|
21
27
|
_excluded2 = ["size", "current"];
|
|
22
28
|
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
23
29
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
var defaultDataSource = {
|
|
31
|
+
records: [],
|
|
32
|
+
total: "0",
|
|
33
|
+
size: "0",
|
|
34
|
+
current: "1"
|
|
35
|
+
};
|
|
36
|
+
var useDataSource = function useDataSource(_ref) {
|
|
37
|
+
var reload = _ref.reload,
|
|
38
|
+
dataSource = _ref.dataSource;
|
|
39
|
+
var _useState = React.useState(_objectSpread({}, defaultDataSource)),
|
|
40
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
41
|
+
cpDataSource = _useState2[0],
|
|
42
|
+
setCpDataSource = _useState2[1];
|
|
43
|
+
var localMaker = function localMaker(params) {
|
|
44
|
+
var size = params.size,
|
|
45
|
+
current = params.current;
|
|
46
|
+
var ps = _Number$parseInt(size);
|
|
47
|
+
var pn = _Number$parseInt(current);
|
|
48
|
+
var prvPn = pn - 1;
|
|
49
|
+
var arrDataSource = dataSource;
|
|
50
|
+
var records = _sliceInstanceProperty(arrDataSource).call(arrDataSource, prvPn * ps, pn * ps);
|
|
51
|
+
var total = arrDataSource.length;
|
|
52
|
+
return {
|
|
53
|
+
records: records,
|
|
54
|
+
size: size,
|
|
55
|
+
current: current,
|
|
56
|
+
total: total.toString()
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
var defaultReload = function defaultReload(params) {
|
|
60
|
+
if (_Array$isArray(dataSource)) {
|
|
61
|
+
console.warn("@hw-component/table:非受控模式reload将不起作用");
|
|
62
|
+
setCpDataSource(localMaker(params));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
reload === null || reload === void 0 || reload(params);
|
|
66
|
+
};
|
|
67
|
+
React.useEffect(function () {
|
|
68
|
+
if (_Array$isArray(dataSource)) {
|
|
69
|
+
setCpDataSource(function (old) {
|
|
70
|
+
return localMaker(old);
|
|
71
|
+
});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
setCpDataSource(dataSource || _objectSpread({}, defaultDataSource));
|
|
75
|
+
}, [dataSource]);
|
|
76
|
+
return {
|
|
77
|
+
reload: defaultReload,
|
|
78
|
+
dataSource: cpDataSource
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
var useReq = (function (_ref2) {
|
|
82
|
+
var request = _ref2.request,
|
|
83
|
+
loading = _ref2.loading,
|
|
84
|
+
error = _ref2.error,
|
|
85
|
+
reload = _ref2.reload,
|
|
86
|
+
dataSource = _ref2.dataSource,
|
|
87
|
+
_ref2$manual = _ref2.manual,
|
|
88
|
+
manual = _ref2$manual === void 0 ? false : _ref2$manual,
|
|
89
|
+
_ref2$formInitValues = _ref2.formInitValues,
|
|
90
|
+
formInitValues = _ref2$formInitValues === void 0 ? {} : _ref2$formInitValues;
|
|
34
91
|
var saveParams = React.useMemo(function () {
|
|
35
92
|
return {
|
|
36
93
|
old: {}
|
|
37
94
|
};
|
|
38
95
|
}, []);
|
|
96
|
+
var _useDataSource = useDataSource({
|
|
97
|
+
reload: reload,
|
|
98
|
+
dataSource: dataSource
|
|
99
|
+
}),
|
|
100
|
+
localReload = _useDataSource.reload,
|
|
101
|
+
localDataSource = _useDataSource.dataSource;
|
|
39
102
|
var reloadFn = /*#__PURE__*/function () {
|
|
40
|
-
var
|
|
103
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
41
104
|
var params,
|
|
42
105
|
_params$size,
|
|
43
106
|
size,
|
|
44
107
|
_params$current,
|
|
45
108
|
current,
|
|
46
109
|
oParams,
|
|
47
|
-
|
|
110
|
+
requestParams,
|
|
48
111
|
_args = arguments;
|
|
49
112
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
50
113
|
while (1) switch (_context.prev = _context.next) {
|
|
51
114
|
case 0:
|
|
52
115
|
params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
53
116
|
_params$size = params.size, size = _params$size === void 0 ? "10" : _params$size, _params$current = params.current, current = _params$current === void 0 ? "1" : _params$current, oParams = _objectWithoutProperties(params, _excluded);
|
|
54
|
-
|
|
117
|
+
requestParams = _objectSpread({
|
|
55
118
|
size: size,
|
|
56
119
|
current: current
|
|
57
120
|
}, oParams);
|
|
58
|
-
saveParams.old =
|
|
59
|
-
return _context.abrupt("return",
|
|
121
|
+
saveParams.old = requestParams;
|
|
122
|
+
return _context.abrupt("return", localReload(requestParams));
|
|
60
123
|
case 5:
|
|
61
124
|
case "end":
|
|
62
125
|
return _context.stop();
|
|
@@ -64,7 +127,7 @@ var useReq = (function (_ref) {
|
|
|
64
127
|
}, _callee);
|
|
65
128
|
}));
|
|
66
129
|
return function reloadFn() {
|
|
67
|
-
return
|
|
130
|
+
return _ref3.apply(this, arguments);
|
|
68
131
|
};
|
|
69
132
|
}();
|
|
70
133
|
var resultAction = ahooks.useRequest(function () {
|
|
@@ -101,7 +164,7 @@ var useReq = (function (_ref) {
|
|
|
101
164
|
return {
|
|
102
165
|
loading: loading,
|
|
103
166
|
error: error,
|
|
104
|
-
data:
|
|
167
|
+
data: localDataSource,
|
|
105
168
|
run: reloadFn,
|
|
106
169
|
saveParams: saveParams
|
|
107
170
|
};
|
package/lib/modal.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export interface HTableProps extends Omit<ProTableProps<any, any>, "request" | "
|
|
|
65
65
|
error?: Error;
|
|
66
66
|
reload?: (params: any) => Promise<any>;
|
|
67
67
|
manual?: boolean;
|
|
68
|
-
dataSource?: ResultModal;
|
|
68
|
+
dataSource?: ResultModal | any[];
|
|
69
69
|
paginationStyle?: React.CSSProperties;
|
|
70
70
|
allPageCheck?: boolean;
|
|
71
71
|
rowSelection?: HRowSelection | false;
|
|
@@ -103,6 +103,7 @@ export interface DialogParamsModal {
|
|
|
103
103
|
request?: HTableProps["request"];
|
|
104
104
|
params?: Record<string, any>;
|
|
105
105
|
title?: string | React.ReactNode;
|
|
106
|
+
dataSource?: any[];
|
|
106
107
|
}
|
|
107
108
|
export interface HOnDiaLogTableInstance {
|
|
108
109
|
show: (params?: DialogParamsModal) => void;
|
|
@@ -130,6 +131,7 @@ export interface ModalTableProps extends ModalProps {
|
|
|
130
131
|
configData?: HTableProps["configData"];
|
|
131
132
|
request?: HTableProps["request"];
|
|
132
133
|
contentRender?: (node: React.ReactNode) => React.ReactNode;
|
|
134
|
+
dataSource?: any[];
|
|
133
135
|
}
|
|
134
136
|
export type ValueTypeConfigRenderFn = (config: ConfigItemModal, itemData: any, index: number, tableInstance: HTableInstance) => React.ReactNode;
|
|
135
137
|
export type ValueTypeConfigModal = Record<string, ValueTypeConfigRenderFn>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hw-component/table",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.15",
|
|
4
4
|
"description": "基于antd二次开发table组件",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"table"
|
|
@@ -29,25 +29,29 @@
|
|
|
29
29
|
]
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"copy-to-clipboard": "3.3.1",
|
|
32
33
|
"core-js": "3",
|
|
33
|
-
"
|
|
34
|
+
"react-color": "^2.19.3"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
36
37
|
"@ant-design/icons": "4.6.2",
|
|
37
38
|
"@ant-design/pro-table": "2.70.0",
|
|
39
|
+
"@hw-component/form": "^1.9.4",
|
|
38
40
|
"ahooks": "2.10.9",
|
|
39
41
|
"antd": "4.20.7",
|
|
40
42
|
"react": "17.0.0",
|
|
41
|
-
"react-dom": "17.0.2"
|
|
42
|
-
"@hw-component/form": "^1.8.8"
|
|
43
|
+
"react-dom": "17.0.2"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
46
|
+
"@ant-design/icons": "4.6.2",
|
|
47
|
+
"@ant-design/pro-table": "2.70.0",
|
|
45
48
|
"@babel/core": "^7.21.8",
|
|
46
49
|
"@babel/plugin-transform-runtime": "^7.23.2",
|
|
47
50
|
"@babel/preset-env": "^7.23.2",
|
|
48
51
|
"@babel/preset-react": "^7.18.6",
|
|
49
52
|
"@babel/preset-typescript": "^7.21.5",
|
|
50
53
|
"@babel/runtime-corejs3": "^7.21.5",
|
|
54
|
+
"@hw-component/form": "^1.8.3",
|
|
51
55
|
"@rollup/plugin-babel": "^6.0.3",
|
|
52
56
|
"@rollup/plugin-commonjs": "^25.0.0",
|
|
53
57
|
"@rollup/plugin-image": "^3.0.3",
|
|
@@ -58,8 +62,11 @@
|
|
|
58
62
|
"@types/react-dom": "17.0.9",
|
|
59
63
|
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
|
60
64
|
"@umijs/fabric": "^2.14.1",
|
|
65
|
+
"ahooks": "2.10.9",
|
|
66
|
+
"antd": "4.20.7",
|
|
61
67
|
"autoprefixer": "^10.4.14",
|
|
62
68
|
"babel-loader": "^9.1.2",
|
|
69
|
+
"copy-to-clipboard": "3.3.1",
|
|
63
70
|
"css-loader": "^6.7.4",
|
|
64
71
|
"eslint": "^8.41.0",
|
|
65
72
|
"eslint-plugin-jest": "^27.2.1",
|
|
@@ -73,6 +80,9 @@
|
|
|
73
80
|
"lint-staged": "10.5.4",
|
|
74
81
|
"postcss": "^8.4.23",
|
|
75
82
|
"postcss-less": "^6.0.0",
|
|
83
|
+
"react": "17.0.0",
|
|
84
|
+
"react-dom": "17.0.2",
|
|
85
|
+
"react-router-dom": "^6.11.2",
|
|
76
86
|
"rollup": "^3.23.0",
|
|
77
87
|
"rollup-plugin-clear": "^2.0.7",
|
|
78
88
|
"rollup-plugin-postcss": "4.0.0",
|
|
@@ -83,16 +93,7 @@
|
|
|
83
93
|
"webpack": "^5.83.1",
|
|
84
94
|
"webpack-cli": "^5.1.1",
|
|
85
95
|
"webpack-dev-server": "^4.15.0",
|
|
86
|
-
"webpackbar": "^5.0.2"
|
|
87
|
-
"@ant-design/icons": "4.6.2",
|
|
88
|
-
"@ant-design/pro-table": "2.70.0",
|
|
89
|
-
"@hw-component/form": "^1.8.3",
|
|
90
|
-
"ahooks": "2.10.9",
|
|
91
|
-
"antd": "4.20.7",
|
|
92
|
-
"copy-to-clipboard": "3.3.1",
|
|
93
|
-
"react": "17.0.0",
|
|
94
|
-
"react-dom": "17.0.2",
|
|
95
|
-
"react-router-dom": "^6.11.2"
|
|
96
|
+
"webpackbar": "^5.0.2"
|
|
96
97
|
},
|
|
97
98
|
"publishConfig": {
|
|
98
99
|
"access": "public",
|
|
@@ -7,6 +7,7 @@ export default ({
|
|
|
7
7
|
dialogTable,
|
|
8
8
|
request,
|
|
9
9
|
contentRender,
|
|
10
|
+
dataSource,
|
|
10
11
|
}: ModalTableProps) => {
|
|
11
12
|
const node = (
|
|
12
13
|
<Table
|
|
@@ -15,6 +16,7 @@ export default ({
|
|
|
15
16
|
table={dialogTable}
|
|
16
17
|
request={request}
|
|
17
18
|
affixProps={false}
|
|
19
|
+
dataSource={dataSource}
|
|
18
20
|
/>
|
|
19
21
|
);
|
|
20
22
|
return <>{contentRender ? contentRender(node) : node}</>;
|
|
@@ -29,12 +29,18 @@ export default ({
|
|
|
29
29
|
show: (showParams) => {
|
|
30
30
|
if (showParams) {
|
|
31
31
|
setModalTableParams((oldParams) => {
|
|
32
|
-
const { configData,
|
|
32
|
+
const { configData,
|
|
33
|
+
request,
|
|
34
|
+
title,
|
|
35
|
+
params: oldP ,
|
|
36
|
+
dataSource:oldDataSource
|
|
37
|
+
} = oldParams;
|
|
33
38
|
const {
|
|
34
39
|
title: showTitle = title,
|
|
35
40
|
configData: showConfigData = configData,
|
|
36
41
|
request: showReq = request,
|
|
37
42
|
params = oldP,
|
|
43
|
+
dataSource=oldDataSource
|
|
38
44
|
} = showParams;
|
|
39
45
|
currentTable.params = params;
|
|
40
46
|
return {
|
|
@@ -42,6 +48,7 @@ export default ({
|
|
|
42
48
|
request: showReq,
|
|
43
49
|
configData: showConfigData,
|
|
44
50
|
params,
|
|
51
|
+
dataSource
|
|
45
52
|
};
|
|
46
53
|
});
|
|
47
54
|
}
|
|
@@ -52,7 +59,7 @@ export default ({
|
|
|
52
59
|
},
|
|
53
60
|
dialogTable,
|
|
54
61
|
});
|
|
55
|
-
const { configData, request, title, params } = modalTableParams;
|
|
62
|
+
const { configData, request,dataSource, title, params } = modalTableParams;
|
|
56
63
|
const req = request
|
|
57
64
|
? (reqParams) => {
|
|
58
65
|
return request({ ...params, ...reqParams });
|
|
@@ -94,6 +101,7 @@ export default ({
|
|
|
94
101
|
configData={configData || []}
|
|
95
102
|
dialogTable={currentTable}
|
|
96
103
|
request={req}
|
|
104
|
+
dataSource={dataSource}
|
|
97
105
|
/>
|
|
98
106
|
</Drawer>
|
|
99
107
|
);
|
|
@@ -26,11 +26,18 @@ export default ({
|
|
|
26
26
|
show: (showParams) => {
|
|
27
27
|
if (showParams) {
|
|
28
28
|
setModalTableParams((oldParams) => {
|
|
29
|
-
const {
|
|
29
|
+
const {
|
|
30
|
+
configData,
|
|
31
|
+
request,
|
|
32
|
+
title,
|
|
33
|
+
params: oldP,
|
|
34
|
+
dataSource:oldDataSource,
|
|
35
|
+
} = oldParams;
|
|
30
36
|
const {
|
|
31
37
|
title: showTitle = title,
|
|
32
38
|
configData: showConfigData = configData,
|
|
33
39
|
request: showReq = request,
|
|
40
|
+
dataSource=oldDataSource,
|
|
34
41
|
params = oldP,
|
|
35
42
|
} = showParams;
|
|
36
43
|
currentTable.params = params;
|
|
@@ -39,6 +46,7 @@ export default ({
|
|
|
39
46
|
request: showReq,
|
|
40
47
|
configData: showConfigData,
|
|
41
48
|
params,
|
|
49
|
+
dataSource
|
|
42
50
|
};
|
|
43
51
|
});
|
|
44
52
|
}
|
|
@@ -50,7 +58,7 @@ export default ({
|
|
|
50
58
|
dialogTable,
|
|
51
59
|
});
|
|
52
60
|
|
|
53
|
-
const { configData, request, title, params } = modalTableParams;
|
|
61
|
+
const { configData,dataSource, request, title, params } = modalTableParams;
|
|
54
62
|
const req = request
|
|
55
63
|
? (reqParams) => {
|
|
56
64
|
return request({ ...params, ...reqParams });
|
|
@@ -80,6 +88,7 @@ export default ({
|
|
|
80
88
|
configData={configData || []}
|
|
81
89
|
dialogTable={currentTable}
|
|
82
90
|
request={req}
|
|
91
|
+
dataSource={dataSource}
|
|
83
92
|
/>
|
|
84
93
|
</Modal>
|
|
85
94
|
);
|
|
@@ -26,12 +26,14 @@ export const useTableProps = ({
|
|
|
26
26
|
params,
|
|
27
27
|
title,
|
|
28
28
|
request,
|
|
29
|
+
dataSource,
|
|
29
30
|
}: Omit<ModalTableProps, "tableProps">) => {
|
|
30
31
|
const [modalTableParams, setModalTableParams] = useState({
|
|
31
32
|
params,
|
|
32
33
|
title,
|
|
33
34
|
configData,
|
|
34
35
|
request,
|
|
36
|
+
dataSource,
|
|
35
37
|
});
|
|
36
38
|
return {
|
|
37
39
|
modalTableParams,
|
package/src/components/Table.tsx
CHANGED
|
@@ -29,12 +29,16 @@ export default ({
|
|
|
29
29
|
labelWidth,
|
|
30
30
|
onReset,
|
|
31
31
|
style,
|
|
32
|
+
dataSource,
|
|
33
|
+
reload,
|
|
32
34
|
...props
|
|
33
35
|
}: HTableProps) => {
|
|
34
36
|
const { run, loading, data, error, saveParams } = useReq({
|
|
35
37
|
request,
|
|
36
38
|
manual,
|
|
37
39
|
formInitValues,
|
|
40
|
+
dataSource,
|
|
41
|
+
reload
|
|
38
42
|
});
|
|
39
43
|
const dispatch = useDispatch(action);
|
|
40
44
|
const { selectedRowData, rowOnChange, allSelectChange, setSelectedRowData } =
|
|
@@ -84,10 +88,8 @@ export default ({
|
|
|
84
88
|
labelWidth,
|
|
85
89
|
}}
|
|
86
90
|
>
|
|
87
|
-
<
|
|
88
|
-
|
|
89
|
-
size={0}
|
|
90
|
-
style={{ width: "100%" ,...style}}
|
|
91
|
+
<div
|
|
92
|
+
style={{ ...style}}
|
|
91
93
|
className={`${contentClassName} ${className}`}
|
|
92
94
|
>
|
|
93
95
|
{!hideHeader && (
|
|
@@ -107,7 +109,7 @@ export default ({
|
|
|
107
109
|
rowKey={rowKey}
|
|
108
110
|
{...props}
|
|
109
111
|
/>
|
|
110
|
-
</
|
|
112
|
+
</div>
|
|
111
113
|
</HTableContext.Provider>
|
|
112
114
|
);
|
|
113
115
|
};
|
|
@@ -1,15 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
1
|
+
import {useEffect, useMemo, useState} from "react";
|
|
2
|
+
import {useRequest} from "ahooks";
|
|
3
|
+
import type {ParamsModal, ResultModal} from "../modal";
|
|
4
|
+
|
|
4
5
|
export interface IParamsModal {
|
|
5
6
|
request?: (params: ParamsModal) => Promise<ResultModal>;
|
|
6
7
|
loading?: boolean;
|
|
7
8
|
error?: Error;
|
|
8
9
|
reload?: (params: any) => Promise<any>;
|
|
9
|
-
dataSource?: any;
|
|
10
|
+
dataSource?: ResultModal|any[];
|
|
10
11
|
manual?: boolean;
|
|
11
12
|
formInitValues?: Record<string, any>;
|
|
12
13
|
}
|
|
14
|
+
const defaultDataSource={
|
|
15
|
+
records:[],
|
|
16
|
+
total:"0",
|
|
17
|
+
size:"0",
|
|
18
|
+
current:"1"
|
|
19
|
+
}
|
|
20
|
+
const useDataSource=({reload,dataSource}:IParamsModal)=>{
|
|
21
|
+
const [cpDataSource,setCpDataSource]=useState<ResultModal>({
|
|
22
|
+
...defaultDataSource
|
|
23
|
+
});
|
|
24
|
+
const localMaker=(params)=>{
|
|
25
|
+
const {size,current}=params;
|
|
26
|
+
const ps=Number.parseInt(size);
|
|
27
|
+
const pn=Number.parseInt(current);
|
|
28
|
+
const prvPn=pn-1;
|
|
29
|
+
const arrDataSource=(dataSource as any[]);
|
|
30
|
+
const records=arrDataSource.slice(prvPn*ps,pn*ps);
|
|
31
|
+
const total=arrDataSource.length;
|
|
32
|
+
return {
|
|
33
|
+
records,
|
|
34
|
+
size,
|
|
35
|
+
current,
|
|
36
|
+
total:total.toString()
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const defaultReload=(params)=>{
|
|
40
|
+
if (Array.isArray(dataSource)){
|
|
41
|
+
console.warn("@hw-component/table:非受控模式reload将不起作用");
|
|
42
|
+
setCpDataSource(localMaker(params));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
reload?.(params);
|
|
46
|
+
}
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (Array.isArray(dataSource)){
|
|
49
|
+
setCpDataSource((old)=>{
|
|
50
|
+
return localMaker(old);
|
|
51
|
+
})
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setCpDataSource(dataSource||{...defaultDataSource});
|
|
55
|
+
}, [dataSource]);
|
|
56
|
+
return {
|
|
57
|
+
reload:defaultReload,
|
|
58
|
+
dataSource:cpDataSource
|
|
59
|
+
}
|
|
60
|
+
}
|
|
13
61
|
export default ({
|
|
14
62
|
request,
|
|
15
63
|
loading,
|
|
@@ -24,11 +72,12 @@ export default ({
|
|
|
24
72
|
old: {},
|
|
25
73
|
};
|
|
26
74
|
}, []);
|
|
75
|
+
const {reload:localReload,dataSource:localDataSource}=useDataSource({reload,dataSource})
|
|
27
76
|
const reloadFn = async (params: Record<string, any> = {}) => {
|
|
28
77
|
const { size = "10", current = "1", ...oParams } = params;
|
|
29
|
-
const
|
|
30
|
-
saveParams.old =
|
|
31
|
-
return
|
|
78
|
+
const requestParams={size, current, ...oParams};
|
|
79
|
+
saveParams.old = requestParams
|
|
80
|
+
return localReload(requestParams);
|
|
32
81
|
};
|
|
33
82
|
const resultAction = useRequest(
|
|
34
83
|
(params = {}) => {
|
|
@@ -60,7 +109,7 @@ export default ({
|
|
|
60
109
|
return {
|
|
61
110
|
loading,
|
|
62
111
|
error,
|
|
63
|
-
data:
|
|
112
|
+
data: localDataSource,
|
|
64
113
|
run: reloadFn,
|
|
65
114
|
saveParams,
|
|
66
115
|
};
|
package/src/components/modal.ts
CHANGED
|
@@ -98,7 +98,7 @@ export interface HTableProps
|
|
|
98
98
|
error?: Error;
|
|
99
99
|
reload?: (params: any) => Promise<any>;
|
|
100
100
|
manual?: boolean;
|
|
101
|
-
dataSource?: ResultModal;
|
|
101
|
+
dataSource?: ResultModal|any[];
|
|
102
102
|
paginationStyle?: React.CSSProperties;
|
|
103
103
|
allPageCheck?: boolean;
|
|
104
104
|
rowSelection?: HRowSelection | false;
|
|
@@ -136,6 +136,7 @@ export interface DialogParamsModal {
|
|
|
136
136
|
request?: HTableProps["request"];
|
|
137
137
|
params?: Record<string, any>;
|
|
138
138
|
title?: string | React.ReactNode;
|
|
139
|
+
dataSource?:any[];
|
|
139
140
|
}
|
|
140
141
|
export interface HOnDiaLogTableInstance {
|
|
141
142
|
show: (params?: DialogParamsModal) => void;
|
|
@@ -164,6 +165,7 @@ export interface ModalTableProps extends ModalProps {
|
|
|
164
165
|
configData?: HTableProps["configData"];
|
|
165
166
|
request?: HTableProps["request"];
|
|
166
167
|
contentRender?: (node: React.ReactNode) => React.ReactNode;
|
|
168
|
+
dataSource?:any[];
|
|
167
169
|
}
|
|
168
170
|
|
|
169
171
|
export type ValueTypeConfigRenderFn = (
|
|
@@ -119,6 +119,17 @@ const Test = () => {
|
|
|
119
119
|
</>
|
|
120
120
|
);
|
|
121
121
|
};
|
|
122
|
+
const maker=(name)=>{
|
|
123
|
+
const data=[];
|
|
124
|
+
for (let i=0;i<10;i+=1){
|
|
125
|
+
data.push({
|
|
126
|
+
name,
|
|
127
|
+
id:i
|
|
128
|
+
})
|
|
129
|
+
};
|
|
130
|
+
return data;
|
|
131
|
+
}
|
|
132
|
+
let num=0;
|
|
122
133
|
export default () => {
|
|
123
134
|
const dialogTable = useHDialogTable();
|
|
124
135
|
const dialogTable1 = useHDialogTable();
|
|
@@ -126,14 +137,17 @@ export default () => {
|
|
|
126
137
|
<>
|
|
127
138
|
<Button
|
|
128
139
|
onClick={() => {
|
|
129
|
-
|
|
140
|
+
num++
|
|
141
|
+
dialogTable.show({
|
|
142
|
+
title: "3333",
|
|
143
|
+
dataSource:[...maker(`第${num}一页`),...maker("第二页"),...maker("第三页")]
|
|
144
|
+
});
|
|
130
145
|
}}
|
|
131
146
|
>
|
|
132
147
|
点我333
|
|
133
148
|
</Button>
|
|
134
149
|
<HDwTable
|
|
135
150
|
dialogTable={dialogTable}
|
|
136
|
-
request={req2}
|
|
137
151
|
width={1200}
|
|
138
152
|
configData={configData}
|
|
139
153
|
tableProps={{
|
|
@@ -119,6 +119,16 @@ const Test = () => {
|
|
|
119
119
|
</>
|
|
120
120
|
);
|
|
121
121
|
};
|
|
122
|
+
const maker=(name)=>{
|
|
123
|
+
const data=[];
|
|
124
|
+
for (let i=0;i<10;i+=1){
|
|
125
|
+
data.push({
|
|
126
|
+
name,
|
|
127
|
+
id:i
|
|
128
|
+
})
|
|
129
|
+
};
|
|
130
|
+
return data;
|
|
131
|
+
}
|
|
122
132
|
export default () => {
|
|
123
133
|
const dialogTable = useHDialogTable();
|
|
124
134
|
const dialogTable1 = useHDialogTable();
|
|
@@ -126,14 +136,16 @@ export default () => {
|
|
|
126
136
|
<>
|
|
127
137
|
<Button
|
|
128
138
|
onClick={() => {
|
|
129
|
-
dialogTable.show({
|
|
139
|
+
dialogTable.show({
|
|
140
|
+
title: "3333",
|
|
141
|
+
dataSource:[...maker("第一页"),...maker("第二页"),...maker("第三页")]
|
|
142
|
+
});
|
|
130
143
|
}}
|
|
131
144
|
>
|
|
132
145
|
点我333
|
|
133
146
|
</Button>
|
|
134
147
|
<HModalTable
|
|
135
148
|
dialogTable={dialogTable}
|
|
136
|
-
request={req2}
|
|
137
149
|
width={1200}
|
|
138
150
|
configData={configData}
|
|
139
151
|
tableProps={{
|