Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
WebPublic
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
前端开发小组
WebPublic
Commits
d78afa12
提交
d78afa12
authored
3月 25, 2020
作者:
徐立
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改
上级
eeb2bf51
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
338 行增加
和
7 行删除
+338
-7
Authorized.jsx
one_stop_public/Authorized/Authorized.jsx
+10
-0
AuthorizedRoute.jsx
one_stop_public/Authorized/AuthorizedRoute.jsx
+25
-0
CheckPermissions.jsx
one_stop_public/Authorized/CheckPermissions.jsx
+76
-0
PromiseRender.jsx
one_stop_public/Authorized/PromiseRender.jsx
+78
-0
Secured.jsx
one_stop_public/Authorized/Secured.jsx
+70
-0
index.jsx
one_stop_public/Authorized/index.jsx
+42
-0
renderAuthorize.js
one_stop_public/Authorized/renderAuthorize.js
+30
-0
functionList.js
one_stop_public/excelInitFuc/functionList.js
+2
-2
modilehome.js
one_stop_public/models/modilehome.js
+1
-1
Authorized.js
one_stop_public/utils/Authorized.js
+1
-1
request.js
one_stop_public/utils/request.js
+3
-3
没有找到文件。
one_stop_public/Authorized/Authorized.jsx
0 → 100644
浏览文件 @
d78afa12
import
React
from
'react'
;
import
check
from
'./CheckPermissions'
;
const
Authorized
=
({
children
,
authority
,
noMatch
=
null
})
=>
{
const
childrenRender
=
typeof
children
===
'undefined'
?
null
:
children
;
const
dom
=
check
(
authority
,
childrenRender
,
noMatch
);
return
<>
{
dom
}
</>;
};
export
default
Authorized
;
one_stop_public/Authorized/AuthorizedRoute.jsx
0 → 100644
浏览文件 @
d78afa12
import
{
Redirect
,
Route
}
from
'umi'
;
import
React
from
'react'
;
import
Authorized
from
'./Authorized'
;
const
AuthorizedRoute
=
({
component
:
Component
,
render
,
authority
,
redirectPath
,
...
rest
})
=>
(
<
Authorized
authority=
{
authority
}
noMatch=
{
<
Route
{
...
rest
}
render=
{
()
=>
(
<
Redirect
to=
{
{
pathname
:
redirectPath
,
}
}
/>
)
}
/>
}
>
<
Route
{
...
rest
}
render=
{
props
=>
(
Component
?
<
Component
{
...
props
}
/>
:
render
(
props
))
}
/>
</
Authorized
>
);
export
default
AuthorizedRoute
;
one_stop_public/Authorized/CheckPermissions.jsx
0 → 100644
浏览文件 @
d78afa12
import
React
from
'react'
;
import
{
CURRENT
}
from
'./renderAuthorize'
;
// eslint-disable-next-line import/no-cycle
import
PromiseRender
from
'./PromiseRender'
;
/**
* 通用权限检查方法
* Common check permissions method
* @param { 权限判定 | Permission judgment } authority
* @param { 你的权限 | Your permission description } currentAuthority
* @param { 通过的组件 | Passing components } target
* @param { 未通过的组件 | no pass components } Exception
*/
const
checkPermissions
=
(
authority
,
currentAuthority
,
target
,
Exception
)
=>
{
// 没有判定权限.默认查看所有
// Retirement authority, return target;
if
(
!
authority
)
{
return
target
;
}
// 数组处理
if
(
Array
.
isArray
(
authority
))
{
if
(
Array
.
isArray
(
currentAuthority
))
{
if
(
currentAuthority
.
some
(
item
=>
authority
.
includes
(
item
)))
{
return
target
;
}
}
else
if
(
authority
.
includes
(
currentAuthority
))
{
return
target
;
}
return
Exception
;
}
// string 处理
if
(
typeof
authority
===
'string'
)
{
if
(
Array
.
isArray
(
currentAuthority
))
{
if
(
currentAuthority
.
some
(
item
=>
authority
===
item
))
{
return
target
;
}
}
else
if
(
authority
===
currentAuthority
)
{
return
target
;
}
return
Exception
;
}
// Promise 处理
if
(
authority
instanceof
Promise
)
{
return
<
PromiseRender
ok=
{
target
}
error=
{
Exception
}
promise=
{
authority
}
/>;
}
// Function 处理
if
(
typeof
authority
===
'function'
)
{
try
{
const
bool
=
authority
(
currentAuthority
);
// 函数执行后返回值是 Promise
if
(
bool
instanceof
Promise
)
{
return
<
PromiseRender
ok=
{
target
}
error=
{
Exception
}
promise=
{
bool
}
/>;
}
if
(
bool
)
{
return
target
;
}
return
Exception
;
}
catch
(
error
)
{
throw
error
;
}
}
throw
new
Error
(
'unsupported parameters'
);
};
export
{
checkPermissions
};
function
check
(
authority
,
target
,
Exception
)
{
return
checkPermissions
(
authority
,
CURRENT
,
target
,
Exception
);
}
export
default
check
;
one_stop_public/Authorized/PromiseRender.jsx
0 → 100644
浏览文件 @
d78afa12
import
React
from
'react'
;
import
{
Spin
}
from
'antd'
;
import
isEqual
from
'lodash/isEqual'
;
import
{
isComponentClass
}
from
'./Secured'
;
// eslint-disable-next-line import/no-cycle
export
default
class
PromiseRender
extends
React
.
Component
{
state
=
{
component
:
()
=>
null
,
};
componentDidMount
()
{
this
.
setRenderComponent
(
this
.
props
);
}
shouldComponentUpdate
=
(
nextProps
,
nextState
)
=>
{
const
{
component
}
=
this
.
state
;
if
(
!
isEqual
(
nextProps
,
this
.
props
))
{
this
.
setRenderComponent
(
nextProps
);
}
if
(
nextState
.
component
!==
component
)
return
true
;
return
false
;
};
// set render Component : ok or error
setRenderComponent
(
props
)
{
const
ok
=
this
.
checkIsInstantiation
(
props
.
ok
);
const
error
=
this
.
checkIsInstantiation
(
props
.
error
);
props
.
promise
.
then
(()
=>
{
this
.
setState
({
component
:
ok
,
});
return
true
;
})
.
catch
(()
=>
{
this
.
setState
({
component
:
error
,
});
});
}
// Determine whether the incoming component has been instantiated
// AuthorizedRoute is already instantiated
// Authorized render is already instantiated, children is no instantiated
// Secured is not instantiated
checkIsInstantiation
=
target
=>
{
if
(
isComponentClass
(
target
))
{
const
Target
=
target
;
return
props
=>
<
Target
{
...
props
}
/>;
}
if
(
React
.
isValidElement
(
target
))
{
return
props
=>
React
.
cloneElement
(
target
,
props
);
}
return
()
=>
target
;
};
render
()
{
const
{
component
:
Component
}
=
this
.
state
;
const
{
ok
,
error
,
promise
,
...
rest
}
=
this
.
props
;
return
Component
?
(
<
Component
{
...
rest
}
/>
)
:
(
<
div
style=
{
{
width
:
'100%'
,
height
:
'100%'
,
margin
:
'auto'
,
paddingTop
:
50
,
textAlign
:
'center'
,
}
}
>
<
Spin
size=
"large"
/>
</
div
>
);
}
}
one_stop_public/Authorized/Secured.jsx
0 → 100644
浏览文件 @
d78afa12
import
React
from
'react'
;
import
CheckPermissions
from
'./CheckPermissions'
;
/**
* 默认不能访问任何页面
* default is "NULL"
*/
const
Exception403
=
()
=>
403
;
export
const
isComponentClass
=
component
=>
{
if
(
!
component
)
return
false
;
const
proto
=
Object
.
getPrototypeOf
(
component
);
if
(
proto
===
React
.
Component
||
proto
===
Function
.
prototype
)
return
true
;
return
isComponentClass
(
proto
);
};
// Determine whether the incoming component has been instantiated
// AuthorizedRoute is already instantiated
// Authorized render is already instantiated, children is no instantiated
// Secured is not instantiated
const
checkIsInstantiation
=
target
=>
{
if
(
isComponentClass
(
target
))
{
const
Target
=
target
;
return
props
=>
<
Target
{
...
props
}
/>;
}
if
(
React
.
isValidElement
(
target
))
{
return
props
=>
React
.
cloneElement
(
target
,
props
);
}
return
()
=>
target
;
};
/**
* 用于判断是否拥有权限访问此 view 权限
* authority 支持传入 string, () => boolean | Promise
* e.g. 'user' 只有 user 用户能访问
* e.g. 'user,admin' user 和 admin 都能访问
* e.g. ()=>boolean 返回true能访问,返回false不能访问
* e.g. Promise then 能访问 catch不能访问
* e.g. authority support incoming string, () => boolean | Promise
* e.g. 'user' only user user can access
* e.g. 'user, admin' user and admin can access
* e.g. () => boolean true to be able to visit, return false can not be accessed
* e.g. Promise then can not access the visit to catch
* @param {string | function | Promise} authority
* @param {ReactNode} error 非必需参数
*/
const
authorize
=
(
authority
,
error
)
=>
{
/**
* conversion into a class
* 防止传入字符串时找不到staticContext造成报错
* String parameters can cause staticContext not found error
*/
let
classError
=
false
;
if
(
error
)
{
classError
=
()
=>
error
;
}
if
(
!
authority
)
{
throw
new
Error
(
'authority is required'
);
}
return
function
decideAuthority
(
target
)
{
const
component
=
CheckPermissions
(
authority
,
target
,
classError
||
Exception403
);
return
checkIsInstantiation
(
component
);
};
};
export
default
authorize
;
one_stop_public/Authorized/index.jsx
0 → 100644
浏览文件 @
d78afa12
import
Authorized
from
'./Authorized'
;
import
AuthorizedRoute
from
'./AuthorizedRoute'
;
import
Secured
from
'./Secured'
;
import
check
from
'./CheckPermissions'
;
import
renderAuthorize
from
'./renderAuthorize'
;
import
React
from
"react"
;
import
{
connect
}
from
"dva"
;
import
{
querySysCode
,
queryCheckPath
}
from
"../utils/queryConfig"
;
import
{
unwatchFile
}
from
'fs'
;
Authorized
.
Secured
=
Secured
;
Authorized
.
AuthorizedRoute
=
AuthorizedRoute
;
Authorized
.
check
=
check
;
const
RenderAuthorize
=
renderAuthorize
(
Authorized
);
export
default
RenderAuthorize
;
@
connect
(({
global
})
=>
{
const
myPath
=
global
.
myPath
||
[];
return
{
myPath
:
myPath
};
})
class
AuthorizedWarp
extends
React
.
PureComponent
{
render
()
{
const
isCheckPath
=
queryCheckPath
();
if
(
!
isCheckPath
){
return
this
.
props
.
children
}
const
{
myPath
,
...
props
}
=
this
.
props
;
const
MYAuthorized
=
RenderAuthorize
(
myPath
);
return
(
<
MYAuthorized
{
...
props
}
/>
);
}
}
export
{
AuthorizedWarp
}
one_stop_public/Authorized/renderAuthorize.js
0 → 100644
浏览文件 @
d78afa12
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable import/no-mutable-exports */
let
CURRENT
=
'NULL'
;
/**
* use authority or getAuthority
* @param {string|()=>String} currentAuthority
*/
const
renderAuthorize
=
Authorized
=>
currentAuthority
=>
{
if
(
currentAuthority
)
{
if
(
typeof
currentAuthority
===
'function'
)
{
CURRENT
=
currentAuthority
();
}
if
(
Object
.
prototype
.
toString
.
call
(
currentAuthority
)
===
'[object String]'
||
Array
.
isArray
(
currentAuthority
)
)
{
CURRENT
=
currentAuthority
;
}
}
else
{
CURRENT
=
'NULL'
;
}
return
Authorized
;
};
export
{
CURRENT
};
export
default
Authorized
=>
renderAuthorize
(
Authorized
);
one_stop_public/excelInitFuc/functionList.js
浏览文件 @
d78afa12
import
{
isNaN
,
findIndex
,
chunk
,
drop
,
camelCase
,
endsWith
,
pick
,
words
}
from
'lodash'
;
import
{
isNaN
,
findIndex
,
chunk
,
drop
,
camelCase
,
endsWith
,
pick
,
words
}
from
'lodash'
;
import
moment
from
'moment'
;
import
moment
from
'moment'
;
import
{
openToast
}
from
'
@/components
/Notification'
;
import
{
openToast
}
from
'
../location
/Notification'
;
import
{
showToast
}
from
'
@/pages/MobileSystem/components
/Toast'
;
import
{
showToast
}
from
'
../location
/Toast'
;
// 图片引入
// 图片引入
import
Compatibility
from
'../assets/Compatibility.png'
;
import
Compatibility
from
'../assets/Compatibility.png'
;
import
Compatibility2
from
'../assets/Compatibility2.png'
;
import
Compatibility2
from
'../assets/Compatibility2.png'
;
...
...
one_stop_public/models/modilehome.js
浏览文件 @
d78afa12
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
* 2019年9月20日
* 2019年9月20日
* 主页接口
* 主页接口
*/
*/
import
{
uaaRequest
}
from
"
@
/utils/request"
;
import
{
uaaRequest
}
from
"
..
/utils/request"
;
const
myCollect
=
{
const
myCollect
=
{
namespace
:
'modileHome'
,
namespace
:
'modileHome'
,
state
:
{
state
:
{
...
...
one_stop_public/utils/Authorized.js
浏览文件 @
d78afa12
import
RenderAuthorize
from
'
@/components
/Authorized'
;
import
RenderAuthorize
from
'
..
/Authorized'
;
import
{
getAuthority
}
from
'./authority'
;
import
{
getAuthority
}
from
'./authority'
;
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable eslint-comments/disable-enable-pair */
...
...
one_stop_public/utils/request.js
浏览文件 @
d78afa12
...
@@ -4,11 +4,11 @@
...
@@ -4,11 +4,11 @@
*/
*/
import
{
extend
}
from
'umi-request'
;
import
{
extend
}
from
'umi-request'
;
import
{
notification
}
from
'antd'
;
import
{
notification
}
from
'antd'
;
import
FormdataWrapper
from
"
@
/utils/object-to-formdata-custom"
;
import
FormdataWrapper
from
"
..
/utils/object-to-formdata-custom"
;
import
{
getToken
}
from
"./token"
;
import
{
getToken
}
from
"./token"
;
import
{
queryApiActionPath
,
queryOauthActionPath
,
queryPermActionPath
}
from
"
@
/utils/queryConfig"
;
import
{
queryApiActionPath
,
queryOauthActionPath
,
queryPermActionPath
}
from
"
..
/utils/queryConfig"
;
import
{
offline
}
from
'
@/pages/MobileSystem/components
/Toast'
import
{
offline
}
from
'
../location
/Toast'
const
codeMessage
=
{
const
codeMessage
=
{
200
:
'服务器成功返回请求的数据。'
,
200
:
'服务器成功返回请求的数据。'
,
201
:
'新建或修改数据成功。'
,
201
:
'新建或修改数据成功。'
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论