Session.vue
7.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<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>