123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <template>
- <view class="message">
- <view class="message-system" @click="$navigateTo('/pages/messageSystem/messageSystem')">
- <uni-badge class="uni-badge-left-margin" :text="systemCount" absolute="rightTop" size="small">
- <view class="message-system-icon">
- <uni-icons type="email-filled" size="30" color="#fff"></uni-icons>
- </view>
- </uni-badge>
- <view class="message-content">
- <view class="message-title">系统通知</view>
- <view class="message-sub-content">
- {{systemCount === 0 ?'暂无消息通知' : `您有${systemCount}条未读消息,请点击查看~`}}
- </view>
- </view>
- </view>
- <view class="message-titles">即时会话</view>
- <mescroll-empty :option="option" v-if="chatList.length === 0" @emptyclick="$navigateTo('/pages/login/login')">
- </mescroll-empty>
- <view class="message-list" v-else>
- <!-- 消息提示 -->
- <view class="message-item" v-for="(item,index) in chatList" :key="index" @click="linkTo(item)">
- <uni-badge class="uni-badge-left-margin" :text="item.unread" absolute="rightTop" size="small">
- <image :src="item.userInfo.avatarUrl" class="message-image" mode="aspectFill">
- </image>
- </uni-badge>
- <view class="message-content">
- <view class="message-title">{{item.userInfo.nickname}}</view>
- <view class="message-sub-content">
- {{item.lastMessage.type === 'image'?'[图片]':item.lastMessage.body.text}}
- </view>
- </view>
- <view class="message-date">
- <uni-dateformat class="visitor-time" :date="item.updatedAt || item.createdAt"
- :threshold="[60000,3600000 * 24 * 365]">
- </uni-dateformat>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import {
- YeIMUniSDK,
- YeIMUniSDKDefines
- } from '@/uni_modules/wzJun1-YeIM-Uni-SDK/js_sdk/yeim-uni-sdk.min.js'
- import {
- getMessageTest
- } from '@/request/api/message.js'
- export default {
- data() {
- return {
- chatList: [],
- option: {
- tip: '暂无会话'
- },
- systemCount: 0,
- systemDate: ''
- }
- },
- onLoad() {
- uni.$on('changeChatList', this.countNumber);
- },
- onShow() {
- if (!uni.getStorageSync('token')) {
- this.chatList = [];
- this.option = {
- tip: '暂未登录',
- btnText: '点击登录'
- }
- } else {
- this.option = {
- tip: '暂无会话'
- }
- this.$chat.listenerList();
- this.init();
- }
- },
- methods: {
- init() {
- this.$chat.getConversationList(data => {
- this.countNumber(data.data);
- });
- },
- countNumber(data) {
- this.chatList = data.filter(node => node.conversationId !== 'system');
- getMessageTest(this.$store.getters.user.userId).then(res => {
- if (res.code == 200) {
- let num = 0;
- for (var i = 0; i < res.data.length; i++) {
- num += res.data[i].count
- }
- this.systemCount = num;
- this.unread();
- }
- });
- },
- linkTo(item) {
- this.$chat.clearConversationUnread(item.conversationId);
- this.$navigateTo('/pages/chat/chat?userId=' + item.conversationId + '&userName=' + item.userInfo.nickname)
- },
- unread() {
- let badge = this.systemCount;
- let list = this.chatList;
- for (let i = 0; i < list.length; i++) {
- badge += list[i].unread
- }
- if (!badge) {
- uni.removeTabBarBadge({
- index: 1
- })
- } else {
- uni.setTabBarBadge({
- index: 1,
- text: String(badge)
- })
- }
- }
- }
- }
- </script>
- <style lang="scss">
- .message {
- .message-system {
- background: #fff;
- display: flex;
- padding: 24rpx 30rpx;
- position: relative;
- margin-top: 30rpx;
- .message-image {
- width: 100rpx;
- height: 100rpx;
- border-radius: 16rpx;
- overflow: hidden;
- }
- .message-content {
- flex: 1;
- width: 0;
- margin-left: 20rpx;
- display: flex;
- flex-direction: column;
- justify-content: center;
- }
- .message-title {
- font-size: 32rpx;
- font-weight: 600;
- margin-bottom: 10rpx;
- }
- .message-sub-content {
- font-weight: 300;
- color: $uni-secondary-color;
- }
- .message-system-icon {
- width: 100rpx;
- height: 100rpx;
- border-radius: 16rpx;
- text-align: center;
- line-height: 100rpx;
- background: $uni-primary;
- }
- }
- .message-titles {
- font-weight: 300;
- padding: 30rpx 30rpx 10rpx 30rpx;
- }
- .message-list {
- .message-item {
- background: #fff;
- display: flex;
- padding: 24rpx 30rpx;
- position: relative;
- &::before {
- content: '';
- position: absolute;
- bottom: 0;
- right: 0;
- left: 150rpx;
- height: 2rpx;
- background: $uni-border-1;
- }
- }
- .message-image {
- width: 100rpx;
- height: 100rpx;
- border-radius: 16rpx;
- overflow: hidden;
- }
- .message-content {
- flex: 1;
- width: 0;
- margin-left: 20rpx;
- display: flex;
- flex-direction: column;
- justify-content: center;
- }
- .message-title {
- font-size: 32rpx;
- font-weight: 600;
- margin-bottom: 10rpx;
- }
- .message-sub-content {
- font-weight: 300;
- color: $uni-secondary-color;
- }
- .message-date {
- position: absolute;
- top: 34rpx;
- right: 30rpx;
- font-size: 24rpx;
- font-weight: 300;
- color: $uni-secondary-color;
- }
- }
- }
- </style>
|