@hw-component/form 1.9.28 → 1.9.30
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.
|
@@ -2,6 +2,7 @@ import { TreeSelectProps } from "antd/lib/tree-select";
|
|
|
2
2
|
import { PromiseFnResult } from "../modal";
|
|
3
3
|
interface IProps extends TreeSelectProps {
|
|
4
4
|
request?: PromiseFnResult;
|
|
5
|
+
onlyCheckChild?: boolean;
|
|
5
6
|
}
|
|
6
|
-
declare const _default: ({ request, treeData, ...props }: IProps) => JSX.Element;
|
|
7
|
+
declare const _default: ({ request, onlyCheckChild, multiple, treeCheckable, treeData, fieldNames, ...props }: IProps) => JSX.Element;
|
|
7
8
|
export default _default;
|
package/es/Select/TreeSelect.js
CHANGED
|
@@ -1,28 +1,81 @@
|
|
|
1
1
|
// welcome to hoo hoo hoo
|
|
2
|
-
import
|
|
2
|
+
import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
|
|
3
3
|
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
|
|
4
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
|
|
5
|
+
import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
|
|
4
6
|
import { jsx } from 'react/jsx-runtime';
|
|
5
7
|
import { TreeSelect } from 'antd';
|
|
6
8
|
import { useRequest } from 'ahooks';
|
|
7
9
|
|
|
8
|
-
var _excluded = ["request", "treeData"];
|
|
10
|
+
var _excluded = ["request", "onlyCheckChild", "multiple", "treeCheckable", "treeData", "fieldNames"];
|
|
9
11
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
12
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
var _opMk = function opMk(_ref) {
|
|
14
|
+
var options = _ref.options,
|
|
15
|
+
_ref$onlyCheckChild = _ref.onlyCheckChild,
|
|
16
|
+
onlyCheckChild = _ref$onlyCheckChild === void 0 ? false : _ref$onlyCheckChild,
|
|
17
|
+
fieldNames = _ref.fieldNames;
|
|
18
|
+
var _ref2 = fieldNames || {},
|
|
19
|
+
_ref2$children = _ref2.children,
|
|
20
|
+
children = _ref2$children === void 0 ? "children" : _ref2$children;
|
|
21
|
+
return options === null || options === void 0 ? void 0 : options.map(function (item) {
|
|
22
|
+
var child = item[children];
|
|
23
|
+
var len = child === null || child === void 0 ? void 0 : child.length;
|
|
24
|
+
if (!len) {
|
|
25
|
+
return _objectSpread({}, item);
|
|
26
|
+
}
|
|
27
|
+
var newChild = _opMk({
|
|
28
|
+
options: child,
|
|
29
|
+
onlyCheckChild: onlyCheckChild,
|
|
30
|
+
fieldNames: fieldNames
|
|
31
|
+
});
|
|
32
|
+
return _objectSpread(_objectSpread({}, item), {}, _defineProperty({
|
|
33
|
+
selectable: !onlyCheckChild
|
|
34
|
+
}, children, newChild));
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var HTreeSelect = (function (_ref3) {
|
|
38
|
+
var request = _ref3.request,
|
|
39
|
+
onlyCheckChild = _ref3.onlyCheckChild,
|
|
40
|
+
multiple = _ref3.multiple,
|
|
41
|
+
treeCheckable = _ref3.treeCheckable,
|
|
42
|
+
treeData = _ref3.treeData,
|
|
43
|
+
fieldNames = _ref3.fieldNames,
|
|
44
|
+
props = _objectWithoutProperties(_ref3, _excluded);
|
|
45
|
+
var _useRequest = useRequest(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
46
|
+
var options;
|
|
47
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
48
|
+
while (1) switch (_context.prev = _context.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
options = treeData;
|
|
51
|
+
if (!request) {
|
|
52
|
+
_context.next = 5;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
_context.next = 4;
|
|
56
|
+
return request({});
|
|
57
|
+
case 4:
|
|
58
|
+
options = _context.sent;
|
|
59
|
+
case 5:
|
|
60
|
+
return _context.abrupt("return", _opMk({
|
|
61
|
+
options: options,
|
|
62
|
+
onlyCheckChild: onlyCheckChild,
|
|
63
|
+
fieldNames: fieldNames
|
|
64
|
+
}));
|
|
65
|
+
case 6:
|
|
66
|
+
case "end":
|
|
67
|
+
return _context.stop();
|
|
68
|
+
}
|
|
69
|
+
}, _callee);
|
|
70
|
+
}))),
|
|
21
71
|
loading = _useRequest.loading,
|
|
22
72
|
data = _useRequest.data;
|
|
23
73
|
return jsx(TreeSelect, _objectSpread({
|
|
24
74
|
treeData: data,
|
|
25
|
-
loading: loading
|
|
75
|
+
loading: loading,
|
|
76
|
+
fieldNames: fieldNames,
|
|
77
|
+
treeCheckable: treeCheckable,
|
|
78
|
+
multiple: multiple
|
|
26
79
|
}, props));
|
|
27
80
|
});
|
|
28
81
|
|
|
@@ -2,6 +2,7 @@ import { TreeSelectProps } from "antd/lib/tree-select";
|
|
|
2
2
|
import { PromiseFnResult } from "../modal";
|
|
3
3
|
interface IProps extends TreeSelectProps {
|
|
4
4
|
request?: PromiseFnResult;
|
|
5
|
+
onlyCheckChild?: boolean;
|
|
5
6
|
}
|
|
6
|
-
declare const _default: ({ request, treeData, ...props }: IProps) => JSX.Element;
|
|
7
|
+
declare const _default: ({ request, onlyCheckChild, multiple, treeCheckable, treeData, fieldNames, ...props }: IProps) => JSX.Element;
|
|
7
8
|
export default _default;
|
package/lib/Select/TreeSelect.js
CHANGED
|
@@ -2,30 +2,83 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
6
6
|
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
7
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
8
|
+
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
7
9
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
10
|
var antd = require('antd');
|
|
9
11
|
var ahooks = require('ahooks');
|
|
10
12
|
|
|
11
|
-
var _excluded = ["request", "treeData"];
|
|
13
|
+
var _excluded = ["request", "onlyCheckChild", "multiple", "treeCheckable", "treeData", "fieldNames"];
|
|
12
14
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
15
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
var _opMk = function opMk(_ref) {
|
|
17
|
+
var options = _ref.options,
|
|
18
|
+
_ref$onlyCheckChild = _ref.onlyCheckChild,
|
|
19
|
+
onlyCheckChild = _ref$onlyCheckChild === void 0 ? false : _ref$onlyCheckChild,
|
|
20
|
+
fieldNames = _ref.fieldNames;
|
|
21
|
+
var _ref2 = fieldNames || {},
|
|
22
|
+
_ref2$children = _ref2.children,
|
|
23
|
+
children = _ref2$children === void 0 ? "children" : _ref2$children;
|
|
24
|
+
return options === null || options === void 0 ? void 0 : options.map(function (item) {
|
|
25
|
+
var child = item[children];
|
|
26
|
+
var len = child === null || child === void 0 ? void 0 : child.length;
|
|
27
|
+
if (!len) {
|
|
28
|
+
return _objectSpread({}, item);
|
|
29
|
+
}
|
|
30
|
+
var newChild = _opMk({
|
|
31
|
+
options: child,
|
|
32
|
+
onlyCheckChild: onlyCheckChild,
|
|
33
|
+
fieldNames: fieldNames
|
|
34
|
+
});
|
|
35
|
+
return _objectSpread(_objectSpread({}, item), {}, _defineProperty({
|
|
36
|
+
selectable: !onlyCheckChild
|
|
37
|
+
}, children, newChild));
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
var HTreeSelect = (function (_ref3) {
|
|
41
|
+
var request = _ref3.request,
|
|
42
|
+
onlyCheckChild = _ref3.onlyCheckChild,
|
|
43
|
+
multiple = _ref3.multiple,
|
|
44
|
+
treeCheckable = _ref3.treeCheckable,
|
|
45
|
+
treeData = _ref3.treeData,
|
|
46
|
+
fieldNames = _ref3.fieldNames,
|
|
47
|
+
props = _objectWithoutProperties(_ref3, _excluded);
|
|
48
|
+
var _useRequest = ahooks.useRequest(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
49
|
+
var options;
|
|
50
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
51
|
+
while (1) switch (_context.prev = _context.next) {
|
|
52
|
+
case 0:
|
|
53
|
+
options = treeData;
|
|
54
|
+
if (!request) {
|
|
55
|
+
_context.next = 5;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
_context.next = 4;
|
|
59
|
+
return request({});
|
|
60
|
+
case 4:
|
|
61
|
+
options = _context.sent;
|
|
62
|
+
case 5:
|
|
63
|
+
return _context.abrupt("return", _opMk({
|
|
64
|
+
options: options,
|
|
65
|
+
onlyCheckChild: onlyCheckChild,
|
|
66
|
+
fieldNames: fieldNames
|
|
67
|
+
}));
|
|
68
|
+
case 6:
|
|
69
|
+
case "end":
|
|
70
|
+
return _context.stop();
|
|
71
|
+
}
|
|
72
|
+
}, _callee);
|
|
73
|
+
}))),
|
|
24
74
|
loading = _useRequest.loading,
|
|
25
75
|
data = _useRequest.data;
|
|
26
76
|
return jsxRuntime.jsx(antd.TreeSelect, _objectSpread({
|
|
27
77
|
treeData: data,
|
|
28
|
-
loading: loading
|
|
78
|
+
loading: loading,
|
|
79
|
+
fieldNames: fieldNames,
|
|
80
|
+
treeCheckable: treeCheckable,
|
|
81
|
+
multiple: multiple
|
|
29
82
|
}, props));
|
|
30
83
|
});
|
|
31
84
|
|
package/package.json
CHANGED
|
@@ -4,13 +4,47 @@ import { PromiseFnResult } from "../modal";
|
|
|
4
4
|
import { useRequest } from "ahooks";
|
|
5
5
|
interface IProps extends TreeSelectProps {
|
|
6
6
|
request?: PromiseFnResult;
|
|
7
|
+
onlyCheckChild?:boolean;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
interface OpMkParamsModal {
|
|
10
|
+
options?:any[];
|
|
11
|
+
onlyCheckChild?:boolean;
|
|
12
|
+
fieldNames?:TreeSelectProps["fieldNames"]
|
|
13
|
+
}
|
|
14
|
+
const opMk=({options,onlyCheckChild=false,fieldNames}:OpMkParamsModal)=>{
|
|
15
|
+
const {children="children"}=fieldNames||{}
|
|
16
|
+
return options?.map((item)=>{
|
|
17
|
+
const {[children]:child}=item;
|
|
18
|
+
const len=child?.length;
|
|
19
|
+
if (!len){
|
|
20
|
+
return {
|
|
21
|
+
...item
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const newChild=opMk({options:child,onlyCheckChild,fieldNames});
|
|
25
|
+
return {
|
|
26
|
+
...item,
|
|
27
|
+
selectable:!onlyCheckChild,
|
|
28
|
+
[children]:newChild
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
export default ({ request,onlyCheckChild,multiple,treeCheckable,treeData,fieldNames, ...props }: IProps) => {
|
|
33
|
+
const { loading, data } = useRequest(async () => {
|
|
34
|
+
let options=treeData;
|
|
10
35
|
if (request) {
|
|
11
|
-
|
|
36
|
+
options=await request({});
|
|
12
37
|
}
|
|
13
|
-
return
|
|
38
|
+
return opMk({
|
|
39
|
+
options,
|
|
40
|
+
onlyCheckChild:onlyCheckChild,
|
|
41
|
+
fieldNames
|
|
42
|
+
});
|
|
14
43
|
});
|
|
15
|
-
return <TreeSelect treeData={data}
|
|
44
|
+
return <TreeSelect treeData={data}
|
|
45
|
+
loading={loading}
|
|
46
|
+
fieldNames={fieldNames}
|
|
47
|
+
treeCheckable={treeCheckable}
|
|
48
|
+
multiple={multiple}
|
|
49
|
+
{...props}/>;
|
|
16
50
|
};
|