Archer_cdm 2 years ago
parent
commit
bb4b59d164
  1. 260
      web/client/src/sections/organization/containers/authority.js

260
web/client/src/sections/organization/containers/authority.js

@ -6,144 +6,144 @@ import { getResource, getUserResource, postUserRes } from '../actions/authority'
import Resource from '../components/resource'; import Resource from '../components/resource';
const Authority = (props) => { const Authority = (props) => {
const { dispatch, loading, depMessage, depUser, resource, userResource, clientHeight } = props const { dispatch, loading, depMessage, depUser, resource, userResource, clientHeight } = props
const [depSelectedKeys, setDepSelectedKeys] = useState([]) const [depSelectedKeys, setDepSelectedKeys] = useState([])
const [userSelectedKeys, setUserSelectedKeys] = useState([]) const [userSelectedKeys, setUserSelectedKeys] = useState([])
const [depSelected, setDepSelected] = useState() const [depSelected, setDepSelected] = useState()
const [userSelected, setUserSelected] = useState() const [userSelected, setUserSelected] = useState()
const [resCode, setResCode] = useState({}) const [resCode, setResCode] = useState({})
const [useName, setUseName] = useState()// 选中名字 const [useName, setUseName] = useState()// 选中名字
const [userType,setUserType]=useState() const [userType, setUserType] = useState()
console.log(resource) console.log(resource)
useEffect(() => { useEffect(() => {
dispatch(getResource()) dispatch(getResource())
if (!(depMessage && depMessage.length)) { if (!(depMessage && depMessage.length)) {
dispatch(getDepMessage()) dispatch(getDepMessage())
} }
}, []) }, [])
useEffect(() => { useEffect(() => {
if (depMessage.length) { if (depMessage.length) {
setDepSelectedKeys([depMessage[0].id]) setDepSelectedKeys([depMessage[0].id])
setDepSelected([depMessage[0].name]) setDepSelected([depMessage[0].name])
dispatch(getDepUser(depMessage[0].id)) dispatch(getDepUser(depMessage[0].id))
} }
}, [depMessage]) }, [depMessage])
useEffect(() => { useEffect(() => {
if (depUser.length) { if (depUser.length) {
setUserSelectedKeys([depUser[0].id]) setUserSelectedKeys([depUser[0].id])
setUserSelected(depUser[0].username) setUserSelected(depUser[0].username)
dispatch(getUserResource(depUser[0].id)) dispatch(getUserResource(depUser[0].id))
setUseName(depUser[0].name) setUseName(depUser[0].name)
} }
console.log(depUser, 'depUser') console.log(depUser, 'depUser')
}, [depUser]) }, [depUser])
const handleSave = () => { const handleSave = () => {
dispatch(postUserRes({ userId: userSelectedKeys[0], resCode: resCode })).then(res => { dispatch(postUserRes({ userId: userSelectedKeys[0], resCode: resCode })).then(res => {
if (res.success) { if (res.success) {
dispatch(getUserResource(userSelectedKeys[0])) dispatch(getUserResource(userSelectedKeys[0]))
} }
}) })
} }
return ( return (
<Spin spinning={loading}> <Spin spinning={loading}>
<Row gutter={16}> <Row gutter={16}>
<Col span={4} style={{ height: '100%' }}> <Col span={4} style={{ height: '100%' }}>
<Card title="部门" bordered={false} bodyStyle={{ padding: 8, paddingTop: 24 }}> <Card title="部门" bordered={false} bodyStyle={{ padding: 8, paddingTop: 24 }}>
{ {
depMessage.length ? depMessage.length ?
<Tree <Tree
height={clientHeight - 100} height={clientHeight - 100}
defaultExpandedKeys={[depMessage[0].id]} defaultExpandedKeys={[depMessage[0].id]}
selectedKeys={depSelectedKeys} selectedKeys={depSelectedKeys}
onSelect={(selectedKeys, { selected, selectedNodes, node }) => { onSelect={(selectedKeys, { selected, selectedNodes, node }) => {
setUserType(selectedNodes[0].type) setUserType(selectedNodes[0].type)
if (selected) { if (selected) {
setDepSelectedKeys(selectedKeys) setDepSelectedKeys(selectedKeys)
setDepSelected(selectedNodes[0].name || "") setDepSelected(selectedNodes[0].name || "")
dispatch(getDepUser(selectedKeys[0])) dispatch(getDepUser(selectedKeys[0]))
} }
}} }}
treeData={depMessage} treeData={depMessage}
fieldNames={{ fieldNames={{
title: 'name', title: 'name',
key: 'id', key: 'id',
children: 'subordinate' children: 'subordinate'
}} }}
/> : '' /> : ''
} }
</Card> </Card>
</Col> </Col>
<Col span={4} style={{ height: '100%', }}> <Col span={4} style={{ height: '100%', }}>
<Card title={`[${depSelected}] 用户列表`} bordered={false} bodyStyle={{ padding: 8, paddingTop: 24 }}> <Card title={(depSelected ? `[${depSelected}]` : "") + '用户列表'} bordered={false} bodyStyle={{ padding: 8, paddingTop: 24 }}>
{ {
depUser.length ? depUser.length ?
<Tree <Tree
height={clientHeight - 100} height={clientHeight - 100}
defaultSelectedKeys={[depUser[0].id]} defaultSelectedKeys={[depUser[0].id]}
selectedKeys={userSelectedKeys} selectedKeys={userSelectedKeys}
onSelect={(selectedKeys, { selected, selectedNodes, node, event }) => { onSelect={(selectedKeys, { selected, selectedNodes, node, event }) => {
const name = node.name const name = node.name
setUseName(name) setUseName(name)
if (selected) { if (selected) {
setUserSelectedKeys(selectedKeys) setUserSelectedKeys(selectedKeys)
setUserSelected(selectedNodes[0].username || '') setUserSelected(selectedNodes[0].username || '')
dispatch(getUserResource(selectedKeys[0])) dispatch(getUserResource(selectedKeys[0]))
} }
}} }}
treeData={depUser} treeData={depUser}
fieldNames={{ fieldNames={{
title: 'name', title: 'name',
key: 'id' key: 'id'
}} }}
/> : <Empty /> /> : <Empty />
} }
</Card> </Card>
</Col> </Col>
<Col span={16} style={{ height: '100%', }}> <Col span={16} style={{ height: '100%', }}>
{depUser.length ? {depUser.length ?
<Card title={`[${useName ? useName : '管理员'}] 功能范围`} bordered={false} bodyStyle={{ padding: 8, paddingTop: 24 }}> <Card title={`[${useName ? useName : '管理员'}] 功能范围`} bordered={false} bodyStyle={{ padding: 8, paddingTop: 24 }}>
<Resource <Resource
userSelected={userSelected} userSelected={userSelected}
roleData={resource} roleData={resource}
userRole={userResource} userRole={userResource}
setResCode={setResCode} setResCode={setResCode}
userType={userType} userType={userType}
/> />
<Row type="flex" justify="center" style={{ marginBottom: 16, marginTop: 16, textAlign: 'center' }}> <Row type="flex" justify="center" style={{ marginBottom: 16, marginTop: 16, textAlign: 'center' }}>
<Col span="24"> <Col span="24">
<Button <Button
disabled={userSelected === "SuperAdmin"||userType===4} disabled={userSelected === "SuperAdmin" || userType === 4}
onClick={handleSave} onClick={handleSave}
style={{ width: '60%' }} style={{ width: '60%' }}
type='primary'>保存修改</Button> type='primary'>保存修改</Button>
</Col></Row> </Col></Row>
</Card> </Card>
: <Card title={`[]功能范围`} bordered={false} bodyStyle={{ padding: 8, paddingTop: 24 }}> : <Card title={`[]功能范围`} bordered={false} bodyStyle={{ padding: 8, paddingTop: 24 }}>
<Empty /> <Empty />
</Card> </Card>
} }
</Col> </Col>
</Row> </Row>
</Spin > </Spin >
) )
} }
function mapStateToProps(state) { function mapStateToProps (state) {
const { userResource, resource, depMessage, depUser, global } = state; const { userResource, resource, depMessage, depUser, global } = state;
return { return {
clientHeight: global.clientHeight, clientHeight: global.clientHeight,
loading: depMessage.isRequesting || depUser.isRequesting || resource.isRequesting, loading: depMessage.isRequesting || depUser.isRequesting || resource.isRequesting,
userResource: userResource.data || [], userResource: userResource.data || [],
resource: resource.data || [], resource: resource.data || [],
depMessage: depMessage.data || [], depMessage: depMessage.data || [],
depUser: depUser.data || [] depUser: depUser.data || []
}; };
} }
export default connect(mapStateToProps)(Authority); export default connect(mapStateToProps)(Authority);
Loading…
Cancel
Save