@hw-component/form 1.9.86 → 1.9.88
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/.eslintcache +1 -1
- package/es/Form/config.d.ts +2 -1
- package/es/Form/config.js +3 -1
- package/es/Select/TagSelect/Content.d.ts +7 -0
- package/es/Select/TagSelect/Content.js +90 -0
- package/es/Select/TagSelect/hooks.d.ts +14 -0
- package/es/Select/TagSelect/hooks.js +122 -0
- package/es/Select/TagSelect/index.d.ts +3 -0
- package/es/Select/TagSelect/index.js +110 -0
- package/es/Select/index.js +0 -1
- package/es/Select/modal.d.ts +8 -1
- package/es/index.css +15 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/lib/Form/config.d.ts +2 -1
- package/lib/Form/config.js +3 -1
- package/lib/Select/TagSelect/Content.d.ts +7 -0
- package/lib/Select/TagSelect/Content.js +93 -0
- package/lib/Select/TagSelect/hooks.d.ts +14 -0
- package/lib/Select/TagSelect/hooks.js +125 -0
- package/lib/Select/TagSelect/index.d.ts +3 -0
- package/lib/Select/TagSelect/index.js +113 -0
- package/lib/Select/index.js +0 -1
- package/lib/Select/modal.d.ts +8 -1
- package/lib/index.css +15 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -0
- package/package.json +1 -1
- package/src/components/Form/config.ts +2 -1
- package/src/components/Form/index.less +6 -0
- package/src/components/Select/TagSelect/Content.tsx +50 -0
- package/src/components/Select/TagSelect/hooks.ts +102 -0
- package/src/components/Select/TagSelect/index.tsx +79 -0
- package/src/components/Select/index.less +13 -0
- package/src/components/Select/index.tsx +0 -1
- package/src/components/Select/modal.ts +9 -1
- package/src/components/index.tsx +2 -0
- package/src/pages/Form/index.tsx +149 -132
- package/src/pages/Select/index.tsx +32 -5
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
4
|
+
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
var useTagControl = function useTagControl(_ref) {
|
|
8
|
+
var value = _ref.value,
|
|
9
|
+
options = _ref.options,
|
|
10
|
+
title = _ref.title;
|
|
11
|
+
var _useMemo = React.useMemo(function () {
|
|
12
|
+
var len = value === null || value === void 0 ? void 0 : value.length;
|
|
13
|
+
var opLen = options === null || options === void 0 ? void 0 : options.length;
|
|
14
|
+
if (!opLen) {
|
|
15
|
+
return {
|
|
16
|
+
checked: false
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (len === opLen) {
|
|
20
|
+
return {
|
|
21
|
+
checked: true
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
indeterminate: !!len
|
|
26
|
+
};
|
|
27
|
+
}, [value, options]),
|
|
28
|
+
checked = _useMemo.checked,
|
|
29
|
+
indeterminate = _useMemo.indeterminate;
|
|
30
|
+
var labelNode = React.useMemo(function () {
|
|
31
|
+
if (title) {
|
|
32
|
+
return title;
|
|
33
|
+
}
|
|
34
|
+
if (checked) {
|
|
35
|
+
return "取消";
|
|
36
|
+
}
|
|
37
|
+
return "全选";
|
|
38
|
+
}, [title, checked, indeterminate]);
|
|
39
|
+
return {
|
|
40
|
+
labelNode: labelNode,
|
|
41
|
+
checked: checked,
|
|
42
|
+
indeterminate: indeterminate
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
var useChangeControl = function useChangeControl(_ref2) {
|
|
46
|
+
var options = _ref2.options,
|
|
47
|
+
value = _ref2.value,
|
|
48
|
+
onChange = _ref2.onChange,
|
|
49
|
+
fieldNames = _ref2.fieldNames;
|
|
50
|
+
var _ref3 = fieldNames || {},
|
|
51
|
+
_ref3$value = _ref3.value,
|
|
52
|
+
valueKey = _ref3$value === void 0 ? "value" : _ref3$value;
|
|
53
|
+
var optsNk = function optsNk(newVal) {
|
|
54
|
+
var newOpts = [];
|
|
55
|
+
newVal === null || newVal === void 0 || newVal.forEach(function (itemVal) {
|
|
56
|
+
var index = options === null || options === void 0 ? void 0 : options.findIndex(function (item) {
|
|
57
|
+
return itemVal === item[valueKey];
|
|
58
|
+
});
|
|
59
|
+
if (typeof index !== "undefined") {
|
|
60
|
+
newOpts.push(options === null || options === void 0 ? void 0 : options[index]);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return newOpts;
|
|
64
|
+
};
|
|
65
|
+
var checkedVal = function checkedVal(val) {
|
|
66
|
+
var newVal = _toConsumableArray(value);
|
|
67
|
+
newVal.push(val);
|
|
68
|
+
onChange === null || onChange === void 0 || onChange(newVal, optsNk(newVal));
|
|
69
|
+
};
|
|
70
|
+
var removeVal = function removeVal(index) {
|
|
71
|
+
var newVal = _toConsumableArray(value);
|
|
72
|
+
newVal.splice(index, 1);
|
|
73
|
+
onChange === null || onChange === void 0 || onChange(newVal, optsNk(newVal));
|
|
74
|
+
};
|
|
75
|
+
var change = function change(val) {
|
|
76
|
+
var index = value === null || value === void 0 ? void 0 : value.indexOf(val);
|
|
77
|
+
var checked = index === -1;
|
|
78
|
+
if (checked) {
|
|
79
|
+
return checkedVal(val);
|
|
80
|
+
}
|
|
81
|
+
return removeVal(index);
|
|
82
|
+
};
|
|
83
|
+
var allCheck = function allCheck(e) {
|
|
84
|
+
if (!e.target.checked) {
|
|
85
|
+
return onChange === null || onChange === void 0 ? void 0 : onChange([], []);
|
|
86
|
+
}
|
|
87
|
+
var newVal = options === null || options === void 0 ? void 0 : options.map(function (item) {
|
|
88
|
+
return item[valueKey];
|
|
89
|
+
});
|
|
90
|
+
return onChange === null || onChange === void 0 ? void 0 : onChange(newVal, options);
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
change: change,
|
|
94
|
+
allCheck: allCheck
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
var useCollapseControl = function useCollapseControl(_ref4) {
|
|
98
|
+
var visible = _ref4.visible,
|
|
99
|
+
defaultVisible = _ref4.defaultVisible,
|
|
100
|
+
onVisibleChange = _ref4.onVisibleChange;
|
|
101
|
+
var _useState = React.useState(defaultVisible ? ["1"] : []),
|
|
102
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
103
|
+
activeKey = _useState2[0],
|
|
104
|
+
setActiveKey = _useState2[1];
|
|
105
|
+
React.useEffect(function () {
|
|
106
|
+
if (typeof visible === "undefined") {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
setActiveKey(visible ? ["1"] : []);
|
|
110
|
+
}, [visible]);
|
|
111
|
+
var onChange = function onChange(keys) {
|
|
112
|
+
var len = keys === null || keys === void 0 ? void 0 : keys.length;
|
|
113
|
+
onVisibleChange === null || onVisibleChange === void 0 || onVisibleChange(!!len);
|
|
114
|
+
setActiveKey(keys);
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
activeKey: activeKey,
|
|
118
|
+
onChange: onChange
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
exports.useChangeControl = useChangeControl;
|
|
123
|
+
exports.useCollapseControl = useCollapseControl;
|
|
124
|
+
exports.useTagControl = useTagControl;
|
|
125
|
+
// powered by h
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
6
|
+
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var antd = require('antd');
|
|
9
|
+
var index = require('../../hooks/index.js');
|
|
10
|
+
var norHooks = require('../hooks/norHooks.js');
|
|
11
|
+
var Content = require('./Content.js');
|
|
12
|
+
var hooks = require('./hooks.js');
|
|
13
|
+
var HFormConnect = require('../../Form/HFormConnect.js');
|
|
14
|
+
|
|
15
|
+
var _excluded = ["children"];
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
var Panel = antd.Collapse.Panel;
|
|
19
|
+
var ItemTitle = function ItemTitle(_ref) {
|
|
20
|
+
var children = _ref.children,
|
|
21
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
22
|
+
return jsxRuntime.jsx("div", {
|
|
23
|
+
onClick: function onClick(event) {
|
|
24
|
+
event.stopPropagation();
|
|
25
|
+
},
|
|
26
|
+
children: jsxRuntime.jsx(antd.Checkbox, _objectSpread(_objectSpread({}, props), {}, {
|
|
27
|
+
children: children
|
|
28
|
+
}))
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
var Index = function Index(_ref2) {
|
|
32
|
+
var options = _ref2.options,
|
|
33
|
+
_ref2$value = _ref2.value,
|
|
34
|
+
value = _ref2$value === void 0 ? [] : _ref2$value,
|
|
35
|
+
onChange = _ref2.onChange,
|
|
36
|
+
dispatch = _ref2.dispatch,
|
|
37
|
+
propsFieldNames = _ref2.fieldNames,
|
|
38
|
+
request = _ref2.request,
|
|
39
|
+
title = _ref2.title,
|
|
40
|
+
manual = _ref2.manual,
|
|
41
|
+
_ref2$className = _ref2.className,
|
|
42
|
+
className = _ref2$className === void 0 ? "" : _ref2$className,
|
|
43
|
+
visible = _ref2.visible,
|
|
44
|
+
defaultVisible = _ref2.defaultVisible,
|
|
45
|
+
onVisibleChange = _ref2.onVisibleChange,
|
|
46
|
+
addDispatchListener = _ref2.addDispatchListener;
|
|
47
|
+
var collapseClassName = index.useClassName("hw-tag-select");
|
|
48
|
+
var _useMatchConfigProps = index.useMatchConfigProps({
|
|
49
|
+
fieldNames: propsFieldNames
|
|
50
|
+
}),
|
|
51
|
+
fieldNames = _useMatchConfigProps.fieldNames;
|
|
52
|
+
var _useCollapseControl = hooks.useCollapseControl({
|
|
53
|
+
defaultVisible: defaultVisible,
|
|
54
|
+
visible: visible,
|
|
55
|
+
onVisibleChange: onVisibleChange
|
|
56
|
+
}),
|
|
57
|
+
activeKey = _useCollapseControl.activeKey,
|
|
58
|
+
colChange = _useCollapseControl.onChange;
|
|
59
|
+
var _useSelectReq = norHooks.useSelectReq({
|
|
60
|
+
options: options,
|
|
61
|
+
manual: manual,
|
|
62
|
+
request: request,
|
|
63
|
+
dispatch: dispatch
|
|
64
|
+
}),
|
|
65
|
+
loading = _useSelectReq.loading,
|
|
66
|
+
resultData = _useSelectReq.data,
|
|
67
|
+
error = _useSelectReq.error,
|
|
68
|
+
reload = _useSelectReq.reload;
|
|
69
|
+
var _useTagControl = hooks.useTagControl({
|
|
70
|
+
value: value,
|
|
71
|
+
options: resultData,
|
|
72
|
+
title: title
|
|
73
|
+
}),
|
|
74
|
+
labelNode = _useTagControl.labelNode,
|
|
75
|
+
checked = _useTagControl.checked,
|
|
76
|
+
indeterminate = _useTagControl.indeterminate;
|
|
77
|
+
var _useChangeControl = hooks.useChangeControl({
|
|
78
|
+
value: value,
|
|
79
|
+
options: resultData,
|
|
80
|
+
onChange: onChange,
|
|
81
|
+
fieldNames: fieldNames
|
|
82
|
+
}),
|
|
83
|
+
allCheck = _useChangeControl.allCheck;
|
|
84
|
+
addDispatchListener === null || addDispatchListener === void 0 || addDispatchListener("reload", reload);
|
|
85
|
+
return jsxRuntime.jsx(antd.Collapse, {
|
|
86
|
+
bordered: false,
|
|
87
|
+
ghost: true,
|
|
88
|
+
activeKey: activeKey,
|
|
89
|
+
onChange: colChange,
|
|
90
|
+
className: "".concat(collapseClassName, " ").concat(className),
|
|
91
|
+
children: jsxRuntime.jsx(Panel, {
|
|
92
|
+
header: jsxRuntime.jsx(ItemTitle, {
|
|
93
|
+
indeterminate: indeterminate,
|
|
94
|
+
checked: checked,
|
|
95
|
+
onChange: allCheck,
|
|
96
|
+
children: labelNode
|
|
97
|
+
}),
|
|
98
|
+
children: jsxRuntime.jsx(Content.default, {
|
|
99
|
+
loading: loading,
|
|
100
|
+
options: resultData,
|
|
101
|
+
value: value,
|
|
102
|
+
error: error,
|
|
103
|
+
onChange: onChange,
|
|
104
|
+
reload: reload,
|
|
105
|
+
fieldNames: fieldNames
|
|
106
|
+
})
|
|
107
|
+
}, "1")
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
var HTagSelect = HFormConnect.default(Index);
|
|
111
|
+
|
|
112
|
+
exports.default = HTagSelect;
|
|
113
|
+
// powered by h
|
package/lib/Select/index.js
CHANGED
package/lib/Select/modal.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface OptionsPageResultModal {
|
|
|
21
21
|
total: number;
|
|
22
22
|
}
|
|
23
23
|
export type OptionsDataType = OptionsListType | OptionsPageResultModal;
|
|
24
|
-
export interface HSelectProps extends Omit<SelectProps, "options" | "placeholder"> {
|
|
24
|
+
export interface HSelectProps extends Omit<SelectProps, "options" | "placeholder" | "onChange"> {
|
|
25
25
|
style?: React.CSSProperties;
|
|
26
26
|
request?: PromiseFnResult<any, OptionsDataType>;
|
|
27
27
|
manual?: boolean;
|
|
@@ -38,10 +38,17 @@ export interface HSelectProps extends Omit<SelectProps, "options" | "placeholder
|
|
|
38
38
|
isList?: boolean;
|
|
39
39
|
addonBefore?: React.ReactNode;
|
|
40
40
|
addonAfter?: React.ReactNode;
|
|
41
|
+
onChange?: (value: any, opts?: OptionType[] | OptionType) => void;
|
|
41
42
|
}
|
|
42
43
|
export interface FilterDataModal {
|
|
43
44
|
value: any;
|
|
44
45
|
index: number;
|
|
45
46
|
}
|
|
47
|
+
export interface HTagSelectProps extends HSelectProps {
|
|
48
|
+
title?: React.ReactNode;
|
|
49
|
+
defaultVisible?: boolean;
|
|
50
|
+
visible?: boolean;
|
|
51
|
+
onVisibleChange?: (visible: boolean) => void;
|
|
52
|
+
}
|
|
46
53
|
export type PartialHSelectProps = Partial<HSelectProps>;
|
|
47
54
|
export {};
|
package/lib/index.css
CHANGED
|
@@ -42,6 +42,18 @@
|
|
|
42
42
|
border-top-right-radius: 0 !important;
|
|
43
43
|
border-bottom-right-radius: 0 !important;
|
|
44
44
|
}
|
|
45
|
+
.ant-hw-tag-select {
|
|
46
|
+
width: 100%;
|
|
47
|
+
}
|
|
48
|
+
.ant-hw-tag-select .ant-collapse-content-box {
|
|
49
|
+
padding: 0px 40px !important;
|
|
50
|
+
}
|
|
51
|
+
.ant-hw-tag-select .ant-hw-tag-select {
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
}
|
|
54
|
+
.ant-hw-tag-select .ant-collapse-header {
|
|
55
|
+
padding: 5px 16px !important;
|
|
56
|
+
}
|
|
45
57
|
.ant-hw-form-item-colon:after {
|
|
46
58
|
position: relative;
|
|
47
59
|
top: -0.5px;
|
|
@@ -167,6 +179,9 @@
|
|
|
167
179
|
display: -ms-flexbox;
|
|
168
180
|
display: flex;
|
|
169
181
|
}
|
|
182
|
+
.ant-hw-tag-select .ant-hw-tag-item {
|
|
183
|
+
cursor: pointer;
|
|
184
|
+
}
|
|
170
185
|
.ant-hw-input-group .ant-hw-input-group-disabled {
|
|
171
186
|
background-color: #f5f5f5;
|
|
172
187
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare const HRadioGroup: ({ value, options, onChange, fieldNames: props
|
|
|
22
22
|
export declare const HTimePicker: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
|
|
23
23
|
export declare const HInputNumber: ({ style, ...props }: import("antd").InputNumberProps) => JSX.Element;
|
|
24
24
|
export declare const HPageHandler: import("react").FC<import("./PageHandler/modal").IHPageHandler<any>>;
|
|
25
|
-
export declare const HTextArea: ({ autoSize, bordered, className, ...props }: import("./TextArea").HTextAreaProps) => JSX.Element;
|
|
25
|
+
export declare const HTextArea: ({ autoSize, bordered, className, style, ...props }: import("./TextArea").HTextAreaProps) => JSX.Element;
|
|
26
26
|
export declare const HColorInput: ({ value, onChange, defaultColor, ...props }: import("./Input/modal").HInputProps) => JSX.Element;
|
|
27
27
|
export declare const HModalForm: import("react").FC<import("./DialogForm/modal").DialogFormProps<any, any>>;
|
|
28
28
|
export declare const HDrawerForm: import("react").FC<import("./DialogForm/modal").DialogFormProps<any, any>>;
|
|
@@ -31,3 +31,4 @@ export declare const HVerificationCodeInput: import("react").ForwardRefExoticCom
|
|
|
31
31
|
export declare const HTrimInput: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
|
|
32
32
|
export declare const HTrimTextArea: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
|
|
33
33
|
export declare const HInputNumberGroup: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
|
|
34
|
+
export declare const HTagSelect: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
|
package/lib/index.js
CHANGED
|
@@ -37,6 +37,7 @@ var HVerificationCodeInput = config.default.verificationCodeInput;
|
|
|
37
37
|
var HTrimInput = config.default.trimInput;
|
|
38
38
|
var HTrimTextArea = config.default.trimTextArea;
|
|
39
39
|
var HInputNumberGroup = config.default.inputNumberGroup.Component;
|
|
40
|
+
var HTagSelect = config.default.tagSelect;
|
|
40
41
|
|
|
41
42
|
exports.HForm = index.default;
|
|
42
43
|
exports.useHForm = useHForm.default;
|
|
@@ -63,6 +64,7 @@ exports.HRichEditor = HRichEditor;
|
|
|
63
64
|
exports.HSelect = HSelect;
|
|
64
65
|
exports.HSelectInput = HSelectInput;
|
|
65
66
|
exports.HSwitch = HSwitch;
|
|
67
|
+
exports.HTagSelect = HTagSelect;
|
|
66
68
|
exports.HTextArea = HTextArea;
|
|
67
69
|
exports.HTimePicker = HTimePicker;
|
|
68
70
|
exports.HTrimInput = HTrimInput;
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@ import TrimTextArea from "../TextArea/TrimTextArea";
|
|
|
23
23
|
import HInputNumberGroup from "../Input/InputNumberGroup";
|
|
24
24
|
import HText from "../Text";
|
|
25
25
|
import HRichEditor from "../RichEditor";
|
|
26
|
-
|
|
26
|
+
import HTagSelect from '../Select/TagSelect';
|
|
27
27
|
export const placeholderConfig = {
|
|
28
28
|
inputType: [
|
|
29
29
|
"input",
|
|
@@ -70,6 +70,7 @@ const componentConfig = {
|
|
|
70
70
|
treeSelect: HTreeSelect,
|
|
71
71
|
text: HText,
|
|
72
72
|
richEditor: HRichEditor,
|
|
73
|
+
tagSelect:HTagSelect
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
export default componentConfig;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {HTagSelectProps} from "../modal";
|
|
2
|
+
import {useClassName} from "@/components/hooks";
|
|
3
|
+
import {Row, Skeleton, Space, Tag,Empty} from "antd";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import {useChangeControl} from "./hooks";
|
|
6
|
+
import NotFoundContent from "../components/NotFoundContent";
|
|
7
|
+
|
|
8
|
+
const ItemOption=({options,value,onChange,fieldNames}:HTagSelectProps)=>{
|
|
9
|
+
const tagClassName = useClassName("hw-tag-item");
|
|
10
|
+
const {label:labelKey="label",value:valueKey="value"}=fieldNames||{};
|
|
11
|
+
const {change}=useChangeControl({options,value,onChange,fieldNames});
|
|
12
|
+
return <Row gutter={[0,8]}>
|
|
13
|
+
{options?.map((item)=>{
|
|
14
|
+
const {[labelKey]:label,[valueKey]:itemVal}=item;
|
|
15
|
+
const index=value?.indexOf(itemVal);
|
|
16
|
+
const checkedTag=index!==-1;
|
|
17
|
+
return <Tag color={checkedTag?"processing":undefined}
|
|
18
|
+
className={tagClassName}
|
|
19
|
+
key={itemVal}
|
|
20
|
+
onClick={()=>{
|
|
21
|
+
change(itemVal);
|
|
22
|
+
}}
|
|
23
|
+
>
|
|
24
|
+
{label}
|
|
25
|
+
</Tag>
|
|
26
|
+
})}
|
|
27
|
+
</Row>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface IContentProps extends HTagSelectProps{
|
|
31
|
+
error?:Error;
|
|
32
|
+
reload:VoidFunction;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default ({loading,value,options,onChange,fieldNames,error,reload}:IContentProps)=>{
|
|
36
|
+
const len=options?.length||0;
|
|
37
|
+
if (loading&&len===0){
|
|
38
|
+
return <Space direction={"vertical"} style={{width:"100%"}}>
|
|
39
|
+
<Skeleton.Button active size={"small"} block />
|
|
40
|
+
<Skeleton.Button active size={"small"} block />
|
|
41
|
+
</Space>
|
|
42
|
+
}
|
|
43
|
+
if (error && len === 0) {
|
|
44
|
+
return <NotFoundContent error={error} reload={reload}/>;
|
|
45
|
+
}
|
|
46
|
+
if (len===0){
|
|
47
|
+
return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
|
48
|
+
}
|
|
49
|
+
return <ItemOption options={options} value={value} onChange={onChange} fieldNames={fieldNames}/>
|
|
50
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {useEffect, useMemo, useState} from "react";
|
|
2
|
+
import {HTagSelectProps, OptionType} from "@/components/Select/modal";
|
|
3
|
+
|
|
4
|
+
export const useTagControl=({value,options,title}:HTagSelectProps)=>{
|
|
5
|
+
const {checked,indeterminate}=useMemo(()=>{
|
|
6
|
+
const len=value?.length;
|
|
7
|
+
const opLen=options?.length;
|
|
8
|
+
if (!opLen){
|
|
9
|
+
return {
|
|
10
|
+
checked:false
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (len===opLen){
|
|
14
|
+
return {
|
|
15
|
+
checked:true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
indeterminate:!!len
|
|
20
|
+
}
|
|
21
|
+
},[value,options]);
|
|
22
|
+
const labelNode=useMemo(()=>{
|
|
23
|
+
if (title){
|
|
24
|
+
return title;
|
|
25
|
+
}
|
|
26
|
+
if (checked){
|
|
27
|
+
return "取消"
|
|
28
|
+
}
|
|
29
|
+
return "全选"
|
|
30
|
+
},[title,checked,indeterminate]);
|
|
31
|
+
return {
|
|
32
|
+
labelNode,
|
|
33
|
+
checked,
|
|
34
|
+
indeterminate
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const useChangeControl=({options,value,onChange,fieldNames}:HTagSelectProps)=>{
|
|
39
|
+
const {value:valueKey="value"}=fieldNames||{};
|
|
40
|
+
const optsNk=(newVal)=>{
|
|
41
|
+
const newOpts:OptionType[]=[];
|
|
42
|
+
newVal?.forEach((itemVal)=>{
|
|
43
|
+
const index=options?.findIndex((item)=>{
|
|
44
|
+
return itemVal===item[valueKey];
|
|
45
|
+
});
|
|
46
|
+
if (typeof index!=="undefined"){
|
|
47
|
+
newOpts.push((options?.[index] as OptionType));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return newOpts;
|
|
51
|
+
}
|
|
52
|
+
const checkedVal=(val)=>{
|
|
53
|
+
const newVal=[...value];
|
|
54
|
+
newVal.push(val);
|
|
55
|
+
onChange?.(newVal,optsNk(newVal));
|
|
56
|
+
}
|
|
57
|
+
const removeVal=(index)=>{
|
|
58
|
+
const newVal=[...value];
|
|
59
|
+
newVal.splice(index,1);
|
|
60
|
+
onChange?.(newVal,optsNk(newVal));
|
|
61
|
+
}
|
|
62
|
+
const change=(val)=>{
|
|
63
|
+
const index=value?.indexOf(val);
|
|
64
|
+
const checked=index===-1;
|
|
65
|
+
if (checked){
|
|
66
|
+
return checkedVal(val);
|
|
67
|
+
}
|
|
68
|
+
return removeVal(index);
|
|
69
|
+
}
|
|
70
|
+
const allCheck=(e)=>{
|
|
71
|
+
if (!e.target.checked){
|
|
72
|
+
return onChange?.([],[]);
|
|
73
|
+
}
|
|
74
|
+
const newVal=options?.map((item)=>{
|
|
75
|
+
return item[valueKey];
|
|
76
|
+
});
|
|
77
|
+
return onChange?.(newVal,options);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
change,
|
|
81
|
+
allCheck
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const useCollapseControl=({visible,defaultVisible,onVisibleChange}:HTagSelectProps)=>{
|
|
86
|
+
const [activeKey,setActiveKey]=useState(defaultVisible?["1"]:[]);
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (typeof visible==="undefined"){
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
setActiveKey(visible?["1"]:[]);
|
|
92
|
+
}, [visible]);
|
|
93
|
+
const onChange=(keys)=>{
|
|
94
|
+
const len=keys?.length;
|
|
95
|
+
onVisibleChange?.(!!len);
|
|
96
|
+
setActiveKey(keys)
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
activeKey,
|
|
100
|
+
onChange
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {Collapse, Checkbox} from 'antd';
|
|
2
|
+
import {useClassName, useMatchConfigProps} from "../../hooks";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import {useSelectReq} from "../hooks/norHooks";
|
|
5
|
+
import {HTagSelectProps} from "../modal";
|
|
6
|
+
import {CheckboxProps} from "antd/lib/checkbox/Checkbox";
|
|
7
|
+
import Content from './Content';
|
|
8
|
+
import {useChangeControl, useCollapseControl, useTagControl} from "@/components/Select/TagSelect/hooks";
|
|
9
|
+
import HFormConnect from "@/components/Form/HFormConnect";
|
|
10
|
+
const { Panel } = Collapse;
|
|
11
|
+
|
|
12
|
+
const ItemTitle:React.FC<CheckboxProps>=({children,...props})=>{
|
|
13
|
+
return <div onClick={(event)=>{
|
|
14
|
+
event.stopPropagation();
|
|
15
|
+
}}>
|
|
16
|
+
<Checkbox {...props}>
|
|
17
|
+
{children}
|
|
18
|
+
</Checkbox>
|
|
19
|
+
</div>
|
|
20
|
+
}
|
|
21
|
+
const Index:React.FC<HTagSelectProps>=({
|
|
22
|
+
options,
|
|
23
|
+
value=[],
|
|
24
|
+
onChange,
|
|
25
|
+
dispatch,
|
|
26
|
+
fieldNames:propsFieldNames,
|
|
27
|
+
request,
|
|
28
|
+
title,
|
|
29
|
+
manual,
|
|
30
|
+
className="",
|
|
31
|
+
visible,
|
|
32
|
+
defaultVisible,
|
|
33
|
+
onVisibleChange,
|
|
34
|
+
addDispatchListener
|
|
35
|
+
})=>{
|
|
36
|
+
const collapseClassName = useClassName("hw-tag-select");
|
|
37
|
+
const { fieldNames } = useMatchConfigProps({ fieldNames: propsFieldNames });
|
|
38
|
+
const {activeKey,onChange:colChange}=useCollapseControl({defaultVisible,visible,onVisibleChange})
|
|
39
|
+
const {
|
|
40
|
+
loading,
|
|
41
|
+
data: resultData,
|
|
42
|
+
error,
|
|
43
|
+
reload,
|
|
44
|
+
} = useSelectReq({
|
|
45
|
+
options,
|
|
46
|
+
manual,
|
|
47
|
+
request,
|
|
48
|
+
dispatch,
|
|
49
|
+
}); //options
|
|
50
|
+
const {labelNode,checked,indeterminate}=useTagControl({value,options:resultData,title});
|
|
51
|
+
const {allCheck}=useChangeControl({
|
|
52
|
+
value,
|
|
53
|
+
options:resultData,
|
|
54
|
+
onChange,
|
|
55
|
+
fieldNames
|
|
56
|
+
});
|
|
57
|
+
addDispatchListener?.("reload", reload);
|
|
58
|
+
return <Collapse bordered={false}
|
|
59
|
+
ghost
|
|
60
|
+
activeKey={activeKey}
|
|
61
|
+
onChange={colChange}
|
|
62
|
+
className={`${collapseClassName} ${className}`}
|
|
63
|
+
>
|
|
64
|
+
<Panel key="1" header={<ItemTitle indeterminate={indeterminate}
|
|
65
|
+
checked={checked}
|
|
66
|
+
onChange={allCheck}
|
|
67
|
+
>{labelNode}</ItemTitle>}>
|
|
68
|
+
<Content loading={loading}
|
|
69
|
+
options={resultData}
|
|
70
|
+
value={value}
|
|
71
|
+
error={error}
|
|
72
|
+
onChange={onChange}
|
|
73
|
+
reload={reload}
|
|
74
|
+
fieldNames={fieldNames}
|
|
75
|
+
/>
|
|
76
|
+
</Panel>
|
|
77
|
+
</Collapse>
|
|
78
|
+
}
|
|
79
|
+
export default HFormConnect(Index);
|
|
@@ -55,3 +55,16 @@
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
.@{ant-prefix}-hw-tag-select {
|
|
59
|
+
width: 100%;
|
|
60
|
+
.@{ant-prefix}-collapse-content-box {
|
|
61
|
+
padding: 0px 40px !important;
|
|
62
|
+
}
|
|
63
|
+
.@{ant-prefix}-hw-tag-select{
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
}
|
|
66
|
+
.@{ant-prefix}-collapse-header{
|
|
67
|
+
padding: 5px 16px !important;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
@@ -2,6 +2,7 @@ import type { SelectProps } from "antd";
|
|
|
2
2
|
import type React from "react";
|
|
3
3
|
import type { PromiseFnResult } from "../modal";
|
|
4
4
|
import type { addFormatItemModal, argsFn, DispatchModal } from "../Form/modal";
|
|
5
|
+
import {CollapseProps} from "antd/lib/collapse/Collapse";
|
|
5
6
|
|
|
6
7
|
export type OptionType = Record<string, any>;
|
|
7
8
|
export type RenderFn = (data: OptionType) => React.ReactNode;
|
|
@@ -24,7 +25,7 @@ export interface OptionsPageResultModal {
|
|
|
24
25
|
}
|
|
25
26
|
export type OptionsDataType = OptionsListType | OptionsPageResultModal;
|
|
26
27
|
export interface HSelectProps
|
|
27
|
-
extends Omit<SelectProps, "options" | "placeholder"> {
|
|
28
|
+
extends Omit<SelectProps, "options" | "placeholder"|"onChange"> {
|
|
28
29
|
style?: React.CSSProperties;
|
|
29
30
|
request?: PromiseFnResult<any, OptionsDataType>;
|
|
30
31
|
manual?: boolean;
|
|
@@ -41,9 +42,16 @@ export interface HSelectProps
|
|
|
41
42
|
isList?: boolean;
|
|
42
43
|
addonBefore?: React.ReactNode;
|
|
43
44
|
addonAfter?: React.ReactNode;
|
|
45
|
+
onChange?:(value:any,opts?:OptionType[]|OptionType)=>void;
|
|
44
46
|
}
|
|
45
47
|
export interface FilterDataModal {
|
|
46
48
|
value: any;
|
|
47
49
|
index: number;
|
|
48
50
|
}
|
|
51
|
+
export interface HTagSelectProps extends HSelectProps{
|
|
52
|
+
title?:React.ReactNode;
|
|
53
|
+
defaultVisible?:boolean;
|
|
54
|
+
visible?:boolean;
|
|
55
|
+
onVisibleChange?:(visible:boolean)=>void;
|
|
56
|
+
}
|
|
49
57
|
export type PartialHSelectProps = Partial<HSelectProps>;
|
package/src/components/index.tsx
CHANGED