group-member-info.vue
8.65 KB
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
<template>
<div>
<div>
<span class="label">ID:</span>
{{ member.userID }}
<el-button v-if="showCancelBan" type="text" @click="cancelMute"
>取消禁言</el-button
>
<el-popover title="禁言" v-model="popoverVisible" v-show="showBan">
<el-input
v-model="muteTime"
placeholder="请输入禁言时间"
@keydown.enter.native="setGroupMemberMuteTime"
/>
<el-button slot="reference" type="text" style="color: red"
>禁言</el-button
>
</el-popover>
</div>
<div>
<span class="label">昵称:</span>
{{ member.nick || "暂无" }}
</div>
<div>
<span class="label">名片:</span>
{{ member.nameCard || "暂无" }}
<el-popover
title="修改群名片"
v-model="nameCardPopoverVisible"
v-show="showEditNameCard"
>
<el-input
v-model="nameCard"
placeholder="请输入群名片"
@keydown.enter.native="setGroupMemberNameCard"
/>
<i
class="el-icon-edit"
title="修改群名片"
slot="reference"
style="cursor: pointer; font-size: 1.6rem"
></i>
</el-popover>
</div>
<!-- <div>-->
<!-- <span class="label">身份:</span>-->
<!-- <span class="content role" :title="changeRoleTitle">{{ member.role | role }}</span>-->
<!-- </div>-->
<div v-if="showMuteUntil">
<span class="label">禁言至:</span>
<span class="content">{{ muteUntil }}</span>
</div>
<!-- <el-button type="text" v-if="canChangeRole" @click="changeMemberRole">-->
<!-- {{-->
<!-- member.role === 'Admin' ? '取消管理员' : '设为管理员'-->
<!-- }}-->
<!-- </el-button>-->
<!-- <el-button type="text" v-if="showKickout" style="color:red;" @click="kickoutGroupMember">踢出群组</el-button>-->
<!-- <el-button type="text" style="color:red;" @click="kickoutGroupMember">踢出群组</el-button>-->
</div>
</template>
<script>
import { mapState } from "vuex";
import { Popover } from "element-ui";
import { getFullDate } from "../../../utils/date";
import Helper from "../../../utils/helper";
export default {
components: {
ElPopover: Popover,
},
props: ["member"],
filters: {
role: (val) =>
val === "Member" ? "成员" : val === "Admin" ? "管理员" : "群主",
},
data() {
return {
muteTime: "",
popoverVisible: false,
nameCardPopoverVisible: false,
nameCard: this.member.nameCard,
};
},
mounted() {
// 初始化监听器
console.log("this.currentUserProfile is ", this.currentUserProfile);
console.log(
"this.currentConversation.groupProfile.selfInfo is ",
this.currentConversation.groupProfile.selfInfo
);
},
computed: {
...mapState({
currentConversation: (state) => state.conversation.currentConversation,
currentUserProfile: (state) => state.user.currentUserProfile,
current: (state) => state.current,
}),
// 是否显示踢出群成员按钮
showKickout() {
return (this.isOwner || this.isAdmin) && !this.isMine;
},
isOwner() {
return this.currentConversation.groupProfile.selfInfo.role === "Owner";
},
isAdmin() {
let isA = false;
if (this.currentConversation.groupProfile.selfInfo.role === "Admin") {
isA = true;
} else if (
this.currentUserProfile.userID.substr(0, 13) == "Administrator" &&
this.currentUserProfile.nick == "超级管理员"
) {
isA = true;
}
return isA;
},
isMine() {
console.log("in isMine ", this.member.userID);
return this.currentUserProfile.userID === this.member.userID;
},
canChangeRole() {
return (
this.isOwner &&
["ChatRoom", "Public"].includes(this.currentConversation.subType)
);
},
changeRoleTitle() {
if (!this.canChangeRole) {
return "";
}
return this.isOwner && this.member.role === "Admin"
? "设为:Member"
: "设为:Admin";
},
// 是否显示禁言时间
showMuteUntil() {
// 禁言时间小于当前时间
return this.member.muteUntil * 1000 > this.current;
},
// 是否显示取消禁言按钮
showCancelBan() {
if (
this.showMuteUntil &&
this.currentConversation.type === this.TIM.TYPES.CONV_GROUP &&
!this.isMine
) {
return this.isOwner || this.isAdmin;
}
return false;
},
// 是否显示禁言按钮
showBan() {
if (this.currentConversation.type === this.TIM.TYPES.CONV_GROUP) {
return this.isOwner || this.isAdmin;
}
return false;
},
// 是否显示编辑群名片按钮
showEditNameCard() {
return this.isOwner || this.isAdmin;
},
// 日期格式化后的禁言时间
muteUntil() {
return getFullDate(new Date(this.member.muteUntil * 1000));
},
},
methods: {
kickoutGroupMember() {
Helper.groupMemberDelete(
this.currentConversation.groupProfile.groupID,
this.member.userID
)
.then(() => {
this.$store.commit("deleteGroupMember", this.member.userID);
this.$store.commit("updateCurrentUnMemberList", [
{
esm_id: this.member.userID,
name: this.member.nick,
avatar: this.member.avatar,
},
]);
})
.catch((error) => {
this.$store.commit("showMessage", {
type: "error",
message: error.message,
});
});
// this.tim
// .deleteGroupMember({
// groupID: this.currentConversation.groupProfile.groupID,
// reason: '我要踢你出群',
// userIDList: [this.member.userID]
// })
// .then(() => {
// this.$store.commit('deleteGroupMember', this.member.userID)
// })
// .catch(error => {
// this.$store.commit('showMessage', {
// type: 'error',
// message: error.message
// })
// })
},
changeMemberRole() {
if (!this.canChangeRole) {
return;
}
let currentRole = this.member.role;
this.tim
.setGroupMemberRole({
groupID: this.currentConversation.groupProfile.groupID,
userID: this.member.userID,
role: currentRole === "Admin" ? "Member" : "Admin",
})
.catch((error) => {
this.$store.commit("showMessage", {
type: "error",
message: error.message,
});
});
},
setGroupMemberMuteTime() {
// console.log('Number(this.muteTime) is ',Number(this.muteTime))
let _muteTime = Number(this.muteTime)
if(_muteTime > 99999999) {
_muteTime = 99999999
}
this.tim
.setGroupMemberMuteTime({
groupID: this.currentConversation.groupProfile.groupID,
userID: this.member.userID,
muteTime: _muteTime,
})
.then(() => {
this.muteTime = "";
this.popoverVisible = false;
})
.catch((error) => {
this.$store.commit("showMessage", {
type: "error",
message: error.message,
});
});
},
// 取消禁言
cancelMute() {
this.tim
.setGroupMemberMuteTime({
groupID: this.currentConversation.groupProfile.groupID,
userID: this.member.userID,
muteTime: 0,
})
.then(() => {
this.muteTime = "";
})
.catch((error) => {
this.$store.commit("showMessage", {
type: "error",
message: error.message,
});
});
},
setGroupMemberNameCard() {
if (this.nameCard.trim().length === 0) {
this.$store.commit("showMessage", {
message: "不能设置空的群名片",
type: "warning",
});
return;
}
this.tim
.setGroupMemberNameCard({
groupID: this.currentConversation.groupProfile.groupID,
userID: this.member.userID,
nameCard: this.nameCard,
})
.then(() => {
this.nameCardPopoverVisible = false;
this.$store.commit("showMessage", {
message: "修改成功",
});
})
.catch((error) => {
this.$store.commit("showMessage", {
type: "error",
message: error.message,
});
});
},
},
};
</script>
<style lang="stylus" scoped>
.label {
color: rgb(204, 200, 200);
}
.cursor-pointer {
cursor: pointer;
}
</style>