From 1493695817b391d6d062865df133b12ce794b528 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 15 Oct 2022 00:38:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=BF=BB=E8=AF=91=E7=BC=BA=E5=A4=B1=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 加载时机问题 --- client/shared/index.tsx | 2 +- client/shared/redux/hooks/useGroupPermission.ts | 4 ++-- client/shared/utils/role-helper.ts | 6 ++++-- .../modals/GroupDetail/Role/tabs/permission.tsx | 8 +++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/client/shared/index.tsx b/client/shared/index.tsx index 7ceb6aa8..d31e8636 100644 --- a/client/shared/index.tsx +++ b/client/shared/index.tsx @@ -227,7 +227,7 @@ export { MessageHelper } from './utils/message-helper'; export { PERMISSION, AllPermission, - permissionList, + getPermissionList, getDefaultPermissionList, applyDefaultFallbackGroupPermission, } from './utils/role-helper'; diff --git a/client/shared/redux/hooks/useGroupPermission.ts b/client/shared/redux/hooks/useGroupPermission.ts index a050e2fa..b7b69a97 100644 --- a/client/shared/redux/hooks/useGroupPermission.ts +++ b/client/shared/redux/hooks/useGroupPermission.ts @@ -3,7 +3,7 @@ import { useUserId } from './useUserInfo'; import _uniq from 'lodash/uniq'; import _flatten from 'lodash/flatten'; import { useDebugValue, useMemo } from 'react'; -import { permissionList } from '../..'; +import { getPermissionList } from '../..'; /** * 获取群组用户的所有权限 @@ -19,7 +19,7 @@ export function useGroupMemberAllPermissions(groupId: string): string[] { if (groupInfo.owner === userId) { // 群组管理员拥有一切权限 // 返回所有权限 - return permissionList.map((p) => p.key); + return getPermissionList().map((p) => p.key); } const members = groupInfo.members; diff --git a/client/shared/utils/role-helper.ts b/client/shared/utils/role-helper.ts index 47a2e496..faa0a134 100644 --- a/client/shared/utils/role-helper.ts +++ b/client/shared/utils/role-helper.ts @@ -45,7 +45,7 @@ export const PERMISSION = { }, }; -export const permissionList: PermissionItemType[] = [ +export const getPermissionList = (): PermissionItemType[] => [ { key: PERMISSION.core.message, title: t('发送消息'), @@ -98,7 +98,9 @@ export const permissionList: PermissionItemType[] = [ * 获取默认权限列表 */ export function getDefaultPermissionList(): string[] { - return permissionList.filter((p) => p.default).map((p) => p.key); + return getPermissionList() + .filter((p) => p.default) + .map((p) => p.key); } /** diff --git a/client/web/src/components/modals/GroupDetail/Role/tabs/permission.tsx b/client/web/src/components/modals/GroupDetail/Role/tabs/permission.tsx index ea71396b..36a28e68 100644 --- a/client/web/src/components/modals/GroupDetail/Role/tabs/permission.tsx +++ b/client/web/src/components/modals/GroupDetail/Role/tabs/permission.tsx @@ -1,4 +1,4 @@ -import { AllPermission, permissionList } from 'tailchat-shared'; +import { AllPermission, getPermissionList } from 'tailchat-shared'; import { Button, Divider } from 'antd'; import React, { useCallback, useMemo } from 'react'; import { model, t } from 'tailchat-shared'; @@ -31,7 +31,9 @@ export const RolePermission: React.FC = React.memo( const handleResetPermission = useCallback(() => { setEditingPermission( - permissionList.filter((p) => p.default === true).map((p) => p.key) + getPermissionList() + .filter((p) => p.default === true) + .map((p) => p.key) ); }, []); @@ -50,7 +52,7 @@ export const RolePermission: React.FC = React.memo( {/* 权限详情 */} - {permissionList.map((p) => ( + {getPermissionList().map((p) => (