在线聊天

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(){ chat(){
this.$refs.chatFrom.show() this.$refs.chatFrom.show(this.prodDetail.id)
} }
} }
} }

View File

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

View File

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