ls-pro-common 3.0.30 → 3.0.32
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/dist/common.js +1 -1
- package/dist/common.min.js +1 -1
- package/es/components/IconBack.d.ts +5 -4
- package/es/components/IconBack.js +1 -1
- package/es/components/IconBell.d.ts +2 -4
- package/es/components/IconBell.js +1 -1
- package/es/components/IconQuestion.d.ts +2 -4
- package/es/components/IconQuestion.js +1 -1
- package/es/components/IconSearch.d.ts +2 -4
- package/es/components/IconSearch.js +1 -1
- package/es/components/IconText.d.ts +2 -4
- package/es/components/IconText.js +1 -1
- package/es/utils/index.d.ts +31 -2
- package/es/utils/index.js +113 -2
- package/lib/components/404.js +7 -15
- package/lib/components/AreaCascader.js +23 -32
- package/lib/components/AreaCascaderPanel.js +52 -61
- package/lib/components/DescritionCard.js +23 -32
- package/lib/components/DtlLayout.js +28 -37
- package/lib/components/GroupTip.js +11 -19
- package/lib/components/IconBack.d.ts +5 -4
- package/lib/components/IconBack.js +7 -15
- package/lib/components/IconBell.d.ts +2 -4
- package/lib/components/IconBell.js +7 -15
- package/lib/components/IconQuestion.d.ts +2 -4
- package/lib/components/IconQuestion.js +9 -17
- package/lib/components/IconSearch.d.ts +2 -4
- package/lib/components/IconSearch.js +7 -15
- package/lib/components/IconSelector.js +49 -57
- package/lib/components/IconText.d.ts +2 -4
- package/lib/components/IconText.js +12 -20
- package/lib/components/ImageSelector.js +93 -101
- package/lib/components/InputMultiLine.js +35 -44
- package/lib/components/InputTable.js +71 -80
- package/lib/components/Loading.js +11 -19
- package/lib/components/Permission.js +7 -15
- package/lib/hooks/useDtl/index.js +88 -96
- package/lib/hooks/useGetState.js +6 -13
- package/lib/hooks/usePermission/index.js +14 -21
- package/lib/hooks/useSingle/index.js +74 -82
- package/lib/http/index.js +42 -56
- package/lib/index.js +26 -207
- package/lib/service/BaseService.js +33 -41
- package/lib/typing.js +1 -5
- package/lib/utils/index.d.ts +31 -2
- package/lib/utils/index.js +187 -173
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare
|
|
3
|
-
onClick?: (
|
|
4
|
-
}
|
|
1
|
+
import { CustomIconComponentProps } from '@ant-design/icons/es/components/Icon';
|
|
2
|
+
export declare type LsIconProps = Partial<CustomIconComponentProps> & {
|
|
3
|
+
onClick?: (e: any) => any;
|
|
4
|
+
};
|
|
5
|
+
declare const IconBack: (props: LsIconProps) => JSX.Element;
|
|
5
6
|
export default IconBack;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import Icon from '@ant-design/icons';
|
|
3
|
+
import Icon from '@ant-design/icons/es/components/Icon';
|
|
4
4
|
var Svg = function Svg() {
|
|
5
5
|
return /*#__PURE__*/React.createElement("svg", {
|
|
6
6
|
width: "1em",
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const IconBell: (props:
|
|
3
|
-
onClick?: ((e: any) => any) | undefined;
|
|
4
|
-
}) => JSX.Element;
|
|
1
|
+
import { LsIconProps } from './IconBack';
|
|
2
|
+
declare const IconBell: (props: LsIconProps) => JSX.Element;
|
|
5
3
|
export default IconBell;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import Icon from '@ant-design/icons';
|
|
3
|
+
import Icon from '@ant-design/icons/es/components/Icon';
|
|
4
4
|
var Svg = function Svg() {
|
|
5
5
|
return /*#__PURE__*/React.createElement("svg", {
|
|
6
6
|
width: "1em",
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const IconQuestion: (props:
|
|
3
|
-
onClick?: ((e: any) => any) | undefined;
|
|
4
|
-
}) => JSX.Element;
|
|
1
|
+
import { LsIconProps } from './IconBack';
|
|
2
|
+
declare const IconQuestion: (props: LsIconProps) => JSX.Element;
|
|
5
3
|
export default IconQuestion;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import Icon from '@ant-design/icons';
|
|
3
|
+
import Icon from '@ant-design/icons/es/components/Icon';
|
|
4
4
|
var Svg = function Svg() {
|
|
5
5
|
return /*#__PURE__*/React.createElement("svg", {
|
|
6
6
|
width: "1em",
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const IconSearch: (props:
|
|
3
|
-
onClick?: ((e: any) => any) | undefined;
|
|
4
|
-
}) => JSX.Element;
|
|
1
|
+
import { LsIconProps } from './IconBack';
|
|
2
|
+
declare const IconSearch: (props: LsIconProps) => JSX.Element;
|
|
5
3
|
export default IconSearch;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import Icon from '@ant-design/icons';
|
|
3
|
+
import Icon from '@ant-design/icons/es/components/Icon';
|
|
4
4
|
var Svg = function Svg() {
|
|
5
5
|
return /*#__PURE__*/React.createElement("svg", {
|
|
6
6
|
width: "1em",
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const IconText: (props:
|
|
3
|
-
onClick?: ((e: any) => any) | undefined;
|
|
4
|
-
}) => JSX.Element;
|
|
1
|
+
import { LsIconProps } from './IconBack';
|
|
2
|
+
declare const IconText: (props: LsIconProps) => JSX.Element;
|
|
5
3
|
export default IconText;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import Icon from '@ant-design/icons';
|
|
3
|
+
import Icon from '@ant-design/icons/es/components/Icon';
|
|
4
4
|
var Svg = function Svg() {
|
|
5
5
|
return /*#__PURE__*/React.createElement("svg", {
|
|
6
6
|
width: "1em",
|
package/es/utils/index.d.ts
CHANGED
|
@@ -2,7 +2,36 @@ import { ModalFuncProps } from 'antd';
|
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
export { throttle, debounce } from 'lodash';
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* 获取 url 参数
|
|
7
|
+
* @param name
|
|
8
|
+
* @param url
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare const getUrlQuery: (name: string, url?: string) => string;
|
|
12
|
+
export declare const getResourceProps: (name: string) => any;
|
|
13
|
+
/**
|
|
14
|
+
* 设置url传参
|
|
15
|
+
* @param {*} url
|
|
16
|
+
* @param {*} keyvals
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare const setUrlQuery: (url: string, keyvals?: Record<string, any>) => string;
|
|
20
|
+
/**
|
|
21
|
+
* 日期格式化
|
|
22
|
+
* @param dt 日期
|
|
23
|
+
* @param showTime 是否显示时间
|
|
24
|
+
* @returns YYYY-MM-DD
|
|
25
|
+
*/
|
|
26
|
+
export declare const dateFormat: (dt?: Date | null | undefined, showTime?: boolean) => string;
|
|
27
|
+
/**
|
|
28
|
+
* 给 url 添加网关
|
|
29
|
+
* @param url 原url,以 / 打头
|
|
30
|
+
* @param gatewayKey 设置gateway关键字 默认为 'gateway'
|
|
31
|
+
* @param defGateway 默认网关 ''
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare const toGatewayUrl: (url: string, gatewayKey?: string, defGateway?: string) => string;
|
|
6
35
|
/**
|
|
7
36
|
* 设置文档title
|
|
8
37
|
* @param {*} title
|
|
@@ -15,7 +44,7 @@ export declare const setTitle: (title: string) => void;
|
|
|
15
44
|
* @param showTime 是否显示时间 默认true
|
|
16
45
|
* @returns YYYY-MM-DD hh:mm:ss
|
|
17
46
|
*/
|
|
18
|
-
export declare const formatDate: (dt
|
|
47
|
+
export declare const formatDate: (dt?: Date | null | undefined, showTime?: boolean) => string;
|
|
19
48
|
/**
|
|
20
49
|
* 返回当前日期
|
|
21
50
|
* @returns YYYY-MM-DD
|
package/es/utils/index.js
CHANGED
|
@@ -9,11 +9,122 @@ import _message from "antd/es/message";
|
|
|
9
9
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
10
10
|
import ReactDOM from 'react-dom';
|
|
11
11
|
import { QuestionCircleOutlined } from '@ant-design/icons';
|
|
12
|
-
import { dateFormat, toGatewayUrl } from 'ls-pro-table';
|
|
13
12
|
import { httpPost } from '../http';
|
|
14
13
|
import React from 'react';
|
|
15
14
|
export { throttle, debounce } from 'lodash';
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* 获取 url 参数
|
|
17
|
+
* @param name
|
|
18
|
+
* @param url
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export var getUrlQuery = function getUrlQuery(name) {
|
|
22
|
+
var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : location.search.slice(1) || '';
|
|
23
|
+
if (!name) return '';
|
|
24
|
+
var reg = new RegExp('(^|[&|?])' + name + '=([^&]*)(&|$)');
|
|
25
|
+
var r = url.match(reg);
|
|
26
|
+
if (r != null) {
|
|
27
|
+
return decodeURIComponent(decodeURI(r[2]));
|
|
28
|
+
}
|
|
29
|
+
return '';
|
|
30
|
+
};
|
|
31
|
+
export var getResourceProps = function getResourceProps(name) {
|
|
32
|
+
if (!name) return '';
|
|
33
|
+
var id = getUrlQuery('resCode');
|
|
34
|
+
var obj;
|
|
35
|
+
// window.lsResourceList 为主工程写入的资源
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
var resList = window.lsResourceList || parent.window.lsResourceList || [];
|
|
38
|
+
if (id) {
|
|
39
|
+
obj = resList.find(function (o) {
|
|
40
|
+
return o.resourceId === id;
|
|
41
|
+
});
|
|
42
|
+
} else if (location.pathname && location.pathname.length > 2) {
|
|
43
|
+
obj = resList.find(function (o) {
|
|
44
|
+
return o.microUrl === location.pathname;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (!obj) return '';
|
|
48
|
+
return obj[name] || '';
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 设置url传参
|
|
52
|
+
* @param {*} url
|
|
53
|
+
* @param {*} keyvals
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
export var setUrlQuery = function setUrlQuery(url) {
|
|
57
|
+
var keyvals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
58
|
+
var newUrl = url;
|
|
59
|
+
for (var name in keyvals) {
|
|
60
|
+
var reg = new RegExp('(^|[&|?])' + name + '=([^&]*)(|$)');
|
|
61
|
+
var tmp = (newUrl.includes('?') ? '&' : '?') + name + '=' + keyvals[name];
|
|
62
|
+
if (newUrl.match(reg) != null) {
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
newUrl = newUrl.replace(eval(reg), tmp);
|
|
65
|
+
if (!newUrl.includes('?')) {
|
|
66
|
+
newUrl = newUrl.replace('&', '?');
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
newUrl = newUrl + tmp;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return newUrl;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* 日期格式化
|
|
76
|
+
* @param dt 日期
|
|
77
|
+
* @param showTime 是否显示时间
|
|
78
|
+
* @returns YYYY-MM-DD
|
|
79
|
+
*/
|
|
80
|
+
export var dateFormat = function dateFormat(dt) {
|
|
81
|
+
var showTime = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
82
|
+
var ct = dt ? dt : new Date(Date.now());
|
|
83
|
+
var str = ct.getFullYear() + '-' + ('' + (ct.getMonth() + 1)).padStart(2, '0') + '-' + ('' + ct.getDate()).padStart(2, '0');
|
|
84
|
+
if (showTime) {
|
|
85
|
+
str += ' ' + (ct.getHours() + '').padStart(2, '0') + ':' + (ct.getMinutes() + '').padStart(2, '0') + ":" + (ct.getSeconds() + '').padStart(2, '0');
|
|
86
|
+
}
|
|
87
|
+
return str;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* 给 url 添加网关
|
|
91
|
+
* @param url 原url,以 / 打头
|
|
92
|
+
* @param gatewayKey 设置gateway关键字 默认为 'gateway'
|
|
93
|
+
* @param defGateway 默认网关 ''
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
export var toGatewayUrl = function toGatewayUrl(url) {
|
|
97
|
+
var gatewayKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'gateway';
|
|
98
|
+
var defGateway = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
99
|
+
// 如果url带有名称,不需要设置网关
|
|
100
|
+
if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//')) return url;
|
|
101
|
+
// 读取项目的默认网关
|
|
102
|
+
if (!defGateway) {
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
defGateway = window.defaultGateway || '';
|
|
105
|
+
}
|
|
106
|
+
// 取网关的顺序, 1.取url里的传参,2.取资源里的网关, 3. 取项目里设置的默认网关
|
|
107
|
+
var gateway = getUrlQuery(gatewayKey) || getResourceProps(gatewayKey) || defGateway;
|
|
108
|
+
// 如果没有找到网关,直接从项目配置中取网关
|
|
109
|
+
if (!gateway) {
|
|
110
|
+
var projects = JSON.parse(sessionStorage.getItem('lsProjects') || '[]');
|
|
111
|
+
var projectKey = localStorage.getItem("projectId");
|
|
112
|
+
if (projectKey && projects.length) {
|
|
113
|
+
var project = projects.find(function (o) {
|
|
114
|
+
return o.projectId === projectKey;
|
|
115
|
+
});
|
|
116
|
+
if (project) {
|
|
117
|
+
gateway = project.gatewayUrl || '';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// 网关加上域名,避免多次设置
|
|
122
|
+
if (gateway && !gateway.startsWith("http")) {
|
|
123
|
+
var h = location.origin ? location.origin : "".concat(location.protocol, "//").concat(location.hostname).concat(location.port ? ':' + location.port : '');
|
|
124
|
+
gateway = h + gateway;
|
|
125
|
+
}
|
|
126
|
+
return gateway + url;
|
|
127
|
+
};
|
|
17
128
|
/**
|
|
18
129
|
* 设置文档title
|
|
19
130
|
* @param {*} title
|
package/lib/components/404.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
require("./common.less");
|
|
11
|
-
var _default = function _default(props) {
|
|
12
|
-
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import './common.less';
|
|
4
|
+
export default (function (props) {
|
|
5
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
13
6
|
className: "page404"
|
|
14
|
-
}, props), /*#__PURE__*/
|
|
7
|
+
}, props), /*#__PURE__*/React.createElement("img", {
|
|
15
8
|
src: require('./404.jpg')
|
|
16
9
|
}), " \u60A8\u8BBF\u95EE\u7684\u8D44\u6E90\u4E0D\u5B58\u5728~~");
|
|
17
|
-
};
|
|
18
|
-
exports.default = _default;
|
|
10
|
+
});
|
|
@@ -1,39 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
14
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
16
|
-
var _http = require("../http");
|
|
17
|
-
var _utils = require("../utils");
|
|
18
|
-
var AreaCascader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
19
|
-
var _useState = (0, _react.useState)([]),
|
|
20
|
-
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
1
|
+
import "antd/es/cascader/style";
|
|
2
|
+
import _Cascader from "antd/es/cascader";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
|
+
import React, { useRef, useState, useEffect, useImperativeHandle } from 'react';
|
|
8
|
+
import { httpGet } from '../http';
|
|
9
|
+
import { getCache, setCache, treeEach } from '../utils';
|
|
10
|
+
var AreaCascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
11
|
+
var _useState = useState([]),
|
|
12
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
21
13
|
options = _useState2[0],
|
|
22
14
|
setOptions = _useState2[1];
|
|
23
|
-
var areaRef =
|
|
24
|
-
|
|
15
|
+
var areaRef = useRef();
|
|
16
|
+
useImperativeHandle(ref, function () {
|
|
25
17
|
return areaRef.current;
|
|
26
18
|
});
|
|
27
|
-
|
|
19
|
+
useEffect(function () {
|
|
28
20
|
initOptions();
|
|
29
21
|
}, []);
|
|
30
22
|
var initOptions = /*#__PURE__*/function () {
|
|
31
|
-
var _ref = (
|
|
23
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
32
24
|
var cacheItems, api, result, opts;
|
|
33
|
-
return
|
|
25
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
34
26
|
while (1) switch (_context.prev = _context.next) {
|
|
35
27
|
case 0:
|
|
36
|
-
cacheItems =
|
|
28
|
+
cacheItems = getCache("areaOptions", true);
|
|
37
29
|
if (!(cacheItems && Array.isArray(cacheItems))) {
|
|
38
30
|
_context.next = 4;
|
|
39
31
|
break;
|
|
@@ -43,11 +35,11 @@ var AreaCascader = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
|
|
|
43
35
|
case 4:
|
|
44
36
|
api = '/petrel/petrel-location-center-api/sysAdministrativeDivision/allByTree';
|
|
45
37
|
_context.next = 7;
|
|
46
|
-
return
|
|
38
|
+
return httpGet(api, {}, false);
|
|
47
39
|
case 7:
|
|
48
40
|
result = _context.sent;
|
|
49
41
|
opts = result.rows || [];
|
|
50
|
-
|
|
42
|
+
treeEach(opts, function (item) {
|
|
51
43
|
item.label = item.name;
|
|
52
44
|
item.value = item.id;
|
|
53
45
|
if (item.level === 'district') {
|
|
@@ -58,7 +50,7 @@ var AreaCascader = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
|
|
|
58
50
|
delete item.level;
|
|
59
51
|
delete item.parentId;
|
|
60
52
|
});
|
|
61
|
-
|
|
53
|
+
setCache('areaOptions', opts, true);
|
|
62
54
|
setOptions(opts);
|
|
63
55
|
case 12:
|
|
64
56
|
case "end":
|
|
@@ -70,7 +62,7 @@ var AreaCascader = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
|
|
|
70
62
|
return _ref.apply(this, arguments);
|
|
71
63
|
};
|
|
72
64
|
}();
|
|
73
|
-
return /*#__PURE__*/
|
|
65
|
+
return /*#__PURE__*/React.createElement(_Cascader, _extends({
|
|
74
66
|
options: options,
|
|
75
67
|
style: {
|
|
76
68
|
width: '100%'
|
|
@@ -81,5 +73,4 @@ var AreaCascader = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
|
|
|
81
73
|
ref: areaRef
|
|
82
74
|
}));
|
|
83
75
|
});
|
|
84
|
-
|
|
85
|
-
exports.default = _default;
|
|
76
|
+
export default AreaCascader;
|
|
@@ -1,64 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
18
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
19
|
-
var _http = require("../http");
|
|
20
|
-
var _utils = require("../utils");
|
|
21
|
-
require("./common.less");
|
|
22
|
-
var AreaPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
23
|
-
var propsConfig = (0, _objectSpread2.default)({
|
|
1
|
+
import "antd/es/cascader/style";
|
|
2
|
+
import _Cascader from "antd/es/cascader";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import "antd/es/button/style";
|
|
5
|
+
import _Button from "antd/es/button";
|
|
6
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
7
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
8
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
9
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
10
|
+
import React, { useRef, useState, useEffect, useImperativeHandle } from 'react';
|
|
11
|
+
import { httpGet } from '../http';
|
|
12
|
+
import { getCache, setCache, treeEach } from '../utils';
|
|
13
|
+
import './common.less';
|
|
14
|
+
var AreaPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
15
|
+
var propsConfig = _objectSpread({
|
|
24
16
|
getPopupContainer: function getPopupContainer(triggerNode) {
|
|
25
17
|
var _document;
|
|
26
18
|
return (_document = document) === null || _document === void 0 ? void 0 : _document.body;
|
|
27
19
|
},
|
|
28
20
|
placeholder: "请选择"
|
|
29
21
|
}, props);
|
|
30
|
-
var _useState =
|
|
31
|
-
_useState2 = (
|
|
22
|
+
var _useState = useState(getCache('areaOptionsPanel', true) || []),
|
|
23
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
32
24
|
options = _useState2[0],
|
|
33
25
|
setOptions = _useState2[1];
|
|
34
26
|
//显示数据
|
|
35
|
-
var _useState3 =
|
|
36
|
-
_useState4 = (
|
|
27
|
+
var _useState3 = useState(getCache('areaOptionsPanel', true) || []),
|
|
28
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
37
29
|
showData = _useState4[0],
|
|
38
30
|
setShowData = _useState4[1];
|
|
39
31
|
//暂存值
|
|
40
|
-
var _useState5 =
|
|
41
|
-
_useState6 = (
|
|
32
|
+
var _useState5 = useState([]),
|
|
33
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
42
34
|
listData = _useState6[0],
|
|
43
35
|
setListData = _useState6[1];
|
|
44
36
|
//省市区实际值
|
|
45
|
-
var _useState7 =
|
|
46
|
-
_useState8 = (
|
|
37
|
+
var _useState7 = useState(props.value || []),
|
|
38
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
47
39
|
actualData = _useState8[0],
|
|
48
40
|
setActualData = _useState8[1];
|
|
49
41
|
//标题显示值
|
|
50
|
-
var _useState9 =
|
|
51
|
-
_useState10 = (
|
|
42
|
+
var _useState9 = useState('province'),
|
|
43
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
52
44
|
areaTitle = _useState10[0],
|
|
53
45
|
setAreaTitle = _useState10[1];
|
|
54
|
-
var areaRef =
|
|
55
|
-
|
|
46
|
+
var areaRef = useRef();
|
|
47
|
+
useImperativeHandle(ref, function () {
|
|
56
48
|
return areaRef.current;
|
|
57
49
|
});
|
|
58
|
-
|
|
50
|
+
useEffect(function () {
|
|
59
51
|
initOptions();
|
|
60
52
|
}, []);
|
|
61
|
-
|
|
53
|
+
useEffect(function () {
|
|
62
54
|
if (actualData.length !== 0) {
|
|
63
55
|
var _props$onChange;
|
|
64
56
|
(_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, actualData, listData);
|
|
@@ -66,10 +58,10 @@ var AreaPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
66
58
|
setAreaTitle('province');
|
|
67
59
|
}
|
|
68
60
|
}, [actualData]);
|
|
69
|
-
|
|
61
|
+
useEffect(function () {
|
|
70
62
|
var _props$value;
|
|
71
63
|
if (!options.length || !((_props$value = props.value) === null || _props$value === void 0 ? void 0 : _props$value.length)) return;
|
|
72
|
-
var _props$value2 = (
|
|
64
|
+
var _props$value2 = _slicedToArray(props.value, 3),
|
|
73
65
|
pKey = _props$value2[0],
|
|
74
66
|
cKey = _props$value2[1],
|
|
75
67
|
dKey = _props$value2[2];
|
|
@@ -88,12 +80,12 @@ var AreaPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
88
80
|
setShowData(area.length === 3 ? city.children : area.length === 2 ? province.children : options);
|
|
89
81
|
}, [options]);
|
|
90
82
|
var initOptions = /*#__PURE__*/function () {
|
|
91
|
-
var _ref = (
|
|
83
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
92
84
|
var cacheItems, api, result, opts;
|
|
93
|
-
return
|
|
85
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
94
86
|
while (1) switch (_context.prev = _context.next) {
|
|
95
87
|
case 0:
|
|
96
|
-
cacheItems =
|
|
88
|
+
cacheItems = getCache('areaOptionsPanel', true);
|
|
97
89
|
if (!(cacheItems && Array.isArray(cacheItems) && cacheItems.length)) {
|
|
98
90
|
_context.next = 3;
|
|
99
91
|
break;
|
|
@@ -102,11 +94,11 @@ var AreaPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
102
94
|
case 3:
|
|
103
95
|
api = '/petrel/petrel-location-center-api/sysAdministrativeDivision/allByTree';
|
|
104
96
|
_context.next = 6;
|
|
105
|
-
return
|
|
97
|
+
return httpGet(api, {}, false);
|
|
106
98
|
case 6:
|
|
107
99
|
result = _context.sent;
|
|
108
100
|
opts = result.rows || [];
|
|
109
|
-
|
|
101
|
+
treeEach(opts, function (item) {
|
|
110
102
|
item.label = item.name;
|
|
111
103
|
item.value = item.id;
|
|
112
104
|
if (item.level === 'district') {
|
|
@@ -116,7 +108,7 @@ var AreaPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
116
108
|
delete item.id;
|
|
117
109
|
delete item.parentId;
|
|
118
110
|
});
|
|
119
|
-
|
|
111
|
+
setCache('areaOptionsPanel', opts, true);
|
|
120
112
|
setOptions(opts);
|
|
121
113
|
setShowData(opts);
|
|
122
114
|
case 12:
|
|
@@ -131,11 +123,11 @@ var AreaPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
131
123
|
}();
|
|
132
124
|
var dropdownRender = function dropdownRender(menus) {
|
|
133
125
|
var _listData$, _listData$3;
|
|
134
|
-
var title = /*#__PURE__*/
|
|
126
|
+
var title = /*#__PURE__*/React.createElement("div", {
|
|
135
127
|
className: "ls-area-cascaded-header"
|
|
136
|
-
}, /*#__PURE__*/
|
|
128
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
137
129
|
className: "ls-word-box-display"
|
|
138
|
-
}, /*#__PURE__*/
|
|
130
|
+
}, /*#__PURE__*/React.createElement(_Button, {
|
|
139
131
|
type: "text",
|
|
140
132
|
onClick: function onClick() {
|
|
141
133
|
setAreaTitle('province');
|
|
@@ -144,11 +136,11 @@ var AreaPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
144
136
|
return val.length ? [val[0]] : [];
|
|
145
137
|
});
|
|
146
138
|
}
|
|
147
|
-
}, /*#__PURE__*/
|
|
139
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
148
140
|
className: 'ls-myself-select-title-style'
|
|
149
|
-
}, listData[0] ? (_listData$ = listData[0]) === null || _listData$ === void 0 ? void 0 : _listData$.label : '省/直辖市'))), /*#__PURE__*/
|
|
141
|
+
}, listData[0] ? (_listData$ = listData[0]) === null || _listData$ === void 0 ? void 0 : _listData$.label : '省/直辖市'))), /*#__PURE__*/React.createElement("div", {
|
|
150
142
|
className: "ls-word-box-display"
|
|
151
|
-
}, /*#__PURE__*/
|
|
143
|
+
}, /*#__PURE__*/React.createElement(_Button, {
|
|
152
144
|
type: "text",
|
|
153
145
|
disabled: listData.length < 2,
|
|
154
146
|
onClick: function onClick() {
|
|
@@ -161,22 +153,22 @@ var AreaPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
161
153
|
});
|
|
162
154
|
});
|
|
163
155
|
}
|
|
164
|
-
}, /*#__PURE__*/
|
|
156
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
165
157
|
className: 'ls-myself-select-title-style'
|
|
166
|
-
}, areaTitle !== 'province' && listData[1] ? (_listData$3 = listData[1]) === null || _listData$3 === void 0 ? void 0 : _listData$3.label : '市'))), /*#__PURE__*/
|
|
158
|
+
}, areaTitle !== 'province' && listData[1] ? (_listData$3 = listData[1]) === null || _listData$3 === void 0 ? void 0 : _listData$3.label : '市'))), /*#__PURE__*/React.createElement("div", {
|
|
167
159
|
className: "ls-word-box-display"
|
|
168
|
-
}, /*#__PURE__*/
|
|
160
|
+
}, /*#__PURE__*/React.createElement(_Button, {
|
|
169
161
|
type: "text",
|
|
170
162
|
disabled: listData.length < 3
|
|
171
|
-
}, /*#__PURE__*/
|
|
163
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
172
164
|
className: 'ls-myself-select-title-style'
|
|
173
165
|
}, listData[2] ? listData[2].label : '区'))));
|
|
174
|
-
return /*#__PURE__*/
|
|
166
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
175
167
|
className: "ls-area-cascaded-box"
|
|
176
|
-
}, title, /*#__PURE__*/
|
|
168
|
+
}, title, /*#__PURE__*/React.createElement("div", {
|
|
177
169
|
className: "ls-area-cascaded-body"
|
|
178
170
|
}, showData.map(function (item) {
|
|
179
|
-
return /*#__PURE__*/
|
|
171
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
180
172
|
className: "ls-area-cascaded-span ".concat(actualData.find(function (o) {
|
|
181
173
|
return o === item.value;
|
|
182
174
|
}) ? ' ls-area-selected' : ''),
|
|
@@ -219,7 +211,7 @@ var AreaPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
219
211
|
}, item.label);
|
|
220
212
|
})));
|
|
221
213
|
};
|
|
222
|
-
return /*#__PURE__*/
|
|
214
|
+
return /*#__PURE__*/React.createElement(_Cascader, _extends({
|
|
223
215
|
options: options,
|
|
224
216
|
style: {
|
|
225
217
|
width: '100%'
|
|
@@ -235,5 +227,4 @@ var AreaPicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
235
227
|
dropdownRender: dropdownRender
|
|
236
228
|
}, propsConfig));
|
|
237
229
|
});
|
|
238
|
-
|
|
239
|
-
exports.default = _default;
|
|
230
|
+
export default AreaPicker;
|