ls-pro-common 3.1.1 → 3.1.2
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/hooks/usePermission/index.js +10 -4
- package/es/utils/index.js +6 -0
- package/lib/hooks/usePermission/index.js +10 -4
- package/lib/utils/index.js +6 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useMemo, useCallback } from 'react';
|
|
1
|
+
import { useMemo, useCallback, useEffect } from 'react';
|
|
2
2
|
import { useLocation } from 'react-router-dom';
|
|
3
|
-
import { getUrlQuery, getResourceProps, getCache, getLoginName } from '../../utils';
|
|
3
|
+
import { getUrlQuery, getResourceProps, getCache, getLoginName, getCookie, setCookie } from '../../utils';
|
|
4
4
|
function usePermission() {
|
|
5
5
|
var routeLocation = useLocation();
|
|
6
6
|
/** @name 资源ID */
|
|
@@ -32,13 +32,20 @@ function usePermission() {
|
|
|
32
32
|
}, []);
|
|
33
33
|
/**
|
|
34
34
|
* 检查是否有权限
|
|
35
|
+
*
|
|
35
36
|
* @param val 权限值
|
|
36
37
|
*/
|
|
37
38
|
var checkRight = useCallback(function (val) {
|
|
38
39
|
if (!val) return true;
|
|
39
|
-
if (location.href.includes(
|
|
40
|
+
if (location.href.includes('//localhost')) return true;
|
|
40
41
|
return (permissionVal & val) === val && (resRightVal & val) === val;
|
|
41
42
|
}, []);
|
|
43
|
+
useEffect(function () {
|
|
44
|
+
// 如果外部转入token,而cookie中没有,则设置cookie。
|
|
45
|
+
if (getUrlQuery('token') && !getCookie('token')) {
|
|
46
|
+
setCookie('token', getUrlQuery('token'));
|
|
47
|
+
}
|
|
48
|
+
}, []);
|
|
42
49
|
return {
|
|
43
50
|
resourceId: resourceId,
|
|
44
51
|
permissionVal: permissionVal,
|
|
@@ -54,5 +61,4 @@ function usePermission() {
|
|
|
54
61
|
canPrint: checkRight(512)
|
|
55
62
|
};
|
|
56
63
|
}
|
|
57
|
-
;
|
|
58
64
|
export default usePermission;
|
package/es/utils/index.js
CHANGED
|
@@ -31,6 +31,12 @@ export var getResourceProps = function getResourceProps(name) {
|
|
|
31
31
|
// window.lsResourceList 为主工程写入的资源
|
|
32
32
|
// @ts-ignore
|
|
33
33
|
var resList = window.lsResourceList || parent.window.lsResourceList || [];
|
|
34
|
+
if (resList.length === 0) {
|
|
35
|
+
resList = getCache('allRes') || [];
|
|
36
|
+
if (!Array.isArray(resList)) {
|
|
37
|
+
resList = [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
34
40
|
if (id) {
|
|
35
41
|
obj = resList.find(function (o) {
|
|
36
42
|
return o.resourceId === id;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useMemo, useCallback } from 'react';
|
|
1
|
+
import { useMemo, useCallback, useEffect } from 'react';
|
|
2
2
|
import { useLocation } from 'react-router-dom';
|
|
3
|
-
import { getUrlQuery, getResourceProps, getCache, getLoginName } from '../../utils';
|
|
3
|
+
import { getUrlQuery, getResourceProps, getCache, getLoginName, getCookie, setCookie } from '../../utils';
|
|
4
4
|
function usePermission() {
|
|
5
5
|
var routeLocation = useLocation();
|
|
6
6
|
/** @name 资源ID */
|
|
@@ -32,13 +32,20 @@ function usePermission() {
|
|
|
32
32
|
}, []);
|
|
33
33
|
/**
|
|
34
34
|
* 检查是否有权限
|
|
35
|
+
*
|
|
35
36
|
* @param val 权限值
|
|
36
37
|
*/
|
|
37
38
|
var checkRight = useCallback(function (val) {
|
|
38
39
|
if (!val) return true;
|
|
39
|
-
if (location.href.includes(
|
|
40
|
+
if (location.href.includes('//localhost')) return true;
|
|
40
41
|
return (permissionVal & val) === val && (resRightVal & val) === val;
|
|
41
42
|
}, []);
|
|
43
|
+
useEffect(function () {
|
|
44
|
+
// 如果外部转入token,而cookie中没有,则设置cookie。
|
|
45
|
+
if (getUrlQuery('token') && !getCookie('token')) {
|
|
46
|
+
setCookie('token', getUrlQuery('token'));
|
|
47
|
+
}
|
|
48
|
+
}, []);
|
|
42
49
|
return {
|
|
43
50
|
resourceId: resourceId,
|
|
44
51
|
permissionVal: permissionVal,
|
|
@@ -54,5 +61,4 @@ function usePermission() {
|
|
|
54
61
|
canPrint: checkRight(512)
|
|
55
62
|
};
|
|
56
63
|
}
|
|
57
|
-
;
|
|
58
64
|
export default usePermission;
|
package/lib/utils/index.js
CHANGED
|
@@ -31,6 +31,12 @@ export var getResourceProps = function getResourceProps(name) {
|
|
|
31
31
|
// window.lsResourceList 为主工程写入的资源
|
|
32
32
|
// @ts-ignore
|
|
33
33
|
var resList = window.lsResourceList || parent.window.lsResourceList || [];
|
|
34
|
+
if (resList.length === 0) {
|
|
35
|
+
resList = getCache('allRes') || [];
|
|
36
|
+
if (!Array.isArray(resList)) {
|
|
37
|
+
resList = [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
34
40
|
if (id) {
|
|
35
41
|
obj = resList.find(function (o) {
|
|
36
42
|
return o.resourceId === id;
|