page.js
1.46 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
import config from '../configs'
const pageMap = {
'login': config.loginUrl,
'regist': config.registUrl,
}
var scrollTimer = null
var page = {
// 切换页面,并错误提示
turnPage: (message, url) => {
if (message) {
alert(message)
}
if (url) {
if (pageMap[url]) {
url = pageMap[url]
}
window.location.href = url
}
},
// 确定导航tab页,是否show nav
showNav: path => {
switch (path) {
case '/':
return true
case '/session':
return true
case '/contacts':
return true
case '/room':
return true
case '/general':
return true
default:
return false
}
},
// 滚动聊天列表到底部
scrollChatListDown: (pos, initCount) => {
let dom = document.getElementById('chat-list')
if (!dom) {
return
}
let maxCount = 5
initCount = initCount || 1
if (typeof pos !== 'number') {
pos = Math.max(dom.scrollHeight - dom.clientHeight, 888888)
}
dom.scrollTop = pos
if ((dom.scrollTop < pos) && (initCount < maxCount)) {
clearTimeout(scrollTimer)
scrollTimer = setTimeout(() => {
initCount++
page.scrollChatListDown(pos, initCount)
}, 200)
}
},
getChatListHeight: () => {
return document.getElementById('chat-list').scrollHeight
},
getChatListScroll: () => {
return document.getElementById('chat-list').scrollTop
},
}
export default page