Skip to content

Commit

Permalink
bird-button权限props改为permission
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxx-u committed Jul 20, 2018
1 parent b59574f commit 158f881
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 33 deletions.
8 changes: 4 additions & 4 deletions doc/bird-button.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ bird-button是基于react antd的Button组件进行封装的支持权限控制
## 使用方式

```
<BirdButton permissionName={'sys'} type='primary'>测试按钮</BirdButton>
<BirdButton permission={'sys'} type='primary'>测试按钮</BirdButton>
```

## API
除permissionName外属性都会渲染至antd的Button组件
除permission外属性都会渲染至antd的Button组件


参数 | 说明 | 类型 | 默认值
---|---|---|---
permissionName | 所需权限名 | string | ''
permission | 所需权限名 | string | ''

默认permissionName为'',表示不验证权限。当permissionName有值时则验证当前用户是否拥有该权限,有则显示。
默认permission为'',表示不验证权限。当permission有值时则验证当前用户是否拥有该权限,有则显示。
10 changes: 5 additions & 5 deletions src/components/Form/BirdButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class BirdButton extends React.Component {
constructor(props) {
super(props);

const permissionName = this.props.permissionName;
const permission = this.props.permission;

this.state = {
hasPermission: permissionName === '' || permission.check(permissionName)
hasPermission: permission === '' || permission.check(permission)
}
}

Expand All @@ -24,7 +24,7 @@ class BirdButton extends React.Component {
render() {
if (this.state.hasPermission) {
let props = deepClone(this.props);
delete props.permissionName;
delete props.permission;

return <Button {...props}>
{this.props.children}
Expand All @@ -36,11 +36,11 @@ class BirdButton extends React.Component {
}

BirdButton.propTypes = {
permissionName:PropTypes.string
permission:PropTypes.string
};

BirdButton.defaultProps = {
permissionName:''
permission:''
};

export default BirdButton;
4 changes: 2 additions & 2 deletions src/components/Grid/BirdGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BirdGrid extends React.Component {
}

/* 初始化渲染执行之前执行 */
componentWillMount () {
componentDidMount () {
let gridOption = this.props.gridOption;
let p = gridOption.permission;
let tp = {};
Expand Down Expand Up @@ -489,7 +489,7 @@ class BirdGrid extends React.Component {
action.onClick(checkedValues, checkedDatas);
}}><Button key={"action_" + index} icon={action.icon} type="primary">{action.name}</Button>
</Popconfirm> :
<Button permissionName={action.permissionName} key={"action_" + index} icon={action.icon} type="primary"
<Button permission={action.permissionName} key={"action_" + index} icon={action.icon} type="primary"
onClick={() => {
let primaryKey = self.state.primaryKey;
let checkedValues = self.state.checkedValues;
Expand Down
44 changes: 24 additions & 20 deletions src/models/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { routerRedux } from 'dva/router'
import { parse } from 'qs'
import config from 'config'
import {permission} from 'utils'
import { permission } from 'utils'
import { query, logout } from 'services/app'
import * as menusService from 'services/menus'
import * as permissionsService from 'services/permissions'
Expand Down Expand Up @@ -34,7 +34,7 @@ export default {
},
subscriptions: {

setupHistory ({ dispatch, history }) {
setupHistory({ dispatch, history }) {
history.listen((location) => {
dispatch({
type: 'updateState',
Expand All @@ -46,7 +46,7 @@ export default {
})
},

setup ({ dispatch }) {
setup({ dispatch }) {
dispatch({ type: 'query' })
let tid
window.onresize = () => {
Expand All @@ -60,7 +60,7 @@ export default {
},
effects: {

* query ({
* query({
payload,
}, { call, put, select }) {
const { success, user } = yield call(query, payload)
Expand Down Expand Up @@ -95,27 +95,31 @@ export default {
}
},

* logout ({
* logout({
payload,
}, { call, put }) {
const data = yield call(logout, parse(payload))
if (data.success) {
yield put({ type: 'updateState', payload: {
user: {},
menu: [{
id: 1,
icon: 'laptop',
name: 'Dashboard',
router: '/dashboard',
}],
}})
yield put({
type: 'updateState', payload: {
user: {},
menu: [
{
id: 1,
icon: 'laptop',
name: 'Dashboard',
url: '/dashboard'
},
],
}
})
yield put({ type: 'query' })
} else {
throw (data)
}
},

* changeNavbar (action, { put, select }) {
* changeNavbar(action, { put, select }) {
const { app } = yield (select(_ => _))
const isNavbar = document.body.clientWidth < 769
if (isNavbar !== app.isNavbar) {
Expand All @@ -132,37 +136,37 @@ export default {
}
},

switchSider (state) {
switchSider(state) {
window.localStorage.setItem(`${prefix}siderFold`, !state.siderFold)
return {
...state,
siderFold: !state.siderFold,
}
},

switchTheme (state) {
switchTheme(state) {
window.localStorage.setItem(`${prefix}darkTheme`, !state.darkTheme)
return {
...state,
darkTheme: !state.darkTheme,
}
},

switchMenuPopver (state) {
switchMenuPopver(state) {
return {
...state,
menuPopoverVisible: !state.menuPopoverVisible,
}
},

handleNavbar (state, { payload }) {
handleNavbar(state, { payload }) {
return {
...state,
isNavbar: payload,
}
},

handleNavOpenKeys (state, { payload: navOpenKeys }) {
handleNavOpenKeys(state, { payload: navOpenKeys }) {
return {
...state,
...navOpenKeys,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/demo/bird-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class BirdButtonDemoPage extends React.Component {
render() {
return (
<Card>
<BirdButton permissionName={'sys:authorize:user:add'} type="primary">权限按钮</BirdButton>
<BirdButton permission={'sys:authorize:user:add'} type="primary">权限按钮</BirdButton>
<div>
除permissionName外,其他api与antd的Button组件完全一致
除permission外,其他api与antd的Button组件完全一致
</div>
</Card>
)
Expand Down

0 comments on commit 158f881

Please sign in to comment.