I found a good way:
const access = {} // 权限字段列表
const createElement = React.createElement
React.createElement = function rCreateElement(...args: any): any {
const mixProps = args[1]
if (mixProps) {
const auth = mixProps.auth
delete mixProps.auth
// 权限校验
// auth: 指定权限字段的prop
if (access && access[auth] === false) {
return null
}
}
return createElement(args[0], ...args.slice(1))
}
usage:
// 标签
<p auth="test">please Login</p>
// 组件
<Resizeable
auth="test"
className="k-left__top"
horizontal
storeName="left-top-height"
max={600}
min={200}
defaultValue={200}
>
555
</Resizeable>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…