This commit is contained in:
Vinjor 2025-08-05 17:30:31 +08:00
commit b1866a8cdd
7 changed files with 77 additions and 39 deletions

View File

@ -95,7 +95,7 @@ public class WebSocketServer {
public void CountPerson(String count){
for (String name : webSocketSet.keySet()){
try {
webSocketSet.get(name).session.getBasicRemote().sendText(count);
webSocketSet.get(name).session.getBasicRemote().sendText("close,"+name+"退出聊天");
}catch (Exception e){
e.printStackTrace();
}

View File

@ -24,6 +24,7 @@
<result property="prodName" column="prod_name"/>
<result property="userName" column="user_name"/>
<result property="siteName" column="site_name"/>
<result property="itemJson" column="item_json"/>
</resultMap>
<sql id="selectBusiChatMainVo">

View File

@ -28,6 +28,7 @@ export default {
this.$store.dispatch('websocket_init', process.env.VUE_APP_WEBSOCKET+username)
},
mounted(){
//线
EventBus.$on('newMessage', (message) => {
this.$refs.chatFrom.openForm()
});

View File

@ -26,6 +26,14 @@ export function addChatMain(data) {
})
}
export function saveMessage(data) {
return request({
url: '/web/saveMessage',
method: 'post',
data: data
})
}
// 修改在线聊天
export function updateChatMain(data) {
return request({

View File

@ -19,7 +19,9 @@ const websocket = {
} else if (e.data.startsWith("系统通知")){
state.notice.push(e.data);
console.log(state.notice);
} else {
} else if (e.data.startsWith("close")){
console.log(e.data)
}else {
console.log(e.data,'消息内容')
//这里捕获消息
const messageData = JSON.parse(e.data)
@ -42,6 +44,9 @@ const websocket = {
},
WEBSOCKET_CLOSE(state){
state.socket.close();
},
SET_MESSAGE(state,msg){
state.message = msg
}
},
@ -54,6 +59,9 @@ const websocket = {
},
websocket_close({commit}){
commit('WEBSOCKET_CLOSE')
},
set_message({commit},msg){
commit('SET_MESSAGE',msg)
}
}
}

View File

@ -1,6 +1,6 @@
<template>
<!-- 选择产品对话框 -->
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
<el-dialog @close="close" :title="title" :visible.sync="open" width="800px" append-to-body>
<div class="dl-chat-box" >
<template v-for="(item,index) in messages">
<div v-if="item.dataFrom=='customer'" class="dl-customer-dom">
@ -13,12 +13,13 @@
</div>
</div>
<div v-if="item.dataFrom=='platform'" class="dl-platform-dom">
<div class="dl-platform-right">
<div class="dl-platform-time">{{item.createTime}}</div>
<div class="dl-platform-content">{{ item.content }}</div>
</div>
<div class="dl-platform-photo">
<img :src="picPrex+item.userImg" >
<img src="@/assets/images/customer.jpg" >
</div>
</div>
</template>
@ -36,7 +37,7 @@
</template>
<script>
import { listChatItem, getChatItem, delChatItem, addChatItem, updateChatItem } from "@/api/busi/chatItem";
import { saveMessage } from "@/api/busi/chatMain";
export default {
name: 'chatForm',
data() {
@ -52,6 +53,8 @@ export default {
pages:0,
//
text:'',
//id
chatId:'',
//
queryParams: {
mainId: null,
@ -62,40 +65,46 @@ export default {
/**
* 组件显示
*/
show(id,title) {
show(row) {
this.reset()
this.title = title?title:"聊天记录"
this.open = true
this.queryParams.mainId = id
this.getList()
console.log(row)
this.chatId = row.id
if (row.itemJson!=null) {
this.messages = JSON.parse(row.itemJson)
this.$store.dispatch('set_message',this.messages);
}
},
openForm(){
if (!this.open) {
this.open = true
this.messages = this.$store._modules.root.state.websocket.message
}
},
reset(){
this.chatItemList=[]
},
// --
cancelSelect() {
this.open = false;
},
/** 查询在线聊天记录列表 */
getList() {
listChatItem(this.queryParams).then(response => {
this.chatItemList = response.data;
});
},
/**发送消息*/
sendToServer() {
this.$store.dispatch('websocket_send',"platform," + this.text);
this.messages = this.$store._modules.root.state.websocket.message
this.text=''
},
close(){
this.open = false;
let data = {
id:this.chatId,
jsonArray:this.messages
}
saveMessage(data).then(res=>{
})
}
}
}
</script>

View File

@ -96,7 +96,7 @@
<el-table v-loading="loading" :data="chatMainList" @selection-change="handleSelectionChange">
<!-- <el-table-column type="selection" width="55" align="center" />-->
<el-table-column type="index" width="60" label="序号" align="center"/>
<el-table-column label="客户唯一编码" align="center" prop="cusCode" />
<!-- <el-table-column label="客户唯一编码" align="center" prop="cusCode" />-->
<el-table-column align="center" prop="prodName" :min-width="120">
<template slot="header" slot-scope="scope">
<span>产品名称</span>
@ -116,29 +116,39 @@
<el-table-column label="洲" align="center" prop="oceania" />
<el-table-column label="设备类型" align="center" prop="equipment"/>
<el-table-column label="负责员工" align="center" prop="userName" />
<el-table-column align="center" prop="nums" >
<template slot="header" slot-scope="scope">
<span>聊天记录数</span>
<el-tooltip class="item" effect="dark" content="鼠标单机数据可查看聊天记录"
placement="bottom"
>
<i class="el-icon-question"></i>
</el-tooltip>
</template>
<template slot-scope="scope">
<el-tag style="cursor: pointer" @click="handleDetail(scope.row)">{{scope.row.nums}}</el-tag>
</template>
</el-table-column>
<el-table-column label="最早聊天时间" align="center" prop="createTime" >
<!-- <el-table-column align="center" prop="nums" >-->
<!-- <template slot="header" slot-scope="scope">-->
<!-- <span>聊天记录数</span>-->
<!-- <el-tooltip class="item" effect="dark" content="鼠标单机数据可查看聊天记录"-->
<!-- placement="bottom"-->
<!-- >-->
<!-- <i class="el-icon-question"></i>-->
<!-- </el-tooltip>-->
<!-- </template>-->
<!-- <template slot-scope="scope">-->
<!-- <el-tag style="cursor: pointer" @click="handleDetail(scope.row)">{{scope.row.nums}}</el-tag>-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column label="最早聊天时间" width="180" align="center" prop="createTime" >
<template slot-scope="scope">
{{scope.row.createTime | formatDate}}
</template>
</el-table-column>
<el-table-column label="最近聊天时间" align="center" prop="updateTime" >
<el-table-column label="最近聊天时间" width="180" align="center" prop="updateTime" >
<template slot-scope="scope">
{{scope.row.updateTime | formatDate}}
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-s-comment"
@click="handleDetail(scope.row)"
>聊天</el-button>
</template>
</el-table-column>
</el-table>
<pagination
@ -265,7 +275,8 @@ export default {
* @param row
*/
handleDetail(row){
this.$refs.chatFrom.show(row.id,"来自"+row.national+"-"+row.cusCode+"("+row.ip+")聊天记录")
console.log(row,'sdfadsafadsf')
this.$refs.chatFrom.show(row)
}
}
};