@fle-ui/plus-address-selection 1.0.12 → 1.0.14
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 +4 -2
- package/es/index.js +43 -61
- package/es/utils/api.d.ts +10 -0
- package/es/utils/api.js +24 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.js +43 -61
- package/lib/utils/api.d.ts +10 -0
- package/lib/utils/api.js +31 -0
- package/package.json +2 -2
- package/es/utils/httpClient.d.ts +0 -13
- package/es/utils/httpClient.js +0 -76
- package/es/utils/index.d.ts +0 -2
- package/es/utils/index.js +0 -2
- package/lib/utils/httpClient.d.ts +0 -13
- package/lib/utils/httpClient.js +0 -82
- package/lib/utils/index.d.ts +0 -2
- package/lib/utils/index.js +0 -13
package/es/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CascaderProps } from 'antd';
|
|
3
|
+
import { Env } from './utils/api';
|
|
3
4
|
export declare type CascaderValueType = string | Array<string | number>;
|
|
4
5
|
export interface CascaderOptionType {
|
|
5
6
|
value?: string | number;
|
|
@@ -19,7 +20,7 @@ export interface addressItem {
|
|
|
19
20
|
tree?: string;
|
|
20
21
|
level?: string;
|
|
21
22
|
isLeaf?: boolean;
|
|
22
|
-
hasChildren?: boolean;
|
|
23
|
+
hasChildren?: boolean | 0 | 1;
|
|
23
24
|
children?: addressItem[];
|
|
24
25
|
}
|
|
25
26
|
export interface SiteSelectProps extends Omit<CascaderProps<any>, 'options' | 'value'> {
|
|
@@ -34,7 +35,7 @@ export interface SiteSelectProps extends Omit<CascaderProps<any>, 'options' | 'v
|
|
|
34
35
|
*/
|
|
35
36
|
apiUrl?: string;
|
|
36
37
|
/**
|
|
37
|
-
* @description 地址层级 默认四级
|
|
38
|
+
* @description 地址层级 默认四级 --
|
|
38
39
|
* @default 4
|
|
39
40
|
*/
|
|
40
41
|
level?: number;
|
|
@@ -48,6 +49,7 @@ export interface SiteSelectProps extends Omit<CascaderProps<any>, 'options' | 'v
|
|
|
48
49
|
* @default []
|
|
49
50
|
*/
|
|
50
51
|
options?: CascaderOptionType[];
|
|
52
|
+
env?: Env;
|
|
51
53
|
}
|
|
52
54
|
declare const AddressSelection: React.FC<SiteSelectProps>;
|
|
53
55
|
export default AddressSelection;
|
package/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
import "antd/es/cascader/style";
|
|
3
3
|
import _Cascader from "antd/es/cascader";
|
|
4
|
-
var _excluded = ["level", "value", "onChange", "valueDivision", "apiUrl"];
|
|
4
|
+
var _excluded = ["env", "level", "value", "onChange", "valueDivision", "apiUrl"];
|
|
5
5
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
6
6
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
7
7
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -22,25 +22,28 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
22
22
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
23
23
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
24
24
|
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; }
|
|
25
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var
|
|
25
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } } return target; }
|
|
26
26
|
import React, { useEffect, useState } from 'react';
|
|
27
27
|
import _ from 'lodash';
|
|
28
|
-
import {
|
|
28
|
+
import { apiCreate } from './utils/api';
|
|
29
29
|
var defaultProps = {
|
|
30
30
|
level: 4,
|
|
31
31
|
valueDivision: '',
|
|
32
32
|
value: [],
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
apiUrl: '/basic/area/areas',
|
|
34
|
+
onChange: function onChange() {}
|
|
35
35
|
};
|
|
36
36
|
var AddressSelection = function AddressSelection(props) {
|
|
37
37
|
var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props),
|
|
38
|
+
env = _defaultProps$props.env,
|
|
38
39
|
level = _defaultProps$props.level,
|
|
39
40
|
value = _defaultProps$props.value,
|
|
40
41
|
onChange = _defaultProps$props.onChange,
|
|
41
42
|
valueDivision = _defaultProps$props.valueDivision,
|
|
42
43
|
apiUrl = _defaultProps$props.apiUrl,
|
|
43
44
|
otherProps = _objectWithoutProperties(_defaultProps$props, _excluded);
|
|
45
|
+
var _apiCreate = apiCreate(apiUrl, env),
|
|
46
|
+
getAddress = _apiCreate.getAddress;
|
|
44
47
|
var _useState = useState([]),
|
|
45
48
|
_useState2 = _slicedToArray(_useState, 2),
|
|
46
49
|
addressList = _useState2[0],
|
|
@@ -65,15 +68,16 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
65
68
|
while (1) switch (_context.prev = _context.next) {
|
|
66
69
|
case 0:
|
|
67
70
|
_context.next = 2;
|
|
68
|
-
return
|
|
71
|
+
return getAddress({
|
|
69
72
|
parentCode: 0
|
|
70
73
|
});
|
|
71
74
|
case 2:
|
|
72
75
|
data = _context.sent;
|
|
73
76
|
provinceList = formatArea(data, level === 1);
|
|
77
|
+
console.log(apiUrl, provinceList);
|
|
74
78
|
setAddressList(provinceList);
|
|
75
79
|
setStateValue(val);
|
|
76
|
-
case
|
|
80
|
+
case 7:
|
|
77
81
|
case "end":
|
|
78
82
|
return _context.stop();
|
|
79
83
|
}
|
|
@@ -109,66 +113,44 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
109
113
|
};
|
|
110
114
|
var formatArea = function formatArea(list, isLeaf) {
|
|
111
115
|
return list === null || list === void 0 ? void 0 : list.map(function (item) {
|
|
116
|
+
var _isLeaf = isLeaf;
|
|
117
|
+
if (item.hasChildren === 0) {
|
|
118
|
+
_isLeaf = true;
|
|
119
|
+
}
|
|
112
120
|
return {
|
|
113
121
|
value: item.code,
|
|
114
122
|
label: item.name,
|
|
115
123
|
tree: item.tree,
|
|
116
124
|
level: item.level,
|
|
117
|
-
isLeaf:
|
|
125
|
+
isLeaf: _isLeaf
|
|
118
126
|
};
|
|
119
127
|
});
|
|
120
128
|
};
|
|
121
|
-
var getAddressAPI = /*#__PURE__*/function () {
|
|
122
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
123
|
-
var params,
|
|
124
|
-
_yield$httpClient$pos,
|
|
125
|
-
data,
|
|
126
|
-
_args2 = arguments;
|
|
127
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
128
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
129
|
-
case 0:
|
|
130
|
-
params = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
131
|
-
_context2.next = 3;
|
|
132
|
-
return httpClient.post(apiUrl || '/basic/area/areas', params);
|
|
133
|
-
case 3:
|
|
134
|
-
_yield$httpClient$pos = _context2.sent;
|
|
135
|
-
data = _yield$httpClient$pos.data;
|
|
136
|
-
return _context2.abrupt("return", data);
|
|
137
|
-
case 6:
|
|
138
|
-
case "end":
|
|
139
|
-
return _context2.stop();
|
|
140
|
-
}
|
|
141
|
-
}, _callee2);
|
|
142
|
-
}));
|
|
143
|
-
return function getAddressAPI() {
|
|
144
|
-
return _ref.apply(this, arguments);
|
|
145
|
-
};
|
|
146
|
-
}();
|
|
147
129
|
var initAddress = /*#__PURE__*/function () {
|
|
148
|
-
var
|
|
130
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(defaultValue, parentCode) {
|
|
149
131
|
var provinceList, len, thisAddress, _loop, i;
|
|
150
|
-
return _regeneratorRuntime().wrap(function
|
|
151
|
-
while (1) switch (
|
|
132
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context3) {
|
|
133
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
152
134
|
case 0:
|
|
153
135
|
provinceList = _.cloneDeep(addressList);
|
|
154
136
|
len = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length;
|
|
155
137
|
if (!len) {
|
|
156
|
-
|
|
138
|
+
_context3.next = 11;
|
|
157
139
|
break;
|
|
158
140
|
}
|
|
159
141
|
thisAddress = provinceList;
|
|
160
142
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop(i) {
|
|
161
143
|
var _thisAddress;
|
|
162
144
|
var levelData, thisIndex;
|
|
163
|
-
return _regeneratorRuntime().wrap(function _loop$(
|
|
164
|
-
while (1) switch (
|
|
145
|
+
return _regeneratorRuntime().wrap(function _loop$(_context2) {
|
|
146
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
165
147
|
case 0:
|
|
166
|
-
|
|
167
|
-
return
|
|
148
|
+
_context2.next = 2;
|
|
149
|
+
return getAddress({
|
|
168
150
|
parentCode: defaultValue[i]
|
|
169
151
|
});
|
|
170
152
|
case 2:
|
|
171
|
-
levelData =
|
|
153
|
+
levelData = _context2.sent;
|
|
172
154
|
thisIndex = -1;
|
|
173
155
|
(_thisAddress = thisAddress) === null || _thisAddress === void 0 ? void 0 : _thisAddress.forEach(function (item, index) {
|
|
174
156
|
if (item.value === defaultValue[i]) {
|
|
@@ -184,53 +166,53 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
184
166
|
}
|
|
185
167
|
case 7:
|
|
186
168
|
case "end":
|
|
187
|
-
return
|
|
169
|
+
return _context2.stop();
|
|
188
170
|
}
|
|
189
171
|
}, _loop);
|
|
190
172
|
});
|
|
191
173
|
i = 0;
|
|
192
174
|
case 6:
|
|
193
175
|
if (!(i < len - 1)) {
|
|
194
|
-
|
|
176
|
+
_context3.next = 11;
|
|
195
177
|
break;
|
|
196
178
|
}
|
|
197
|
-
return
|
|
179
|
+
return _context3.delegateYield(_loop(i), "t0", 8);
|
|
198
180
|
case 8:
|
|
199
181
|
i++;
|
|
200
|
-
|
|
182
|
+
_context3.next = 6;
|
|
201
183
|
break;
|
|
202
184
|
case 11:
|
|
203
185
|
setAddressList(provinceList);
|
|
204
186
|
case 12:
|
|
205
187
|
case "end":
|
|
206
|
-
return
|
|
188
|
+
return _context3.stop();
|
|
207
189
|
}
|
|
208
|
-
},
|
|
190
|
+
}, _callee2);
|
|
209
191
|
}));
|
|
210
192
|
return function initAddress(_x, _x2) {
|
|
211
|
-
return
|
|
193
|
+
return _ref.apply(this, arguments);
|
|
212
194
|
};
|
|
213
195
|
}();
|
|
214
196
|
var loadData = /*#__PURE__*/function () {
|
|
215
|
-
var
|
|
197
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(selectedOptions) {
|
|
216
198
|
var targetOption, data;
|
|
217
|
-
return _regeneratorRuntime().wrap(function
|
|
218
|
-
while (1) switch (
|
|
199
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
200
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
219
201
|
case 0:
|
|
220
202
|
targetOption = selectedOptions[selectedOptions.length - 1];
|
|
221
203
|
if (!(stateValue === null || stateValue === void 0 ? void 0 : stateValue.includes(targetOption.value))) {
|
|
222
|
-
|
|
204
|
+
_context4.next = 3;
|
|
223
205
|
break;
|
|
224
206
|
}
|
|
225
|
-
return
|
|
207
|
+
return _context4.abrupt("return");
|
|
226
208
|
case 3:
|
|
227
209
|
targetOption.loading = true;
|
|
228
|
-
|
|
229
|
-
return
|
|
210
|
+
_context4.next = 6;
|
|
211
|
+
return getAddress({
|
|
230
212
|
parentCode: targetOption.value
|
|
231
213
|
});
|
|
232
214
|
case 6:
|
|
233
|
-
data =
|
|
215
|
+
data = _context4.sent;
|
|
234
216
|
targetOption.loading = false;
|
|
235
217
|
if (data.length) {
|
|
236
218
|
targetOption.children = formatArea(data, targetOption.level + 1 === level);
|
|
@@ -241,12 +223,12 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
241
223
|
setAddressList(_toConsumableArray(addressList));
|
|
242
224
|
case 11:
|
|
243
225
|
case "end":
|
|
244
|
-
return
|
|
226
|
+
return _context4.stop();
|
|
245
227
|
}
|
|
246
|
-
},
|
|
228
|
+
}, _callee3);
|
|
247
229
|
}));
|
|
248
230
|
return function loadData(_x3) {
|
|
249
|
-
return
|
|
231
|
+
return _ref2.apply(this, arguments);
|
|
250
232
|
};
|
|
251
233
|
}();
|
|
252
234
|
var handleChange = function handleChange(info, selectedOptions) {
|
package/es/utils/api.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
var baseURLMap = {
|
|
3
|
+
dev: 'https://dev-gateway.fxqifu.net/pangu',
|
|
4
|
+
qa: 'https://qa-gateway.fxqifu.net/pangu',
|
|
5
|
+
prod: 'https://gateway.fxqifu.net/pangu'
|
|
6
|
+
};
|
|
7
|
+
export var apiCreate = function apiCreate(apiUrl, env) {
|
|
8
|
+
var envGet = env || localStorage.getItem('env') || 'prod';
|
|
9
|
+
var baseURL = baseURLMap[envGet];
|
|
10
|
+
return {
|
|
11
|
+
getAddress: function getAddress(data) {
|
|
12
|
+
return new Promise(function (resolve, reject) {
|
|
13
|
+
axios.post("".concat(baseURL).concat(apiUrl), data).then(function (res) {
|
|
14
|
+
var _res$data;
|
|
15
|
+
if (Array.isArray((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.data)) {
|
|
16
|
+
resolve(res.data.data);
|
|
17
|
+
} else {
|
|
18
|
+
resolve([]);
|
|
19
|
+
}
|
|
20
|
+
}).catch(reject);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CascaderProps } from 'antd';
|
|
3
|
+
import { Env } from './utils/api';
|
|
3
4
|
export declare type CascaderValueType = string | Array<string | number>;
|
|
4
5
|
export interface CascaderOptionType {
|
|
5
6
|
value?: string | number;
|
|
@@ -19,7 +20,7 @@ export interface addressItem {
|
|
|
19
20
|
tree?: string;
|
|
20
21
|
level?: string;
|
|
21
22
|
isLeaf?: boolean;
|
|
22
|
-
hasChildren?: boolean;
|
|
23
|
+
hasChildren?: boolean | 0 | 1;
|
|
23
24
|
children?: addressItem[];
|
|
24
25
|
}
|
|
25
26
|
export interface SiteSelectProps extends Omit<CascaderProps<any>, 'options' | 'value'> {
|
|
@@ -34,7 +35,7 @@ export interface SiteSelectProps extends Omit<CascaderProps<any>, 'options' | 'v
|
|
|
34
35
|
*/
|
|
35
36
|
apiUrl?: string;
|
|
36
37
|
/**
|
|
37
|
-
* @description 地址层级 默认四级
|
|
38
|
+
* @description 地址层级 默认四级 --
|
|
38
39
|
* @default 4
|
|
39
40
|
*/
|
|
40
41
|
level?: number;
|
|
@@ -48,6 +49,7 @@ export interface SiteSelectProps extends Omit<CascaderProps<any>, 'options' | 'v
|
|
|
48
49
|
* @default []
|
|
49
50
|
*/
|
|
50
51
|
options?: CascaderOptionType[];
|
|
52
|
+
env?: Env;
|
|
51
53
|
}
|
|
52
54
|
declare const AddressSelection: React.FC<SiteSelectProps>;
|
|
53
55
|
export default AddressSelection;
|
package/lib/index.js
CHANGED
|
@@ -8,8 +8,8 @@ exports.default = void 0;
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _antd = require("antd");
|
|
10
10
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
11
|
-
var
|
|
12
|
-
var _excluded = ["level", "value", "onChange", "valueDivision", "apiUrl"];
|
|
11
|
+
var _api = require("./utils/api");
|
|
12
|
+
var _excluded = ["env", "level", "value", "onChange", "valueDivision", "apiUrl"];
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -33,22 +33,25 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
33
33
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
34
34
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
35
35
|
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; }
|
|
36
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var
|
|
36
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } } return target; }
|
|
37
37
|
var defaultProps = {
|
|
38
38
|
level: 4,
|
|
39
39
|
valueDivision: '',
|
|
40
40
|
value: [],
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
apiUrl: '/basic/area/areas',
|
|
42
|
+
onChange: function onChange() {}
|
|
43
43
|
};
|
|
44
44
|
var AddressSelection = function AddressSelection(props) {
|
|
45
45
|
var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props),
|
|
46
|
+
env = _defaultProps$props.env,
|
|
46
47
|
level = _defaultProps$props.level,
|
|
47
48
|
value = _defaultProps$props.value,
|
|
48
49
|
onChange = _defaultProps$props.onChange,
|
|
49
50
|
valueDivision = _defaultProps$props.valueDivision,
|
|
50
51
|
apiUrl = _defaultProps$props.apiUrl,
|
|
51
52
|
otherProps = _objectWithoutProperties(_defaultProps$props, _excluded);
|
|
53
|
+
var _apiCreate = (0, _api.apiCreate)(apiUrl, env),
|
|
54
|
+
getAddress = _apiCreate.getAddress;
|
|
52
55
|
var _useState = (0, _react.useState)([]),
|
|
53
56
|
_useState2 = _slicedToArray(_useState, 2),
|
|
54
57
|
addressList = _useState2[0],
|
|
@@ -73,15 +76,16 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
73
76
|
while (1) switch (_context.prev = _context.next) {
|
|
74
77
|
case 0:
|
|
75
78
|
_context.next = 2;
|
|
76
|
-
return
|
|
79
|
+
return getAddress({
|
|
77
80
|
parentCode: 0
|
|
78
81
|
});
|
|
79
82
|
case 2:
|
|
80
83
|
data = _context.sent;
|
|
81
84
|
provinceList = formatArea(data, level === 1);
|
|
85
|
+
console.log(apiUrl, provinceList);
|
|
82
86
|
setAddressList(provinceList);
|
|
83
87
|
setStateValue(val);
|
|
84
|
-
case
|
|
88
|
+
case 7:
|
|
85
89
|
case "end":
|
|
86
90
|
return _context.stop();
|
|
87
91
|
}
|
|
@@ -117,66 +121,44 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
117
121
|
};
|
|
118
122
|
var formatArea = function formatArea(list, isLeaf) {
|
|
119
123
|
return list === null || list === void 0 ? void 0 : list.map(function (item) {
|
|
124
|
+
var _isLeaf = isLeaf;
|
|
125
|
+
if (item.hasChildren === 0) {
|
|
126
|
+
_isLeaf = true;
|
|
127
|
+
}
|
|
120
128
|
return {
|
|
121
129
|
value: item.code,
|
|
122
130
|
label: item.name,
|
|
123
131
|
tree: item.tree,
|
|
124
132
|
level: item.level,
|
|
125
|
-
isLeaf:
|
|
133
|
+
isLeaf: _isLeaf
|
|
126
134
|
};
|
|
127
135
|
});
|
|
128
136
|
};
|
|
129
|
-
var getAddressAPI = /*#__PURE__*/function () {
|
|
130
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
131
|
-
var params,
|
|
132
|
-
_yield$httpClient$pos,
|
|
133
|
-
data,
|
|
134
|
-
_args2 = arguments;
|
|
135
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
136
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
137
|
-
case 0:
|
|
138
|
-
params = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
139
|
-
_context2.next = 3;
|
|
140
|
-
return _utils.httpClient.post(apiUrl || '/basic/area/areas', params);
|
|
141
|
-
case 3:
|
|
142
|
-
_yield$httpClient$pos = _context2.sent;
|
|
143
|
-
data = _yield$httpClient$pos.data;
|
|
144
|
-
return _context2.abrupt("return", data);
|
|
145
|
-
case 6:
|
|
146
|
-
case "end":
|
|
147
|
-
return _context2.stop();
|
|
148
|
-
}
|
|
149
|
-
}, _callee2);
|
|
150
|
-
}));
|
|
151
|
-
return function getAddressAPI() {
|
|
152
|
-
return _ref.apply(this, arguments);
|
|
153
|
-
};
|
|
154
|
-
}();
|
|
155
137
|
var initAddress = /*#__PURE__*/function () {
|
|
156
|
-
var
|
|
138
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(defaultValue, parentCode) {
|
|
157
139
|
var provinceList, len, thisAddress, _loop, i;
|
|
158
|
-
return _regeneratorRuntime().wrap(function
|
|
159
|
-
while (1) switch (
|
|
140
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context3) {
|
|
141
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
160
142
|
case 0:
|
|
161
143
|
provinceList = _lodash.default.cloneDeep(addressList);
|
|
162
144
|
len = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length;
|
|
163
145
|
if (!len) {
|
|
164
|
-
|
|
146
|
+
_context3.next = 11;
|
|
165
147
|
break;
|
|
166
148
|
}
|
|
167
149
|
thisAddress = provinceList;
|
|
168
150
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop(i) {
|
|
169
151
|
var _thisAddress;
|
|
170
152
|
var levelData, thisIndex;
|
|
171
|
-
return _regeneratorRuntime().wrap(function _loop$(
|
|
172
|
-
while (1) switch (
|
|
153
|
+
return _regeneratorRuntime().wrap(function _loop$(_context2) {
|
|
154
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
173
155
|
case 0:
|
|
174
|
-
|
|
175
|
-
return
|
|
156
|
+
_context2.next = 2;
|
|
157
|
+
return getAddress({
|
|
176
158
|
parentCode: defaultValue[i]
|
|
177
159
|
});
|
|
178
160
|
case 2:
|
|
179
|
-
levelData =
|
|
161
|
+
levelData = _context2.sent;
|
|
180
162
|
thisIndex = -1;
|
|
181
163
|
(_thisAddress = thisAddress) === null || _thisAddress === void 0 ? void 0 : _thisAddress.forEach(function (item, index) {
|
|
182
164
|
if (item.value === defaultValue[i]) {
|
|
@@ -192,53 +174,53 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
192
174
|
}
|
|
193
175
|
case 7:
|
|
194
176
|
case "end":
|
|
195
|
-
return
|
|
177
|
+
return _context2.stop();
|
|
196
178
|
}
|
|
197
179
|
}, _loop);
|
|
198
180
|
});
|
|
199
181
|
i = 0;
|
|
200
182
|
case 6:
|
|
201
183
|
if (!(i < len - 1)) {
|
|
202
|
-
|
|
184
|
+
_context3.next = 11;
|
|
203
185
|
break;
|
|
204
186
|
}
|
|
205
|
-
return
|
|
187
|
+
return _context3.delegateYield(_loop(i), "t0", 8);
|
|
206
188
|
case 8:
|
|
207
189
|
i++;
|
|
208
|
-
|
|
190
|
+
_context3.next = 6;
|
|
209
191
|
break;
|
|
210
192
|
case 11:
|
|
211
193
|
setAddressList(provinceList);
|
|
212
194
|
case 12:
|
|
213
195
|
case "end":
|
|
214
|
-
return
|
|
196
|
+
return _context3.stop();
|
|
215
197
|
}
|
|
216
|
-
},
|
|
198
|
+
}, _callee2);
|
|
217
199
|
}));
|
|
218
200
|
return function initAddress(_x, _x2) {
|
|
219
|
-
return
|
|
201
|
+
return _ref.apply(this, arguments);
|
|
220
202
|
};
|
|
221
203
|
}();
|
|
222
204
|
var loadData = /*#__PURE__*/function () {
|
|
223
|
-
var
|
|
205
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(selectedOptions) {
|
|
224
206
|
var targetOption, data;
|
|
225
|
-
return _regeneratorRuntime().wrap(function
|
|
226
|
-
while (1) switch (
|
|
207
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
208
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
227
209
|
case 0:
|
|
228
210
|
targetOption = selectedOptions[selectedOptions.length - 1];
|
|
229
211
|
if (!(stateValue === null || stateValue === void 0 ? void 0 : stateValue.includes(targetOption.value))) {
|
|
230
|
-
|
|
212
|
+
_context4.next = 3;
|
|
231
213
|
break;
|
|
232
214
|
}
|
|
233
|
-
return
|
|
215
|
+
return _context4.abrupt("return");
|
|
234
216
|
case 3:
|
|
235
217
|
targetOption.loading = true;
|
|
236
|
-
|
|
237
|
-
return
|
|
218
|
+
_context4.next = 6;
|
|
219
|
+
return getAddress({
|
|
238
220
|
parentCode: targetOption.value
|
|
239
221
|
});
|
|
240
222
|
case 6:
|
|
241
|
-
data =
|
|
223
|
+
data = _context4.sent;
|
|
242
224
|
targetOption.loading = false;
|
|
243
225
|
if (data.length) {
|
|
244
226
|
targetOption.children = formatArea(data, targetOption.level + 1 === level);
|
|
@@ -249,12 +231,12 @@ var AddressSelection = function AddressSelection(props) {
|
|
|
249
231
|
setAddressList(_toConsumableArray(addressList));
|
|
250
232
|
case 11:
|
|
251
233
|
case "end":
|
|
252
|
-
return
|
|
234
|
+
return _context4.stop();
|
|
253
235
|
}
|
|
254
|
-
},
|
|
236
|
+
}, _callee3);
|
|
255
237
|
}));
|
|
256
238
|
return function loadData(_x3) {
|
|
257
|
-
return
|
|
239
|
+
return _ref2.apply(this, arguments);
|
|
258
240
|
};
|
|
259
241
|
}();
|
|
260
242
|
var handleChange = function handleChange(info, selectedOptions) {
|
package/lib/utils/api.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.apiCreate = void 0;
|
|
7
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
var baseURLMap = {
|
|
10
|
+
dev: 'https://dev-gateway.fxqifu.net/pangu',
|
|
11
|
+
qa: 'https://qa-gateway.fxqifu.net/pangu',
|
|
12
|
+
prod: 'https://gateway.fxqifu.net/pangu'
|
|
13
|
+
};
|
|
14
|
+
var apiCreate = exports.apiCreate = function apiCreate(apiUrl, env) {
|
|
15
|
+
var envGet = env || localStorage.getItem('env') || 'prod';
|
|
16
|
+
var baseURL = baseURLMap[envGet];
|
|
17
|
+
return {
|
|
18
|
+
getAddress: function getAddress(data) {
|
|
19
|
+
return new Promise(function (resolve, reject) {
|
|
20
|
+
_axios.default.post("".concat(baseURL).concat(apiUrl), data).then(function (res) {
|
|
21
|
+
var _res$data;
|
|
22
|
+
if (Array.isArray((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.data)) {
|
|
23
|
+
resolve(res.data.data);
|
|
24
|
+
} else {
|
|
25
|
+
resolve([]);
|
|
26
|
+
}
|
|
27
|
+
}).catch(reject);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
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.14",
|
|
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": "2c212687f40c44697c835063ca68fc46ebde730a"
|
|
45
45
|
}
|
package/es/utils/httpClient.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface Response {
|
|
2
|
-
status: number;
|
|
3
|
-
data: any;
|
|
4
|
-
statusText: string;
|
|
5
|
-
}
|
|
6
|
-
export interface AxiosRequestConfig {
|
|
7
|
-
baseURL?: string;
|
|
8
|
-
timeout: number;
|
|
9
|
-
headers?: any;
|
|
10
|
-
url?: string;
|
|
11
|
-
}
|
|
12
|
-
declare const httpClient: import("axios").AxiosInstance;
|
|
13
|
-
export default httpClient;
|
package/es/utils/httpClient.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import "antd/es/notification/style";
|
|
2
|
-
import _notification from "antd/es/notification";
|
|
3
|
-
import axios from 'axios';
|
|
4
|
-
import Cookies from 'js-cookie';
|
|
5
|
-
var axiosConfig = {
|
|
6
|
-
baseURL: 'https://gateway.fxqifu.net/pangu',
|
|
7
|
-
timeout: 60000
|
|
8
|
-
};
|
|
9
|
-
var httpClient = axios.create(axiosConfig);
|
|
10
|
-
// 登陆页面接口列表,不需要带token
|
|
11
|
-
var loginMap = [''];
|
|
12
|
-
httpClient.interceptors.request.use(function (config) {
|
|
13
|
-
config.headers['Content-Type'] = 'application/json;charset=UTF-8';
|
|
14
|
-
if (loginMap.find(function (item) {
|
|
15
|
-
return config.url.endsWith(item);
|
|
16
|
-
})) {
|
|
17
|
-
delete config.headers['authority_token'];
|
|
18
|
-
} else {
|
|
19
|
-
var tokenFrom = config['tokenFrom'];
|
|
20
|
-
var token = '';
|
|
21
|
-
switch (tokenFrom) {
|
|
22
|
-
case 'cookie':
|
|
23
|
-
token = Cookies.get('token');
|
|
24
|
-
break;
|
|
25
|
-
case 'localstorage':
|
|
26
|
-
token = localStorage.getItem('token');
|
|
27
|
-
break;
|
|
28
|
-
default:
|
|
29
|
-
token = Cookies.get('token') || localStorage.getItem('token');
|
|
30
|
-
}
|
|
31
|
-
config.headers['authority_token'] = token;
|
|
32
|
-
}
|
|
33
|
-
return config;
|
|
34
|
-
}, function (err) {
|
|
35
|
-
_notification.error({
|
|
36
|
-
message: '发送请求失败',
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
description: err
|
|
39
|
-
});
|
|
40
|
-
return false;
|
|
41
|
-
});
|
|
42
|
-
httpClient.interceptors.response.use(function (res) {
|
|
43
|
-
var status = res.status,
|
|
44
|
-
data = res.data,
|
|
45
|
-
statusText = res.statusText;
|
|
46
|
-
return new Promise(function (resolve, reject) {
|
|
47
|
-
if (status < 200 || status > 300) {
|
|
48
|
-
_notification.error({
|
|
49
|
-
message: "\u8BF7\u6C42\u9519\u8BEF: ".concat(status),
|
|
50
|
-
description: statusText
|
|
51
|
-
});
|
|
52
|
-
} else if (!data.success) {
|
|
53
|
-
if (data.code === '915003') {
|
|
54
|
-
return reject(data);
|
|
55
|
-
}
|
|
56
|
-
if (data.code === '100003') {
|
|
57
|
-
return reject(data);
|
|
58
|
-
}
|
|
59
|
-
_notification.error({
|
|
60
|
-
message: '提示',
|
|
61
|
-
description: data.message
|
|
62
|
-
});
|
|
63
|
-
return reject(data);
|
|
64
|
-
} else {
|
|
65
|
-
return resolve(data || true);
|
|
66
|
-
}
|
|
67
|
-
return reject();
|
|
68
|
-
});
|
|
69
|
-
}, function () {
|
|
70
|
-
_notification.error({
|
|
71
|
-
message: '提示',
|
|
72
|
-
description: '系统错误'
|
|
73
|
-
});
|
|
74
|
-
return false;
|
|
75
|
-
});
|
|
76
|
-
export default httpClient;
|
package/es/utils/index.d.ts
DELETED
package/es/utils/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface Response {
|
|
2
|
-
status: number;
|
|
3
|
-
data: any;
|
|
4
|
-
statusText: string;
|
|
5
|
-
}
|
|
6
|
-
export interface AxiosRequestConfig {
|
|
7
|
-
baseURL?: string;
|
|
8
|
-
timeout: number;
|
|
9
|
-
headers?: any;
|
|
10
|
-
url?: string;
|
|
11
|
-
}
|
|
12
|
-
declare const httpClient: import("axios").AxiosInstance;
|
|
13
|
-
export default httpClient;
|
package/lib/utils/httpClient.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _axios = _interopRequireDefault(require("axios"));
|
|
8
|
-
var _antd = require("antd");
|
|
9
|
-
var _jsCookie = _interopRequireDefault(require("js-cookie"));
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
var axiosConfig = {
|
|
12
|
-
baseURL: 'https://gateway.fxqifu.net/pangu',
|
|
13
|
-
timeout: 60000
|
|
14
|
-
};
|
|
15
|
-
var httpClient = _axios.default.create(axiosConfig);
|
|
16
|
-
// 登陆页面接口列表,不需要带token
|
|
17
|
-
var loginMap = [''];
|
|
18
|
-
httpClient.interceptors.request.use(function (config) {
|
|
19
|
-
config.headers['Content-Type'] = 'application/json;charset=UTF-8';
|
|
20
|
-
if (loginMap.find(function (item) {
|
|
21
|
-
return config.url.endsWith(item);
|
|
22
|
-
})) {
|
|
23
|
-
delete config.headers['authority_token'];
|
|
24
|
-
} else {
|
|
25
|
-
var tokenFrom = config['tokenFrom'];
|
|
26
|
-
var token = '';
|
|
27
|
-
switch (tokenFrom) {
|
|
28
|
-
case 'cookie':
|
|
29
|
-
token = _jsCookie.default.get('token');
|
|
30
|
-
break;
|
|
31
|
-
case 'localstorage':
|
|
32
|
-
token = localStorage.getItem('token');
|
|
33
|
-
break;
|
|
34
|
-
default:
|
|
35
|
-
token = _jsCookie.default.get('token') || localStorage.getItem('token');
|
|
36
|
-
}
|
|
37
|
-
config.headers['authority_token'] = token;
|
|
38
|
-
}
|
|
39
|
-
return config;
|
|
40
|
-
}, function (err) {
|
|
41
|
-
_antd.notification.error({
|
|
42
|
-
message: '发送请求失败',
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
description: err
|
|
45
|
-
});
|
|
46
|
-
return false;
|
|
47
|
-
});
|
|
48
|
-
httpClient.interceptors.response.use(function (res) {
|
|
49
|
-
var status = res.status,
|
|
50
|
-
data = res.data,
|
|
51
|
-
statusText = res.statusText;
|
|
52
|
-
return new Promise(function (resolve, reject) {
|
|
53
|
-
if (status < 200 || status > 300) {
|
|
54
|
-
_antd.notification.error({
|
|
55
|
-
message: "\u8BF7\u6C42\u9519\u8BEF: ".concat(status),
|
|
56
|
-
description: statusText
|
|
57
|
-
});
|
|
58
|
-
} else if (!data.success) {
|
|
59
|
-
if (data.code === '915003') {
|
|
60
|
-
return reject(data);
|
|
61
|
-
}
|
|
62
|
-
if (data.code === '100003') {
|
|
63
|
-
return reject(data);
|
|
64
|
-
}
|
|
65
|
-
_antd.notification.error({
|
|
66
|
-
message: '提示',
|
|
67
|
-
description: data.message
|
|
68
|
-
});
|
|
69
|
-
return reject(data);
|
|
70
|
-
} else {
|
|
71
|
-
return resolve(data || true);
|
|
72
|
-
}
|
|
73
|
-
return reject();
|
|
74
|
-
});
|
|
75
|
-
}, function () {
|
|
76
|
-
_antd.notification.error({
|
|
77
|
-
message: '提示',
|
|
78
|
-
description: '系统错误'
|
|
79
|
-
});
|
|
80
|
-
return false;
|
|
81
|
-
});
|
|
82
|
-
var _default = exports.default = httpClient;
|
package/lib/utils/index.d.ts
DELETED
package/lib/utils/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "httpClient", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _httpClient.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _httpClient = _interopRequireDefault(require("./httpClient"));
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|