-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
179 lines (172 loc) · 5.56 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" />
<link rel="stylesheet" type="text/css" href="css/index.css" charset="utf-8">
<title>RO Pocket</title>
</head>
<body>
<div id="root">
<div class="title">
<el-select v-model="roomName" filterable clearable remote reserve-keyword placeholder="搜索偶像" :remote-method="remoteMethod"
:loading="loading">
<el-option v-for="item in searchArr" :key="item.roomId" :label="item.name" :value="item.name">
</el-option>
</el-select>
<el-button class="title-btn" round @click="searchByName">搜索</el-button>
</div>
<div>
</div>
<div v-if="stage==='ONLINE'" class="container">
<div class="room-head">
{{roomName}}
</div>
<div class="room-box">
<div v-for="msg in filterMsgs" :key="msg.idClient" @click="inspect(msg)">
<div class="msg-item">
<img class="avatar" :src="base+msg.custom.user?.avatar" alt="">
<div class="msg-item-content">
<span class="nickName">
{{msg.custom.user?.nickName}}
</span>
<span class="time">
{{time(msg.time)}}
<!-- {{new Date(msg.time)}} -->
</span>
<div class="content">
{{msg.custom.text}}
</div>
</div>
</div>
</div>
</div>
</div>
<!-- <div id="msgs">
<div class="each" v-for="msg in msgs" :key="msg.idClient" @click="inspect(msg)">
{{msg.custom.user?.nickName}}
{{new Date(msg.time).toLocaleString()}}
<br />
{{msg.custom.text}}
</div>
</div> -->
</div>
<script src="js/NIM_Web_SDK_v8.3.5.js"></script>
<script src="js/data_people.js"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!--<script src="https://unpkg.com/vue@next"></script>-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
import parseTime from './utils/index.js'
const appKey = '632feff1f4c838541ab75195d1ceb3fa';
const chatroomAddresses = ['chatweblink01.netease.im:443'];
const roomId = '67362271';
const onwillreconnect = (...args) => { console.log('r', args); };
const onerror = (...args) => { console.log('e', args); };
new Vue({
el: '#root',
data: {
base: 'https://source.48.cn/',
chatroom: null,
stage: 'OFFLINE',
msgs: [],
roomName: '',
roomArr: [],
searchArr: [],
loading: false,
},
created() {
console.log('DataPeople', DataPeople)
},
watch: {
roomName() {
const len = this.roomName.length
this.roomArr = DataPeople.filter(people => {
return this.roomName !== '' && (people.name.includes(this.roomName) || people.abbr.slice(0, len) === this.roomName)
})
},
},
computed: {
filterMsgs() {
const a = this.msgs.filter(msg => {
return msg.custom.messageType !== 'DELETE' && msg.custom.user.roleId === 3
})
console.log('a',a)
return a
},
time() {
return function(a) {
console.log(parseTime(a))
return 1
}
}
},
methods: {
init(id) {
this.chatroom = SDK.Chatroom.getInstance({
appKey,
isAnonymous: true,
chatroomNick: 'RO',
// account: account,
// token: account,
chatroomId: id,
chatroomAddresses,
onconnect: this.onconnect.bind(this),
onwillreconnect,
ondisconnect: () => { this.stage = 'OFFLINE'; },
onerror,
onmsgs: this.onmsgs.bind(this),
});
},
onconnect() {
this.stage = 'ONLINE';
this.earlier()
},
onmsgs(msgs) {
this.msgs = [...this.msgs, ...msgs.filter(msg => !msg.resend).map(msg => ({ ...msg, custom: JSON.parse(msg.custom) }))];
},
earlier() {
this.chatroom.getHistoryMsgs({
timetag: this.msgs[0]?.time,
done: (err, obj) => {
if (err) {
console.log(err);
return;
}
const msgs = [...obj.msgs];
console.log(msgs)
msgs.reverse();
this.msgs = [...msgs.filter(msg => !msg.resend).map(msg => ({ ...msg, custom: JSON.parse(msg.custom) })), ...this.msgs];
console.log(this.msgs)
},
})
},
inspect(msg) {
console.log(JSON.parse(JSON.stringify(msg)));
},
searchByName() {
const id = this.roomArr[0].roomId
this.init(id)
},
remoteMethod(serchName) {
if (serchName !== '') {
this.loading = true;
const len = serchName.length
setTimeout(() => {
this.loading = false;
this.searchArr = DataPeople.filter(people => {
return serchName !== '' && (people.name.includes(serchName) || people.abbr.slice(0, len) === serchName)
})
}, 200)
console.log(this.searchArr)
} else {
this.searchArr = []
}
}
},
});
</script>
</body>
</html>