conversation-list.vue
5.29 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<template>
<div class="list-container">
<div class="header-bar">
<button title="刷新列表" @click="handleRefresh">
<i class="tim-icon-refresh"></i>
</button>
<el-button icon="el-icon-mobile-phone" :round="true" title="下载APP" @click="handleDownload"/>
<!-- <button title="创建会话" @click="handleAddButtonClick">-->
<!-- <i class="tim-icon-add"></i>-->
<!-- </button>-->
</div>
<div class="scroll-container">
<conversation-item
:conversation="item"
v-for="item in conversationList"
:key="item.conversationID"
/>
</div>
<el-dialog title="快速发起会话" :visible.sync="showDialog" width="30%">
<el-input placeholder="请输入用户ID" v-model="userID" @keydown.enter.native="handleConfirm"/>
<span slot="footer" class="dialog-footer">
<el-button @click="showDialog = false">取 消</el-button>
<el-button type="primary" @click="handleConfirm">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import ConversationItem from './conversation-item'
import {mapState} from 'vuex'
export default {
name: 'ConversationList',
components: {ConversationItem},
data() {
return {
showDialog: false,
userID: '',
isCheckouting: false, // 是否正在切换会话
timeout: null
}
},
computed: {
...mapState({
conversationList: state => state.conversation.conversationList,
currentConversation: state => state.conversation.currentConversation
})
},
mounted() {
window.addEventListener('keydown', this.handleKeydown)
},
destroyed() {
window.removeEventListener('keydown', this.handleKeydown)
},
methods: {
handleRefresh() {
this.refreshConversation()()
},
refreshConversation() {
let that = this
return function () {
if (!that.timeout) {
that.timeout = setTimeout(() => {
that.timeout = null
that.tim.getConversationList().then(() => {
that.$store.commit('showMessage', {
message: '刷新成功',
type: 'success'
})
})
}, 1000)
}
}
},
handleAddButtonClick() {
this.showDialog = true
},
handleConfirm() {
if (this.userID !== '@TIM#SYSTEM') {
this.$store
.dispatch('checkoutConversation', `C2C${this.userID}`)
.then(() => {
this.showDialog = false
}).catch(() => {
this.$store.commit('showMessage', {
message: '没有找到该用户',
type: 'warning'
})
})
} else {
this.$store.commit('showMessage', {
message: '没有找到该用户',
type: 'warning'
})
}
this.userID = ''
},
handleKeydown(event) {
if (event.keyCode !== 38 && event.keyCode !== 40 || this.isCheckouting) {
return
}
const currentIndex = this.conversationList.findIndex(
item => item.conversationID === this.currentConversation.conversationID
)
if (event.keyCode === 38 && currentIndex - 1 >= 0) {
this.checkoutPrev(currentIndex)
}
if (
event.keyCode === 40 &&
currentIndex + 1 < this.conversationList.length
) {
this.checkoutNext(currentIndex)
}
},
checkoutPrev(currentIndex) {
this.isCheckouting = true
this.$store
.dispatch(
'checkoutConversation',
this.conversationList[currentIndex - 1].conversationID
)
.then(() => {
this.isCheckouting = false
})
.catch(() => {
this.isCheckouting = false
})
},
checkoutNext(currentIndex) {
this.isCheckouting = true
this.$store
.dispatch(
'checkoutConversation',
this.conversationList[currentIndex + 1].conversationID
)
.then(() => {
this.isCheckouting = false
})
.catch(() => {
this.isCheckouting = false
})
},
handleDownload() {
window.open('https://www.pgyer.com/5CqL', 'target')
}
}
}
</script>
<style lang="stylus" scoped>
.list-container
height 100%
width 100%
display flex
flex-direction column // -reverse
.header-bar
flex-shrink 0
height 50px
border-bottom 1px solid $background-deep-dark
padding 10px 10px 10px 20px
button
float right
display: inline-block;
cursor: pointer;
background $background-deep-dark
border: none
color: $font-dark;
box-sizing: border-box;
transition: .3s;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
margin: 0 10px 0 0
padding 0
width 30px
height 30px
line-height 34px
font-size: 24px;
text-align: center;
white-space: nowrap;
border-radius: 50%
outline 0
&:hover
// background $light-primary
// color $white
transform: rotate(360deg);
color $light-primary
.scroll-container
overflow-y scroll
flex 1
.bottom-circle-btn {
position: absolute;
bottom: 20px;
right: 20px;
}
.refresh {
bottom: 70px;
}
</style>