// 分组函数
const groupByAge = (docs: TOSDepositoryDTO[]): Record<number, TOSDepositoryDTO[]> => {
return docs.reduce((acc, d) => {
if (!acc[d.approvalId]) acc[d.approvalId] = [];
acc[d.approvalId].push(d);
return acc;
}, {} as Record<number, TOSDepositoryDTO[]>);
};
// 获取每组最大用户和其他用户的函数
const getMaxUserWithOthersByAge = (docs: TOSDepositoryDTO[]) => {
const groupedUsers = groupByAge(docs);
return Object.entries(groupedUsers).map(([approvalId, usersGroup]) => {
// 根据 id 获取最大用户
const maxUser = usersGroup.reduce((max, current) => (current.revisionNumber > max.revisionNumber ? current : max));
maxUser.items = usersGroup.filter(user => user.id !== maxUser.id); // 过滤掉最大用户,生成其他用户的子数组
return maxUser;
});
};
const getTOSDepository = async () => {
var resDoc = await ClientService.getTOSDepository(model.value.id);
documents.value = getMaxUserWithOthersByAge(resDoc);
console.log(documents.value);
}