@fle-ui/plus-address-selection 1.0.3-beta.2 → 1.0.4
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/index.d.ts +5 -5
- package/es/index.js +89 -68
- package/lib/index.d.ts +5 -5
- package/lib/index.js +88 -67
- package/package.json +2 -2
package/es/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CascaderProps } from 'antd';
|
|
3
|
-
export declare type CascaderValueType = string |
|
|
3
|
+
export declare type CascaderValueType = string | Array<string | number>;
|
|
4
4
|
export interface CascaderOptionType {
|
|
5
5
|
value?: string | number;
|
|
6
6
|
label?: React.ReactNode;
|
|
7
7
|
disabled?: boolean;
|
|
8
8
|
isLeaf?: boolean;
|
|
9
9
|
loading?: boolean;
|
|
10
|
-
children?:
|
|
10
|
+
children?: CascaderOptionType[];
|
|
11
11
|
hasChildren?: boolean;
|
|
12
12
|
[key: string]: any;
|
|
13
13
|
}
|
|
@@ -24,7 +24,7 @@ export interface addressItem {
|
|
|
24
24
|
}
|
|
25
25
|
export interface SiteSelectProps extends Omit<CascaderProps<any>, 'options' | 'value'> {
|
|
26
26
|
/**
|
|
27
|
-
* @description 格式化value
|
|
27
|
+
* @description 格式化 value
|
|
28
28
|
* @default
|
|
29
29
|
*/
|
|
30
30
|
valueDivision?: string;
|
|
@@ -39,12 +39,12 @@ export interface SiteSelectProps extends Omit<CascaderProps<any>, 'options' | 'v
|
|
|
39
39
|
*/
|
|
40
40
|
level?: number;
|
|
41
41
|
/**
|
|
42
|
-
* @description
|
|
42
|
+
* @description 指定选中项
|
|
43
43
|
* @default []
|
|
44
44
|
*/
|
|
45
45
|
value?: CascaderValueType;
|
|
46
46
|
/**
|
|
47
|
-
* @description
|
|
47
|
+
* @description 可选项数据源
|
|
48
48
|
* @default []
|
|
49
49
|
*/
|
|
50
50
|
options?: CascaderOptionType[];
|
package/es/index.js
CHANGED
|
@@ -18,7 +18,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
18
18
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
19
19
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
20
20
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
21
|
-
import React, { useEffect,
|
|
21
|
+
import React, { useEffect, useState } from 'react';
|
|
22
22
|
import _ from 'lodash';
|
|
23
23
|
import { httpClient } from './utils';
|
|
24
24
|
var AddressSelection = function AddressSelection(props) {
|
|
@@ -40,29 +40,46 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
40
40
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
41
41
|
stateValue = _useState6[0],
|
|
42
42
|
setStateValue = _useState6[1];
|
|
43
|
-
var firstTime = useRef(true);
|
|
44
43
|
useEffect(function () {
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
val = formatValue(props.defaultValue || '');
|
|
44
|
+
var val = formatValue((value === null || value === void 0 ? void 0 : value.length) ? value : props.defaultValue || '');
|
|
45
|
+
function init() {
|
|
46
|
+
return _init.apply(this, arguments);
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
function _init() {
|
|
49
|
+
_init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
50
|
+
var data, provinceList;
|
|
51
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
52
|
+
while (1) switch (_context.prev = _context.next) {
|
|
53
|
+
case 0:
|
|
54
|
+
_context.next = 2;
|
|
55
|
+
return getAddressAPI({
|
|
56
|
+
parentCode: 0
|
|
57
|
+
});
|
|
58
|
+
case 2:
|
|
59
|
+
data = _context.sent;
|
|
60
|
+
provinceList = formatArea(data, level === 1);
|
|
61
|
+
setAddressList(provinceList);
|
|
62
|
+
setStateValue(val);
|
|
63
|
+
case 6:
|
|
64
|
+
case "end":
|
|
65
|
+
return _context.stop();
|
|
66
|
+
}
|
|
67
|
+
}, _callee);
|
|
68
|
+
}));
|
|
69
|
+
return _init.apply(this, arguments);
|
|
55
70
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
init();
|
|
72
|
+
}, [level]);
|
|
73
|
+
useEffect(function () {
|
|
74
|
+
var val = formatValue((value === null || value === void 0 ? void 0 : value.length) ? value : props.defaultValue || '');
|
|
75
|
+
if (addressList.length && (val === null || val === void 0 ? void 0 : val.length) && !isLoad) {
|
|
76
|
+
initAddress(val);
|
|
77
|
+
setStateValue(val);
|
|
60
78
|
}
|
|
61
|
-
|
|
62
|
-
}, [value, level]);
|
|
79
|
+
}, [value, addressList.length, isLoad]);
|
|
63
80
|
var formatValue = function formatValue(value) {
|
|
64
81
|
var localvalue = [];
|
|
65
|
-
if (
|
|
82
|
+
if (value) {
|
|
66
83
|
if (!!valueDivision && !_.isArray(value)) {
|
|
67
84
|
localvalue = value.split(valueDivision);
|
|
68
85
|
} else {
|
|
@@ -89,62 +106,56 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
89
106
|
});
|
|
90
107
|
};
|
|
91
108
|
var getAddressAPI = /*#__PURE__*/function () {
|
|
92
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
109
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
93
110
|
var params,
|
|
94
111
|
_yield$httpClient$pos,
|
|
95
112
|
data,
|
|
96
|
-
|
|
97
|
-
return _regeneratorRuntime().wrap(function
|
|
98
|
-
while (1) switch (
|
|
113
|
+
_args2 = arguments;
|
|
114
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
115
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
99
116
|
case 0:
|
|
100
|
-
params =
|
|
101
|
-
|
|
117
|
+
params = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
118
|
+
_context2.next = 3;
|
|
102
119
|
return httpClient.post(apiUrl || '/basic/area/areas', params);
|
|
103
120
|
case 3:
|
|
104
|
-
_yield$httpClient$pos =
|
|
121
|
+
_yield$httpClient$pos = _context2.sent;
|
|
105
122
|
data = _yield$httpClient$pos.data;
|
|
106
|
-
return
|
|
123
|
+
return _context2.abrupt("return", data);
|
|
107
124
|
case 6:
|
|
108
125
|
case "end":
|
|
109
|
-
return
|
|
126
|
+
return _context2.stop();
|
|
110
127
|
}
|
|
111
|
-
},
|
|
128
|
+
}, _callee2);
|
|
112
129
|
}));
|
|
113
130
|
return function getAddressAPI() {
|
|
114
131
|
return _ref.apply(this, arguments);
|
|
115
132
|
};
|
|
116
133
|
}();
|
|
117
134
|
var initAddress = /*#__PURE__*/function () {
|
|
118
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
119
|
-
var
|
|
120
|
-
return _regeneratorRuntime().wrap(function
|
|
121
|
-
while (1) switch (
|
|
135
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(defaultValue, parentCode) {
|
|
136
|
+
var provinceList, len, thisAddress, _loop, i;
|
|
137
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
138
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
122
139
|
case 0:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
case 2:
|
|
128
|
-
data = _context3.sent;
|
|
129
|
-
provinceList = formatArea(data, level === 1);
|
|
130
|
-
if (!defaultValue) {
|
|
131
|
-
_context3.next = 14;
|
|
140
|
+
provinceList = _.cloneDeep(addressList);
|
|
141
|
+
len = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length;
|
|
142
|
+
if (!len) {
|
|
143
|
+
_context4.next = 11;
|
|
132
144
|
break;
|
|
133
145
|
}
|
|
134
|
-
len = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length;
|
|
135
146
|
thisAddress = provinceList;
|
|
136
147
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop(i) {
|
|
137
148
|
var _thisAddress;
|
|
138
149
|
var levelData, thisIndex;
|
|
139
|
-
return _regeneratorRuntime().wrap(function _loop$(
|
|
140
|
-
while (1) switch (
|
|
150
|
+
return _regeneratorRuntime().wrap(function _loop$(_context3) {
|
|
151
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
141
152
|
case 0:
|
|
142
|
-
|
|
153
|
+
_context3.next = 2;
|
|
143
154
|
return getAddressAPI({
|
|
144
155
|
parentCode: defaultValue[i]
|
|
145
156
|
});
|
|
146
157
|
case 2:
|
|
147
|
-
levelData =
|
|
158
|
+
levelData = _context3.sent;
|
|
148
159
|
thisIndex = -1;
|
|
149
160
|
(_thisAddress = thisAddress) === null || _thisAddress === void 0 ? void 0 : _thisAddress.forEach(function (item, index) {
|
|
150
161
|
if (item.value === defaultValue[i]) {
|
|
@@ -155,62 +166,71 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
155
166
|
if (thisIndex !== -1 && thisAddress[thisIndex].children) {
|
|
156
167
|
thisAddress = thisAddress[thisIndex].children;
|
|
157
168
|
}
|
|
158
|
-
|
|
169
|
+
if (i === len - 2) {
|
|
170
|
+
setIsLoad(true);
|
|
171
|
+
}
|
|
172
|
+
case 7:
|
|
159
173
|
case "end":
|
|
160
|
-
return
|
|
174
|
+
return _context3.stop();
|
|
161
175
|
}
|
|
162
176
|
}, _loop);
|
|
163
177
|
});
|
|
164
178
|
i = 0;
|
|
165
|
-
case
|
|
179
|
+
case 6:
|
|
166
180
|
if (!(i < len - 1)) {
|
|
167
|
-
|
|
181
|
+
_context4.next = 11;
|
|
168
182
|
break;
|
|
169
183
|
}
|
|
170
|
-
return
|
|
171
|
-
case
|
|
184
|
+
return _context4.delegateYield(_loop(i), "t0", 8);
|
|
185
|
+
case 8:
|
|
172
186
|
i++;
|
|
173
|
-
|
|
187
|
+
_context4.next = 6;
|
|
174
188
|
break;
|
|
175
|
-
case
|
|
189
|
+
case 11:
|
|
176
190
|
setAddressList(provinceList);
|
|
177
|
-
case
|
|
191
|
+
case 12:
|
|
178
192
|
case "end":
|
|
179
|
-
return
|
|
193
|
+
return _context4.stop();
|
|
180
194
|
}
|
|
181
|
-
},
|
|
195
|
+
}, _callee3);
|
|
182
196
|
}));
|
|
183
197
|
return function initAddress(_x, _x2) {
|
|
184
198
|
return _ref2.apply(this, arguments);
|
|
185
199
|
};
|
|
186
200
|
}();
|
|
187
201
|
var loadData = /*#__PURE__*/function () {
|
|
188
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
202
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(selectedOptions) {
|
|
189
203
|
var targetOption, data;
|
|
190
|
-
return _regeneratorRuntime().wrap(function
|
|
191
|
-
while (1) switch (
|
|
204
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context5) {
|
|
205
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
192
206
|
case 0:
|
|
193
207
|
targetOption = selectedOptions[selectedOptions.length - 1];
|
|
208
|
+
if (!(stateValue === null || stateValue === void 0 ? void 0 : stateValue.includes(targetOption.value))) {
|
|
209
|
+
_context5.next = 3;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
return _context5.abrupt("return");
|
|
213
|
+
case 3:
|
|
194
214
|
targetOption.loading = true;
|
|
195
|
-
|
|
215
|
+
_context5.next = 6;
|
|
196
216
|
return getAddressAPI({
|
|
197
217
|
parentCode: targetOption.value
|
|
198
218
|
});
|
|
199
|
-
case
|
|
200
|
-
data =
|
|
219
|
+
case 6:
|
|
220
|
+
data = _context5.sent;
|
|
201
221
|
targetOption.loading = false;
|
|
202
|
-
if (
|
|
222
|
+
if (data.length) {
|
|
203
223
|
targetOption.children = formatArea(data, targetOption.level + 1 === level);
|
|
204
224
|
} else {
|
|
205
225
|
targetOption.isLeaf = true;
|
|
206
226
|
}
|
|
207
227
|
setIsLoad(true);
|
|
208
228
|
setAddressList(_toConsumableArray(addressList));
|
|
209
|
-
case
|
|
229
|
+
case 11:
|
|
210
230
|
case "end":
|
|
211
|
-
return
|
|
231
|
+
return _context5.stop();
|
|
212
232
|
}
|
|
213
|
-
},
|
|
233
|
+
}, _callee4);
|
|
214
234
|
}));
|
|
215
235
|
return function loadData(_x3) {
|
|
216
236
|
return _ref3.apply(this, arguments);
|
|
@@ -218,13 +238,14 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
218
238
|
}();
|
|
219
239
|
var handleChange = function handleChange(info, selectedOptions) {
|
|
220
240
|
var cascaderValue = info;
|
|
221
|
-
if (
|
|
241
|
+
if (valueDivision) {
|
|
222
242
|
cascaderValue = cascaderValue.join(valueDivision);
|
|
223
243
|
}
|
|
224
244
|
setStateValue(info);
|
|
225
245
|
onChange && onChange(cascaderValue, selectedOptions);
|
|
226
246
|
};
|
|
227
247
|
return /*#__PURE__*/React.createElement(_Cascader, _extends({}, otherProps, {
|
|
248
|
+
defaultValue: props.defaultValue,
|
|
228
249
|
loadData: loadData,
|
|
229
250
|
options: addressList,
|
|
230
251
|
onChange: handleChange,
|
package/lib/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CascaderProps } from 'antd';
|
|
3
|
-
export declare type CascaderValueType = string |
|
|
3
|
+
export declare type CascaderValueType = string | Array<string | number>;
|
|
4
4
|
export interface CascaderOptionType {
|
|
5
5
|
value?: string | number;
|
|
6
6
|
label?: React.ReactNode;
|
|
7
7
|
disabled?: boolean;
|
|
8
8
|
isLeaf?: boolean;
|
|
9
9
|
loading?: boolean;
|
|
10
|
-
children?:
|
|
10
|
+
children?: CascaderOptionType[];
|
|
11
11
|
hasChildren?: boolean;
|
|
12
12
|
[key: string]: any;
|
|
13
13
|
}
|
|
@@ -24,7 +24,7 @@ export interface addressItem {
|
|
|
24
24
|
}
|
|
25
25
|
export interface SiteSelectProps extends Omit<CascaderProps<any>, 'options' | 'value'> {
|
|
26
26
|
/**
|
|
27
|
-
* @description 格式化value
|
|
27
|
+
* @description 格式化 value
|
|
28
28
|
* @default
|
|
29
29
|
*/
|
|
30
30
|
valueDivision?: string;
|
|
@@ -39,12 +39,12 @@ export interface SiteSelectProps extends Omit<CascaderProps<any>, 'options' | 'v
|
|
|
39
39
|
*/
|
|
40
40
|
level?: number;
|
|
41
41
|
/**
|
|
42
|
-
* @description
|
|
42
|
+
* @description 指定选中项
|
|
43
43
|
* @default []
|
|
44
44
|
*/
|
|
45
45
|
value?: CascaderValueType;
|
|
46
46
|
/**
|
|
47
|
-
* @description
|
|
47
|
+
* @description 可选项数据源
|
|
48
48
|
* @default []
|
|
49
49
|
*/
|
|
50
50
|
options?: CascaderOptionType[];
|
package/lib/index.js
CHANGED
|
@@ -48,29 +48,46 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
48
48
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
49
49
|
stateValue = _useState6[0],
|
|
50
50
|
setStateValue = _useState6[1];
|
|
51
|
-
var firstTime = (0, _react.useRef)(true);
|
|
52
51
|
(0, _react.useEffect)(function () {
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
val = formatValue(props.defaultValue || '');
|
|
52
|
+
var val = formatValue((value === null || value === void 0 ? void 0 : value.length) ? value : props.defaultValue || '');
|
|
53
|
+
function init() {
|
|
54
|
+
return _init.apply(this, arguments);
|
|
57
55
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
function _init() {
|
|
57
|
+
_init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
58
|
+
var data, provinceList;
|
|
59
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
60
|
+
while (1) switch (_context.prev = _context.next) {
|
|
61
|
+
case 0:
|
|
62
|
+
_context.next = 2;
|
|
63
|
+
return getAddressAPI({
|
|
64
|
+
parentCode: 0
|
|
65
|
+
});
|
|
66
|
+
case 2:
|
|
67
|
+
data = _context.sent;
|
|
68
|
+
provinceList = formatArea(data, level === 1);
|
|
69
|
+
setAddressList(provinceList);
|
|
70
|
+
setStateValue(val);
|
|
71
|
+
case 6:
|
|
72
|
+
case "end":
|
|
73
|
+
return _context.stop();
|
|
74
|
+
}
|
|
75
|
+
}, _callee);
|
|
76
|
+
}));
|
|
77
|
+
return _init.apply(this, arguments);
|
|
63
78
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
init();
|
|
80
|
+
}, [level]);
|
|
81
|
+
(0, _react.useEffect)(function () {
|
|
82
|
+
var val = formatValue((value === null || value === void 0 ? void 0 : value.length) ? value : props.defaultValue || '');
|
|
83
|
+
if (addressList.length && (val === null || val === void 0 ? void 0 : val.length) && !isLoad) {
|
|
84
|
+
initAddress(val);
|
|
85
|
+
setStateValue(val);
|
|
68
86
|
}
|
|
69
|
-
|
|
70
|
-
}, [value, level]);
|
|
87
|
+
}, [value, addressList.length, isLoad]);
|
|
71
88
|
var formatValue = function formatValue(value) {
|
|
72
89
|
var localvalue = [];
|
|
73
|
-
if (
|
|
90
|
+
if (value) {
|
|
74
91
|
if (!!valueDivision && !_lodash.default.isArray(value)) {
|
|
75
92
|
localvalue = value.split(valueDivision);
|
|
76
93
|
} else {
|
|
@@ -97,62 +114,56 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
97
114
|
});
|
|
98
115
|
};
|
|
99
116
|
var getAddressAPI = /*#__PURE__*/function () {
|
|
100
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
117
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
101
118
|
var params,
|
|
102
119
|
_yield$httpClient$pos,
|
|
103
120
|
data,
|
|
104
|
-
|
|
105
|
-
return _regeneratorRuntime().wrap(function
|
|
106
|
-
while (1) switch (
|
|
121
|
+
_args2 = arguments;
|
|
122
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
123
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
107
124
|
case 0:
|
|
108
|
-
params =
|
|
109
|
-
|
|
125
|
+
params = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
126
|
+
_context2.next = 3;
|
|
110
127
|
return _utils.httpClient.post(apiUrl || '/basic/area/areas', params);
|
|
111
128
|
case 3:
|
|
112
|
-
_yield$httpClient$pos =
|
|
129
|
+
_yield$httpClient$pos = _context2.sent;
|
|
113
130
|
data = _yield$httpClient$pos.data;
|
|
114
|
-
return
|
|
131
|
+
return _context2.abrupt("return", data);
|
|
115
132
|
case 6:
|
|
116
133
|
case "end":
|
|
117
|
-
return
|
|
134
|
+
return _context2.stop();
|
|
118
135
|
}
|
|
119
|
-
},
|
|
136
|
+
}, _callee2);
|
|
120
137
|
}));
|
|
121
138
|
return function getAddressAPI() {
|
|
122
139
|
return _ref.apply(this, arguments);
|
|
123
140
|
};
|
|
124
141
|
}();
|
|
125
142
|
var initAddress = /*#__PURE__*/function () {
|
|
126
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
127
|
-
var
|
|
128
|
-
return _regeneratorRuntime().wrap(function
|
|
129
|
-
while (1) switch (
|
|
143
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(defaultValue, parentCode) {
|
|
144
|
+
var provinceList, len, thisAddress, _loop, i;
|
|
145
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
146
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
130
147
|
case 0:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
case 2:
|
|
136
|
-
data = _context3.sent;
|
|
137
|
-
provinceList = formatArea(data, level === 1);
|
|
138
|
-
if (!defaultValue) {
|
|
139
|
-
_context3.next = 14;
|
|
148
|
+
provinceList = _lodash.default.cloneDeep(addressList);
|
|
149
|
+
len = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length;
|
|
150
|
+
if (!len) {
|
|
151
|
+
_context4.next = 11;
|
|
140
152
|
break;
|
|
141
153
|
}
|
|
142
|
-
len = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length;
|
|
143
154
|
thisAddress = provinceList;
|
|
144
155
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop(i) {
|
|
145
156
|
var _thisAddress;
|
|
146
157
|
var levelData, thisIndex;
|
|
147
|
-
return _regeneratorRuntime().wrap(function _loop$(
|
|
148
|
-
while (1) switch (
|
|
158
|
+
return _regeneratorRuntime().wrap(function _loop$(_context3) {
|
|
159
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
149
160
|
case 0:
|
|
150
|
-
|
|
161
|
+
_context3.next = 2;
|
|
151
162
|
return getAddressAPI({
|
|
152
163
|
parentCode: defaultValue[i]
|
|
153
164
|
});
|
|
154
165
|
case 2:
|
|
155
|
-
levelData =
|
|
166
|
+
levelData = _context3.sent;
|
|
156
167
|
thisIndex = -1;
|
|
157
168
|
(_thisAddress = thisAddress) === null || _thisAddress === void 0 ? void 0 : _thisAddress.forEach(function (item, index) {
|
|
158
169
|
if (item.value === defaultValue[i]) {
|
|
@@ -163,62 +174,71 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
163
174
|
if (thisIndex !== -1 && thisAddress[thisIndex].children) {
|
|
164
175
|
thisAddress = thisAddress[thisIndex].children;
|
|
165
176
|
}
|
|
166
|
-
|
|
177
|
+
if (i === len - 2) {
|
|
178
|
+
setIsLoad(true);
|
|
179
|
+
}
|
|
180
|
+
case 7:
|
|
167
181
|
case "end":
|
|
168
|
-
return
|
|
182
|
+
return _context3.stop();
|
|
169
183
|
}
|
|
170
184
|
}, _loop);
|
|
171
185
|
});
|
|
172
186
|
i = 0;
|
|
173
|
-
case
|
|
187
|
+
case 6:
|
|
174
188
|
if (!(i < len - 1)) {
|
|
175
|
-
|
|
189
|
+
_context4.next = 11;
|
|
176
190
|
break;
|
|
177
191
|
}
|
|
178
|
-
return
|
|
179
|
-
case
|
|
192
|
+
return _context4.delegateYield(_loop(i), "t0", 8);
|
|
193
|
+
case 8:
|
|
180
194
|
i++;
|
|
181
|
-
|
|
195
|
+
_context4.next = 6;
|
|
182
196
|
break;
|
|
183
|
-
case
|
|
197
|
+
case 11:
|
|
184
198
|
setAddressList(provinceList);
|
|
185
|
-
case
|
|
199
|
+
case 12:
|
|
186
200
|
case "end":
|
|
187
|
-
return
|
|
201
|
+
return _context4.stop();
|
|
188
202
|
}
|
|
189
|
-
},
|
|
203
|
+
}, _callee3);
|
|
190
204
|
}));
|
|
191
205
|
return function initAddress(_x, _x2) {
|
|
192
206
|
return _ref2.apply(this, arguments);
|
|
193
207
|
};
|
|
194
208
|
}();
|
|
195
209
|
var loadData = /*#__PURE__*/function () {
|
|
196
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
210
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(selectedOptions) {
|
|
197
211
|
var targetOption, data;
|
|
198
|
-
return _regeneratorRuntime().wrap(function
|
|
199
|
-
while (1) switch (
|
|
212
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context5) {
|
|
213
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
200
214
|
case 0:
|
|
201
215
|
targetOption = selectedOptions[selectedOptions.length - 1];
|
|
216
|
+
if (!(stateValue === null || stateValue === void 0 ? void 0 : stateValue.includes(targetOption.value))) {
|
|
217
|
+
_context5.next = 3;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
return _context5.abrupt("return");
|
|
221
|
+
case 3:
|
|
202
222
|
targetOption.loading = true;
|
|
203
|
-
|
|
223
|
+
_context5.next = 6;
|
|
204
224
|
return getAddressAPI({
|
|
205
225
|
parentCode: targetOption.value
|
|
206
226
|
});
|
|
207
|
-
case
|
|
208
|
-
data =
|
|
227
|
+
case 6:
|
|
228
|
+
data = _context5.sent;
|
|
209
229
|
targetOption.loading = false;
|
|
210
|
-
if (
|
|
230
|
+
if (data.length) {
|
|
211
231
|
targetOption.children = formatArea(data, targetOption.level + 1 === level);
|
|
212
232
|
} else {
|
|
213
233
|
targetOption.isLeaf = true;
|
|
214
234
|
}
|
|
215
235
|
setIsLoad(true);
|
|
216
236
|
setAddressList(_toConsumableArray(addressList));
|
|
217
|
-
case
|
|
237
|
+
case 11:
|
|
218
238
|
case "end":
|
|
219
|
-
return
|
|
239
|
+
return _context5.stop();
|
|
220
240
|
}
|
|
221
|
-
},
|
|
241
|
+
}, _callee4);
|
|
222
242
|
}));
|
|
223
243
|
return function loadData(_x3) {
|
|
224
244
|
return _ref3.apply(this, arguments);
|
|
@@ -226,13 +246,14 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
226
246
|
}();
|
|
227
247
|
var handleChange = function handleChange(info, selectedOptions) {
|
|
228
248
|
var cascaderValue = info;
|
|
229
|
-
if (
|
|
249
|
+
if (valueDivision) {
|
|
230
250
|
cascaderValue = cascaderValue.join(valueDivision);
|
|
231
251
|
}
|
|
232
252
|
setStateValue(info);
|
|
233
253
|
onChange && onChange(cascaderValue, selectedOptions);
|
|
234
254
|
};
|
|
235
255
|
return /*#__PURE__*/_react.default.createElement(_antd.Cascader, _extends({}, otherProps, {
|
|
256
|
+
defaultValue: props.defaultValue,
|
|
236
257
|
loadData: loadData,
|
|
237
258
|
options: addressList,
|
|
238
259
|
onChange: handleChange,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fle-ui/plus-address-selection",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "@fle-ui/plus-address-selection",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/js-cookie": "^3.0.0"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "e5c22e59ebc5a0af73f90323e8ed3e825b7a5035"
|
|
45
45
|
}
|