@lemon-fe/kits 0.1.148 → 0.1.149
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.
|
@@ -1,14 +1,34 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
1
2
|
import type { Key } from 'react';
|
|
2
3
|
import type { ColumnType, BaseTableProps } from '@lemon-fe/components';
|
|
3
|
-
declare type Result = void | string | Error | symbol;
|
|
4
|
-
export default function useBatchOperate<RecordType = Record<string, any
|
|
4
|
+
declare type Result<ResultType = unknown> = void | string | Error | symbol | ResultType;
|
|
5
|
+
export default function useBatchOperate<RecordType = Record<string, any>, ResultType = unknown>(options: {
|
|
5
6
|
modalTitle: string;
|
|
6
|
-
handler: (record: RecordType) => Promise<string | void>;
|
|
7
|
+
handler: (record: RecordType) => Promise<string | void | ResultType>;
|
|
7
8
|
columns?: ColumnType<RecordType>[];
|
|
8
9
|
rowKey?: BaseTableProps<RecordType>['rowKey'];
|
|
9
|
-
onClose?: (results: Map<Key, Result
|
|
10
|
+
onClose?: (results: Map<Key, Result<ResultType>>) => void;
|
|
10
11
|
/** 弹窗关闭前的检验,返回true校验通过关闭弹窗,false校验不通过 */
|
|
11
|
-
onBeforeClose?: (results: Map<Key, Result
|
|
12
|
+
onBeforeClose?: (results: Map<Key, Result<ResultType>>) => Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* 自定义渲染结果,不要依赖上下文
|
|
15
|
+
* @param params
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
renderResult?: (params: {
|
|
19
|
+
data: RecordType;
|
|
20
|
+
result: ResultType;
|
|
21
|
+
/**
|
|
22
|
+
* 显示用的节点
|
|
23
|
+
*/
|
|
24
|
+
elements: {
|
|
25
|
+
reloadButton: ReactElement;
|
|
26
|
+
failIcon: ReactElement;
|
|
27
|
+
successIcon: ReactElement;
|
|
28
|
+
};
|
|
29
|
+
reload: () => any;
|
|
30
|
+
}) => ReactElement | string | number | null;
|
|
31
|
+
isError?: () => boolean;
|
|
12
32
|
}): {
|
|
13
33
|
node: JSX.Element;
|
|
14
34
|
run: (data: RecordType[]) => void;
|
|
@@ -26,7 +26,8 @@ export default function useBatchOperate(options) {
|
|
|
26
26
|
columns = options.columns,
|
|
27
27
|
onClose = options.onClose,
|
|
28
28
|
onBeforeClose = options.onBeforeClose,
|
|
29
|
-
rowKey = options.rowKey
|
|
29
|
+
rowKey = options.rowKey,
|
|
30
|
+
renderResult = options.renderResult;
|
|
30
31
|
var _useState = useState(false),
|
|
31
32
|
_useState2 = _slicedToArray(_useState, 2),
|
|
32
33
|
visible = _useState2[0],
|
|
@@ -133,13 +134,35 @@ export default function useBatchOperate(options) {
|
|
|
133
134
|
type: "error"
|
|
134
135
|
}), /*#__PURE__*/React.createElement("span", null, " ", result.message, " "), /*#__PURE__*/React.createElement(ReloadOutlined, {
|
|
135
136
|
onClick: function onClick() {
|
|
136
|
-
return
|
|
137
|
+
return _reload(record, index);
|
|
137
138
|
}
|
|
138
139
|
}));
|
|
139
140
|
}
|
|
141
|
+
if (renderResult !== undefined) {
|
|
142
|
+
return renderResult({
|
|
143
|
+
data: record,
|
|
144
|
+
result: result,
|
|
145
|
+
elements: {
|
|
146
|
+
failIcon: /*#__PURE__*/React.createElement(Icons.Tip, {
|
|
147
|
+
type: "error"
|
|
148
|
+
}),
|
|
149
|
+
successIcon: /*#__PURE__*/React.createElement(Icons.Tip, {
|
|
150
|
+
type: "success"
|
|
151
|
+
}),
|
|
152
|
+
reloadButton: /*#__PURE__*/React.createElement(ReloadOutlined, {
|
|
153
|
+
onClick: function onClick() {
|
|
154
|
+
return _reload(record, key);
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
},
|
|
158
|
+
reload: function reload() {
|
|
159
|
+
_reload(record, key);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
140
163
|
return /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Icons.Tip, {
|
|
141
164
|
type: "success"
|
|
142
|
-
}), /*#__PURE__*/React.createElement("span", null, " ", result
|
|
165
|
+
}), /*#__PURE__*/React.createElement("span", null, " ", typeof result === 'string' ? result : '操作成功'));
|
|
143
166
|
}
|
|
144
167
|
});
|
|
145
168
|
return cols;
|
|
@@ -153,7 +176,7 @@ export default function useBatchOperate(options) {
|
|
|
153
176
|
});
|
|
154
177
|
}
|
|
155
178
|
};
|
|
156
|
-
var
|
|
179
|
+
var _reload = useThrottle( /*#__PURE__*/function () {
|
|
157
180
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(item, index) {
|
|
158
181
|
var key, res;
|
|
159
182
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon-fe/kits",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.149",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "鲁盛杰 <lusj@cnlemon.net>",
|
|
6
6
|
"homepage": "",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "b600fe78bf85069df4b7f4f541e9bda8bbed0f53"
|
|
36
36
|
}
|