在线聊天

This commit is contained in:
PQZ 2025-08-04 17:43:57 +08:00
parent e770d2dc19
commit 3a88754647
3 changed files with 29 additions and 8 deletions

View File

@ -295,7 +295,7 @@ export default {
},
/**打开聊天窗口,并建立连接*/
chat(){
this.$refs.chatFrom.show()
this.$refs.chatFrom.show(this.prodDetail.id)
}
}
}

View File

@ -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 dispatchWebSocket
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)
})
},
/**发送消息*/

View File

@ -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)
}
}