Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjme committed Nov 8, 2017
1 parent 1372b92 commit aff4160
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
27 changes: 17 additions & 10 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<script>
import ReconnectWebsocket from "./ReconnectWebsocket";
import { scrollBottom } from "./help";
export default {
name: "app",
Expand All @@ -24,13 +25,15 @@ export default {
this.contacts[index].msgs.push(msg);
}
});
scrollBottom();
},
newMsgFromServer: function(msg) {
this.contacts.map((item, index) => {
if (item.token === msg.from) {
this.contacts[index].msgs.push(msg);
}
});
scrollBottom();
},
sendMsg: function(msg) {
this.ws.send(JSON.stringify(msg));
Expand All @@ -40,14 +43,16 @@ export default {
data.map(item => {
item.msgs = [];
this.contacts.push(item);
this.loadHistory(userToken, item.token);
});
});
},
loadHistory: function(accToken, withAccToken) {
console.warn("load history");
let sinceId = 999999999;
this.contacts.map((item, index) => {
if (item.token === accToken) {
if (item.token === withAccToken) {
console.warn("item,message", item);
if (item.msgs[0] !== undefined) {
sinceId = item.msgs[0].id;
console.warn("sinceId", sinceId);
Expand Down Expand Up @@ -97,15 +102,17 @@ export default {
}
if (msg.type == "imAction") {
console.warn("action");
let msgs = msg.data;
let contactIndex;
this.contacts.map((item, index) => {
if (item.token == msg.withAccToken) {
contactIndex = index;
}
});
msgs.reverse();
this.contacts[contactIndex].msgs.unshift(...msgs);
if (msg.data.length > 0) {
let msgs = msg.data;
let contactIndex;
this.contacts.map((item, index) => {
if (item.token == msg.withAccToken) {
contactIndex = index;
}
});
msgs.reverse();
this.contacts[contactIndex].msgs.unshift(...msgs);
}
}
};
Expand Down
9 changes: 9 additions & 0 deletions src/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function scrollBottom() {
setTimeout(()=>{

let chatLists = document.getElementById('chat-messages');
chatLists.scrollTop = chatLists.scrollHeight;
},100)
console.warn('scrollBottom');

}
8 changes: 3 additions & 5 deletions src/route/chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</template>

<script>
import {scrollBottom} from "../../help";
export default {
name: "chat",
props: ["contacts", "newMsg", "sendMsg", "loadHistory"],
Expand All @@ -48,7 +49,7 @@ export default {
methods: {
handleScroll: function() {
let chatMessages = document.getElementById("chat-messages");
if ((chatMessages.scrollTop = 0)) {
if ((chatMessages.scrollTop == 0)) {
this.loadHistory(this.from, this.to);
}
},
Expand Down Expand Up @@ -113,10 +114,7 @@ export default {
msgs = item.msgs;
}
});
if (document.getElementById("chat-messages") != null) {
document.getElementById("chat-messages").scrollTop =
document.getElementById("chat-messages").scrollHeight + 200;
}
scrollBottom();
return msgs;
},
profile: function profile() {
Expand Down

0 comments on commit aff4160

Please sign in to comment.