This commit is contained in:
2022-02-14 10:59:16 +08:00
9 changed files with 437 additions and 329 deletions

View File

@@ -108,6 +108,15 @@ const getGroupInfo = (groupId) => {
}) })
} }
/**
* 群组基础信息
*/
const getGroupBase = (groupId) => {
return request({
url: 'im/groups/' + groupId+ '/base'
})
}
const getGroupUsers = (groupId) => { const getGroupUsers = (groupId) => {
return request({ return request({
url: 'im/groups/' + groupId + '/users' url: 'im/groups/' + groupId + '/users'
@@ -195,6 +204,7 @@ export {
createGroup, createGroup,
updateGroup, updateGroup,
getGroupInfo, getGroupInfo,
getGroupBase,
getGroupUsers, getGroupUsers,
getGroupAnnouncements, getGroupAnnouncements,
createGroupAnnouncement, createGroupAnnouncement,

View File

@@ -2,21 +2,10 @@
<view class="content"> <view class="content">
<!-- tool --> <!-- tool -->
<view class="tool-flex"> <view class="tool-flex">
<view <view class="tool-flex-item" @click="$Router.back()">
class="tool-flex-item" <uni-icons type="closeempty" size="22" color="#666"></uni-icons>
@click="$Router.back()"
>
<uni-icons
type="closeempty"
size="22"
color="#666"
></uni-icons>
</view> </view>
<view <view class="tool-flex-item" @click="onKeyAuth()" v-if="$Route.query.keyPhone == 1">一键登录</view>
class="tool-flex-item"
@click="onKeyAuth()"
v-if="$Route.query.keyPhone == 1"
>一键登录</view>
</view> </view>
<!-- 欢迎使用 --> <!-- 欢迎使用 -->
<view class="header"> <view class="header">
@@ -26,34 +15,14 @@
<!-- 输入手机号相关 --> <!-- 输入手机号相关 -->
<view class="inputs phone"> <view class="inputs phone">
<label class="label">+86</label> <label class="label">+86</label>
<input <input type="number" placeholder="输入您的手机号码" maxlength="11" v-model="phone" />
type="number"
placeholder="输入您的手机号码"
maxlength="11"
v-model="phone"
/>
</view> </view>
<view class="inputs sms"> <view class="inputs sms">
<input <input type="number" placeholder="输入短信验证码" maxlength="4" v-model="code" />
type="number" <button class="sms-btn" type="default" size="mini" :disabled="phone == '' || getSms"
placeholder="输入短信验证码" @click="getPhoneCode">{{getSms ? '重新发送' + smsTime + 's': '发送验证码'}}</button>
maxlength="4"
v-model="code"
/>
<button
class="sms-btn"
type="default"
size="mini"
:disabled="phone == '' || getSms"
@click="getPhoneCode"
>{{getSms ? '重新发送' + smsTime + 's': '发送验证码'}}</button>
</view> </view>
<button <button class="btn" type="default" :disabled="phone == '' || code == ''" @click="login">登录</button>
class="btn"
type="default"
:disabled="phone == '' || code == ''"
@click="login"
>登录</button>
<!-- 用户登录注册协议 --> <!-- 用户登录注册协议 -->
<view class="agreement"> <view class="agreement">
未注册的手机号码验证后自动创建账号登录即表示同意接受平台 未注册的手机号码验证后自动创建账号登录即表示同意接受平台
@@ -65,7 +34,10 @@
</template> </template>
<script> <script>
import { getSms, smsAuth } from "@/apis/interfaces/auth"; import {
getSms,
smsAuth
} from "@/apis/interfaces/auth";
import userAuth from "@/public/userAuth"; import userAuth from "@/public/userAuth";
export default { export default {
data() { data() {
@@ -89,7 +61,6 @@ export default {
); );
this.$Router.back(); this.$Router.back();
}).catch((err) => { }).catch((err) => {
console.log(2222)
uni.showToast({ uni.showToast({
title: err.message, title: err.message,
icon: "none", icon: "none",
@@ -142,6 +113,7 @@ export default {
box-sizing: border-box; box-sizing: border-box;
background: white; background: white;
@extend .vertical; @extend .vertical;
// 操作栏 // 操作栏
.tool-flex { .tool-flex {
position: fixed; position: fixed;
@@ -154,12 +126,14 @@ export default {
padding-right: $padding * 2; padding-right: $padding * 2;
background: white; background: white;
@extend .ios-top; @extend .ios-top;
&-item { &-item {
line-height: 90rpx; line-height: 90rpx;
color: $text-gray; color: $text-gray;
font-size: $title-size-lg; font-size: $title-size-lg;
} }
} }
// 表单 // 表单
.inputs { .inputs {
background: $window-color; background: $window-color;
@@ -168,6 +142,7 @@ export default {
height: 90rpx; height: 90rpx;
line-height: 90rpx; line-height: 90rpx;
border-radius: 45rpx; border-radius: 45rpx;
input { input {
width: 100%; width: 100%;
height: 90rpx; height: 90rpx;
@@ -180,6 +155,7 @@ export default {
&.phone { &.phone {
padding-left: 120rpx; padding-left: 120rpx;
.label { .label {
position: absolute; position: absolute;
left: 0; left: 0;
@@ -193,6 +169,7 @@ export default {
&.sms { &.sms {
padding-right: 200rpx; padding-right: 200rpx;
.sms-btn[size='mini'] { .sms-btn[size='mini'] {
width: 200rpx; width: 200rpx;
height: 90rpx; height: 90rpx;
@@ -206,9 +183,11 @@ export default {
color: $main-color; color: $main-color;
font-size: $title-size-lg; font-size: $title-size-lg;
background: $window-color; background: $window-color;
&::after { &::after {
border: none; border: none;
} }
&[disabled] { &[disabled] {
color: rgba($color: $main-color, $alpha: .6); color: rgba($color: $main-color, $alpha: .6);
background: rgba($color: $window-color, $alpha: 0); background: rgba($color: $window-color, $alpha: 0);
@@ -216,22 +195,26 @@ export default {
} }
} }
} }
// 头部 // 头部
.header { .header {
text-align: center; text-align: center;
margin-bottom: 5vh; margin-bottom: 5vh;
.title { .title {
font-size: $title-size + 10; font-size: $title-size + 10;
font-weight: bold; font-weight: bold;
color: $text-color; color: $text-color;
line-height: 70rpx; line-height: 70rpx;
} }
.sumbit { .sumbit {
line-height: 50rpx; line-height: 50rpx;
font-size: $title-size-m; font-size: $title-size-m;
color: $text-gray-m; color: $text-gray-m;
} }
} }
// 登录按钮 // 登录按钮
.btn { .btn {
margin: 0; margin: 0;
@@ -244,18 +227,22 @@ export default {
background: $main-color; background: $main-color;
color: white; color: white;
font-weight: bold; font-weight: bold;
&::after { &::after {
display: none; display: none;
} }
&[disabled] { &[disabled] {
background: rgba($color: $main-color, $alpha: .5); background: rgba($color: $main-color, $alpha: .5);
} }
} }
// 协议 // 协议
.agreement { .agreement {
padding-top: 5vh; padding-top: 5vh;
font-size: $title-size-sm; font-size: $title-size-sm;
color: $text-gray-m; color: $text-gray-m;
view { view {
color: $main-color; color: $main-color;
display: inline-block; display: inline-block;

View File

@@ -6,7 +6,8 @@
</view> </view>
<view class="content"> <view class="content">
<view class="header"> <view class="header">
<view class="name">{{ contact(item.targetId).name }} <span v-if="item.conversationType === 3" class='qun'>[]</span></view> <view class="name">{{ contact(item.targetId).name }} <text v-if="item.conversationType === 3"
class='qun'>[]</text></view>
<view class="time">{{ item.sentTime|timeCustomCN }}</view> <view class="time">{{ item.sentTime|timeCustomCN }}</view>
</view> </view>
<message-preview class="preview" :msg="item.latestMessage" :conversationType="item.conversationType" <message-preview class="preview" :msg="item.latestMessage" :conversationType="item.conversationType"
@@ -70,7 +71,9 @@
.name { .name {
font-size: $title-size + 2; font-size: $title-size + 2;
color: #454545; color: #454545;
color: #454545; display: flex;
align-items: center;
.qun { .qun {
color: $main-color; color: $main-color;
font-size: $title-size-m; font-size: $title-size-m;

View File

@@ -12,7 +12,7 @@
<u-sticky> <u-sticky>
<view class="header-search"> <view class="header-search">
<u-search placeholder="输入用户账号、手机号" height="74" searchIcon="search" @custom="search" <u-search placeholder="输入用户账号、手机号" height="74" searchIcon="search" @custom="search"
v-model="searchValue" @search="search" inputAlign="center" bgColor="#f9f9f9" :focus="focused" /> v-model="searchValue" @search="search" bgColor="#f9f9f9" :focus="focused" />
</view> </view>
</u-sticky> </u-sticky>
<block v-if="searchResult.length > 0"> <block v-if="searchResult.length > 0">

View File

@@ -24,6 +24,7 @@
methods: { methods: {
onCreate() { onCreate() {
createGroupAnnouncement(this.targetId, this.content).then(res => { createGroupAnnouncement(this.targetId, this.content).then(res => {
uni.$emit('groupAnnouncementCreated')
uni.showToast({ uni.showToast({
title: '发布成功', title: '发布成功',
success: () => { success: () => {

View File

@@ -38,6 +38,10 @@
this.isAdmin = res.group.is_admin this.isAdmin = res.group.is_admin
}) })
this.initData() this.initData()
uni.$on('groupAnnouncementCreated', this.initData)
},
onUnload() {
uni.$off('groupAnnouncementCreated')
}, },
onNavigationBarButtonTap() { onNavigationBarButtonTap() {
if (this.isAdmin) { if (this.isAdmin) {
@@ -55,7 +59,6 @@
initData() { initData() {
getGroupAnnouncements(this.targetId).then(res => { getGroupAnnouncements(this.targetId).then(res => {
this.announcements = res this.announcements = res
console.log(res);
this.loading = false this.loading = false
}) })
}, },

View File

@@ -62,9 +62,11 @@
this.getMessageList() this.getMessageList()
} }
}) })
uni.$once('cleanGroupMessage', this.getMessageList)
}, },
onBackPress() { onBackPress() {
uni.$off('onReceiveMessage') uni.$off('onReceiveMessage')
console.log('Off onReceiveMessage');
}, },
onNavigationBarButtonTap() { onNavigationBarButtonTap() {
uni.navigateTo({ uni.navigateTo({

View File

@@ -13,7 +13,7 @@
</view> </view>
</view> </view>
<view @click="loadMore" class="loadmore">查看更多群成员</view> <view @click="loadMore" class="loadmore">查看更多群成员 ></view>
</view> </view>
<u-cell-group class="cells"> <u-cell-group class="cells">
@@ -26,14 +26,14 @@
</u-cell> </u-cell>
</u-cell-group> </u-cell-group>
<u-cell-group class="cells" v-if="group.is_owner"> <u-cell-group class="cells" v-if="group.is_admin">
<u-cell isLink title="修改群聊名称" :value="group.name" @click="onGroupName"></u-cell> <u-cell isLink title="修改群聊名称" :value="group.name" @click="onGroupName"></u-cell>
<u-cell isLink title="修改群头像"> <u-cell isLink title="修改群头像">
<u-avatar slot="value" size="24" shape="square" :src="group.cover"></u-avatar> <u-avatar slot="value" size="24" shape="square" :src="group.cover"></u-avatar>
</u-cell> </u-cell>
</u-cell-group> </u-cell-group>
<view class="cells actions u-border-top"> <view class="cells actions u-border-top" v-if="loaded">
<view class="action u-border-bottom" @click="onClean">清空聊天记录</view> <view class="action u-border-bottom" @click="onClean">清空聊天记录</view>
<view class="action u-border-bottom" v-if="group.is_owner" @click="onDismiss">解散群聊</view> <view class="action u-border-bottom" v-if="group.is_owner" @click="onDismiss">解散群聊</view>
<view class="action u-border-bottom" v-else @click="onQuite">删除并退出</view> <view class="action u-border-bottom" v-else @click="onQuite">删除并退出</view>
@@ -58,16 +58,11 @@
members: [], members: [],
status: false, status: false,
isTop: false, isTop: false,
loaded: false
} }
}, },
onLoad(e) { onLoad(e) {
this.targetId = e.targetId this.targetId = e.targetId
getGroupInfo(this.targetId).then(res => {
this.group = res.group
console.log(this.group);
this.announcement = res.announcement
this.members = res.members
})
RongIMLib.getConversationNotificationStatus(this.conversationType, this.targetId, ({ RongIMLib.getConversationNotificationStatus(this.conversationType, this.targetId, ({
status status
}) => { }) => {
@@ -81,8 +76,21 @@
this.isTop = conversation.isTop this.isTop = conversation.isTop
} }
}) })
this.initData()
uni.$on('groupAnnouncementCreated', this.initData)
},
onUnload() {
uni.$off('groupAnnouncementCreated')
}, },
methods: { methods: {
initData() {
getGroupInfo(this.targetId).then(res => {
this.group = res.group
this.announcement = res.announcement
this.members = res.members
this.loaded = true
})
},
setStatus() { setStatus() {
RongIMLib.setConversationNotificationStatus(this.conversationType, this.targetId, this.status, RongIMLib.setConversationNotificationStatus(this.conversationType, this.targetId, this.status,
({ ({
@@ -132,6 +140,7 @@
icon: 'none', icon: 'none',
title: '清空成功' title: '清空成功'
}) })
uni.$emit('cleanGroupMessage')
}) })
} }
} }
@@ -178,13 +187,16 @@
width: 126rpx; width: 126rpx;
margin-left: 20rpx; margin-left: 20rpx;
margin-bottom: 20rpx; margin-bottom: 20rpx;
display: flex;
flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
.name { .name {
color: $text-gray-m;
width: 126rpx; width: 126rpx;
text-align: center; text-align: center;
font-size: 28rpx; font-size: 26rpx;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
@@ -194,7 +206,7 @@
} }
.loadmore { .loadmore {
font-size: 28rpx; font-size: 26rpx;
color: $text-gray-m; color: $text-gray-m;
text-align: center; text-align: center;
} }

View File

@@ -1,17 +1,28 @@
<template> <template>
<view class="members"> <view class="members">
<view class="users"> <view class="users">
<view class="user" v-for="(item, index) in members" :key="index" @click="toUser(item)"> <view class="user" v-if="isAdmin">
<u-avatar @click="inviteUser" size="44" shape="square" icon="plus" bg-color="#eeeeee" color="#999999">
</u-avatar>
<view class="name">邀请用户</view>
</view>
<view :class="['user', {'active': item.targetId == currentUser.targetId}]" @longpress="showAction(item)"
v-for="(item, index) in members" :key="index" @click="toUser(item)">
<u-avatar size="44" shape="square" :src="item.portraitUrl"></u-avatar> <u-avatar size="44" shape="square" :src="item.portraitUrl"></u-avatar>
<view class="name">{{ item.name }}</view> <view class="name">{{ item.name }}</view>
</view> </view>
</view> </view>
<view class="loadmore">成员总数{{ members.length }}</view>
<u-action-sheet :actions="userActions" :title="actionTitle" cancelText="取消" @close="hideAction"
@select="doAction" :show="actionShow">
</u-action-sheet>
</view> </view>
</template> </template>
<script> <script>
import { import {
getGroupInfo, getGroupBase,
getGroupUsers getGroupUsers
} from '@/apis/interfaces/im.js' } from '@/apis/interfaces/im.js'
@@ -19,23 +30,89 @@
data() { data() {
return { return {
targetId: '', targetId: '',
members: [] members: [],
isOwner: false,
isAdmin: false,
actionShow: false,
userActions: [{
type: 0,
name: '设置管理员',
disabled: false
},
{
type: 1,
name: '解除管理员',
disabled: false
},
{
type: 2,
name: '移除成员',
disabled: false
}
],
actionTitle: '',
currentUser: {}
} }
}, },
onLoad(e) { onLoad(e) {
this.targetId = e.targetId this.targetId = e.targetId
getGroupInfo(this.targetId).then(res => { getGroupBase(this.targetId).then(res => {
this.isOwner = res.is_owner
this.isAdmin = res.is_admin
if (this.isOwner) {
this.userActions.push({
type: 3,
name: '转移群主',
disabled: false
}) })
}
})
this.getUserList()
},
methods: {
getUserList() {
getGroupUsers(this.targetId).then(res => { getGroupUsers(this.targetId).then(res => {
this.members = res this.members = res
}) })
}, },
methods: {
toUser(item) { toUser(item) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/im/friends/info?targetId=' + item.targetId url: '/pages/im/friends/info?targetId=' + item.targetId
}) })
},
showAction(item) {
this.currentUser = item
this.actionTitle = item.name
this.actionShow = true
// 根据当前用户,是不是管理,来控制按钮的可用性
this.userActions[0].disabled = true
},
hideAction(item) {
this.actionShow = false
this.actionTitle = ''
this.currentUser = {}
this.userActions[0].disabled = false
this.userActions[1].disabled = false
},
doAction(e) {
switch (e.type) {
case 0:
// 设置管理
break;
case 1:
// 取消管理
break;
case 2:
// 移除成员
break;
case 3:
// 转移管理员
break;
}
this.getUserList()
},
inviteUser() {
} }
} }
} }
@@ -56,13 +133,20 @@
width: 126rpx; width: 126rpx;
margin-left: 20rpx; margin-left: 20rpx;
margin-bottom: 20rpx; margin-bottom: 20rpx;
display: flex;
flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
&.active {
background-color: $window-color;
}
.name { .name {
color: $text-gray-m;
width: 126rpx; width: 126rpx;
text-align: center; text-align: center;
font-size: 28rpx; font-size: 26rpx;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
@@ -70,5 +154,11 @@
} }
} }
} }
.loadmore {
font-size: 26rpx;
color: $text-gray-m;
text-align: center;
}
} }
</style> </style>