Commit 6e9b4a0c authored by 张烨's avatar 张烨

fix: value callback return values

parent 97edfa8c
...@@ -7,16 +7,16 @@ import { orgTest } from '@/services/orgnazation/api'; ...@@ -7,16 +7,16 @@ import { orgTest } from '@/services/orgnazation/api';
const tip = 'loading...'; const tip = 'loading...';
const ListCard = props => { const ListCard = props => {
const { ouid, searchWord, valueCallback } = props; const { ouid, searchWord, valueCallback } = props;
const [valueList, setValueList] = useState([]); const [valueList, setValueList] = useState({});
const [dataList, setdataList] = useState([]); const [dataList, setdataList] = useState([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const callbackValue = useRef([]);
const getValueCallback = useCallback((value, index) => { const getValueCallback = useCallback((value, index) => {
console.log(value, index); valueList[index] = value;
setValueList((valueList[index] = value)); setValueList({ ...valueList });
callbackValue.current = valueList; valueCallback({ ...valueList });
console.log(valueList, 'valueList');
}, []); }, []);
useEffect(() => { useEffect(() => {
setLoading(true); setLoading(true);
const defaultConfig = { const defaultConfig = {
...@@ -34,8 +34,9 @@ const ListCard = props => { ...@@ -34,8 +34,9 @@ const ListCard = props => {
.then(res => { .then(res => {
setLoading(false); setLoading(false);
const list = []; const list = [];
// eslint-disable-next-line no-unused-expressions
res && res &&
res.map(item => { res.forEach(item => {
list.push({ ...defaultConfig, ...item }); list.push({ ...defaultConfig, ...item });
}); });
setdataList(list); setdataList(list);
...@@ -48,9 +49,6 @@ const ListCard = props => { ...@@ -48,9 +49,6 @@ const ListCard = props => {
// orgTest().then(res =>{ // orgTest().then(res =>{
// console.log(res,'res') // console.log(res,'res')
// }) // })
return () => {
callbackValue.current = [];
};
}, [ouid]); }, [ouid]);
return ( return (
<div> <div>
......
...@@ -41,8 +41,12 @@ const ListCardItem = props => { ...@@ -41,8 +41,12 @@ const ListCardItem = props => {
arr2.push(item.userID || item.roleID || item.stationID); arr2.push(item.userID || item.roleID || item.stationID);
} }
}); });
setIndeterminate(userList.some(u => u.isChecked)); // eslint-disable-next-line no-unused-expressions
setAllChecked(userList.every(u => u.isChecked)); getValueCallback && getValueCallback(arr2, itemid);
const all = userList.every(u => u.isChecked);
setIndeterminate(!all && userList.some(u => u.isChecked));
setAllChecked(all);
setCheckList(arr2); setCheckList(arr2);
}, [userList]); }, [userList]);
...@@ -55,7 +59,8 @@ const ListCardItem = props => { ...@@ -55,7 +59,8 @@ const ListCardItem = props => {
} }
setIndeterminate(false); setIndeterminate(false);
setCheckList(arr); setCheckList(arr);
getValueCallback(arr, itemid); // eslint-disable-next-line no-unused-expressions
getValueCallback && getValueCallback(arr, itemid);
}; };
const handleChecked = e => { const handleChecked = e => {
...@@ -64,7 +69,9 @@ const ListCardItem = props => { ...@@ -64,7 +69,9 @@ const ListCardItem = props => {
setIndeterminate(!!e.length && e.length < defaultList.length); setIndeterminate(!!e.length && e.length < defaultList.length);
getValueCallback(e, itemid); getValueCallback(e, itemid);
}; };
if (defaultList.length === 0) {
return null;
}
return ( return (
<> <>
<div className={`${styles.divBox}`}> <div className={`${styles.divBox}`}>
......
...@@ -46,10 +46,10 @@ import { ...@@ -46,10 +46,10 @@ import {
setUserState as postSetUserState, setUserState as postSetUserState,
editUser as postEditUser, editUser as postEditUser,
updateUserPassword, updateUserPassword,
setUserRelation,
} from '@/services/userCenter/userManage/api'; } from '@/services/userCenter/userManage/api';
const UserManage = () => { const UserManage = () => {
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 [loading, setLoading] = useState(true);
...@@ -79,10 +79,10 @@ const UserManage = () => { ...@@ -79,10 +79,10 @@ const UserManage = () => {
const [newOrgID, setNewOrgID] = useState(); const [newOrgID, setNewOrgID] = useState();
const [currentUser, setCurrentUser] = useState({}); const [currentUser, setCurrentUser] = useState({});
const [rolelist, setRolelist] = useState([]); const [rolelist, setRolelist] = useState([]);
const [stationlist, setStationlist] = useState([]); const [stationlist, setStationlist] = useState([]);
const [valueList, setRoleValueList] = useState([]);
const [stationValueList, setStationValueList] = useState([]); const [roleValueList, setRoleValueList] = useState({});
const [stationValueList, setStationValueList] = useState({});
const [searchUserForm] = Form.useForm(); const [searchUserForm] = Form.useForm();
const [addUserForm] = Form.useForm(); const [addUserForm] = Form.useForm();
...@@ -93,15 +93,13 @@ const UserManage = () => { ...@@ -93,15 +93,13 @@ const UserManage = () => {
const { TabPane } = Tabs; const { TabPane } = Tabs;
const getRoleValueCallback = useCallback((value, index) => { const getRoleValueCallback = useCallback((value, index) => {
const result = [...valueList]; roleValueList[index] = value;
result[index] = value; setRoleValueList({ ...roleValueList });
setRoleValueList(result);
}, []); }, []);
const getStationValueCallback = useCallback((value, index) => { const getStationValueCallback = useCallback((value, index) => {
const result = [...stationValueList]; stationValueList[index] = value;
result[index] = value; setStationValueList({ ...stationValueList });
setStationValueList(result);
}, []); }, []);
// 用户表列名 // 用户表列名
...@@ -533,7 +531,15 @@ const UserManage = () => { ...@@ -533,7 +531,15 @@ const UserManage = () => {
}); });
}; };
const submitRole = () => { const submitRole = () => {
addToOrg(currentUser.userID, orgID, newOrgID) setUserRelation(
currentUser.userID,
Object.keys(roleValueList)
.map(k => roleValueList[k])
.flat(),
Object.keys(stationValueList)
.map(k => stationValueList[k])
.flat(),
)
.then(res => { .then(res => {
if (res.success) { if (res.success) {
setChangeOrgVisible(false); setChangeOrgVisible(false);
...@@ -872,7 +878,7 @@ const UserManage = () => { ...@@ -872,7 +878,7 @@ const UserManage = () => {
<Modal <Modal
title="用户关联" title="用户关联"
visible={roleVisible} visible={roleVisible}
// onOk={submitRole} onOk={submitRole}
onCancel={() => setRoleVisible(false)} onCancel={() => setRoleVisible(false)}
okText="确认" okText="确认"
cancelText="取消" cancelText="取消"
......
...@@ -134,8 +134,8 @@ const SiteManage = () => { ...@@ -134,8 +134,8 @@ const SiteManage = () => {
setEditVisible(false); setEditVisible(false);
setFlag(flag + 1); setFlag(flag + 1);
}; };
const valueCallback = props => { const valueCallback = valueOBJ => {
console.log(props); console.log(valueOBJ);
}; };
return ( return (
<PageContainer> <PageContainer>
......
...@@ -132,3 +132,25 @@ export const deleteUser = userID => ...@@ -132,3 +132,25 @@ export const deleteUser = userID =>
_dc: Date.now(), _dc: Date.now(),
userID, userID,
}); });
export const setUserRelation = (userID, roleList = [], stationList) => {
const formData = new FormData();
formData.append('userID', userID);
formData.append('roleList', `${roleList.join(',')},`);
formData.append(
'stationList',
stationList.length ? `${stationList.join(',')},` : '',
);
formData.append('headList', '');
formData.append('mobileMapList', '');
formData.append('currentSolution', '熊猫智慧水务平台');
return post(
`/Cityinterface/rest/services/OMS.svc/U_SetUserRelationList?_version=9999`,
formData,
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
},
);
};
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