@hw-component/form 0.0.5-beta-v8 → 0.0.5-beta-v9
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/Form/Context/FormConfigProvider.js +27 -0
- package/es/Form/Context/index.js +11 -0
- package/es/Form/HFormConnect.js +68 -0
- package/es/Select/components/AllSelect.js +55 -0
- package/es/Select/components/CheckBoxOption.js +16 -0
- package/es/Select/components/DropdownComponent.js +44 -0
- package/es/Select/components/NoFindItem.js +14 -0
- package/es/Select/components/NotFoundContent.js +43 -0
- package/es/Select/defaultConfig.js +32 -0
- package/es/Select/hooks/changeHooks.js +196 -0
- package/es/Select/hooks/norHooks.js +118 -0
- package/es/Select/index.js +149 -0
- package/es/Select/utils.js +37 -0
- package/es/Upload/util.js +18 -0
- package/es/config.js +65 -0
- package/es/hooks/index.js +74 -0
- package/es/index.css +44 -0
- package/es/index.d.ts +3 -1
- package/es/index.js +3 -22
- package/lib/Form/Context/FormConfigProvider.js +28 -0
- package/lib/Form/Context/index.js +14 -0
- package/lib/Form/HFormConnect.js +71 -0
- package/lib/Select/components/AllSelect.js +58 -0
- package/lib/Select/components/CheckBoxOption.js +19 -0
- package/lib/Select/components/DropdownComponent.js +47 -0
- package/lib/Select/components/NoFindItem.js +17 -0
- package/lib/Select/components/NotFoundContent.js +46 -0
- package/lib/Select/defaultConfig.js +34 -0
- package/lib/Select/hooks/changeHooks.js +197 -0
- package/lib/Select/hooks/norHooks.js +120 -0
- package/lib/Select/index.js +152 -0
- package/lib/Select/utils.js +39 -0
- package/lib/Upload/util.js +19 -0
- package/lib/config.js +66 -0
- package/lib/hooks/index.js +77 -0
- package/lib/index.css +44 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -22
- package/package.json +1 -1
- package/src/components/index.tsx +4 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import 'core-js/modules/es.symbol.js';
|
|
3
|
+
import 'core-js/modules/es.array.filter.js';
|
|
4
|
+
import 'core-js/modules/es.object.get-own-property-descriptor.js';
|
|
5
|
+
import 'core-js/modules/es.object.get-own-property-descriptors.js';
|
|
6
|
+
import '@babel/runtime-corejs3/helpers/objectWithoutProperties';
|
|
7
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
|
|
8
|
+
import 'core-js/modules/es.object.keys.js';
|
|
9
|
+
import 'core-js/modules/es.object.to-string.js';
|
|
10
|
+
import 'core-js/modules/web.dom-collections.for-each.js';
|
|
11
|
+
import 'react/jsx-runtime';
|
|
12
|
+
import { FormConfigContext } from './index.js';
|
|
13
|
+
import { useContext } from 'react';
|
|
14
|
+
import { baseConfig } from '../../config.js';
|
|
15
|
+
|
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
18
|
+
var useFormConfigContext = function useFormConfigContext(key) {
|
|
19
|
+
var defaultProps = useContext(FormConfigContext);
|
|
20
|
+
if (!key) {
|
|
21
|
+
return Object.keys(defaultProps).length === 0 ? _objectSpread({}, baseConfig) : defaultProps;
|
|
22
|
+
}
|
|
23
|
+
return defaultProps[key] || _objectSpread({}, baseConfig[key]);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { useFormConfigContext };
|
|
27
|
+
// powered by hdj
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
|
|
4
|
+
var FormContext = /*#__PURE__*/React.createContext({});
|
|
5
|
+
var useFormContext = function useFormContext() {
|
|
6
|
+
return useContext(FormContext);
|
|
7
|
+
};
|
|
8
|
+
var FormConfigContext = /*#__PURE__*/React.createContext({});
|
|
9
|
+
|
|
10
|
+
export { FormConfigContext, FormContext, useFormContext };
|
|
11
|
+
// powered by hdj
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import 'core-js/modules/es.object.keys.js';
|
|
3
|
+
import 'core-js/modules/es.symbol.js';
|
|
4
|
+
import 'core-js/modules/es.array.filter.js';
|
|
5
|
+
import 'core-js/modules/es.object.to-string.js';
|
|
6
|
+
import 'core-js/modules/es.object.get-own-property-descriptor.js';
|
|
7
|
+
import 'core-js/modules/web.dom-collections.for-each.js';
|
|
8
|
+
import 'core-js/modules/es.object.get-own-property-descriptors.js';
|
|
9
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
|
|
10
|
+
import 'core-js/modules/es.function.name.js';
|
|
11
|
+
import { jsx } from 'react/jsx-runtime';
|
|
12
|
+
import { useFormContext } from './Context/index.js';
|
|
13
|
+
import React, { useEffect } from 'react';
|
|
14
|
+
|
|
15
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
var formatMaker = function formatMaker(itemProps, formats) {
|
|
18
|
+
if (!formats) {
|
|
19
|
+
return formats;
|
|
20
|
+
}
|
|
21
|
+
var _inputValue = formats.inputValue,
|
|
22
|
+
_outputValue = formats.outputValue;
|
|
23
|
+
return {
|
|
24
|
+
inputValue: function inputValue(value) {
|
|
25
|
+
return _inputValue(itemProps, value);
|
|
26
|
+
},
|
|
27
|
+
outputValue: function outputValue(value) {
|
|
28
|
+
return _outputValue(itemProps, value);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
var HFormConnect = (function (component) {
|
|
33
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
34
|
+
var _config$format = config.format,
|
|
35
|
+
format = _config$format === void 0 ? {} : _config$format;
|
|
36
|
+
var Index = function Index(props, ref) {
|
|
37
|
+
var _props$name = props.name,
|
|
38
|
+
name = _props$name === void 0 ? "" : _props$name,
|
|
39
|
+
dispatch = props.dispatch;
|
|
40
|
+
var _useFormContext = useFormContext(),
|
|
41
|
+
form = _useFormContext.form,
|
|
42
|
+
_useFormContext$value = _useFormContext.valueType,
|
|
43
|
+
valueType = _useFormContext$value === void 0 ? "float" : _useFormContext$value;
|
|
44
|
+
useEffect(function () {
|
|
45
|
+
form === null || form === void 0 || form.addFormat(name, formatMaker(props, format[valueType]));
|
|
46
|
+
}, [valueType, props]);
|
|
47
|
+
var addFormat = function addFormat(aFormat) {
|
|
48
|
+
form === null || form === void 0 || form.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
49
|
+
};
|
|
50
|
+
var addDispatchListener = function addDispatchListener(key, fn) {
|
|
51
|
+
form === null || form === void 0 || form.addDispatchListener({
|
|
52
|
+
key: key,
|
|
53
|
+
name: name,
|
|
54
|
+
dispatch: dispatch
|
|
55
|
+
}, fn);
|
|
56
|
+
};
|
|
57
|
+
var Component = component;
|
|
58
|
+
return jsx(Component, _objectSpread(_objectSpread({}, props), {}, {
|
|
59
|
+
addFormat: addFormat,
|
|
60
|
+
addDispatchListener: addDispatchListener,
|
|
61
|
+
ref: ref
|
|
62
|
+
}));
|
|
63
|
+
};
|
|
64
|
+
return /*#__PURE__*/React.forwardRef(Index);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export { HFormConnect as default };
|
|
68
|
+
// powered by hdj
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import 'core-js/modules/es.array.concat.js';
|
|
3
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
4
|
+
import { Space, Checkbox } from 'antd';
|
|
5
|
+
import { itemOpProvider } from '../utils.js';
|
|
6
|
+
import { useClassName } from '../../hooks/index.js';
|
|
7
|
+
|
|
8
|
+
var useRootClassName = function useRootClassName(checked) {
|
|
9
|
+
var norClassNames = ["select-item", "select-item-option"];
|
|
10
|
+
return checked ? [].concat(norClassNames, ["select-item-option-selected"]) : norClassNames;
|
|
11
|
+
};
|
|
12
|
+
var Index = function Index(_ref) {
|
|
13
|
+
var allSelect = _ref.allSelect,
|
|
14
|
+
mode = _ref.mode,
|
|
15
|
+
onChange = _ref.onChange,
|
|
16
|
+
value = _ref.value,
|
|
17
|
+
serviceSearch = _ref.serviceSearch,
|
|
18
|
+
options = _ref.options,
|
|
19
|
+
_ref$fieldNames = _ref.fieldNames,
|
|
20
|
+
fieldNames = _ref$fieldNames === void 0 ? {} : _ref$fieldNames,
|
|
21
|
+
children = _ref.children;
|
|
22
|
+
var opLen = (options === null || options === void 0 ? void 0 : options.length) || 0;
|
|
23
|
+
var checked = (value === null || value === void 0 ? void 0 : value.length) >= opLen;
|
|
24
|
+
var classNames = useRootClassName(checked);
|
|
25
|
+
var optionsClassName = useClassName(classNames);
|
|
26
|
+
var allCheckBox = useClassName("hw-all-check-box");
|
|
27
|
+
var change = function change() {
|
|
28
|
+
if (!checked) {
|
|
29
|
+
var subItemOps = itemOpProvider(options, fieldNames);
|
|
30
|
+
onChange === null || onChange === void 0 || onChange(options, subItemOps);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
onChange === null || onChange === void 0 || onChange([], []);
|
|
34
|
+
};
|
|
35
|
+
if (!allSelect || mode !== "multiple" || serviceSearch) {
|
|
36
|
+
return jsx(Fragment, {
|
|
37
|
+
children: children
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return jsxs("div", {
|
|
41
|
+
className: allCheckBox,
|
|
42
|
+
children: [jsx("div", {
|
|
43
|
+
className: optionsClassName,
|
|
44
|
+
onClick: change,
|
|
45
|
+
children: jsxs(Space, {
|
|
46
|
+
children: [jsx(Checkbox, {
|
|
47
|
+
checked: checked
|
|
48
|
+
}), "\u5168\u90E8"]
|
|
49
|
+
})
|
|
50
|
+
}), children]
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { Index as default };
|
|
55
|
+
// powered by hdj
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Space, Checkbox } from 'antd';
|
|
4
|
+
|
|
5
|
+
var CheckBoxOption = (function (_ref) {
|
|
6
|
+
var label = _ref.label,
|
|
7
|
+
checked = _ref.checked;
|
|
8
|
+
return jsxs(Space, {
|
|
9
|
+
children: [jsx(Checkbox, {
|
|
10
|
+
checked: checked
|
|
11
|
+
}), label]
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export { CheckBoxOption as default };
|
|
16
|
+
// powered by hdj
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import { Typography, Row, Space, Spin } from 'antd';
|
|
4
|
+
import NotFoundContent from './NotFoundContent.js';
|
|
5
|
+
|
|
6
|
+
var Text = Typography.Text;
|
|
7
|
+
var Index = function Index(_ref) {
|
|
8
|
+
var loading = _ref.loading,
|
|
9
|
+
error = _ref.error,
|
|
10
|
+
_ref$options = _ref.options,
|
|
11
|
+
options = _ref$options === void 0 ? [] : _ref$options,
|
|
12
|
+
reload = _ref.reload,
|
|
13
|
+
children = _ref.children;
|
|
14
|
+
var len = options === null || options === void 0 ? void 0 : options.length;
|
|
15
|
+
if (loading && len === 0) {
|
|
16
|
+
return jsx(Row, {
|
|
17
|
+
style: {
|
|
18
|
+
height: 125
|
|
19
|
+
},
|
|
20
|
+
justify: "center",
|
|
21
|
+
align: "middle",
|
|
22
|
+
children: jsxs(Space, {
|
|
23
|
+
direction: "vertical",
|
|
24
|
+
align: "center",
|
|
25
|
+
children: [jsx(Spin, {}), jsx(Text, {
|
|
26
|
+
type: "secondary",
|
|
27
|
+
children: "\u62FC\u547D\u52A0\u8F7D\u4E2D..."
|
|
28
|
+
})]
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (error && len === 0) {
|
|
33
|
+
return jsx(NotFoundContent, {
|
|
34
|
+
error: error,
|
|
35
|
+
reload: reload
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return jsx(Fragment, {
|
|
39
|
+
children: children
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { Index as default };
|
|
44
|
+
// powered by hdj
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Typography } from 'antd';
|
|
4
|
+
|
|
5
|
+
var NoFindItem = (function (_ref) {
|
|
6
|
+
var label = _ref.label;
|
|
7
|
+
return jsx(Typography.Text, {
|
|
8
|
+
type: "danger",
|
|
9
|
+
children: label
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export { NoFindItem as default };
|
|
14
|
+
// powered by hdj
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { Typography, Row, Space, Button, Empty } from 'antd';
|
|
4
|
+
import { ExclamationCircleOutlined } from '@ant-design/icons';
|
|
5
|
+
|
|
6
|
+
var Text = Typography.Text;
|
|
7
|
+
var NotFoundContent = (function (_ref) {
|
|
8
|
+
var error = _ref.error,
|
|
9
|
+
reload = _ref.reload;
|
|
10
|
+
if (error) {
|
|
11
|
+
return jsx(Row, {
|
|
12
|
+
justify: "center",
|
|
13
|
+
align: "middle",
|
|
14
|
+
style: {
|
|
15
|
+
height: 125
|
|
16
|
+
},
|
|
17
|
+
children: jsxs(Space, {
|
|
18
|
+
align: "center",
|
|
19
|
+
direction: "vertical",
|
|
20
|
+
children: [jsx(Text, {
|
|
21
|
+
type: "danger",
|
|
22
|
+
children: jsx(ExclamationCircleOutlined, {
|
|
23
|
+
size: 24
|
|
24
|
+
})
|
|
25
|
+
}), jsx(Text, {
|
|
26
|
+
type: "danger",
|
|
27
|
+
children: error.message
|
|
28
|
+
}), jsx(Button, {
|
|
29
|
+
type: "primary",
|
|
30
|
+
size: "small",
|
|
31
|
+
onClick: reload,
|
|
32
|
+
children: "\u91CD\u65B0\u52A0\u8F7D"
|
|
33
|
+
})]
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return jsx(Empty, {
|
|
38
|
+
image: Empty.PRESENTED_IMAGE_SIMPLE
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export { NotFoundContent as default };
|
|
43
|
+
// powered by hdj
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import 'core-js/modules/es.array.map.js';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import CheckBoxOption from './components/CheckBoxOption.js';
|
|
5
|
+
import NoFindItem from './components/NoFindItem.js';
|
|
6
|
+
|
|
7
|
+
var defaultModeConfig = {
|
|
8
|
+
multiple: {
|
|
9
|
+
icon: null,
|
|
10
|
+
render: function render(item, value) {
|
|
11
|
+
var checkVal = value === null || value === void 0 ? void 0 : value.map(function (itemVal) {
|
|
12
|
+
return itemVal.value;
|
|
13
|
+
});
|
|
14
|
+
var newVal = checkVal || [];
|
|
15
|
+
var checked = newVal.indexOf(item.value) !== -1;
|
|
16
|
+
return jsx(CheckBoxOption, {
|
|
17
|
+
label: item.label,
|
|
18
|
+
checked: checked
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var defaultSelectConfig = {
|
|
24
|
+
noMatchItemRender: function noMatchItemRender() {
|
|
25
|
+
return jsx(NoFindItem, {
|
|
26
|
+
label: "选项被删除,请重新选择"
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { defaultModeConfig, defaultSelectConfig };
|
|
32
|
+
// powered by hdj
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import 'core-js/modules/es.object.keys.js';
|
|
3
|
+
import 'core-js/modules/es.symbol.js';
|
|
4
|
+
import 'core-js/modules/es.array.filter.js';
|
|
5
|
+
import 'core-js/modules/es.object.get-own-property-descriptor.js';
|
|
6
|
+
import 'core-js/modules/es.object.get-own-property-descriptors.js';
|
|
7
|
+
import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
|
|
8
|
+
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
|
|
9
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
|
|
10
|
+
import 'core-js/modules/es.array.find-index.js';
|
|
11
|
+
import 'core-js/modules/es.object.to-string.js';
|
|
12
|
+
import 'core-js/modules/web.dom-collections.for-each.js';
|
|
13
|
+
import 'core-js/modules/es.array.map.js';
|
|
14
|
+
import { useState, useEffect } from 'react';
|
|
15
|
+
import { itemOpProvider } from '../utils.js';
|
|
16
|
+
|
|
17
|
+
var _excluded = ["index"],
|
|
18
|
+
_excluded2 = ["index"];
|
|
19
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
var single = function single(_ref) {
|
|
22
|
+
var options = _ref.options,
|
|
23
|
+
value = _ref.value,
|
|
24
|
+
noMatchItemRender = _ref.noMatchItemRender;
|
|
25
|
+
var newOptions = options || [];
|
|
26
|
+
var index = newOptions.findIndex(function (item) {
|
|
27
|
+
return item.value === value;
|
|
28
|
+
});
|
|
29
|
+
if (index !== -1) {
|
|
30
|
+
var label = newOptions[index].label;
|
|
31
|
+
return {
|
|
32
|
+
value: value,
|
|
33
|
+
label: label
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
value: value,
|
|
38
|
+
label: (noMatchItemRender === null || noMatchItemRender === void 0 ? void 0 : noMatchItemRender({
|
|
39
|
+
value: value
|
|
40
|
+
})) || value
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
var findNewValInOldVal = function findNewValInOldVal(val, oldVal) {
|
|
44
|
+
if (!oldVal) {
|
|
45
|
+
return -1;
|
|
46
|
+
}
|
|
47
|
+
return oldVal.findIndex(function (item) {
|
|
48
|
+
return item.value === val;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
var sourceDataProvider = function sourceDataProvider(_ref2, oldVal) {
|
|
52
|
+
_ref2.options;
|
|
53
|
+
var value = _ref2.value;
|
|
54
|
+
var oldData = [];
|
|
55
|
+
var newData = [];
|
|
56
|
+
value.forEach(function (item, i) {
|
|
57
|
+
var index = findNewValInOldVal(item, oldVal);
|
|
58
|
+
if (index === -1) {
|
|
59
|
+
newData.push({
|
|
60
|
+
value: item,
|
|
61
|
+
index: i
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
var newVal = oldVal === null || oldVal === void 0 ? void 0 : oldVal[index];
|
|
66
|
+
oldData.push(_objectSpread(_objectSpread({}, newVal), {}, {
|
|
67
|
+
index: i
|
|
68
|
+
}));
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
oldData: oldData,
|
|
72
|
+
newData: newData
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
var resultProvider = function resultProvider(newData, oldData, value) {
|
|
76
|
+
var newResult = new Array(value.length);
|
|
77
|
+
oldData.forEach(function (item) {
|
|
78
|
+
var index = item.index,
|
|
79
|
+
val = _objectWithoutProperties(item, _excluded);
|
|
80
|
+
newResult[index] = _objectSpread({}, val);
|
|
81
|
+
});
|
|
82
|
+
newData.forEach(function (item) {
|
|
83
|
+
var index = item.index,
|
|
84
|
+
val = _objectWithoutProperties(item, _excluded2);
|
|
85
|
+
newResult[index] = _objectSpread({}, val);
|
|
86
|
+
});
|
|
87
|
+
return newResult;
|
|
88
|
+
};
|
|
89
|
+
var multiple = function multiple(_ref3, oldVal) {
|
|
90
|
+
var options = _ref3.options,
|
|
91
|
+
value = _ref3.value,
|
|
92
|
+
noMatchItemRender = _ref3.noMatchItemRender;
|
|
93
|
+
var _sourceDataProvider = sourceDataProvider({
|
|
94
|
+
options: options,
|
|
95
|
+
value: value
|
|
96
|
+
}, oldVal),
|
|
97
|
+
newData = _sourceDataProvider.newData,
|
|
98
|
+
oldData = _sourceDataProvider.oldData;
|
|
99
|
+
var newMatchVal = newData.map(function (item) {
|
|
100
|
+
var itemVal = item.value,
|
|
101
|
+
index = item.index;
|
|
102
|
+
var newItem = single({
|
|
103
|
+
options: options,
|
|
104
|
+
value: itemVal,
|
|
105
|
+
noMatchItemRender: noMatchItemRender
|
|
106
|
+
});
|
|
107
|
+
return _objectSpread(_objectSpread({}, newItem), {}, {
|
|
108
|
+
index: index
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
return resultProvider(newMatchVal, oldData, value);
|
|
112
|
+
};
|
|
113
|
+
var tag = function tag(_ref4, oldVal) {
|
|
114
|
+
var options = _ref4.options,
|
|
115
|
+
value = _ref4.value;
|
|
116
|
+
var _sourceDataProvider2 = sourceDataProvider({
|
|
117
|
+
options: options,
|
|
118
|
+
value: value
|
|
119
|
+
}, oldVal),
|
|
120
|
+
newData = _sourceDataProvider2.newData,
|
|
121
|
+
oldData = _sourceDataProvider2.oldData;
|
|
122
|
+
return resultProvider(newData, oldData, value);
|
|
123
|
+
};
|
|
124
|
+
var matchNotFind = function matchNotFind(_ref5, oldVale) {
|
|
125
|
+
var options = _ref5.options,
|
|
126
|
+
value = _ref5.value,
|
|
127
|
+
mode = _ref5.mode,
|
|
128
|
+
noMatchItemRender = _ref5.noMatchItemRender;
|
|
129
|
+
if (!mode) {
|
|
130
|
+
return single({
|
|
131
|
+
options: options,
|
|
132
|
+
value: value,
|
|
133
|
+
noMatchItemRender: noMatchItemRender
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (mode === "multiple") {
|
|
137
|
+
return multiple({
|
|
138
|
+
options: options,
|
|
139
|
+
value: value,
|
|
140
|
+
noMatchItemRender: noMatchItemRender
|
|
141
|
+
}, oldVale);
|
|
142
|
+
}
|
|
143
|
+
return tag({
|
|
144
|
+
options: options,
|
|
145
|
+
value: value
|
|
146
|
+
}, oldVale);
|
|
147
|
+
};
|
|
148
|
+
var useValueChange = function useValueChange(params) {
|
|
149
|
+
var labelInValue = params.labelInValue,
|
|
150
|
+
onChange = params.onChange,
|
|
151
|
+
value = params.value,
|
|
152
|
+
options = params.options,
|
|
153
|
+
mode = params.mode,
|
|
154
|
+
noMatchItemRender = params.noMatchItemRender,
|
|
155
|
+
_params$fieldNames = params.fieldNames,
|
|
156
|
+
fieldNames = _params$fieldNames === void 0 ? {} : _params$fieldNames;
|
|
157
|
+
var _useState = useState(),
|
|
158
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
159
|
+
val = _useState2[0],
|
|
160
|
+
setVal = _useState2[1];
|
|
161
|
+
var change = function change(changeVal, itemOps) {
|
|
162
|
+
if (!onChange) {
|
|
163
|
+
setVal(changeVal);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
var newChangeVal = changeVal.value;
|
|
167
|
+
if (labelInValue) {
|
|
168
|
+
newChangeVal = changeVal;
|
|
169
|
+
}
|
|
170
|
+
if (Array.isArray(changeVal)) {
|
|
171
|
+
newChangeVal = changeVal.map(function (item) {
|
|
172
|
+
return item.value;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
var subItemOps = itemOpProvider(itemOps, fieldNames);
|
|
176
|
+
onChange(newChangeVal, subItemOps);
|
|
177
|
+
};
|
|
178
|
+
useEffect(function () {
|
|
179
|
+
if (mode === "tags" || value === null || value === undefined) {
|
|
180
|
+
setVal(value);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (options && value) {
|
|
184
|
+
setVal(function (oldVale) {
|
|
185
|
+
return matchNotFind(params, oldVale);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}, [value, options, mode, noMatchItemRender]);
|
|
189
|
+
return {
|
|
190
|
+
val: val,
|
|
191
|
+
change: change
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export { useValueChange };
|
|
196
|
+
// powered by hdj
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
|
|
3
|
+
import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
|
|
4
|
+
import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
|
|
5
|
+
import 'core-js/modules/es.array.iterator.js';
|
|
6
|
+
import 'core-js/modules/es.object.to-string.js';
|
|
7
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
8
|
+
import 'core-js/modules/es.promise.js';
|
|
9
|
+
import { useState, useEffect } from 'react';
|
|
10
|
+
import { useRequest } from 'ahooks';
|
|
11
|
+
import { useFormContext } from '../../Form/Context/index.js';
|
|
12
|
+
|
|
13
|
+
var useOptionReq = function useOptionReq(_ref) {
|
|
14
|
+
var manual = _ref.manual,
|
|
15
|
+
request = _ref.request,
|
|
16
|
+
options = _ref.options,
|
|
17
|
+
serviceSearch = _ref.serviceSearch,
|
|
18
|
+
showSearch = _ref.showSearch,
|
|
19
|
+
propsOnSearch = _ref.onSearch,
|
|
20
|
+
_ref$dispatch = _ref.dispatch,
|
|
21
|
+
dispatch = _ref$dispatch === void 0 ? {} : _ref$dispatch;
|
|
22
|
+
var dispatchManual = dispatch.manual;
|
|
23
|
+
var _useFormContext = useFormContext(),
|
|
24
|
+
form = _useFormContext.form;
|
|
25
|
+
var _useState = useState(),
|
|
26
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
+
data = _useState2[0],
|
|
28
|
+
setData = _useState2[1];
|
|
29
|
+
var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
30
|
+
var requestParams,
|
|
31
|
+
_requestParams$params,
|
|
32
|
+
params,
|
|
33
|
+
values,
|
|
34
|
+
_requestParams$type,
|
|
35
|
+
type,
|
|
36
|
+
formData,
|
|
37
|
+
_args = arguments;
|
|
38
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
39
|
+
while (1) switch (_context.prev = _context.next) {
|
|
40
|
+
case 0:
|
|
41
|
+
requestParams = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
42
|
+
_requestParams$params = requestParams.params, params = _requestParams$params === void 0 ? {} : _requestParams$params, values = requestParams.values, _requestParams$type = requestParams.type, type = _requestParams$type === void 0 ? "init" : _requestParams$type;
|
|
43
|
+
formData = values || (form === null || form === void 0 ? void 0 : form.getFieldsValue());
|
|
44
|
+
if (type === "init") {
|
|
45
|
+
setData(undefined);
|
|
46
|
+
}
|
|
47
|
+
if (!request) {
|
|
48
|
+
_context.next = 6;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
return _context.abrupt("return", request(params, formData));
|
|
52
|
+
case 6:
|
|
53
|
+
return _context.abrupt("return", Promise.resolve(options));
|
|
54
|
+
case 7:
|
|
55
|
+
case "end":
|
|
56
|
+
return _context.stop();
|
|
57
|
+
}
|
|
58
|
+
}, _callee);
|
|
59
|
+
})), {
|
|
60
|
+
manual: dispatchManual === false ? true : manual,
|
|
61
|
+
debounceInterval: 300,
|
|
62
|
+
onSuccess: function onSuccess(resultData) {
|
|
63
|
+
setData(resultData);
|
|
64
|
+
}
|
|
65
|
+
}),
|
|
66
|
+
run = _useRequest.run,
|
|
67
|
+
loading = _useRequest.loading,
|
|
68
|
+
error = _useRequest.error;
|
|
69
|
+
var reload = function reload(_ref3) {
|
|
70
|
+
var changeOpts = _ref3.options,
|
|
71
|
+
params = _ref3.params;
|
|
72
|
+
if (changeOpts) {
|
|
73
|
+
return setData(changeOpts);
|
|
74
|
+
}
|
|
75
|
+
return run({
|
|
76
|
+
params: params
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
var onSearch = function onSearch(inputValue) {
|
|
80
|
+
if (!serviceSearch) {
|
|
81
|
+
propsOnSearch === null || propsOnSearch === void 0 || propsOnSearch(inputValue);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
run({
|
|
85
|
+
params: {
|
|
86
|
+
inputValue: inputValue
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
useEffect(function () {
|
|
91
|
+
if (options) {
|
|
92
|
+
setData(options);
|
|
93
|
+
}
|
|
94
|
+
}, [options]);
|
|
95
|
+
var mathShowSearch = showSearch || serviceSearch;
|
|
96
|
+
return {
|
|
97
|
+
run: run,
|
|
98
|
+
loading: loading,
|
|
99
|
+
error: error,
|
|
100
|
+
data: data,
|
|
101
|
+
onSearch: mathShowSearch ? onSearch : propsOnSearch,
|
|
102
|
+
mathShowSearch: showSearch || serviceSearch,
|
|
103
|
+
reload: reload
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
var useFilterOption = function useFilterOption(_ref4) {
|
|
107
|
+
var filterOption = _ref4.filterOption,
|
|
108
|
+
serviceSearch = _ref4.serviceSearch;
|
|
109
|
+
if (serviceSearch) {
|
|
110
|
+
return function () {
|
|
111
|
+
return true;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return filterOption;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export { useFilterOption, useOptionReq };
|
|
118
|
+
// powered by hdj
|