ls-pro-common 3.1.8 → 3.1.10
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.css +1 -0
- package/dist/common.js +1 -1
- package/dist/common.min.css +1 -0
- package/dist/common.min.js +1 -1
- package/es/http/index.js +3 -2
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +11 -4
- package/es/utils/promise.d.ts +15 -0
- package/es/utils/promise.js +21 -0
- package/lib/http/index.js +3 -2
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +11 -4
- package/lib/utils/promise.d.ts +15 -0
- package/lib/utils/promise.js +21 -0
- package/package.json +1 -1
package/es/http/index.js
CHANGED
|
@@ -53,7 +53,7 @@ export var isCrossDomain = function isCrossDomain(url) {
|
|
|
53
53
|
};
|
|
54
54
|
/** 请求拦截器,统一添加token */
|
|
55
55
|
request.interceptors.request.use(function (url, options) {
|
|
56
|
-
var _options$params;
|
|
56
|
+
var _window$crypto$random, _window$crypto, _options$params;
|
|
57
57
|
options.headers = options.headers || {};
|
|
58
58
|
// 处理浏览器指纹
|
|
59
59
|
if (browserId) {
|
|
@@ -92,7 +92,8 @@ request.interceptors.request.use(function (url, options) {
|
|
|
92
92
|
url = url.replace('&noToken=1', '').replace('noToken=1', '');
|
|
93
93
|
var resCode = getUrlQuery('resCode', url) || getUrlQuery('resCode') || getUrlQuery('resourceId') || getResourceProps('resourceId');
|
|
94
94
|
var param = {
|
|
95
|
-
_t1: Date.now()
|
|
95
|
+
_t1: Date.now(),
|
|
96
|
+
__r: ((_window$crypto$random = (_window$crypto = window.crypto)['randomUUID']) === null || _window$crypto$random === void 0 ? void 0 : _window$crypto$random.call(_window$crypto)) || Math.random()
|
|
96
97
|
};
|
|
97
98
|
// 当没有明文参数resCode的时候,添加resCode参数为资源Id
|
|
98
99
|
//@ts-ignore
|
package/es/utils/index.d.ts
CHANGED
package/es/utils/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from './modal';
|
|
|
6
6
|
export * from './array';
|
|
7
7
|
export * from './format';
|
|
8
8
|
export * from './size';
|
|
9
|
+
export * from './promise';
|
|
9
10
|
export { getBrowserId } from 'ls-pro-tools';
|
|
10
11
|
/**
|
|
11
12
|
* 获取 url 参数
|
|
@@ -41,9 +42,10 @@ export var getResourceProps = function getResourceProps(name) {
|
|
|
41
42
|
obj = resList.find(function (o) {
|
|
42
43
|
return o.resourceId === id;
|
|
43
44
|
});
|
|
44
|
-
} else if (location.pathname && location.pathname.length >
|
|
45
|
+
} else if (location.pathname && location.pathname.length > 3) {
|
|
46
|
+
var url = location.pathname + location.hash;
|
|
45
47
|
obj = resList.find(function (o) {
|
|
46
|
-
return o.microUrl === location.pathname;
|
|
48
|
+
return o.microUrl && o.microUrl === location.pathname || o.url === url;
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
if (!obj) return '';
|
|
@@ -398,9 +400,14 @@ export var appPath = function appPath() {
|
|
|
398
400
|
return window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
|
|
399
401
|
}
|
|
400
402
|
if (path) return path;
|
|
403
|
+
//本地开发环境,判断是否hash路由,如果是hash路由,则返回./
|
|
404
|
+
if (isDev) {
|
|
405
|
+
return location.hash ? './' : '/';
|
|
406
|
+
}
|
|
407
|
+
// 生产环境,返回当前路径
|
|
401
408
|
var p = location.pathname || '';
|
|
402
|
-
|
|
403
|
-
return
|
|
409
|
+
if (p === '/') return location.origin + '/';
|
|
410
|
+
return location.origin + '/' + p.split('/')[1] + '/';
|
|
404
411
|
};
|
|
405
412
|
/**
|
|
406
413
|
* 深度复制对象
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 执行promise,返回结果和错误数组,结果在前,错误在后
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const [result, error] = await execPromise(httpGet('/api'));
|
|
6
|
+
* if (error) {
|
|
7
|
+
* console.error('请求数据异常', error);
|
|
8
|
+
* } else {
|
|
9
|
+
* console.log(result);
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* @param promise
|
|
13
|
+
* @returns Result, Error
|
|
14
|
+
*/
|
|
15
|
+
export declare function execPromise<T>(promise: Promise<T>): Promise<[T | null, Error | null]>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 执行promise,返回结果和错误数组,结果在前,错误在后
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const [result, error] = await execPromise(httpGet('/api'));
|
|
6
|
+
* if (error) {
|
|
7
|
+
* console.error('请求数据异常', error);
|
|
8
|
+
* } else {
|
|
9
|
+
* console.log(result);
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* @param promise
|
|
13
|
+
* @returns Result, Error
|
|
14
|
+
*/
|
|
15
|
+
export function execPromise(promise) {
|
|
16
|
+
return promise.then(function (res) {
|
|
17
|
+
return [res, null];
|
|
18
|
+
}).catch(function (err) {
|
|
19
|
+
return [null, err];
|
|
20
|
+
});
|
|
21
|
+
}
|
package/lib/http/index.js
CHANGED
|
@@ -53,7 +53,7 @@ export var isCrossDomain = function isCrossDomain(url) {
|
|
|
53
53
|
};
|
|
54
54
|
/** 请求拦截器,统一添加token */
|
|
55
55
|
request.interceptors.request.use(function (url, options) {
|
|
56
|
-
var _options$params;
|
|
56
|
+
var _window$crypto$random, _window$crypto, _options$params;
|
|
57
57
|
options.headers = options.headers || {};
|
|
58
58
|
// 处理浏览器指纹
|
|
59
59
|
if (browserId) {
|
|
@@ -92,7 +92,8 @@ request.interceptors.request.use(function (url, options) {
|
|
|
92
92
|
url = url.replace('&noToken=1', '').replace('noToken=1', '');
|
|
93
93
|
var resCode = getUrlQuery('resCode', url) || getUrlQuery('resCode') || getUrlQuery('resourceId') || getResourceProps('resourceId');
|
|
94
94
|
var param = {
|
|
95
|
-
_t1: Date.now()
|
|
95
|
+
_t1: Date.now(),
|
|
96
|
+
__r: ((_window$crypto$random = (_window$crypto = window.crypto)['randomUUID']) === null || _window$crypto$random === void 0 ? void 0 : _window$crypto$random.call(_window$crypto)) || Math.random()
|
|
96
97
|
};
|
|
97
98
|
// 当没有明文参数resCode的时候,添加resCode参数为资源Id
|
|
98
99
|
//@ts-ignore
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from './modal';
|
|
|
6
6
|
export * from './array';
|
|
7
7
|
export * from './format';
|
|
8
8
|
export * from './size';
|
|
9
|
+
export * from './promise';
|
|
9
10
|
export { getBrowserId } from 'ls-pro-tools';
|
|
10
11
|
/**
|
|
11
12
|
* 获取 url 参数
|
|
@@ -41,9 +42,10 @@ export var getResourceProps = function getResourceProps(name) {
|
|
|
41
42
|
obj = resList.find(function (o) {
|
|
42
43
|
return o.resourceId === id;
|
|
43
44
|
});
|
|
44
|
-
} else if (location.pathname && location.pathname.length >
|
|
45
|
+
} else if (location.pathname && location.pathname.length > 3) {
|
|
46
|
+
var url = location.pathname + location.hash;
|
|
45
47
|
obj = resList.find(function (o) {
|
|
46
|
-
return o.microUrl === location.pathname;
|
|
48
|
+
return o.microUrl && o.microUrl === location.pathname || o.url === url;
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
if (!obj) return '';
|
|
@@ -398,9 +400,14 @@ export var appPath = function appPath() {
|
|
|
398
400
|
return window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
|
|
399
401
|
}
|
|
400
402
|
if (path) return path;
|
|
403
|
+
//本地开发环境,判断是否hash路由,如果是hash路由,则返回./
|
|
404
|
+
if (isDev) {
|
|
405
|
+
return location.hash ? './' : '/';
|
|
406
|
+
}
|
|
407
|
+
// 生产环境,返回当前路径
|
|
401
408
|
var p = location.pathname || '';
|
|
402
|
-
|
|
403
|
-
return
|
|
409
|
+
if (p === '/') return location.origin + '/';
|
|
410
|
+
return location.origin + '/' + p.split('/')[1] + '/';
|
|
404
411
|
};
|
|
405
412
|
/**
|
|
406
413
|
* 深度复制对象
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 执行promise,返回结果和错误数组,结果在前,错误在后
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const [result, error] = await execPromise(httpGet('/api'));
|
|
6
|
+
* if (error) {
|
|
7
|
+
* console.error('请求数据异常', error);
|
|
8
|
+
* } else {
|
|
9
|
+
* console.log(result);
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* @param promise
|
|
13
|
+
* @returns Result, Error
|
|
14
|
+
*/
|
|
15
|
+
export declare function execPromise<T>(promise: Promise<T>): Promise<[T | null, Error | null]>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 执行promise,返回结果和错误数组,结果在前,错误在后
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const [result, error] = await execPromise(httpGet('/api'));
|
|
6
|
+
* if (error) {
|
|
7
|
+
* console.error('请求数据异常', error);
|
|
8
|
+
* } else {
|
|
9
|
+
* console.log(result);
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* @param promise
|
|
13
|
+
* @returns Result, Error
|
|
14
|
+
*/
|
|
15
|
+
export function execPromise(promise) {
|
|
16
|
+
return promise.then(function (res) {
|
|
17
|
+
return [res, null];
|
|
18
|
+
}).catch(function (err) {
|
|
19
|
+
return [null, err];
|
|
20
|
+
});
|
|
21
|
+
}
|