Commit 8e393159 authored by 陈前坚's avatar 陈前坚

perf: listCardItem

parent 8ae4fd46
...@@ -10,6 +10,8 @@ const ListCardItem = props => { ...@@ -10,6 +10,8 @@ const ListCardItem = props => {
const [allChecked, setAllChecked] = useState(false); // 全选状态 const [allChecked, setAllChecked] = useState(false); // 全选状态
const [checkList, setCheckList] = useState([]); // 复选框列表选中的值 const [checkList, setCheckList] = useState([]); // 复选框列表选中的值
const [defaultList, setDefaultList] = useState([]); // 默认的选项 const [defaultList, setDefaultList] = useState([]); // 默认的选项
const [submitArr, setSubmitArr] = useState([]); // 提交的数组
// const submitArr = [];
useEffect(() => { useEffect(() => {
console.log(userList, '执行了`````'); console.log(userList, '执行了`````');
let arr = []; let arr = [];
...@@ -23,10 +25,10 @@ const ListCardItem = props => { ...@@ -23,10 +25,10 @@ const ListCardItem = props => {
: '' : ''
} }
> >
{obj.userName} {obj.userName || obj.roleName || obj.stationName}
</span> </span>
); );
obj.value = obj.userID; obj.value = obj.userID || obj.roleID || obj.stationName;
arr.push(obj); arr.push(obj);
}); });
setDefaultList(arr); setDefaultList(arr);
...@@ -36,7 +38,7 @@ const ListCardItem = props => { ...@@ -36,7 +38,7 @@ const ListCardItem = props => {
let arr2 = []; let arr2 = [];
userList.map((item, index) => { userList.map((item, index) => {
if (item.isChecked) { if (item.isChecked) {
arr2.push(item.userID); arr2.push(item.userID || item.roleID || item.stationID);
} }
}); });
setCheckList(arr2); setCheckList(arr2);
......
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useCallback } from 'react';
import { import {
Tree, Tree,
Table, Table,
...@@ -38,6 +38,7 @@ const UserManage = () => { ...@@ -38,6 +38,7 @@ const UserManage = () => {
const time = new Date(); const time = new Date();
const [treeLoading, setTreeLoading] = useState(false); const [treeLoading, setTreeLoading] = useState(false);
const [tableLoading, setTableLoading] = useState(false); const [tableLoading, setTableLoading] = useState(false);
const [loading, setLoading] = useState(true);
const [treeData, setTreeData] = useState([]); // 用户机构树 const [treeData, setTreeData] = useState([]); // 用户机构树
const [treeData1, setTreeData1] = useState([]); const [treeData1, setTreeData1] = useState([]);
...@@ -65,7 +66,11 @@ const UserManage = () => { ...@@ -65,7 +66,11 @@ const UserManage = () => {
const [newOrgID, setNewOrgID] = useState(); const [newOrgID, setNewOrgID] = useState();
const [userID, setUserID] = useState(); const [userID, setUserID] = useState();
const [rolelist, setRolelist] = useState([]); const [rolelist, setRolelist] = useState([]);
const [stationlist, setStationlist] = useState([]); const [stationlist, setStationlist] = useState([]);
const [valueList, setValueList] = useState([]);
const [sumList, setSumList] = useState([]);
const submitArr = [];
const [searchUserForm] = Form.useForm(); const [searchUserForm] = Form.useForm();
const [addUserForm] = Form.useForm(); const [addUserForm] = Form.useForm();
...@@ -75,6 +80,13 @@ const UserManage = () => { ...@@ -75,6 +80,13 @@ const UserManage = () => {
const [passwordForm] = Form.useForm(); const [passwordForm] = Form.useForm();
const { TabPane } = Tabs; const { TabPane } = Tabs;
const getValueCallback = useCallback((value, index) => {
setValueList((valueList[index] = value));
submitArr.push(...value);
// console.log(sumList, 'sumList');
console.log(valueList, 'valueList');
}, []);
let freezeText = '即将冻结该用户,是否确认冻结?'; let freezeText = '即将冻结该用户,是否确认冻结?';
if (userState) { if (userState) {
freezeText = '即将激活该用户,是否确认激活?'; freezeText = '即将激活该用户,是否确认激活?';
...@@ -345,14 +357,33 @@ const UserManage = () => { ...@@ -345,14 +357,33 @@ const UserManage = () => {
setTreeState(true); setTreeState(true);
}; };
// 在userID变化后获取
useEffect(() => {
if (userID) {
console.log(userID);
getRoleList();
}
}, [userID]);
useEffect(() => {
if (sumList) {
console.log(sumList);
}
}, [sumList]);
// 右侧表格相关操作 // 右侧表格相关操作
const relateRole = record => { const relateRole = record => {
setRoleVisible(true); setRoleVisible(true);
setUserID(record.userID); setUserID(record.userID);
getRoleList();
// setTimeout(() => { // setTimeout(() => {
// setUserID(record.userID);
// console.log(userID);
// });
// setTimeout(() => {
// console.log(userID);
// getRoleList(); // getRoleList();
// }, 1000); // }, 500);
}; };
const changeOrg = record => { const changeOrg = record => {
setChangeOrgVisible(true); setChangeOrgVisible(true);
...@@ -532,17 +563,7 @@ const UserManage = () => { ...@@ -532,17 +563,7 @@ const UserManage = () => {
message.error(err); message.error(err);
}); });
}; };
const listitem = list =>
list.map(item1 => (
<Col className="gutter-row" span={6} key={item1.roleID}>
<Checkbox defaultChecked={item1.isChecked} />
<span>{item1.roleName}</span>
</Col>
));
const checkBox = () => {
console.log('123');
};
// const style = { padding: '8px 0', fontSize: '14px' };
const getRoleList = () => { const getRoleList = () => {
get(`/Cityinterface/rest/services/OMS.svc/W4_GetUserRelationList`, { get(`/Cityinterface/rest/services/OMS.svc/W4_GetUserRelationList`, {
_version: 9999, _version: 9999,
...@@ -554,18 +575,42 @@ const UserManage = () => { ...@@ -554,18 +575,42 @@ const UserManage = () => {
// const { roleList, stationList } = res; // const { roleList, stationList } = res;
setRolelist( setRolelist(
res.roleList.map((item, index) => { res.roleList.map((item, index) => {
item.key = index; const arr = [];
item.roleList.map(item1 => {
if (item1.isChecked) {
arr.push(item1.roleID);
}
return item1;
});
setSumList(...arr);
return ( return (
<> <ListCardItem
<Divider style={{ fontSize: '14px', color: '#1890FF' }}> // {...item}
<Checkbox onClick={checkBox} /> itemid={index}
{item.visibleTitle} key={`item${index}key`}
</Divider> userList={item.roleList}
<Row gutter={16}>{listitem(item.roleList)}</Row> OUName={item.visibleTitle}
</> getValueCallback={getValueCallback}
// searchWord={searchWord}
// {...props}
/>
); );
}), }),
); );
setStationlist(
res.stationList.map((item, index) => (
<ListCardItem
// {...item}
itemid={index}
key={`item${index}key`}
userList={item.stationList}
OUName={item.visibleTitle}
getValueCallback={getValueCallback}
// searchWord={searchWord}
// {...props}
/>
)),
);
} else { } else {
notification.error({ notification.error({
message: '提交失败', message: '提交失败',
...@@ -769,21 +814,24 @@ const UserManage = () => { ...@@ -769,21 +814,24 @@ const UserManage = () => {
/> />
</Tooltip> </Tooltip>
</span> </span>
<Tree {treeData.length > 0 && (
showLine="true" <Tree
showIcon="true" showLine="true"
defaultExpandAll="true" showIcon="true"
selectedKeys={[currentSelect]} defaultExpandAll="true"
loading={treeLoading} selectedKeys={[currentSelect]}
onSelect={onSelect} loading={treeLoading}
treeData={treeData} onSelect={onSelect}
/> treeData={treeData}
/>
)}
</div> </div>
<div className={styles.userContainer}> <div className={styles.userContainer}>
<Table <Table
columns={columns} columns={columns}
dataSource={tableData} dataSource={tableData}
loading={tableLoading} loading={tableLoading}
scroll={{ scrollToFirstRowOnChange: 'true', x: true }}
/> />
</div> </div>
{/* 查找用户 */} {/* 查找用户 */}
...@@ -965,7 +1013,7 @@ const UserManage = () => { ...@@ -965,7 +1013,7 @@ const UserManage = () => {
{rolelist} {rolelist}
</TabPane> </TabPane>
<TabPane tab="站点" key="2"> <TabPane tab="站点" key="2">
Content of Tab Pane 2 {stationlist}
</TabPane> </TabPane>
</Tabs> </Tabs>
</Modal> </Modal>
...@@ -978,16 +1026,18 @@ const UserManage = () => { ...@@ -978,16 +1026,18 @@ const UserManage = () => {
cancelText="取消" cancelText="取消"
width="330px" width="330px"
> >
<Tree {treeData2.length > 0 && (
showLine="true" <Tree
showIcon="true" showLine="true"
defaultExpandAll="true" showIcon="true"
// selectedKeys={[currentSelect]} defaultExpandAll="true"
onSelect={props => { // selectedKeys={[currentSelect]}
setNewOrgID(props[0]); onSelect={props => {
}} setNewOrgID(props[0]);
treeData={treeData2} }}
/> treeData={treeData2}
/>
)}
</Modal> </Modal>
{/* 修改密码 */} {/* 修改密码 */}
<Modal <Modal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment