|
@@ -20,7 +20,6 @@
|
|
|
:mine="mine"
|
|
|
:ext="ext"
|
|
|
:max-size="maxSize"
|
|
|
- :action="action"
|
|
|
:history="history"
|
|
|
:upload-name="uploadName"
|
|
|
:store="store"/>
|
|
@@ -40,8 +39,8 @@
|
|
|
import { device, typeOf } from '@/utils/utils'
|
|
|
import storage from '@/utils/storage'
|
|
|
import IMStore from '@/store/store'
|
|
|
- import {list,getMine,getHistory} from '@/api/webim/index'
|
|
|
- import '@/dist/vue-im.min.js'
|
|
|
+ import {list,getMine,getHistory,getChatlog} from '@/api/webim/index'
|
|
|
+
|
|
|
|
|
|
export default {
|
|
|
name: 'vue-im',
|
|
@@ -88,7 +87,6 @@
|
|
|
return []
|
|
|
}
|
|
|
},
|
|
|
- action: '/webim/sendFileMessage',
|
|
|
uploadName: {
|
|
|
type: String,
|
|
|
default: 'image'
|
|
@@ -144,7 +142,8 @@
|
|
|
},
|
|
|
websocketonmessage: function (e) {
|
|
|
console.log(e.data);
|
|
|
- this.message = eval('('+e.data+')');
|
|
|
+ this
|
|
|
+ this.message = eval('(' + e.data + ')');
|
|
|
this.getMessage(this.message);
|
|
|
},
|
|
|
websocketclose: function (e) {
|
|
@@ -161,44 +160,29 @@
|
|
|
},
|
|
|
getHistory(id){
|
|
|
const self = this
|
|
|
- getHistory(id).then(function (response) {
|
|
|
+ getChatlog(id).then(function (response) {
|
|
|
let history = response.data
|
|
|
- return history
|
|
|
- })
|
|
|
- },
|
|
|
- fetchUserList () {
|
|
|
- const self = this
|
|
|
- list().then(function (response) {
|
|
|
- let lists = response.data
|
|
|
- self.lists = lists
|
|
|
- })
|
|
|
- },
|
|
|
- initIM () {
|
|
|
- if (!this.mine || !this.mine.id) {
|
|
|
- return
|
|
|
- } else {
|
|
|
- this.store.states.mine = this.mine
|
|
|
- this.store.commit('updateUserInfoCenter', this.mine)
|
|
|
+ debugger
|
|
|
const localData = storage.readData('iminfo')
|
|
|
let currentChat = storage.readData('currentChat')
|
|
|
- if (currentChat && currentChat.hostId === this.mine.id) {
|
|
|
- this.store.commit('setCurrentChat', currentChat)
|
|
|
+ if (currentChat && currentChat.hostId === id) {
|
|
|
+ self.store.commit('setCurrentChat', currentChat)
|
|
|
} else {
|
|
|
- this.store.commit('setCurrentChat', null)
|
|
|
+ self.store.commit('setCurrentChat', null)
|
|
|
}
|
|
|
- if (this.brief && this.chat && this.chat.id) {
|
|
|
- this.chat.type = this.chat.type || 'friend'
|
|
|
- currentChat = this.chat
|
|
|
- this.store.commit('updateUserInfoCenter', this.chat)
|
|
|
- this.store.commit('setCurrentChat', this.chat)
|
|
|
- this.store.commit('setCurrentTab', 'chat')
|
|
|
+ if (self.brief && self.chat && self.chat.id) {
|
|
|
+ self.chat.type = self.chat.type || 'friend'
|
|
|
+ currentChat = self.chat
|
|
|
+ self.store.commit('updateUserInfoCenter', self.chat)
|
|
|
+ self.store.commit('setCurrentChat', self.chat)
|
|
|
+ self.store.commit('setCurrentTab', 'chat')
|
|
|
}
|
|
|
let tempData = {
|
|
|
- avatar: this.mine.avatar,
|
|
|
- id: this.mine.id,
|
|
|
- username: this.mine.username
|
|
|
+ avatar: self.mine.avatar,
|
|
|
+ id: self.mine.id,
|
|
|
+ username: self.mine.username
|
|
|
}
|
|
|
- if (localData && localData.id === this.mine.id) {
|
|
|
+ if (localData && localData.id === self.mine.id) {
|
|
|
tempData.history = localData.history
|
|
|
tempData.chatList = localData.chatList
|
|
|
} else {
|
|
@@ -209,14 +193,32 @@
|
|
|
let chatLogsList = tempData.chatList
|
|
|
if (currentChat !== null && currentChat !== undefined) {
|
|
|
const flag = chatLogsList.find(item => {
|
|
|
- return item.id === currentChat.id
|
|
|
+ return item.id == currentChat.id.toString()
|
|
|
})
|
|
|
if (!flag) {
|
|
|
chatLogsList.unshift(currentChat)
|
|
|
}
|
|
|
}
|
|
|
- this.store.commit('setLocalHistory', tempData.history)
|
|
|
- this.store.commit('updateChatLogsList', chatLogsList)
|
|
|
+ self.store.commit('setLocalHistory', tempData.history)
|
|
|
+ self.store.commit('updateChatLogsList', chatLogsList)
|
|
|
+ self.history=history
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fetchUserList () {
|
|
|
+ const self = this
|
|
|
+ list().then(function (response) {
|
|
|
+ let lists = response.data
|
|
|
+ self.lists = lists
|
|
|
+ })
|
|
|
+ },
|
|
|
+ initIM () {
|
|
|
+ if (!this.mine || !this.mine.id) {
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ this.store.states.mine = this.mine
|
|
|
+ this.store.commit('updateUserInfoCenter', this.mine)
|
|
|
+
|
|
|
+ this.getHistory(this.mine.id)
|
|
|
}
|
|
|
this.initWebSocket()
|
|
|
},
|
|
@@ -224,6 +226,9 @@
|
|
|
this.$emit('on-send', message)
|
|
|
},
|
|
|
getMessage (message) {
|
|
|
+ if(message.chatlogType=="file"){
|
|
|
+ message.content=eval('(' + message.content + ')')
|
|
|
+ }
|
|
|
this.handleVoice()
|
|
|
this.store.commit('getNewMsg', message)
|
|
|
message.username = message.sendername
|
|
@@ -325,8 +330,11 @@
|
|
|
</script>
|
|
|
<style lang="scss">
|
|
|
.wrapper {
|
|
|
- width: 100%;
|
|
|
+ /*width: 100%;*/
|
|
|
height: 100%;
|
|
|
+ margin: 12px;
|
|
|
+ background: #fff;
|
|
|
+ padding: 20px;
|
|
|
::-webkit-scrollbar {
|
|
|
width: 5px;
|
|
|
height: 12px;
|