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