Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-im
提交
afdef3d6
U
uni-im
项目概览
DCloud
/
uni-im
通知
3
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-im
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
afdef3d6
编写于
4月 24, 2024
作者:
DCloud_JSON
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新 延迟渲染,避免页面卡顿
上级
e88830fd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
847 addition
and
837 deletion
+847
-837
pages/group/members.nvue
pages/group/members.nvue
+847
-837
未找到文件。
pages/group/members.nvue
浏览文件 @
afdef3d6
<template>
<template>
<view class="group-members-box">
<view class="group-members-box">
<uni-search-bar v-model="keyword" class="search-bar" radius="5" placeholder="输入昵称搜索" clearButton="auto"
<uni-search-bar v-model="keyword" class="search-bar" radius="5" placeholder="输入昵称搜索" clearButton="auto"
cancelButton="none"></uni-search-bar>
cancelButton="none"></uni-search-bar>
<view v-if="!leave_group" class="members-list-container" :class="{'show-less':!showAllMember}">
<view v-if="!leave_group" class="members-list-container" :class="{'show-less':!showAllMember}">
<view class="invite-box item" v-if="isAdmin">
<view class="invite-box item" v-if="isAdmin">
<view class="invite">
<view class="invite">
<uni-icons @click="invite" color="#989898" size="20px"
class="invite"
type="plusempty"></uni-icons>
<uni-icons @click="invite" color="#989898" size="20px" type="plusempty"></uni-icons>
</view>
</view>
<text class="nickname">邀请</text>
<text class="nickname">邀请</text>
</view>
</view>
<template v-for="(member,index) in memberList" :key="index">
<template v-for="(member,index) in memberList" :key="index">
<view class="item" :title="member.users.nickname"
<view class="item" :title="member.users.nickname"
:class="{'pointer': canPrivateChat,'focus':member.focus}" @click="toChat(member.users._id)"
:class="{'pointer': canPrivateChat,'focus':member.focus}" @click="toChat(member.users._id)"
@longpress.prevent="openConversationMenu($event,index)"
@longpress.prevent="openConversationMenu($event,index)"
@contextmenu.prevent="openConversationMenu($event,index)"
@contextmenu.prevent="openConversationMenu($event,index)"
@mousemove="hoverUserId = member.users._id"
@mousemove="hoverUserId = member.users._id"
>
>
<image class="avatar"
<image class="avatar"
:src="(member.users.avatar_file && member.users.avatar_file.url) ? member.users.avatar_file.url:'/uni_modules/uni-im/static/avatarUrl.png'"
:src="(member.users.avatar_file && member.users.avatar_file.url) ? member.users.avatar_file.url:'/uni_modules/uni-im/static/avatarUrl.png'"
mode="widthFix"></image>
mode="widthFix"></image>
<text class="nickname">{{member.users.nickname||'匿名用户'}}</text>
<text class="nickname">{{member.users.nickname||'匿名用户'}}</text>
<text v-if="member.role.includes('admin')" class="group-admin">管</text>
<text v-if="member.role.includes('admin')" class="group-admin">管</text>
<text v-if="!mute_all_members && member.mute_type" class="mute-type-1">已被禁言</text>
<text v-if="!mute_all_members && member.mute_type" class="mute-type-1">已被禁言</text>
</view>
</view>
</template>
</template>
</view>
</view>
<view class="show-all-menber" v-if="showMoreBtn">
<view class="show-all-menber" v-if="showMoreBtn">
<view class="show-all-menber-btn" @click="onClickShowAllMenber">
<view class="show-all-menber-btn" @click="onClickShowAllMenber">
<text>{{showAllMember ? '收起' : '查看更多'}}</text>
<text>{{showAllMember ? '收起' : '查看更多'}}</text>
</view>
</view>
</view>
</view>
<uni-im-contextmenu ref="uni-im-contextmenu"></uni-im-contextmenu>
<uni-im-contextmenu ref="uni-im-contextmenu"></uni-im-contextmenu>
</view>
</view>
</template>
</template>
<script>
<script>
const db = uniCloud.database()
const db = uniCloud.database()
import uniIm from '@/uni_modules/uni-im/sdk/index.js';
import uniIm from '@/uni_modules/uni-im/sdk/index.js';
export default {
export default {
data() {
data() {
return {
return {
conversation: {
conversation: {
group_info: {
group_info: {
user_id: "",
user_id: "",
mute_all_members: false
mute_all_members: false
},
},
group_member: {},
group_member: {},
mute: false
mute: false
},
},
leave_group: false,
leave_group: false,
member_list: [],
member_list: [],
isManage: false,
isManage: false,
editorFields: {
editorFields: {
"name": " 群聊名称",
"name": " 群聊名称",
"introduction": "群简介",
"introduction": "群简介",
"notification": "群公告"
"notification": "群公告"
},
},
editorType: '',
editorType: '',
editorDefaultValue: '',
editorDefaultValue: '',
groupType: '',
groupType: '',
isAdmin: false,
isAdmin: false,
keyword: '',
keyword: '',
mute_all_members: false,
mute_all_members: false,
showAllMember: false,
showAllMember: false,
// 鼠标在哪个用户id上
// 鼠标在哪个用户id上
hoverUserId: '',
hoverUserId: '',
showMoreBtn: true
showMoreBtn: true,
};
// 延迟渲染,避免页面卡顿
},
laterRenderIndex: 1
computed: {
};
...uniIm.mapState(['isWidescreen']),
},
logoUrl() {
computed: {
return this.conversation.group_info.avatar_file ? this.conversation.group_info.avatar_file.url : false
...uniIm.mapState(['isWidescreen']),
},
logoUrl() {
join_option() {
return this.conversation.group_info.avatar_file ? this.conversation.group_info.avatar_file.url : false
let val = this.conversation.group_info.join_option
},
return {
join_option() {
needPermission: "需要验证权限",
let val = this.conversation.group_info.join_option
freeAccess: "自由加入",
return {
disableApply: "禁止加入"
needPermission: "需要验证权限",
} [val]
freeAccess: "自由加入",
},
disableApply: "禁止加入"
memberList() {
} [val]
let memberList = this.member_list
},
// 根据关键词搜索
memberList() {
.filter(member => {
let memberList = this.member_list
// 忽略大小写
// 根据关键词搜索
return member.users.nickname.toLowerCase().includes(this.keyword.toLowerCase())
.filter(member => {
})
// 忽略大小写
// 是管理员排序靠前
return member.users.nickname.toLowerCase().includes(this.keyword.toLowerCase())
.sort((a, b) => {
})
if (a.role.includes('admin') && !b.role.includes('admin')) {
// 是管理员排序靠前
return -1
.sort((a, b) => {
} else if (!a.role.includes('admin') && b.role.includes('admin')) {
if (a.role.includes('admin') && !b.role.includes('admin')) {
return 1
return -1
} else {
} else if (!a.role.includes('admin') && b.role.includes('admin')) {
return 0
return 1
}
} else {
return 0
}
})
// laterRenderIndex
.filter((item, index) => {
return index < this.laterRenderIndex * 50
})
})
const memberCount = memberList.length
const memberCount = memberList.length
if(memberCount && memberCount < 10){
if(memberCount && memberCount < 10){
console.log('this.member_list.length',this.member_list.length);
console.log('this.member_list.length',this.member_list.length);
...
@@ -107,562 +114,565 @@
...
@@ -107,562 +114,565 @@
if (!this.showAllMember) {
if (!this.showAllMember) {
memberList = memberList.slice(0, 9)
memberList = memberList.slice(0, 9)
}
}
return memberList
return memberList
},
},
isGroupCreator() {
isGroupCreator() {
return this.conversation.group_info.user_id == uniCloud.getCurrentUserInfo().uid
return this.conversation.group_info.user_id == uniCloud.getCurrentUserInfo().uid
},
},
canPrivateChat(){
canPrivateChat(){
// 当前登录的账号是管理员,或者当前消息是群管理员发的
// 当前登录的账号是管理员,或者当前消息是群管理员发的
return this.uniIDHasRole('staff') || this.hoverUserId && this.conversation.group_member[this.hoverUserId].role.includes('admin')
return this.uniIDHasRole('staff') || this.hoverUserId && this.conversation.group_member[this.hoverUserId].role.includes('admin')
}
},
watch: {
"conversation.group_info.user_id"(adminUserId) {
// 当前用户是群的创建者或者管理员(在群成员中找到当前用户的角色包含admin)
const currentUserId = uniCloud.getCurrentUserInfo().uid
this.isAdmin = this.isGroupCreator || this.conversation.group_member[currentUserId]?.role.includes('admin')
//非群主 隐藏【管理】按钮
if (!this.isAdmin) {
if (!this.isWidescreen) {
// #ifdef H5
let dom = document.getElementsByClassName('uni-page-head-btn')[1]
dom.style.visibility = 'hidden'; // 隐藏元素
// #endif
// #ifdef APP-PLUS
var webview = this.$scope.$getAppWebview();
// console.log('webview', webview);
webview.setStyle({
titleNView: {
buttons: []
}
});
// #endif
}
} else {
if (this.isWidescreen) {
this.isManage = true
}
}
},
"conversation.group_member": {
handler(group_member, oldValue) {
// console.log('group_member',group_member);
this.member_list = []
for (let key in group_member) {
this.member_list.push(group_member[key])
}
if (!uniIm.isWidescreen) { // pc宽屏不需要
let title = "群信息(" + this.member_list.length + "人)"
uni.setNavigationBarTitle({
title
});
}
},
deep: true,
immediate: true
},
// (后续)通过监听实现实时切换管理员实时刷新权限
// console.log('isAdmin',isAdmin);
conversation: {
handler(conversation, oldValue) {
const currentUserId = uniCloud.getCurrentUserInfo().uid
this.isAdmin = this.isGroupCreator || this.conversation.group_member[currentUserId]?.role.includes('admin')
this.leave_group = conversation.leave
this.mute_all_members = conversation.group_info.mute_all_members
},
deep: true
},
},
props: {
conversation_id: {
default () {
return false
}
}
}
},
},
async onLoad(e) {
onReachBottom() {
if (!e.conversation_id) {
this.laterRenderIndex++
throw new Error("会话id不能为空")
},
watch: {
"conversation.group_info.user_id"(adminUserId) {
// 当前用户是群的创建者或者管理员(在群成员中找到当前用户的角色包含admin)
const currentUserId = uniCloud.getCurrentUserInfo().uid
this.isAdmin = this.isGroupCreator || this.conversation.group_member[currentUserId]?.role.includes('admin')
//非群主 隐藏【管理】按钮
if (!this.isAdmin) {
if (!this.isWidescreen) {
// #ifdef H5
let dom = document.getElementsByClassName('uni-page-head-btn')[1]
dom.style.visibility = 'hidden'; // 隐藏元素
// #endif
// #ifdef APP-PLUS
var webview = this.$scope.$getAppWebview();
// console.log('webview', webview);
webview.setStyle({
titleNView: {
buttons: []
}
});
// #endif
}
} else {
if (this.isWidescreen) {
this.isManage = true
}
}
},
"conversation.group_member": {
handler(group_member, oldValue) {
// console.log('group_member',group_member);
this.member_list = []
for (let key in group_member) {
this.member_list.push(group_member[key])
}
if (!uniIm.isWidescreen) { // pc宽屏不需要
let title = "群信息(" + this.member_list.length + "人)"
uni.setNavigationBarTitle({
title
});
}
},
deep: true,
immediate: true
},
// (后续)通过监听实现实时切换管理员实时刷新权限
// console.log('isAdmin',isAdmin);
conversation: {
handler(conversation, oldValue) {
const currentUserId = uniCloud.getCurrentUserInfo().uid
this.isAdmin = this.isGroupCreator || this.conversation.group_member[currentUserId]?.role.includes('admin')
this.leave_group = conversation.leave
this.mute_all_members = conversation.group_info.mute_all_members
},
deep: true
},
},
props: {
conversation_id: {
default () {
return false
}
}
},
async onLoad(e) {
if (!e.conversation_id) {
throw new Error("会话id不能为空")
}
}
// 以页面的方式打开,不需要显示更多的按钮和隐藏部分用户
// 以页面的方式打开,不需要显示更多的按钮和隐藏部分用户
this.showMoreBtn = false
this.showMoreBtn = false
this.showAllMember = true
this.showAllMember = true
this.load(e.conversation_id)
this.load(e.conversation_id)
},
},
mounted() { //pc端以组件模式加载时逻辑
mounted() { //pc端以组件模式加载时逻辑
if (this.conversation_id) {
if (this.conversation_id) {
this.load(this.conversation_id)
this.load(this.conversation_id)
}
}
},
},
onShow() {
onShow() {
// console.log("this.conversation: ", this.conversation.group_member);
// console.log("this.conversation: ", this.conversation.group_member);
},
},
// 长按头像出现管理菜单
// 长按头像出现管理菜单
// onNavigationBarButtonTap(e) {
// onNavigationBarButtonTap(e) {
// if (e.index === 0) {}
// if (e.index === 0) {}
// },
// },
methods: {
methods: {
async load(conversation_id) {
async load(conversation_id) {
this.conversation = await uniIm.conversation.get(conversation_id)
this.conversation = await uniIm.conversation.get(conversation_id)
},
},
async expelAndToBlack(item) {
async expelAndToBlack(item) {
uni.showModal({
uni.showModal({
title: '确定要将该用户移出本群并拉黑吗?',
title: '确定要将该用户移出本群并拉黑吗?',
content: '拉黑后此用户将不能再次加入本群,不能撤销,请谨慎操作',
content: '拉黑后此用户将不能再次加入本群,不能撤销,请谨慎操作',
cancelText: '取消',
cancelText: '取消',
confirmText: '确认',
confirmText: '确认',
complete: async (e) => {
complete: async (e) => {
// console.log(e);
// console.log(e);
if (e.confirm) {
if (e.confirm) {
uni.showLoading({
uni.showLoading({
mask: true
mask: true
});
});
try {
try {
let res = await db.collection('uni-im-group-member').where({
let res = await db.collection('uni-im-group-member').where({
user_id: item.users._id,
user_id: item.users._id,
group_id: this.conversation.group_info._id
group_id: this.conversation.group_info._id
})
})
.remove()
.remove()
console.log('expel', res);
console.log('expel', res);
const uniImCo = uniCloud.importObject("uni-im-co")
const uniImCo = uniCloud.importObject("uni-im-co")
res = await uniImCo.addToGroupMenberBlackList({
res = await uniImCo.addToGroupMenberBlackList({
user_id: item.users._id,
user_id: item.users._id,
group_id: this.conversation.group_info._id
group_id: this.conversation.group_info._id
})
})
console.log('expelAndToBlack', res);
console.log('expelAndToBlack', res);
} catch (error) {
} catch (error) {
uni.showToast({
uni.showToast({
title: error.message,
title: error.message,
icon: 'error',
icon: 'error',
complete: () => {}
complete: () => {}
});
});
}
}
uni.hideLoading()
uni.hideLoading()
}
}
}
}
});
});
},
},
async expel(item) {
async expel(item) {
uni.showModal({
uni.showModal({
title: '确定要将该用户移出本群吗?',
title: '确定要将该用户移出本群吗?',
content: '不能撤销,请谨慎操作',
content: '不能撤销,请谨慎操作',
cancelText: '取消',
cancelText: '取消',
confirmText: '确认',
confirmText: '确认',
complete: async (e) => {
complete: async (e) => {
// console.log(e);
// console.log(e);
if (e.confirm) {
if (e.confirm) {
uni.showLoading({
uni.showLoading({
mask: true
mask: true
});
});
try {
try {
let res = await db.collection('uni-im-group-member').where({
let res = await db.collection('uni-im-group-member').where({
user_id: item.users._id,
user_id: item.users._id,
group_id: this.conversation.group_info._id
group_id: this.conversation.group_info._id
})
})
.remove()
.remove()
if (res.result.deleted) {
if (res.result.deleted) {
uni.showToast({
uni.showToast({
title: '成功移除',
title: '成功移除',
icon: 'none',
icon: 'none',
complete: () => {}
complete: () => {}
});
});
// console.log('exitGroup', res);
// console.log('exitGroup', res);
}
}
} catch (error) {
} catch (error) {
uni.showToast({
uni.showToast({
title: error.message,
title: error.message,
icon: 'error',
icon: 'error',
complete: () => {}
complete: () => {}
});
});
}
}
uni.hideLoading()
uni.hideLoading()
}
}
}
}
});
});
},
},
async changeMemberMute(item) {
async changeMemberMute(item) {
let nickname = item.users.nickname || '匿名用户'
let nickname = item.users.nickname || '匿名用户'
uni.showModal({
uni.showModal({
title: '确定要' + (item.mute_type ? `为"${nickname}"解除禁言吗?` : `禁言"${nickname}"吗?`),
title: '确定要' + (item.mute_type ? `为"${nickname}"解除禁言吗?` : `禁言"${nickname}"吗?`),
cancelText: '取消',
cancelText: '取消',
confirmText: '确认',
confirmText: '确认',
complete: async (e) => {
complete: async (e) => {
// console.log(e);
// console.log(e);
if (e.confirm) {
if (e.confirm) {
uni.showLoading({
uni.showLoading({
mask: true
mask: true
});
});
try {
try {
let res = await db.collection('uni-im-group-member').where({
let res = await db.collection('uni-im-group-member').where({
_id: item._id,
_id: item._id,
mute_type: item.mute_type // 防止此时云端已经变化
mute_type: item.mute_type // 防止此时云端已经变化
})
})
.update({
.update({
mute_type: item.mute_type ? 0 : 1
mute_type: item.mute_type ? 0 : 1
})
})
// console.log('mute_type', res);
// console.log('mute_type', res);
if (res.result.updated) {
if (res.result.updated) {
item.mute_type = item.mute_type ? 0 : 1
item.mute_type = item.mute_type ? 0 : 1
uni.showToast({
uni.showToast({
title: '设置成功',
title: '设置成功',
icon: 'none',
icon: 'none',
complete: () => {}
complete: () => {}
});
});
}
}
} catch (error) {
} catch (error) {
// console.log('error',merror)
// console.log('error',merror)
uni.showToast({
uni.showToast({
title: error.message,
title: error.message,
icon: 'error',
icon: 'error',
complete: () => {}
complete: () => {}
});
});
}
}
uni.hideLoading()
uni.hideLoading()
}
}
}
}
});
});
},
},
openConversationMenu(e, index) {
openConversationMenu(e, index) {
let member = this.memberList[index]
let member = this.memberList[index]
// console.log('member', member);
// console.log('member', member);
let menuList = []
let menuList = []
if (this.isAdmin) {
if (this.isAdmin) {
menuList.unshift({
menuList.unshift({
"title": "移除",
"title": "移除",
"action": () => {
"action": () => {
// console.log('移除');
// console.log('移除');
this.expel(member)
this.expel(member)
}
}
})
})
menuList.unshift({
menuList.unshift({
"title": "移除并拉黑",
"title": "移除并拉黑",
"action": () => {
"action": () => {
console.log('移除并拉黑');
console.log('移除并拉黑');
this.expelAndToBlack(member)
this.expelAndToBlack(member)
}
}
})
})
if (!this.conversation.group_info.mute_all_members) {
if (!this.conversation.group_info.mute_all_members) {
menuList.unshift({
menuList.unshift({
"title": member.mute_type ? "解除禁言" : '设为禁言',
"title": member.mute_type ? "解除禁言" : '设为禁言',
"action": () => {
"action": () => {
// console.log('禁言');
// console.log('禁言');
this.changeMemberMute(member)
this.changeMemberMute(member)
}
}
})
})
}
}
const isAdmin = member.role.includes('admin')
const isAdmin = member.role.includes('admin')
menuList.push({
menuList.push({
"title": isAdmin ? "取消管理员" : "设置管理员",
"title": isAdmin ? "取消管理员" : "设置管理员",
"action": () => {
"action": () => {
let role = member.role;
let role = member.role;
if (isAdmin) {
if (isAdmin) {
// console.log('取消管理员');
// console.log('取消管理员');
role = member.role.filter(item => item !== 'admin')
role = member.role.filter(item => item !== 'admin')
} else {
} else {
role.push('admin')
role.push('admin')
// console.log('设置管理员');
// console.log('设置管理员');
}
}
uni.showLoading({
uni.showLoading({
mask: true
mask: true
});
});
db.collection('uni-im-group-member').doc(member._id).update({
db.collection('uni-im-group-member').doc(member._id).update({
"role": role
"role": role
}).then(res => {
}).then(res => {
// console.log('res', res);
// console.log('res', res);
member.role = role
member.role = role
})
})
.catch(err => {
.catch(err => {
console.error(err)
console.error(err)
uni.showToast({
uni.showToast({
title: err.message,
title: err.message,
icon: 'none'
icon: 'none'
});
});
})
})
.finally(() => {
.finally(() => {
uni.hideLoading()
uni.hideLoading()
})
})
}
}
})
})
}
}
if (menuList.length > 0) {
if (menuList.length > 0) {
member.focus = true
member.focus = true
const myContextmenu = this.$refs['uni-im-contextmenu']
const myContextmenu = this.$refs['uni-im-contextmenu']
const position = {
const position = {
"contextmenu": {
"contextmenu": {
"top": e.clientY,
"top": e.clientY,
"left": e.clientX
"left": e.clientX
},
},
"longpress": {
"longpress": {
"top": e.touches[0].screenY || e.touches[0].clientY,
"top": e.touches[0].screenY || e.touches[0].clientY,
"left": e.touches[0].screenX || e.touches[0].clientX
"left": e.touches[0].screenX || e.touches[0].clientX
}
}
} [e.type]
} [e.type]
// #ifdef H5
// #ifdef H5
position.top = position.top + 120
position.top = position.top + 120
// #endif
// #endif
myContextmenu.show(position, menuList)
myContextmenu.show(position, menuList)
myContextmenu.onClose(() => {
myContextmenu.onClose(() => {
member.focus = false
member.focus = false
})
})
}
}
},
},
invite() {
invite() {
// console.log('group_info._id', this.conversation.group_info._id);
// console.log('group_info._id', this.conversation.group_info._id);
uni.navigateTo({
uni.navigateTo({
url: '/uni_modules/uni-im/pages/contacts/createGroup/createGroup?group_id=' + this.conversation.group_info
url: '/uni_modules/uni-im/pages/contacts/createGroup/createGroup?group_id=' + this.conversation.group_info
._id
._id
})
})
},
},
async exitGroup() {
async exitGroup() {
const group_id = this.conversation.group_info._id
const group_id = this.conversation.group_info._id
if (this.isGroupCreator) {
if (this.isGroupCreator) {
uni.showModal({
uni.showModal({
title: '确认要解散群聊吗?',
title: '确认要解散群聊吗?',
content: '不能撤销,请谨慎操作',
content: '不能撤销,请谨慎操作',
cancelText: '取消',
cancelText: '取消',
confirmText: '确认',
confirmText: '确认',
complete: async (e) => {
complete: async (e) => {
// console.log(e);
// console.log(e);
if (e.confirm) {
if (e.confirm) {
uni.showLoading({
uni.showLoading({
mask: true
mask: true
});
});
let res = await db.collection('uni-im-group')
let res = await db.collection('uni-im-group')
.where({
.where({
_id: group_id
_id: group_id
})
})
.remove()
.remove()
.finally((res) => {
.finally((res) => {
// uni.navigateBack({ // 收到离群的推送通知会自动关闭当前页面
// uni.navigateBack({ // 收到离群的推送通知会自动关闭当前页面
// delta: 2
// delta: 2
// })
// })
uni.hideLoading()
uni.hideLoading()
})
})
// console.log('exitGroup', res);
// console.log('exitGroup', res);
}
}
}
}
});
});
} else {
} else {
uni.showModal({
uni.showModal({
title: '确认要退出群聊吗?',
title: '确认要退出群聊吗?',
content: '不能撤销,请谨慎操作',
content: '不能撤销,请谨慎操作',
cancelText: '取消',
cancelText: '取消',
confirmText: '确认',
confirmText: '确认',
complete: async (e) => {
complete: async (e) => {
// console.log(e);
// console.log(e);
if (e.confirm) {
if (e.confirm) {
// uni.navigateBack({ // 收到离群的推送通知会自动关闭当前页面
// uni.navigateBack({ // 收到离群的推送通知会自动关闭当前页面
// delta: 2
// delta: 2
// })
// })
uni.showLoading({
uni.showLoading({
mask: true
mask: true
});
});
let res = await db.collection('uni-im-group-member').where({
let res = await db.collection('uni-im-group-member').where({
user_id: uniCloud.getCurrentUserInfo().uid,
user_id: uniCloud.getCurrentUserInfo().uid,
group_id
group_id
})
})
.remove()
.remove()
// console.log(res.result);
// console.log(res.result);
if (res.result.deleted) {
if (res.result.deleted) {
uni.showToast({
uni.showToast({
title: '成功退出',
title: '成功退出',
icon: 'none'
icon: 'none'
});
});
}
}
uni.hideLoading()
uni.hideLoading()
// console.log('exitGroup', res);
// console.log('exitGroup', res);
}
}
}
}
});
});
}
}
},
},
openPopupInfo(type) {
openPopupInfo(type) {
// console.log(type);
// console.log(type);
if (!this.isAdmin) return
if (!this.isAdmin) return
this.editorType = type
this.editorType = type
this.editorDefaultValue = this.conversation.group_info[type]
this.editorDefaultValue = this.conversation.group_info[type]
if (this.editorType == "notification") {
if (this.editorType == "notification") {
this.editorDefaultValue = this.editorDefaultValue?.content || ""
this.editorDefaultValue = this.editorDefaultValue?.content || ""
}
}
this.$refs.popupInfo.open()
this.$refs.popupInfo.open()
},
},
closePopupInfo() {
closePopupInfo() {
this.$refs.popupInfo.close()
this.$refs.popupInfo.close()
},
},
confirmPopupInfo(value) {
confirmPopupInfo(value) {
if (!value) {
if (!value) {
uni.showToast({
uni.showToast({
title: '内容不能为空!',
title: '内容不能为空!',
icon: 'none'
icon: 'none'
});
});
return
return
}
}
// console.log('value', value);
// console.log('value', value);
const updateData = {};
const updateData = {};
if (this.editorType == 'notification') {
if (this.editorType == 'notification') {
updateData[this.editorType] = {
updateData[this.editorType] = {
"content": value
"content": value
}; // 创建时间服务端生成
}; // 创建时间服务端生成
} else {
} else {
updateData[this.editorType] = value;
updateData[this.editorType] = value;
}
}
this.updateGroupInfo(updateData)
this.updateGroupInfo(updateData)
this.$refs.popupInfo.close()
this.$refs.popupInfo.close()
},
},
setAddGroupType() {
setAddGroupType() {
if (!this.isAdmin) return
if (!this.isAdmin) return
uni.showActionSheet({
uni.showActionSheet({
itemList: ['自由加入', '需要验证权限', '禁止加入'],
itemList: ['自由加入', '需要验证权限', '禁止加入'],
success: (e) => {
success: (e) => {
let join_option = ['freeAccess', 'needPermission', 'disableApply'][e.tapIndex]
let join_option = ['freeAccess', 'needPermission', 'disableApply'][e.tapIndex]
this.updateGroupInfo({
this.updateGroupInfo({
join_option
join_option
})
})
},
},
fail: (err) => {
fail: (err) => {
console.error("err: ", err);
console.error("err: ", err);
}
}
})
})
},
},
async updateGroupInfo(group_info) {
async updateGroupInfo(group_info) {
// console.log('group_info---------',group_info);
// console.log('group_info---------',group_info);
this.conversation.group_info = Object.assign(this.conversation.group_info, group_info)
this.conversation.group_info = Object.assign(this.conversation.group_info, group_info)
let res = await db.collection('uni-im-group')
let res = await db.collection('uni-im-group')
.doc(this.conversation.group_id)
.doc(this.conversation.group_id)
.update(group_info)
.update(group_info)
// console.log('change group info', res.result.updated,this.conversation);
// console.log('change group info', res.result.updated,this.conversation);
},
},
async setAvatar() {
async setAvatar() {
if (!this.isAdmin) return
if (!this.isAdmin) return
const crop = {
const crop = {
quality: 100,
quality: 100,
width: 600,
width: 600,
height: 600,
height: 600,
resize: true
resize: true
};
};
uni.chooseImage({
uni.chooseImage({
count: 1,
count: 1,
crop,
crop,
success: async (res) => {
success: async (res) => {
let tempFile = res.tempFiles[0],
let tempFile = res.tempFiles[0],
avatar_file = {
avatar_file = {
// #ifdef H5
// #ifdef H5
extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1],
extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1],
// #endif
// #endif
// #ifndef H5
// #ifndef H5
extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1]
extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1]
// #endif
// #endif
},
},
filePath = res.tempFilePaths[0]
filePath = res.tempFilePaths[0]
// #ifndef APP-PLUS
// #ifndef APP-PLUS
//非app端用前端组件剪裁头像,app端用内置的原生裁剪
//非app端用前端组件剪裁头像,app端用内置的原生裁剪
let isPC = false
let isPC = false
// #ifdef H5
// #ifdef H5
isPC = !['ios', 'android'].includes(uni.getSystemInfoSync().platform)
isPC = !['ios', 'android'].includes(uni.getSystemInfoSync().platform)
// #endif
// #endif
if (!isPC) {
if (!isPC) {
filePath = await new Promise((callback) => {
filePath = await new Promise((callback) => {
uni.navigateTo({
uni.navigateTo({
url: '/uni_modules/uni-id-pages/pages/users/cropImage/cropImage?path=' +
url: '/uni_modules/uni-id-pages/pages/users/cropImage/cropImage?path=' +
filePath + `&options=${JSON.stringify(crop)}`,
filePath + `&options=${JSON.stringify(crop)}`,
animationType: "fade-in",
animationType: "fade-in",
events: {
events: {
success: url => {
success: url => {
callback(url)
callback(url)
}
}
},
},
complete(e) {
complete(e) {
// console.log(e);
// console.log(e);
}
}
});
});
})
})
}
}
// #endif
// #endif
// console.log(this.users);
// console.log(this.users);
let cloudPath = uniCloud.getCurrentUserInfo().uid + '' + Date.now()
let cloudPath = uniCloud.getCurrentUserInfo().uid + '' + Date.now()
avatar_file.name = cloudPath
avatar_file.name = cloudPath
uni.showLoading({
uni.showLoading({
title: "更新中",
title: "更新中",
mask: true
mask: true
});
});
let {
let {
fileID
fileID
} = await uniCloud.uploadFile({
} = await uniCloud.uploadFile({
filePath,
filePath,
cloudPath,
cloudPath,
fileType: "image"
fileType: "image"
});
});
// console.log(result)
// console.log(result)
avatar_file.url = fileID
avatar_file.url = fileID
// console.log({avatar_file});
// console.log({avatar_file});
uni.hideLoading()
uni.hideLoading()
this.updateGroupInfo({
this.updateGroupInfo({
avatar_file
avatar_file
})
})
}
}
})
})
},
},
// #ifdef H5
// #ifdef H5
share() {
share() {
// 获取当前域名
// 获取当前域名
const data = location.origin + "/#/?joinGroup=" + this.conversation.group_info._id
const data = location.origin + "/#/?joinGroup=" + this.conversation.group_info._id
uni.setClipboardData({
uni.setClipboardData({
data,
data,
showToast: false,
showToast: false,
success: () => {
success: () => {
uni.showToast({
uni.showToast({
title: "已成功复制分享链接",
title: "已成功复制分享链接",
duration: 2000,
duration: 2000,
icon: 'none'
icon: 'none'
});
});
}
}
})
})
// uni.navigateTo({
// uni.navigateTo({
// url: '/uni_modules/uni-im/pages/group/groupQRCode?id=' +
// url: '/uni_modules/uni-im/pages/group/groupQRCode?id=' +
// this.conversation.group_info._id +
// this.conversation.group_info._id +
// '&name=' + this.conversation.group_info.name +
// '&name=' + this.conversation.group_info.name +
// '&avatar_file=' + url,
// '&avatar_file=' + url,
// complete: (e) => {
// complete: (e) => {
// // console.log(e);
// // console.log(e);
// }
// }
// });
// });
},
},
// #endif
// #endif
joinGroup() {
joinGroup() {
db.collection('uni-im-group-join').add({
db.collection('uni-im-group-join').add({
"group_id": this.conversation.group_id,
"group_id": this.conversation.group_id,
"message": ''
"message": ''
}).then((res) => {
}).then((res) => {
// console.log("res: ", res);
// console.log("res: ", res);
uni.showToast({
uni.showToast({
icon: 'none',
icon: 'none',
title: '已申请'
title: '已申请'
})
})
})
})
},
},
toChat(user_id) {
toChat(user_id) {
if (this.canPrivateChat) {
if (this.canPrivateChat) {
if (uniIm.isWidescreen) {
if (uniIm.isWidescreen) {
uni.$emit('uni-im-toChat', {
uni.$emit('uni-im-toChat', {
user_id
user_id
})
})
} else {
} else {
uni.navigateTo({
uni.navigateTo({
url: '/uni_modules/uni-im/pages/chat/chat?user_id=' + user_id,
url: '/uni_modules/uni-im/pages/chat/chat?user_id=' + user_id,
animationDuration: 300
animationDuration: 300
})
})
}
}
}
}
},
},
onClickShowAllMenber() {
onClickShowAllMenber() {
if(this.isWidescreen){
if(this.isWidescreen){
...
@@ -672,205 +682,205 @@
...
@@ -672,205 +682,205 @@
url: '/uni_modules/uni-im/pages/group/members?conversation_id=' + this.conversation.id
url: '/uni_modules/uni-im/pages/group/members?conversation_id=' + this.conversation.id
})
})
}
}
},
},
setMuteAllMembers(e) {
setMuteAllMembers(e) {
for (let user_id in this.conversation.group_member) {
for (let user_id in this.conversation.group_member) {
const member = this.conversation.group_member[user_id]
const member = this.conversation.group_member[user_id]
member.mute_type += (e.value ? 1 : -1)
member.mute_type += (e.value ? 1 : -1)
}
}
this.updateGroupInfo({
this.updateGroupInfo({
"mute_all_members": e.value
"mute_all_members": e.value
})
})
},
},
changeConversationMute(e) {
changeConversationMute(e) {
this.conversation.changeMute()
this.conversation.changeMute()
}
}
}
}
}
}
</script>
</script>
<style lang="less" scoped>
<style lang="less" scoped>
/* #ifndef APP-NVUE */
/* #ifndef APP-NVUE */
page,
page,
/* #endif */
/* #endif */
.group-members-box {
.group-members-box {
width: 750rpx;
width: 750rpx;
// flex: 1;
// flex: 1;
background-color: #f5f5f5;
background-color: #f5f5f5;
/* #ifdef H5 */
/* #ifdef H5 */
@media screen and (min-device-width:960px) {
@media screen and (min-device-width:960px) {
// height: calc(95vh - 70px);
// height: calc(95vh - 70px);
// overflow-y: auto;
// overflow-y: auto;
// flex: none;
// flex: none;
}
}
/* #endif */
/* #endif */
}
}
.members-list-container {
.members-list-container {
width: 750rpx;
width: 750rpx;
flex-direction: row;
flex-direction: row;
flex-wrap: wrap;
flex-wrap: wrap;
}
}
// 收缩
// 收缩
.show-less {
.show-less {
max-height: 400px;
max-height: 400px;
}
}
.item {
.item {
width: 150rpx;
width: 150rpx;
height: 140rpx;
height: 140rpx;
margin: 5px 0;
margin: 5px 0;
align-items: center;
align-items: center;
justify-content: center;
justify-content: center;
position: relative;
position: relative;
/* #ifndef APP-NVUE */
/* #ifndef APP-NVUE */
display: inline-flex;
display: inline-flex;
/* #endif */
/* #endif */
}
}
/* #ifdef H5 */
/* #ifdef H5 */
.windows .item {
.windows .item {
width: 146rpx;
width: 146rpx;
}
}
/* #endif */
/* #endif */
.item.focus {
.item.focus {
border: 1px dashed #ccc;
border: 1px dashed #ccc;
}
}
.group-admin {
.group-admin {
position: absolute;
position: absolute;
top: 5px;
top: 5px;
right: 5px;
right: 5px;
padding: 1px 3px;
padding: 1px 3px;
border-radius: 6px;
border-radius: 6px;
background-color: #e64141;
background-color: #e64141;
color: #fff;
color: #fff;
font-size: 12px;
font-size: 12px;
}
}
.mute-type-1 {
.mute-type-1 {
position: absolute;
position: absolute;
padding: 1px 10px;
padding: 1px 10px;
background-color: #0b60ff;
background-color: #0b60ff;
color: #fff;
color: #fff;
font-size: 10px;
font-size: 10px;
bottom: 28px;
bottom: 28px;
}
}
/* #ifdef H5 */
/* #ifdef H5 */
.pointer {
.pointer {
cursor: pointer;
cursor: pointer;
}
}
/* #endif */
/* #endif */
.avatar {
.avatar {
width: 100rpx;
width: 100rpx;
height: 100rpx;
height: 100rpx;
border-radius: 10px;
border-radius: 10px;
box-shadow: 0 0 1px #aaa;
box-shadow: 0 0 1px #aaa;
}
}
.nickname {
.nickname {
width: 140rpx;
width: 140rpx;
text-align: center;
text-align: center;
font-size: 14px;
font-size: 14px;
color: #666;
color: #666;
padding: 0 16rpx;
padding: 0 16rpx;
/* #ifndef APP-NVUE */
/* #ifndef APP-NVUE */
white-space: nowrap;
white-space: nowrap;
/* #endif */
/* #endif */
overflow: hidden;
overflow: hidden;
text-overflow: ellipsis;
text-overflow: ellipsis;
lines: 1;
lines: 1;
}
}
.logo {
.logo {
width: 50px;
width: 50px;
height: 50px;
height: 50px;
}
}
.invite-box {
.invite-box {
align-items: center;
align-items: center;
}
}
.invite {
.invite {
width: 100rpx;
width: 100rpx;
height: 100rpx;
height: 100rpx;
align-content: center;
justify-content: center;
border-radius: 10px;
border-radius: 10px;
border: #ccc dashed 1px;
border: #ccc dashed 1px;
/* #ifdef H5 */
/* #ifdef H5 */
cursor: pointer;
cursor: pointer;
/* #endif */
/* #endif */
}
}
.exitGroup {
.exitGroup {
margin: 10px 0;
margin: 10px 0;
background-color: #FFFFFF;
background-color: #FFFFFF;
padding: 6px 0;
padding: 6px 0;
color: #e64141;
color: #e64141;
border-radius: 0;
border-radius: 0;
font-size: 16px;
font-size: 16px;
text-align: center;
text-align: center;
padding: 15px 0;
padding: 15px 0;
/* #ifdef H5 */
/* #ifdef H5 */
cursor: pointer;
cursor: pointer;
/* #endif */
/* #endif */
}
}
/* #ifndef APP-NVUE */
/* #ifndef APP-NVUE */
.exitGroup::after {
.exitGroup::after {
display: none;
display: none;
}
}
/* #endif */
/* #endif */
.group-info-text {
.group-info-text {
color: #666;
color: #666;
font-size: 14px;
font-size: 14px;
/* #ifndef APP-NVUE */
/* #ifndef APP-NVUE */
max-width: 560rpx;
max-width: 560rpx;
/* #endif */
/* #ifdef APP-NVUE */
width: 560rpx;
/* #endif */
text-align: right;
}
.join_option {
color: #666;
font-size: 14px;
}
.slot-code {
align-items: center;
flex-direction: row;
}
.group-code {
width: 50rpx;
height: 50rpx;
margin-left: 10rpx;
}
.show-all-menber {
margin: 5px 0;
flex: 1;
justify-content: center;
}
.show-all-menber-btn {
flex-direction: row;
font-size: 14px;
justify-content: center;
/* #ifndef APP-NVUE */
cursor: pointer;
/* #endif */
/* #endif */
color: #888;
/* #ifdef APP-NVUE */
}
width: 560rpx;
/* #endif */
.show-all-menber-btn:hover {
text-align: right;
color: #666;
}
}
.join_option {
color: #666;
font-size: 14px;
}
.slot-code {
align-items: center;
flex-direction: row;
}
.group-code {
width: 50rpx;
height: 50rpx;
margin-left: 10rpx;
}
.show-all-menber {
margin: 5px 0;
flex: 1;
justify-content: center;
}
.show-all-menber-btn {
flex-direction: row;
font-size: 14px;
justify-content: center;
/* #ifndef APP-NVUE */
cursor: pointer;
/* #endif */
color: #888;
}
.show-all-menber-btn:hover {
color: #666;
}
</style>
</style>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录