在线聊天
This commit is contained in:
parent
e770d2dc19
commit
3a88754647
@ -295,7 +295,7 @@ export default {
|
|||||||
},
|
},
|
||||||
/**打开聊天窗口,并建立连接*/
|
/**打开聊天窗口,并建立连接*/
|
||||||
chat(){
|
chat(){
|
||||||
this.$refs.chatFrom.show()
|
this.$refs.chatFrom.show(this.prodDetail.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,12 +68,13 @@ export default {
|
|||||||
text: null,
|
text: null,
|
||||||
//聊天信息
|
//聊天信息
|
||||||
chatMain: {},
|
chatMain: {},
|
||||||
|
//产品id
|
||||||
|
productId:'',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
// 离开页面生命周期函数
|
// 离开页面生命周期函数
|
||||||
this.$store.dispatch('modules/websocket/websocket_close')
|
this.$store.dispatch('modules/websocket/websocket_close')
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -82,6 +83,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
/**用户列表*/
|
/**用户列表*/
|
||||||
getUserList() {
|
getUserList() {
|
||||||
|
|
||||||
@ -90,15 +92,14 @@ export default {
|
|||||||
/**
|
/**
|
||||||
* 组件显示
|
* 组件显示
|
||||||
*/
|
*/
|
||||||
show() {
|
show(id) {
|
||||||
this.open = true
|
this.open = true
|
||||||
this.getChatMain()
|
this.getChatMain(id)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**获取原有聊天记录*/
|
/**获取原有聊天记录*/
|
||||||
getChatMain() {
|
getChatMain(id) {
|
||||||
//获取当前浏览器唯一id
|
console.log(id,'prodId')
|
||||||
// this.$store.dispatch('modules/websocket/websocket_send', murmur + ',userface,hello');
|
|
||||||
//获取当前浏览器唯一id
|
//获取当前浏览器唯一id
|
||||||
Fingerprint2.get((components) => {
|
Fingerprint2.get((components) => {
|
||||||
const values = components.map((component) => component.value);
|
const values = components.map((component) => component.value);
|
||||||
@ -106,11 +107,16 @@ export default {
|
|||||||
const data = {
|
const data = {
|
||||||
cusCode: fingerprintHash,
|
cusCode: fingerprintHash,
|
||||||
tenantId: 'main',
|
tenantId: 'main',
|
||||||
|
prodId:id
|
||||||
};
|
};
|
||||||
// 这里使用箭头函数,确保 `this` 指向当前 Vue 实例
|
// 这里使用箭头函数,确保 `this` 指向当前 Vue 实例
|
||||||
this.$axios.$post('/web/chatMain', data).then((res) => {
|
this.$axios.$post('/web/chatMain', data).then((res) => {
|
||||||
if (res.id != null) {
|
if (res.id != null) {
|
||||||
this.chatMain = res;
|
this.chatMain = res;
|
||||||
|
if (this.chatMain.jsonArray != null){
|
||||||
|
this.message = this.chatMain.jsonArray
|
||||||
|
this.$store.dispatch('modules/websocket/set_message',this.chatMain.jsonArray);
|
||||||
|
}
|
||||||
const websocketUrl = process.env.NUXT_ENV.VUE_APP_WEBSOCKET+`${fingerprintHash}`;
|
const websocketUrl = process.env.NUXT_ENV.VUE_APP_WEBSOCKET+`${fingerprintHash}`;
|
||||||
// 调用Vuex dispatch,初始化WebSocket
|
// 调用Vuex dispatch,初始化WebSocket
|
||||||
this.$store.dispatch('modules/websocket/websocket_init', websocketUrl)
|
this.$store.dispatch('modules/websocket/websocket_init', websocketUrl)
|
||||||
@ -131,7 +137,16 @@ export default {
|
|||||||
|
|
||||||
/**弹窗关闭方法*/
|
/**弹窗关闭方法*/
|
||||||
close() {
|
close() {
|
||||||
|
console.log(this.chatMain,'this.chatMain')
|
||||||
this.$store.dispatch('modules/websocket/websocket_close')
|
this.$store.dispatch('modules/websocket/websocket_close')
|
||||||
|
let data = {
|
||||||
|
id:this.chatMain.id,
|
||||||
|
jsonArray:this.message
|
||||||
|
}
|
||||||
|
//关闭时将消息保存到数据库
|
||||||
|
this.$axios.$post('/web/saveMessage', data).then((res)=>{
|
||||||
|
console.log(res)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/**发送消息*/
|
/**发送消息*/
|
||||||
|
@ -42,6 +42,9 @@ export const mutations = {
|
|||||||
state.socket.close();
|
state.socket.close();
|
||||||
state.socket = null;
|
state.socket = null;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
SET_MESSAGE(state,msg){
|
||||||
|
state.messages = msg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,5 +57,8 @@ export const actions = {
|
|||||||
},
|
},
|
||||||
websocket_close({commit}){
|
websocket_close({commit}){
|
||||||
commit('WEBSOCKET_CLOSE')
|
commit('WEBSOCKET_CLOSE')
|
||||||
|
},
|
||||||
|
set_message({commit},msg){
|
||||||
|
commit('SET_MESSAGE',msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user