Browse Source

Merge branch 'dev' of https://gitea.anxinyun.cn/gao.zhiyuan/Highways4Good into dev

release_0.0.1
巴林闲侠 2 years ago
parent
commit
ffb1e5ddb9
  1. 39
      web/client/src/sections/organization/actions/user.js
  2. 35
      web/client/src/sections/organization/components/userModal.js
  3. 122
      web/client/src/sections/organization/containers/user.js
  4. 4
      web/client/src/utils/webapi.js

39
web/client/src/sections/organization/actions/user.js

@ -57,22 +57,55 @@ export function delUser(userIds) {
}); });
} }
export function resetPwd(id, data) { export function resetPwd(userId, data) {
return dispatch => basicAction({ return dispatch => basicAction({
type: 'put', type: 'put',
data, data,
dispatch: dispatch, dispatch: dispatch,
actionType: 'CREATE_DEPARTMENT_USER', actionType: 'CREATE_DEPARTMENT_USER',
url: ApiTable.resetPwd.replace('{id}', id), url: ApiTable.resetPwd.replace('{userId}', userId),
msg: { option: '重置用户密码' }, msg: { option: '重置用户密码' },
}); });
} }
export function createDep(data) {
return dispatch => basicAction({
type: 'put',
data,
dispatch: dispatch,
actionType: 'CREATE_DEPARTMENT',
url: ApiTable.createDepMessage,
msg: { option: '新建部门' },
});
}
export function delDep(depId) {
return dispatch => basicAction({
type: 'del',
dispatch: dispatch,
actionType: 'DEL_DEPARTMENT',
url: ApiTable.delDepMessage.replace('{depId}', depId),
msg: { option: '删除部门' },
});
}
export function updateDep(data) {
return dispatch => basicAction({
type: 'put',
data,
dispatch: dispatch,
actionType: 'UPDATE_DEPARTMENT',
url: ApiTable.createDepMessage,
msg: { option: '修改部门' },
});
}
export default { export default {
getDepMessage, getDepMessage,
getDepUser, getDepUser,
createUser, createUser,
updateUser, updateUser,
delUser, delUser,
resetPwd resetPwd,
createDep,
delDep
} }

35
web/client/src/sections/organization/components/userModal.js

@ -41,7 +41,7 @@ const UserModal = (props) => {
<ProForm.Group> <ProForm.Group>
<ProFormText <ProFormText
name={['contract', 'name']} name={['contract', 'name']}
maxLength={24} maxLength={10}
width="md" width="md"
label="姓名" label="姓名"
required required
@ -49,19 +49,20 @@ const UserModal = (props) => {
rules={[{ required: true, message: '请输入姓名' }]} rules={[{ required: true, message: '请输入姓名' }]}
/> />
<ProFormText <ProFormText
name={['contract', 'phone']} name={['contract', 'username']}
width="md" width="md"
label="用户名(手机号)" label="用户名"
maxLength={20}
required required
fieldProps={{ fieldProps={{
maxLength: 11, maxLength: 30,
}} }}
getValueFromEvent={(event) => { getValueFromEvent={(event) => {
return event.target.value.replace(/\D/g, '') return event.target.value
}} }}
placeholder="请输入用户名(手机号)" placeholder="请输入用户名"
rules={[ rules={[
{ required: true, valueType: Number, max: 11 }, { pattern: /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/, message: "请输入正确的手机号" } { required: true }
]} ]}
/> />
</ProForm.Group> </ProForm.Group>
@ -92,17 +93,25 @@ const UserModal = (props) => {
}} }}
rules={[{ required: true, message: '请选择所属部门' }]} rules={[{ required: true, message: '请选择所属部门' }]}
request={async () => { request={async () => {
console.log(depData);
return depData return depData
}} }}
expandedKeys={["title"]} expandedKeys={["title"]}
/> />
< ProFormText < ProFormText
name={['contract', 'post']} name={['contract', 'phone']}
width="md" width="md"
label="职位" label="手机号"
// required required
placeholder="请输入职位" fieldProps={{
maxLength: 11,
}}
getValueFromEvent={(event) => {
return event.target.value.replace(/\D/g, '')
}}
placeholder="请输入手机号"
rules={[
{ required: true, valueType: Number, max: 11 }, { pattern: /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/, message: "请输入正确的手机号" }
]}
/> />
</ProForm.Group> </ProForm.Group>
<ProForm.Group> <ProForm.Group>
@ -149,7 +158,7 @@ const UserModal = (props) => {
function mapStateToProps(state) { function mapStateToProps(state) {
const { depMessage } = state; const { depMessage } = state;
console.log('depMessage:',depMessage);
const pakData = (dep) => { const pakData = (dep) => {
// console.log(dep); // console.log(dep);
return dep.map((d) => { return dep.map((d) => {

122
web/client/src/sections/organization/containers/user.js

@ -1,11 +1,12 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { EllipsisOutlined } from '@ant-design/icons'; import { DeleteOutlined, EllipsisOutlined, FormOutlined } from '@ant-design/icons';
import { Spin, Space, Button, Popconfirm, Row, Col, Tree, Table, Card, Switch } from 'antd'; import { Spin, Space, Button, Popconfirm, Row, Col, Tree, Table, Card, Switch, Tooltip } from 'antd';
import ProTable from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table';
import { getDepMessage, getDepUser, createUser, updateUser, delUser, resetPwd } from '../actions/user'; import { getDepMessage, getDepUser, createUser, updateUser, delUser, resetPwd, createDep, delDep, updateDep } from '../actions/user';
import UserModal from '../components/userModal'; import UserModal from '../components/userModal';
import ResetPwd from '../components/resetPwd'; import ResetPwd from '../components/resetPwd';
import DepModal from '../components/depModal';
const TreeNode = Tree.TreeNode; const TreeNode = Tree.TreeNode;
@ -17,6 +18,10 @@ const UserManage = (props) => {
const [pwdModalVisible, setPwdModalVisible] = useState(false); const [pwdModalVisible, setPwdModalVisible] = useState(false);
const [depSelectedKeys, setDepSelectedKeys] = useState([]) const [depSelectedKeys, setDepSelectedKeys] = useState([])
const [rowSelected, setRowSelected] = useState([]) const [rowSelected, setRowSelected] = useState([])
const [depModalVisible, setDepModalVisible] = useState(false);
const [depModalType, setDepModalType] = useState();
const [depModalRecord, setDepModalRecord] = useState();
useEffect(() => { useEffect(() => {
dispatch(getDepMessage()) dispatch(getDepMessage())
}, []) }, [])
@ -27,20 +32,20 @@ const UserManage = (props) => {
dispatch(getDepUser(depMessage[0].id)) dispatch(getDepUser(depMessage[0].id))
} }
}, [depMessage]) }, [depMessage])
const columns = const columns =
[ [
{ {
title: '姓名', title: '姓名',
dataIndex: 'name', dataIndex: 'name',
}, { }, {
title: '用户名(手机号)', title: '用户名',
dataIndex: 'username', dataIndex: 'username',
}, },
{ {
title: '职位', title: '手机号',
dataIndex: 'post', dataIndex: 'phone',
}, { },
{
title: '邮箱', title: '邮箱',
dataIndex: 'email', dataIndex: 'email',
}, { }, {
@ -53,7 +58,6 @@ const UserManage = (props) => {
title: '操作', title: '操作',
dataIndex: 'action', dataIndex: 'action',
render: (dom, record) => { render: (dom, record) => {
// return record.username == 'SuperAdmin' ? '' : [ // return record.username == 'SuperAdmin' ? '' : [
// <Button type="link" onClick={() => { openModal('edit', record) }}>编辑</Button>, // <Button type="link" onClick={() => { openModal('edit', record) }}>编辑</Button>,
// <Popconfirm // <Popconfirm
@ -107,7 +111,7 @@ const UserManage = (props) => {
dispatch(createUser(values.contract)).then(res => { dispatch(createUser(values.contract)).then(res => {
if (res.success) { if (res.success) {
setModalVisible(false); setModalVisible(false);
dispatch(getDepUser(depSelectedKeys[0])); dispatch(getDepMessage());
} }
}); });
} }
@ -125,6 +129,18 @@ const UserManage = (props) => {
} }
} }
//打开部门弹窗
const openDepModal = (type, record) => {
setDepModalVisible(true)
setDepModalType(type)
if (type == 'edit') {
setDepModalRecord(record);
} else {
setModalRecord(null);
}
}
//删除用户 //删除用户
const delUsers = (ids, type) => { const delUsers = (ids, type) => {
dispatch(delUser(ids)).then(res => { dispatch(delUser(ids)).then(res => {
@ -144,7 +160,53 @@ const UserManage = (props) => {
} }
}); });
} }
//部门新增及编辑
const onDepConfirm = (data) => {
if (depModalType == 'edit') {
dispatch(updateDep(data)).then(res => {
if (res.success) {
setDepModalVisible(false);
dispatch(getDepMessage());
}
});
} else {
dispatch(createDep(data)).then(res => {
if (res.success) {
setDepModalVisible(false);
dispatch(getDepMessage());
}
});
}
}
// 删除部门
const delDepartment = (id) => {
dispatch(delDep(id)).then(res => {
dispatch(getDepMessage())
});
}
const renderTree = (item, id) => {
return <div style={{ display: 'flex', width: '6vw', justifyContent: 'space-between' }}>
<Tooltip title={item.name}>
<div style={{ width: '70%', textOverflow: 'ellipsis', whiteSpace: 'nowrap', overflow: 'hidden' }}>{item.name}</div>
</Tooltip>
<div style={{ width: '30%' }} >
{
depSelectedKeys == id ? <>
<FormOutlined onClick={() => {
setDepModalRecord(item)
setDepModalVisible(true)
setDepModalType('edit')
}} />
<Popconfirm title='是否确认删除?' onConfirm={() => { delDepartment(id) }}>
<DeleteOutlined style={{ marginLeft: 5 }} />
</Popconfirm>
</> : null
}
</div>
</div>
}
return (<div > return (<div >
<Spin spinning={loading} /* style={{ height: "calc(100vh - 70px)" }} */> <Spin spinning={loading} /* style={{ height: "calc(100vh - 70px)" }} */>
<Row gutter={16} /* style={{ overflow: "scroll" }} */> <Row gutter={16} /* style={{ overflow: "scroll" }} */>
@ -155,7 +217,7 @@ const UserManage = (props) => {
type="primary" type="primary"
key="primary" key="primary"
style={{ marginLeft: 50 }} style={{ marginLeft: 50 }}
onClick={() => openModal('create')} onClick={() => openDepModal('create')}
>新建部门</Button> >新建部门</Button>
{ {
depMessage.length ? depMessage.length ?
@ -164,19 +226,33 @@ const UserManage = (props) => {
defaultExpandedKeys={[depMessage[0].id]} defaultExpandedKeys={[depMessage[0].id]}
selectedKeys={depSelectedKeys} selectedKeys={depSelectedKeys}
onSelect={(selectedKeys, e) => { onSelect={(selectedKeys, e) => {
if (e.selected) { if (e.selected) {
setDepSelectedKeys(selectedKeys) setDepSelectedKeys(selectedKeys)
dispatch(getDepUser(selectedKeys[0])) dispatch(getDepUser(selectedKeys[0]))
} }
}} }}
treeData={depMessage}
fieldNames={{
title: 'name',
key: 'id',
children: 'subordinate'
}}
style={{ paddingTop: 20 }} style={{ paddingTop: 20 }}
/> : '' >
{
depMessage?.map((s, index) => {
return <TreeNode title={renderTree(s, s.id)} key={s.id} >
{
s.subordinate.map(k => {
return <TreeNode title={renderTree(k, k.id)} key={k.id} onMouseOver={() => { setIShowIcon(k.id) }} onMouseOut={() => { setIShowIcon(null) }}>
{
k.subordinate.map(i => {
return <TreeNode title={renderTree(i, i.id)} key={i.id} onMouseOver={() => { setIShowIcon(i.id) }} onMouseOut={() => { setIShowIcon(null) }}>
</TreeNode>
})
}
</TreeNode>
})
}
</TreeNode>
})
}
</Tree> : ''
} }
</Card> </Card>
</Col> </Col>
@ -234,6 +310,14 @@ const UserManage = (props) => {
onVisibleChange={setPwdModalVisible} onVisibleChange={setPwdModalVisible}
onConfirm={onPwdConfirm} /> : ''} onConfirm={onPwdConfirm} /> : ''}
{depModalVisible ? <DepModal visible={depModalVisible}
onVisibleChange={setDepModalVisible}
depModalType={depModalType}
data={depModalRecord}
onConfirm={onDepConfirm} /> : ''}
</Col> </Col>
</Row> </Row>
</Spin> </Spin>
@ -254,4 +338,4 @@ function mapStateToProps(state) {
}; };
} }
export default connect(mapStateToProps)(UserManage); export default connect(mapStateToProps)(UserManage);

4
web/client/src/utils/webapi.js

@ -9,7 +9,7 @@ export const ApiTable = {
//组织管理-用户管理-部门 //组织管理-用户管理-部门
    getDepMessage: 'department',     getDepMessage: 'department',
    createMessage: 'department',     createDepMessage: 'department',
    updateDepMessage: 'department',     updateDepMessage: 'department',
    delDepMessage: 'department/{depId}',     delDepMessage: 'department/{depId}',
    //组织管理-用户管理-用户     //组织管理-用户管理-用户
@ -18,7 +18,7 @@ export const ApiTable = {
    updateUser: 'department/user/{userId}',     updateUser: 'department/user/{userId}',
    delUser: 'department/user/{userIds}',     delUser: 'department/user/{userIds}',
    resetPwd: '/organization/department/user/resetPwd/{id}',     resetPwd: 'department/user/{userId}/password',
//用户权限 //用户权限

Loading…
Cancel
Save