-
Notifications
You must be signed in to change notification settings - Fork 68
/
index.vue
450 lines (442 loc) · 14.3 KB
/
index.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<script setup>
import { ref, toRaw, toRefs, computed, nextTick, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
/* IMSDK */
import { EMClient } from '@/IM'
import { GROUP_ROLE_TYPE } from '@/IM/constant'
/* components */
import GroupsManagement from '../GroupsManagement'
/* icons */
import { ArrowRight, Edit, View } from '@element-plus/icons-vue'
import store from '@/store'
/* porps */
const props = defineProps({
groupId: {
type: String,
required: true,
default: ''
}
})
/* emits */
const emits = defineEmits(['handleDrawer'])
/*
* groupDetail(群详情接口返回的数据)
* 主要包含群名称,群主id,群组desc,群组人数,群组禁言状态是否容许邀请...。
**/
const { groupId } = toRefs(props)
//获取加入的群组列表
const getJoinedGroupList = computed(() => store.getters.getJoinedGroupList)
//获取群组详情(展示群组名称等信息)
const getGroupDetailFromGroupList = computed(() => {
const group = getJoinedGroupList.value.filter((groupItem) => {
if (groupItem.groupId === groupId.value) {
return groupItem
}
})
return group[0]
})
/* 群组展示相关核心数据获取 */
//权限判断(黑名单以及禁言列表的获取,只有群主管理员)
const memberRole = computed(() => {
//判断是否在权限名单内
if (
getGroupDetailFromGroupList.value.role === GROUP_ROLE_TYPE.ADMIN ||
getGroupDetailFromGroupList.value.role === GROUP_ROLE_TYPE.OWNER
) {
return true
} else {
return false
}
})
/* 群组管理 */
const groupmanagement = ref(null)
const modalType = ref('')
const groupModalTitle = ref({ title: '', type: 0 })
//群公告
const getGroupAnnouncement = computed(() => {
return store.getters.getGroupDetailMap.get(groupId.value)?.announcement
})
//弹出群管理相关modal框
const alertManagementModal = (type, groupType) => {
const titleType = {
1: '黑名单',
2: '禁言'
}
modalType.value = type
groupmanagement.value.dialogVisible = true
if (groupType > -1) {
groupModalTitle.value.title = titleType[groupType]
groupModalTitle.value.type = groupType
}
}
//修改群组名称
const editGroupNameInput = ref(null)
const isEdit = ref(false)
const groupName = ref('')
const editGroupName = async (type, oldGroupName) => {
if (type === 'save') {
if (groupName.value === oldGroupName) return (isEdit.value = false)
const params = {
groupId: groupId.value,
modifyType: 0,
content: groupName.value
}
try {
await store.dispatch('modifyGroupInfo', params)
ElMessage({
message: '群组名称修改成功~',
type: 'success',
center: true
})
isEdit.value = false
} catch (error) {
console.error(error)
ElMessage({
message: '群组名称修改失败~',
type: 'error',
center: true
})
isEdit.value = false
}
}
if (type === 'edit') {
isEdit.value = true
nextTick(() => {
editGroupNameInput.value.focus()
groupName.value = oldGroupName
})
}
}
//修改我的群组昵称
const editMyGroupNickNameInput = ref(null)
const isEditMyGroupNickname = ref(false)
const myGroupNickname = ref('')
const editMyGroupNickName = async (type, oldMyGroupNickname) => {
if (type === 'save') {
if (myGroupNickname.value === oldMyGroupNickname)
return (isEditMyGroupNickname.value = false)
const params = {
groupId: groupId.value,
nickName: myGroupNickname.value
}
try {
await store.dispatch('setInTheGroupInfo', params)
ElMessage({
message: '本群昵称修改成功~',
type: 'success',
center: true
})
} catch (error) {
ElMessage({
message: '本群昵称修改失败~',
type: 'error',
center: true
})
} finally {
isEditMyGroupNickname.value = false
}
}
if (type === 'edit') {
isEditMyGroupNickname.value = true
nextTick(() => {
editMyGroupNickNameInput.value.focus()
myGroupNickname.value = oldMyGroupNickname
})
}
}
// const inTheGroupNickname = computed(() => {
// const loginUser = EMClient.user
// const myNickname = store.getters.getGroupDetailMap.get(groupId.value)
// ?.groupMemberInfo[loginUser]?.nickName
// return myNickname
// })
const inTheGroupNickname = computed(() => {
const groupIdValue = groupId.value
const loginUserValue = EMClient.user
const groupDetail = store.getters.getGroupDetailMap.get(groupIdValue)
if (!groupDetail) {
console.warn(`Group detail for group ID ${groupIdValue} not found.`)
return '' // 或者返回 null 或 undefined
}
const myNickname = groupDetail.groupMemberInfo?.[loginUserValue]?.nickName
return myNickname || ''
})
//退出、解散群组
const quitThisGroup = async () => {
try {
await ElMessageBox.confirm(
'将要从本群退出,确认要退出此群吗?',
'群组提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning'
}
)
await store.dispatch('leaveIntheGroup', { groupId: groupId.value })
emits('handleDrawer')
} catch (error) {
if (error !== 'cancel') {
ElMessage({
message: '退出群组失败~',
type: 'error',
center: true
})
}
}
}
const dissolveThisGroup = async () => {
try {
await ElMessageBox.confirm(
'将要将本群解散,确认要解散此群吗?',
'群组提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'error'
}
)
await store.dispatch('destroyInTheGroup', { groupId: groupId.value })
emits('handleDrawer')
} catch (error) {
if (error !== 'cancel') {
ElMessage({
message: '解散群组失败~',
type: 'error',
center: true
})
}
}
}
//群组黑名单人数
const groupBlacklist = computed(() => {
return store.getters.getGroupDetailMap.get(groupId.value)?.blacklist
})
//群组禁言人数
const groupMutelist = computed(() => {
return store.getters.getGroupDetailMap.get(groupId.value)?.mutelist
})
const handleUpdateGroupData = async () => {
//更新群组公告
if (!getGroupAnnouncement.value && getGroupAnnouncement.value !== '') {
try {
await store.dispatch('fetchAnnounmentFromServer', groupId.value)
} catch (error) {
console.error(error)
}
}
//获取当前群组内禁言名单或管理员名单(仅群主或管理员有权限调用)
if (memberRole.value) {
try {
!groupBlacklist.value &&
(await store.dispatch(
'fetchGroupsBlackListFromServer',
groupId.value
))
!groupMutelist.value &&
(await store.dispatch(
'fetchGroupsMuteListFromServer',
groupId.value
))
} catch (error) {
console.error(error)
}
}
store.dispatch('fetchInTheGroupInfoFromServer', groupId.value)
}
onMounted(() => {
handleUpdateGroupData()
})
</script>
<template>
<div class="app_container" v-if="getGroupDetailFromGroupList">
<!-- 群名称 -->
<div class="group_func_card group_name">
<div class="title">
群名称
<el-icon
class="icon"
v-if="memberRole"
@click="
editGroupName(
'edit',
getGroupDetailFromGroupList.groupName
)
"
>
<Edit />
</el-icon>
</div>
<div class="content">
<div v-if="!isEdit">
{{ getGroupDetailFromGroupList.groupName || '' }}
</div>
<el-input
v-else
class="group_name_input"
ref="editGroupNameInput"
v-model="groupName"
size="small"
maxlength="15"
show-word-limit
@blur="
editGroupName(
'save',
getGroupDetailFromGroupList.groupName
)
"
>
</el-input>
</div>
</div>
<el-divider style="margin: 0" />
<!-- 群描述 -->
<div class="group_func_card group_description">
<div class="title">
群描述
<el-icon
class="icon"
@click="alertManagementModal('groupDesc')"
>
<Edit v-if="memberRole" />
</el-icon>
</div>
<div class="content">
{{ getGroupDetailFromGroupList.description || '暂无群描述~' }}
</div>
</div>
<el-divider style="margin: 0" />
<!-- 本地群组昵称 -->
<div class="group_func_card group_name">
<div class="title">
我在本群的昵称
<el-icon
class="icon"
@click="editMyGroupNickName('edit', inTheGroupNickname)"
>
<Edit />
</el-icon>
</div>
<div class="content">
<div v-if="!isEditMyGroupNickname">
{{ inTheGroupNickname || '暂未设置该群昵称' }}
</div>
<el-input
v-else
class="group_name_input"
ref="editMyGroupNickNameInput"
v-model="myGroupNickname"
size="small"
maxlength="15"
show-word-limit
@blur="editMyGroupNickName('save', inTheGroupNickname)"
/>
</div>
</div>
<el-divider style="margin: 0" />
<!-- 群公告 -->
<div class="group_func_card group_announcements">
<div class="title">
群公告
<el-icon
class="icon"
@click="alertManagementModal('announcements')"
>
<Edit v-if="memberRole" />
<View v-else />
</el-icon>
</div>
<div class="content" title="查看更多">
{{ getGroupAnnouncement || '暂无群公告~' }}
</div>
</div>
<el-divider style="margin: 0" />
<!-- 群成员 -->
<div class="group_list_card group_member">
<div class="label">群成员</div>
<div class="main">
<div class="member_count">
{{
`${
getGroupDetailFromGroupList.affiliationsCount || '0'
}/${getGroupDetailFromGroupList.maxUsers || '500'}`
}}
</div>
<div
class="more_list"
@click="alertManagementModal('groupmembers')"
>
<ArrowRight />
</div>
</div>
</div>
<el-divider style="margin: 0" />
<template v-if="memberRole">
<!-- 黑名单 -->
<div class="group_list_card group_blacklist">
<div class="label">黑名单</div>
<div class="main">
<div class="member_count">
{{ groupBlacklist?.length || '暂无' }}
</div>
<div
class="more_list"
@click="alertManagementModal('groupBlacklist')"
>
<ArrowRight />
</div>
</div>
</div>
<el-divider style="margin: 0" />
<!-- 禁言名单 -->
<div class="group_list_card group_mutelist">
<div class="label">禁言名单</div>
<div class="main">
<div class="member_count">
{{ groupMutelist?.length || '暂无' }}
</div>
<div
class="more_list"
@click="alertManagementModal('groupMutelist')"
>
<ArrowRight />
</div>
</div>
</div>
<el-divider style="margin: 0" />
</template>
<!-- 群组操作按钮 -->
<div class="group_list_handle_box">
<template
v-if="getGroupDetailFromGroupList.owner === EMClient.user"
>
<el-button
type="danger"
class="group_list_card_btn"
plain
@click="dissolveThisGroup"
>解散群组</el-button
>
</template>
<template v-else>
<el-button
type="danger"
class="group_list_card_btn"
plain
@click="quitThisGroup"
>退出群组</el-button
>
</template>
</div>
<GroupsManagement
ref="groupmanagement"
:modalType="modalType"
:groupModalTitle="groupModalTitle"
:memberRole="memberRole"
:groupId="groupId"
/>
</div>
</template>
<style lang="scss" scoped>
@import './index.scss';
</style>