Session.vue 7.28 KB
<template>
  <div>
    <div class="g-inherit m-main p-session">
      <group class="u-list" v-if="sessionlist.length != 0">
        <cell
                v-for="(session, index) in sessionlist"
                class="u-list-item"
                :title="session.name"
                :inline-desc="session.lastMsgShow"
                :key="session.id"
                :sessionId="session.id"
                v-touch:swipeleft="showDelBtn"
                v-touch:swiperight="hideDelBtn"
                @click.native="enterChat(session)" >
          <img class="icon u-circle" slot="icon" width="24" :src="session.avatar">
          <span class='u-session-time'>
          {{session.updateTimeShow}}
        </span>
          <span v-show="session.unread > 0 && session.unread <= 99" class="u-unread">{{session.unread}}</span>
          <span v-show="session.unread > 99" class="u-unread">...</span>
          <span
                  class="u-tag-del"
                  :class="{active: delSessionId===session.id}"
                  @click="deleteSession"
          ></span>
        </cell>
      </group>
      <div style="width:100%;height:100%;display:flex;flex-direction:column;justify-content:center;align-items:center" v-if="sessionlist.length == 0">
        <img :src="empty">
        <p style="margin-top:30px;font-size:14px;color:#a7a7a7">目前还没有任何消息哦~</p>
        <p style="margin-top:10px;font-size:16px;color:#5cb438;border-bottom:1px solid #5cb438;font-weight:bolder">来找导购聊聊吧!</p>
      </div>
    </div>
  </div>

</template>

<script>
    import util from '../utils'
    import config from '../configs'
    export default {
        data () {
            return {
                delSessionId: null,
                stopBubble: false,
                noticeIcon: config.noticeIcon,
                myPhoneIcon: config.myPhoneIcon,
                myGroupIcon: config.defaultGroupIcon,
                myAdvancedIcon: config.defaultAdvancedIcon,
                empty: '/yunxin/res/im/empty.png',
            }
        },
        computed: {
            sysMsgUnread () {
                let temp = this.$store.state.sysMsgUnread
                let sysMsgUnread = temp.addFriend || 0
                sysMsgUnread += temp.team || 0
                let customSysMsgUnread = this.$store.state.customSysMsgUnread
                return sysMsgUnread + customSysMsgUnread
            },
            userInfos () {
                return this.$store.state.userInfos
            },
            myInfo () {
                return this.$store.state.myInfo
            },
            myPhoneId () {
                return `${this.$store.state.userUID}`
            },
            sessionlist () {
                let allSession = this.$store.state.sessionlist;
                let enableSession = [];
                for(let i=0;i<allSession.length;i++){
                    if( allSession[i].scene == 'p2p' && allSession[i].lastMsg){
                        if(allSession[i].lastMsg.content){
                            let content = JSON.parse(allSession[i].lastMsg.content);
                            if(allSession[i].lastMsg.type == 'custom' && content.type == 10){
                                continue;
                            }else{
                                enableSession.push(allSession[i]);
                            }
                        }else{
                            enableSession.push(allSession[i]);
                        }
                    }
                }
                let sessionlist = enableSession.filter(item => {
                    item.name = ''
                item.avatar = ''
                if (item.scene === 'p2p') {
                    let userInfo = null
                    if (item.to !== this.myPhoneId) {
                        userInfo = this.userInfos[item.to]
                    } else {
                        // userInfo = this.myInfo
                        // userInfo.alias = '我的手机'
                        // userInfo.avatar = `${config.myPhoneIcon}`
                        return false
                    }
                    if (userInfo) {
                        item.name = util.getFriendAlias(userInfo)
                        item.avatar = userInfo.avatar
                    }
                } else if (item.scene === 'team') {
                    let teamInfo = null
                    teamInfo = this.$store.state.teamlist.find(team => {
                            return team.teamId === item.to
                        })
                    if (teamInfo) {
                        item.name = teamInfo.name
                        item.avatar = teamInfo.avatar || (teamInfo.type === 'normal' ? this.myGroupIcon : this.myAdvancedIcon)
                    } else {
                        item.name = `群${item.to}`
                        item.avatar = item.avatar || this.myGroupIcon
                    }
                }
                let lastMsg = item.lastMsg || {}
                if (lastMsg.type === 'text') {
                    item.lastMsgShow = lastMsg.text || ''
                } else if (lastMsg.type === 'custom') {
                    item.lastMsgShow = util.parseCustomMsg(lastMsg)
                } else if (lastMsg.scene === 'team' && lastMsg.type === 'notification') {
                    item.lastMsgShow = util.generateTeamSysmMsg(lastMsg)
                } else if (util.mapMsgType(lastMsg)) {
                    item.lastMsgShow = `[${util.mapMsgType(lastMsg)}]`
                } else {
                    item.lastMsgShow = ''
                }
                if (item.updateTime) {
                    item.updateTimeShow = util.formatDate(item.updateTime, true)
                }
                return item
            })
                return sessionlist
            }
        },
        methods: {
            enterSysMsgs () {//进入系统消息界面
                if (this.hideDelBtn())
                    return
                location.href = '#/sysmsgs'
            },
            enterChat (session) {//进入聊天界面
                if (this.hideDelBtn())
                    return
                if (session && session.id)
                    location.href = `#/chat/${session.id}`
            },
            enterMyChat () {//进入我的手机界面
                // 我的手机页面
                location.href = `#/chat/p2p-${this.myPhoneId}`
            },
            deleteSession () {
                if (this.delSessionId !== null) {
                    this.$store.dispatch('deleteSession', this.delSessionId)
                }
            },
            showDelBtn (vNode) {
                if (vNode && vNode.data && vNode.data.attrs) {
                    this.delSessionId = vNode.data.attrs.sessionId
                    this.stopBubble = true
                    setTimeout(() => {
                        this.stopBubble = false
                    }, 20)
                }
            },
            hideDelBtn () {
                if (this.delSessionId !== null && !this.stopBubble) {
                    // 用于判断是否前置状态是显示删除按钮
                    this.delSessionId = null
                    return true
                }
                return false
            }
        }
    }
</script>

<style type="text/css">
  .p-session {
  .vux-cell-primary {
    max-width: 70%;
  }
  }
</style>