From 69abfc81c13ae09bfdf3474f2ec1ef4ffc84b52f Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Mon, 19 Aug 2024 09:34:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/page/Meeting/index.tsx | 42 ++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/page/Meeting/index.tsx b/src/page/Meeting/index.tsx index 7a24305..299a1f9 100644 --- a/src/page/Meeting/index.tsx +++ b/src/page/Meeting/index.tsx @@ -347,26 +347,38 @@ const Meeting: React.FC = () => { }, [recorder]) const changeAgoraDevice = () => { - function moveAdminsAndSpeakersToFront(arr: any[]): any[] { - // 创建一个新的数组来存放管理员和发言人 - const adminsAndSpeakers = [] as any; - // 创建一个新的数组来存放其他用户 - const otherUsers = [] as any; - // 遍历原始数组 - arr.forEach((item: any) => { - if (item.roleId === '1' || item.isRoomManager) { - // 如果是管理员或发言人,添加到 adminsAndSpeakers 数组 - adminsAndSpeakers.push(item); + function sortUsersByRole(arr: any[]): any[] { + // 使用 sort 方法对数组进行排序 + return arr.sort((a: any, b: any) => { + // 定义角色优先级 + const rolePriority: any = { + admin: 1, + speaker: 2, + user: 3, + }; + // 获取角色优先级 + const aPriority = rolePriority[a.role] || 3; // 默认为普通用户 + const bPriority = rolePriority[b.role] || 3; // 默认为普通用户 + // 比较角色优先级 + if (aPriority < bPriority) { + return -1; // a 的优先级更高 + } else if (aPriority > bPriority) { + return 1; // b 的优先级更高 } else { - // 否则,添加到 otherUsers 数组 - otherUsers.push(item); + // 如果角色相同,则可以按其他标准排序,例如按姓名字母顺序 + return a.name.localeCompare(b.name); } }); - // 将管理员和发言人放在数组的最前面 - return [...adminsAndSpeakers, ...otherUsers]; } setRoomUserList((res: any) => { res.forEach((item: any) => { + if (item.roleId === '1') { + item.role = 'admin' + } else if (item.isRoomManager) { + item.role = 'speaker' + } else { + item.role = 'user' + } if (item.uid === userInfo.uid) { const footerListTemplate = [...footerList] footerListTemplate[0][0].title = item.enableMicr ? '静音' : '解除静音' @@ -387,7 +399,7 @@ const Meeting: React.FC = () => { item.isShow = true; } }); - return moveAdminsAndSpeakersToFront(res) + return sortUsersByRole(res) }) } // 替换数据