ls-pro-common 3.1.47 → 3.1.49
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/InputTable.d.ts +2 -2
- package/es/components/InputTable.js +85 -32
- package/es/utils/cache.d.ts +28 -0
- package/es/utils/cache.js +63 -0
- package/es/utils/constant.d.ts +12 -0
- package/es/utils/constant.js +20 -0
- package/es/utils/cookie.d.ts +15 -0
- package/es/utils/cookie.js +36 -0
- package/es/utils/event.d.ts +16 -0
- package/es/utils/event.js +26 -0
- package/es/utils/index.d.ts +8 -179
- package/es/utils/index.js +12 -423
- package/es/utils/print.d.ts +24 -0
- package/es/utils/print.js +86 -0
- package/es/utils/project.d.ts +33 -0
- package/es/utils/project.js +66 -0
- package/es/utils/url.d.ts +26 -0
- package/es/utils/url.js +113 -0
- package/es/utils/user.d.ts +29 -0
- package/es/utils/user.js +25 -0
- package/lib/components/InputTable.d.ts +2 -2
- package/lib/components/InputTable.js +85 -32
- package/lib/utils/cache.d.ts +28 -0
- package/lib/utils/cache.js +63 -0
- package/lib/utils/constant.d.ts +12 -0
- package/lib/utils/constant.js +20 -0
- package/lib/utils/cookie.d.ts +15 -0
- package/lib/utils/cookie.js +36 -0
- package/lib/utils/event.d.ts +16 -0
- package/lib/utils/event.js +26 -0
- package/lib/utils/index.d.ts +8 -179
- package/lib/utils/index.js +12 -423
- package/lib/utils/print.d.ts +24 -0
- package/lib/utils/print.js +86 -0
- package/lib/utils/project.d.ts +33 -0
- package/lib/utils/project.js +66 -0
- package/lib/utils/url.d.ts +26 -0
- package/lib/utils/url.js +113 -0
- package/lib/utils/user.d.ts +29 -0
- package/lib/utils/user.js +25 -0
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取 url 参数
|
|
3
|
+
*
|
|
4
|
+
* @param name
|
|
5
|
+
* @param url
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const getUrlQuery: (name: string, url?: string) => string;
|
|
9
|
+
export declare const getResourceProps: (name: string) => any;
|
|
10
|
+
/**
|
|
11
|
+
* 设置url传参
|
|
12
|
+
*
|
|
13
|
+
* @param {any} url
|
|
14
|
+
* @param {any} keyvals
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare const setUrlQuery: (url: string, keyvals?: Record<string, any>) => string;
|
|
18
|
+
/**
|
|
19
|
+
* 给 url 添加网关
|
|
20
|
+
*
|
|
21
|
+
* @param url 原url,以 / 打头
|
|
22
|
+
* @param gatewayKey 设置gateway关键字 默认为 'gateway'
|
|
23
|
+
* @param defaultGateway 默认网关 ''
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export declare const toGatewayUrl: (url: string, gatewayKey?: string, defaultGateway?: string) => string;
|
package/lib/utils/url.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { getCache } from './cache';
|
|
2
|
+
/**
|
|
3
|
+
* 获取 url 参数
|
|
4
|
+
*
|
|
5
|
+
* @param name
|
|
6
|
+
* @param url
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export var getUrlQuery = function getUrlQuery(name) {
|
|
10
|
+
var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : location.search.slice(1) || '';
|
|
11
|
+
if (!name) return '';
|
|
12
|
+
var reg = new RegExp('(^|[&|?])' + name + '=([^&]*)(&|$)');
|
|
13
|
+
var r = url.match(reg);
|
|
14
|
+
if (r != null) {
|
|
15
|
+
return decodeURIComponent(decodeURI(r[2]));
|
|
16
|
+
}
|
|
17
|
+
return '';
|
|
18
|
+
};
|
|
19
|
+
export var getResourceProps = function getResourceProps(name) {
|
|
20
|
+
if (!name) return '';
|
|
21
|
+
var id = window.__currentResCode__ || getUrlQuery('resCode');
|
|
22
|
+
var obj;
|
|
23
|
+
// window.lsResourceList 为主工程写入的资源
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
var resList = window.lsResourceList || parent.window.lsResourceList || [];
|
|
26
|
+
if (resList.length === 0) {
|
|
27
|
+
resList = getCache('allRes') || [];
|
|
28
|
+
if (!Array.isArray(resList)) {
|
|
29
|
+
resList = [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (id) {
|
|
33
|
+
obj = resList.find(function (o) {
|
|
34
|
+
return o.resourceId === id;
|
|
35
|
+
});
|
|
36
|
+
} else if (location.pathname && location.pathname.length > 3) {
|
|
37
|
+
var url = location.pathname + location.hash;
|
|
38
|
+
obj = resList.find(function (o) {
|
|
39
|
+
return o.microUrl && o.microUrl === location.pathname || o.url === url;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (!obj) return '';
|
|
43
|
+
return obj[name] || '';
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* 设置url传参
|
|
47
|
+
*
|
|
48
|
+
* @param {any} url
|
|
49
|
+
* @param {any} keyvals
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
export var setUrlQuery = function setUrlQuery(url) {
|
|
53
|
+
var keyvals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
54
|
+
var newUrl = url;
|
|
55
|
+
for (var name in keyvals) {
|
|
56
|
+
var reg = new RegExp('(^|[&|?])' + name + '=([^&]*)(|$)');
|
|
57
|
+
var tmp = (newUrl.includes('?') ? '&' : '?') + name + '=' + keyvals[name];
|
|
58
|
+
if (newUrl.match(reg) != null) {
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
newUrl = newUrl.replace(eval(reg), tmp);
|
|
61
|
+
if (!newUrl.includes('?')) {
|
|
62
|
+
newUrl = newUrl.replace('&', '?');
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
newUrl = newUrl + tmp;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return newUrl;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* 给 url 添加网关
|
|
72
|
+
*
|
|
73
|
+
* @param url 原url,以 / 打头
|
|
74
|
+
* @param gatewayKey 设置gateway关键字 默认为 'gateway'
|
|
75
|
+
* @param defaultGateway 默认网关 ''
|
|
76
|
+
* @returns
|
|
77
|
+
*/
|
|
78
|
+
export var toGatewayUrl = function toGatewayUrl(url) {
|
|
79
|
+
var gatewayKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'gateway';
|
|
80
|
+
var defaultGateway = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
81
|
+
url = url || '';
|
|
82
|
+
// 如果url带有名称,不需要设置网关
|
|
83
|
+
if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//')) return url;
|
|
84
|
+
if (url.startsWith('/lesoon/') || url.startsWith('/petrel/')) {
|
|
85
|
+
return location.origin + url;
|
|
86
|
+
}
|
|
87
|
+
// 读取项目的默认网关
|
|
88
|
+
if (!defaultGateway) {
|
|
89
|
+
var _top;
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
defaultGateway = window.defaultGateway || ((_top = top) === null || _top === void 0 ? void 0 : _top.window.lsMainGateway) || '';
|
|
92
|
+
}
|
|
93
|
+
// 取网关的顺序, 1.取url里的传参,2.取资源里的网关, 3. 取项目里设置的默认网关
|
|
94
|
+
var gateway = getUrlQuery(gatewayKey) || getResourceProps(gatewayKey) || defaultGateway;
|
|
95
|
+
// 如果没有找到网关,直接从项目配置中取网关
|
|
96
|
+
if (!gateway) {
|
|
97
|
+
var projects = JSON.parse(sessionStorage.getItem('lsProjects') || '[]');
|
|
98
|
+
var projectKey = localStorage.getItem('projectId');
|
|
99
|
+
if (projectKey && projects.length) {
|
|
100
|
+
var project = projects.find(function (o) {
|
|
101
|
+
return o.projectId === projectKey;
|
|
102
|
+
});
|
|
103
|
+
if (project) {
|
|
104
|
+
gateway = project.gatewayUrl || '';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// 网关加上域名,避免多次设置
|
|
109
|
+
if (gateway && !gateway.startsWith('http')) {
|
|
110
|
+
gateway = location.origin + gateway;
|
|
111
|
+
}
|
|
112
|
+
return gateway + url;
|
|
113
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare type UserType = {
|
|
2
|
+
id?: string;
|
|
3
|
+
userId?: string;
|
|
4
|
+
userName?: string;
|
|
5
|
+
loginName?: string;
|
|
6
|
+
companyId?: string;
|
|
7
|
+
companyCode?: string;
|
|
8
|
+
companyName?: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
employeeAttr?: string;
|
|
11
|
+
expireTime?: string;
|
|
12
|
+
icon?: string;
|
|
13
|
+
idCard?: string;
|
|
14
|
+
ifAdmin?: number | string;
|
|
15
|
+
orgId?: string;
|
|
16
|
+
orgParentIds?: string;
|
|
17
|
+
phoneNumber?: string;
|
|
18
|
+
remarks?: string;
|
|
19
|
+
};
|
|
20
|
+
/** @name 用户信息 */
|
|
21
|
+
export declare const getUserInfo: () => UserType | null;
|
|
22
|
+
/** @name 用户名 */
|
|
23
|
+
export declare const getUserName: () => string | undefined;
|
|
24
|
+
/** @name 登录名 */
|
|
25
|
+
export declare const getLoginName: () => string | undefined;
|
|
26
|
+
/** @name 公司Id */
|
|
27
|
+
export declare const getCompanyId: () => string | undefined;
|
|
28
|
+
/** @name 用户ID */
|
|
29
|
+
export declare const getUserId: () => string | undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getCache } from './cache';
|
|
2
|
+
/** @name 用户信息 */
|
|
3
|
+
export var getUserInfo = function getUserInfo() {
|
|
4
|
+
return getCache('user');
|
|
5
|
+
};
|
|
6
|
+
/** @name 用户名 */
|
|
7
|
+
export var getUserName = function getUserName() {
|
|
8
|
+
var _getUserInfo;
|
|
9
|
+
return (_getUserInfo = getUserInfo()) === null || _getUserInfo === void 0 ? void 0 : _getUserInfo.userName;
|
|
10
|
+
};
|
|
11
|
+
/** @name 登录名 */
|
|
12
|
+
export var getLoginName = function getLoginName() {
|
|
13
|
+
var _getUserInfo2;
|
|
14
|
+
return (_getUserInfo2 = getUserInfo()) === null || _getUserInfo2 === void 0 ? void 0 : _getUserInfo2.loginName;
|
|
15
|
+
};
|
|
16
|
+
/** @name 公司Id */
|
|
17
|
+
export var getCompanyId = function getCompanyId() {
|
|
18
|
+
var _getUserInfo3;
|
|
19
|
+
return (_getUserInfo3 = getUserInfo()) === null || _getUserInfo3 === void 0 ? void 0 : _getUserInfo3.companyId;
|
|
20
|
+
};
|
|
21
|
+
/** @name 用户ID */
|
|
22
|
+
export var getUserId = function getUserId() {
|
|
23
|
+
var _getUserInfo4;
|
|
24
|
+
return (_getUserInfo4 = getUserInfo()) === null || _getUserInfo4 === void 0 ? void 0 : _getUserInfo4.userId;
|
|
25
|
+
};
|