目录
一、创建群聊界面
界面是参考教学视频编写的;基本步骤为编写结构、调整样式、编写功能等。
部分代码如下:
设置了一个变量记录已选择的人数,判断所选人数大于0且输入了群名称(群名称长度大于0)后创建按钮才不为灰;
<view class="bottom-btn btn1" :class="{notselected:selectedNumber<=0||groupname.length<=0}">创建({{selectedNumber}})</view>
.name{}中后半部分是用于限制内容呈现行数;
.name{
padding-left: 32rpx;
font-size: 36rpx;
color:$uni-text-color;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
}
<template>
<view class="content">
<view class="top-bar">
<view class="top-bar-left" @tap="backOne()">
<view class="text">取消</view>
</view>
<view class="top-bar-center">
<view class="title" style="padding-left: 210rpx;">
创建群聊
</view>
</view>
</view>
<view class="main">
<view class="top">
<view class="group-name">
<input class="group-name-input" type="text" placeholder="请输入群名称" placeholder-style="color:#aaa;" v-model="groupname"/>
</view>
<view class="title">好友</view>
</view>
<view class="friends">
<view class="user" v-for="(item,index) in friendList" :key="index" @tap="selectFriend(index)">
<view class="selected" :class="{isselected:item.selected}">
<image src="../../static/images/common/select.png" v-if="item.selected" class="selected-img"></image>
</view>
<image class="user-img" :src="item.profile.avatar"></image>
<view class="name" v-if="item.profile.nick != ''">{{item.profile.nick}}({{item.profile.userID}})</view>
<view class="name" v-if="item.profile.nick == ''">未设置昵称({{item.profile.userID}})</view>
</view>
</view>
</view>
<view class="bottom-bar">
<view class="bottom-btn btn1" :class="{notselected:selectedNumber<=0||groupname.length<=0}" @tap="createGroup()">创建(已选{{selectedNumber}})</view>
</view>
</view>
</template>
二、搜索/加入群聊界面
通过修改创建群聊界面下方样式,当输入的ID能够查找到相应群聊时,能够展示消息信息,
<template>
<view class="content">
<view class="top-bar">
<view class="top-bar-left" @tap="backOne()">
<view class="text">取消</view>
</view>
<view class="top-bar-center">
<view class="title" style="padding-left: 210rpx;">
加入群聊
</view>
</view>
</view>
<view class="main">
<view class="top">
<view class="group-name">
<input class="group-name-input" type="text" placeholder="请输入群ID" placeholder-style="color:#aaa;" v-model="groupname" @input="searchGroup()"/>
</view>
<view class="searchtip">
<view v-if="searchtip!=''">{{searchtip}}</view>
</view>
</view>
<view class='groupmsg' v-if="issearched==true">
<view class="groupface">
<image class="face" :src="info.avatar"></image>
</view>
<view class="groupdetail">
<view class="groupname">{{info.name}}</view>
<view class="groupid">{{info.groupID}}</view>
<view class="grouptime">{{changeTime(info.createTime*1000)}}</view>
</view>
</view>
</view>
<view class="bottom-bar">
<view class="bottom-btn btn1" :class="{notselected:false}" @tap="joinGroup()">加入</view>
</view>
</view>
</template>
.group-name{
padding-left: 20rpx;
padding-right: 20rpx;
}
.searchtip{
padding-left: 40rpx;
color:$uni-color-error;
}
.group-name-input{
text-align: center;
height: 76rpx;
background:$uni-bg-color-grey;
border-radius: 46rpx;
font-size: 32rpx;
color:$uni-text-color;
}
三、群详情界面
参考了用户详情,并考虑到群组的不同,在增加群名、成员列表展示列。并为相应部分添加修改功能(管理群成员、邀请、修改资料等)。
部分代码:
<template>
<view>
<view class="top-bar">
<view class="top-bar-left" @tap="backOne()">
<image class="back-img" src="../../static/images/common/back.png"></image>
</view>
</view>
<view class="top-bar secbar" :animation="animationData1">
<view class="top-bar-left" @tap="backOne()">
<image class="back-img" src="../../static/images/common/back.png"></image>
</view>
</view>
<view class="main">
<view class="main-inner">
<uni-card :is-shadow="true">
<uni-list-item :title="groupProfile.name"
:thumb="groupProfile.avatar"
thumb-size="lg" :rightText="changeTime(groupProfile.createTime * 1000)" />
</uni-card>
<uni-card :is-shadow="true">
<view class="member">
<view class="member-top">
<view class="title">群成员</view>
<view class="more" @tap="manageChange()" v-if="info.userID == groupProfile.ownerID">管理群成员</view>
<view class="more" @tap="manageChange()" v-if="info.userID != groupProfile.ownerID">查看群成员</view>
<image src="../../static/images/common/more.png" mode="aspectFit" class="more-img" v-if="info.userID == groupProfile.ownerID"></image>
</view>
<view class="member-ls" v-if="info.userID == groupProfile.ownerID">
<view class="member-one" v-if="membermanage == false">
<u-avatar-group
:urls="avatarList"
size="60"
gap="0.4"
></u-avatar-group>
</view>
<view class="member-one" style="margin-left: 300rpx;" v-if="membermanage == false">
<view class="imgs">
<image src="../../static/images/index/add.png" mode="aspectFill" class="user-add" @tap="open('t-invite','邀请','',true)"></image>
</view>
</view>
<view v-if="membermanage == true">
<view v-for="(item,index) in memberList" :key="index">
<view style="display: flex;margin-top: 20rpx;">
<view style="width: 120rpx;display: flex;">
<view><u-avatar :src="item.avatar" shape="circle" size="100rpx"></u-avatar></view>
</view>
<view style="width: 500rpx;display: flex;padding-top: 25rpx; padding-left:20rpx;">
<view class="name" v-if="item.nameCard != ''">{{item.nameCard}}</view>
<view class="name" v-if="item.nameCard == '' && item.nick != ''">{{item.nick}}</view>
<view class="name" v-if="item.nameCard == '' && item.nick == ''">{{item.userID}}</view>
</view>
<view><u-button type="error" text="移除" @click="deleteGroupMember(item.userID,item.nick)"></u-button></view>
</view>
</view>
</view>
</view>
<view class="member-ls" v-if="info.userID != groupProfile.ownerID">
<view class="member-one" v-if="membermanage == false">
<u-avatar-group
:urls="avatarList"
size="60"
gap="0.4"
></u-avatar-group>
</view>
<view class="member-one" style="margin-left: 300rpx;" v-if="membermanage == false">
<view class="imgs">
<image src="../../static/images/index/add.png" mode="aspectFill" class="user-add" @tap="open('t-invite','邀请','',true)"></image>
</view>
</view>
<view v-if="membermanage == true">
<view v-for="(item,index) in memberList" :key="index">
<view style="display: flex;margin-top: 20rpx;">
<view style="width: 120rpx;display: flex;">
<view><u-avatar :src="item.avatar" shape="circle" size="100rpx"></u-avatar></view>
</view>
<view style="width: 500rpx;display: flex;padding-top: 25rpx; padding-left:20rpx;">
<view class="name" v-if="item.nameCard != ''">{{item.nameCard}}</view>
<view class="name" v-if="item.nameCard == '' && item.nick != ''">{{item.nick}}</view>
<view class="name" v-if="item.nameCard == '' && item.nick == ''">{{item.userID}}</view>
</view>
<!-- <view><u-button type="error" text="移除" @click="deleteGroupMember(item.userID,item.nick)"></u-button></view> -->
</view>
</view>
</view>
</view>
<view class="clear"></view>
</view>
</uni-card>
<uni-card :is-shadow="true">
<view class="group-msg">
<view class="row">
<view class="title">群头像</view>
<view class="cont">
<view class="user-head">
<image :src="groupProfile.avatar" @tap="upload" class="group-img" v-if="groupProfile.ownerID == groupProfile.selfInfo.userID"></image>
<image :src="groupProfile.avatar" class="group-img" v-if="groupProfile.ownerID != groupProfile.selfInfo.userID"></image>
</view>
<!-- <image :src="faceImg" class="group-img" mode="aspectFill"></image> -->
</view>
<view class="more">
<image src="../../static/images/common/more.png" mode="aspectFit"></image>
</view>
</view>
<view class="row">
<view class="title">群Id</view>
<view class="cont" @click="copy(groupProfile.groupID)">{{groupProfile.groupID}}</view>
<view class="more">
<image src="../../static/images/common/more.png" mode="aspectFit"></image>
</view>
</view>
<view class="row" @tap="open('t-name','群名称',groupProfile.name,true)" v-if="groupProfile.ownerID == groupProfile.selfInfo.userID">
<view class="title">群名称</view>
<view class="cont">{{groupProfile.name}}</view>
<view class="more">
<image src="../../static/images/common/more.png" mode="aspectFit"></image>
</view>
</view>
<view class="row" v-if="groupProfile.ownerID != groupProfile.selfInfo.userID">
<view class="title">群名称</view>
<view class="cont">{{groupProfile.name}}</view>
<view class="more">
<image src="../../static/images/common/more.png" mode="aspectFit"></image>
</view>
</view>
<view class="row" @tap="open('t-introduction','群介绍',groupProfile.introduction,true)" v-if="groupProfile.ownerID == groupProfile.selfInfo.userID">
<view class="title">群简介</view>
<view class="cont">{{groupProfile.introduction}}</view>
<view class="more">
<image src="../../static/images/common/more.png" mode="aspectFit"></image>
</view>
</view>
<view class="row" v-if="groupProfile.ownerID != groupProfile.selfInfo.userID">
<view class="title">群简介</view>
<view class="cont">{{groupProfile.introduction}}</view>
<view class="more">
<image src="../../static/images/common/more.png" mode="aspectFit"></image>
</view>
</view>
<view class="row" @tap="open('t-notice','群公告',groupProfile.notification,true)" v-if="groupProfile.ownerID == groupProfile.selfInfo.userID">
<view class="title">群公告</view>
<view class="cont">{{groupProfile.notification}}</view>
<view class="more">
<image src="../../static/images/common/more.png" mode="aspectFit"></image>
</view>
</view>
<view class="row" v-if="groupProfile.ownerID != groupProfile.selfInfo.userID">
<view class="title">群公告</view>
<view class="cont">{{groupProfile.notification}}</view>
<view class="more">
<image src="../../static/images/common/more.png" mode="aspectFit"></image>
</view>
</view>
<view class="row" @tap="open('t-nicknameingroup','群昵称',groupProfile.selfInfo.nameCard,true)">
<view class="title">群昵称</view>
<view class="cont">{{groupProfile.selfInfo.nameCard}}</view>
<view class="more">
<image src="../../static/images/common/more.png" mode="aspectFit"></image>
</view>
</view>
</view>
</uni-card>
<view class="btn2-container">
<view class="btn2" @tap="breakup()" v-if="groupProfile.ownerID == groupProfile.selfInfo.userID">解散群</view>
<view class="btn2" @tap="exit()" v-if="groupProfile.ownerID != groupProfile.selfInfo.userID">退出群</view>
</view>
</view>
</view>
<view class="modify":style="{bottom:-+widHeight+'px'}" :animation="animationData">
<view class="modify-header">
<view class="close" @tap="modify">取消</view>
</view>
<view class="modify-main">
<scroll-view scroll-x="true" >
<view v-for="(item,index) in memberList" :key="index">
<view style="display: flex;margin-top: 20rpx;">
<view style="width: 120rpx;display: flex;">
<view><u-avatar :src="item.avatar" shape="circle" size="100rpx"></u-avatar></view>
</view>
<view style="width: 500rpx;display: flex;padding-top: 25rpx; padding-left:20rpx;">
<view class="name" v-if="item.nameCard != ''">{{item.nameCard}}</view>
<view class="name" v-if="item.nameCard == '' && item.nick != ''">{{item.nick}}</view>
<view class="name" v-if="item.nameCard == '' && item.nick == ''">{{item.userID}}</view>
</view>
<view><u-button type="error" text="移除" @click="deleteGroupMember(item.userID,item.nick)"></u-button></view>
</view>
</view>
</scroll-view>
</view>
</view>
<uni-popup ref="popup" type="dialog">
<uni-popup-dialog mode="input" v-model="data" :title="modifyTitle" :placeholder="'请输入' + modifyTitle" :duration="2000" :before-close="true" @close="close" @confirm="textconfirm"></uni-popup-dialog>
</uni-popup>
</view>
</template>
群主界面:
普通成员界面: