Skip to content

Commit

Permalink
feat: 新增显示群主和管理员的功能 (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kkuil authored Oct 22, 2023
1 parent 9831b25 commit 15e05a1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/enums/group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { RoleEnum } from '@/enums/index'

/**
* 群组角色映射
*/
export const GROUP_ROLE_MAP: Record<string, { text: string; class: string }> = {
[RoleEnum.LORD]: {
text: '群主',
class: 'lord',
},
[RoleEnum.ADMIN]: {
text: '管理员',
class: 'admin',
},
}
9 changes: 6 additions & 3 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* @see TSDoc规范https://tsdoc.org/
**/
import type {
OnlineEnum,
MsgEnum,
ActEnum,
SexEnum,
IsYetEnum,
MarkEnum,
MsgEnum,
OnlineEnum,
RoomTypeEnum,
SexEnum,
} from '@/enums'

/***/
Expand Down Expand Up @@ -92,6 +92,8 @@ export type UserItem = {
lastOptTime: number
/** 用户名称 */
name: string
/** 角色ID */
roleId?: number
/** uid */
uid: number
}
Expand Down Expand Up @@ -345,6 +347,7 @@ export enum RequestFriendAgreeStatus {
/** 2同意 */
Agree,
}

/** 请求添加好友的列表项 */
export type RequestFriendItem = {
/** 申请id */
Expand Down
6 changes: 6 additions & 0 deletions src/styles/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ a:active {
animation: icon-loading 1s infinite cubic-bezier(0, 0, 1, 1);
}

.flex-center {
display: flex;
align-items: center;
justify-content: center;
}

@keyframes icon-loading {
0% {
transform: rotate(0);
Expand Down
11 changes: 10 additions & 1 deletion src/views/Home/Chat/components/UserList/UserItem/index.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<script setup lang="ts">
import { toRef, ref } from 'vue'
import { ref, toRef } from 'vue'
import { OnlineEnum } from '@/enums'
import type { UserItem } from '@/services/types'
import { useUserInfo } from '@/hooks/useCached'
import { useUserStore } from '@/stores/user'
import ContextMenu from '../ContextMenu/index.vue'
import { GROUP_ROLE_MAP } from '@/enums/group'
const props = defineProps<{ user: UserItem }>()
const user = toRef(props.user)
const userInfo = useUserInfo(user.value?.uid)
Expand Down Expand Up @@ -42,6 +44,13 @@ const handleRightClick = (e: MouseEvent) => {
:online="user.activeStatus === OnlineEnum.ONLINE"
/>
{{ userInfo.name }}
<div
v-if="GROUP_ROLE_MAP[user.roleId as number]"
class="badge flex-center"
:class="GROUP_ROLE_MAP[user.roleId as number].class"
>
{{ GROUP_ROLE_MAP[user?.roleId as number].text }}
</div>
<ContextMenu v-model:show="isShowMenu" :options="menuOptions" :uid="(user?.uid as number)" />
</li>
</template>
Expand Down
16 changes: 16 additions & 0 deletions src/views/Home/Chat/components/UserList/UserItem/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,20 @@
margin-right: 8px;
}
}

.badge {
padding: 2px 4px;
border: 1px solid #fff;
border-radius: 3px;
}

.lord {
color: #777;
background-color: #f2c55c;
}

.admin {
color: #fff;
background-color: #aa6d4b;
}
}

0 comments on commit 15e05a1

Please sign in to comment.