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

fix: value callback return values

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