From e45624213c2550924e247c7d742eec4bd4cdb8fd Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Wed, 21 Aug 2024 11:16:08 +0800 Subject: [PATCH] =?UTF-8?q?=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 | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/page/Meeting/index.tsx b/src/page/Meeting/index.tsx index e83a858..4845dc3 100644 --- a/src/page/Meeting/index.tsx +++ b/src/page/Meeting/index.tsx @@ -396,6 +396,29 @@ const Meeting: React.FC = () => { }, [recorder]) const changeAgoraDevice = () => { + 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 { + // 如果角色相同,则可以按其他标准排序,例如按姓名字母顺序 + return a.userName.localeCompare(b.userName); + } + }); + } setRoomUserList((res: any) => { res.forEach(async (item: any) => { if (item.roleId === '1') { @@ -441,7 +464,7 @@ const Meeting: React.FC = () => { item.isShow = true; } }); - return res + return sortUsersByRole(res) }) } // 刷新视图