ls-pro-common 3.0.31 → 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/utils/index.d.ts +31 -2
- package/es/utils/index.js +113 -2
- package/lib/utils/index.d.ts +31 -2
- package/lib/utils/index.js +113 -2
- package/package.json +2 -2
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?: Date | null | undefined, showTime?: boolean
|
|
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/es/utils/index';
|
|
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/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?: Date | null | undefined, showTime?: boolean
|
|
47
|
+
export declare const formatDate: (dt?: Date | null | undefined, showTime?: boolean) => string;
|
|
19
48
|
/**
|
|
20
49
|
* 返回当前日期
|
|
21
50
|
* @returns YYYY-MM-DD
|
package/lib/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/es/utils/index';
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ls-pro-common",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.32",
|
|
4
4
|
"description": "ls-pro-common",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": [
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@ant-design/icons": "^4.3.0",
|
|
24
|
-
"ls-pro-table": "^3.0.
|
|
24
|
+
"ls-pro-table": "^3.0.20",
|
|
25
25
|
"ls-pro-form": "^3.0.6",
|
|
26
26
|
"ls-pro-descriptions": "^3.0.1",
|
|
27
27
|
"ls-pro-card": "^3.0.3",
|