Merge branch 'master' of http://124.222.105.7:3000/dianliang/dl_site_system
This commit is contained in:
commit
cdd4faddca
@ -336,7 +336,6 @@ public class WebController extends BaseController {
|
||||
* @param busiChatMain {@link BusiChatMain}
|
||||
* @return com.ruoyi.common.core.domain.AjaxResult
|
||||
**/
|
||||
@Log(title = "在线聊天", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/chatMain")
|
||||
public AjaxResult saveChatMain(@RequestBody BusiChatMain busiChatMain, HttpServletRequest request) {
|
||||
String ip = "";
|
||||
|
@ -7,8 +7,16 @@ import java.util.Date;
|
||||
@Data
|
||||
public class Message {
|
||||
private Integer id;
|
||||
private String username;
|
||||
private String userface;
|
||||
private String text;
|
||||
private Date date;
|
||||
// private String username;
|
||||
// private String userface;
|
||||
// private String text;
|
||||
// private Date date;
|
||||
|
||||
/**发送方*/
|
||||
private String dataFrom;
|
||||
/**聊天内容*/
|
||||
private String content;
|
||||
/**创建时间*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
|
@ -10,17 +10,14 @@ public class MessageUtil {
|
||||
|
||||
public Message toMessage(String content){
|
||||
Message message = new Message();
|
||||
int id = atomicInteger.incrementAndGet();
|
||||
message.setId(id);
|
||||
String[] contents=content.split(",");
|
||||
String name=contents[0];
|
||||
String userface=contents[1];
|
||||
String text=contents[2];
|
||||
message.setUsername(name);
|
||||
message.setUserface(userface);
|
||||
message.setText(text);
|
||||
message.setDate(new Date());
|
||||
|
||||
String text=contents[1];
|
||||
int id = atomicInteger.incrementAndGet();
|
||||
message.setId(id);
|
||||
message.setDataFrom(name);
|
||||
message.setContent(text);
|
||||
message.setCreateTime(new Date());
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,6 @@ public class WebSocketServer {
|
||||
}else{
|
||||
GroupSending(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,28 +2,36 @@
|
||||
<div id="app">
|
||||
<router-view />
|
||||
<theme-picker />
|
||||
<!-- 聊天记录弹出框-->
|
||||
<chat-form ref="chatFrom"></chat-form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ThemePicker from "@/components/ThemePicker";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
import { EventBus } from '@/utils/eventBus';
|
||||
import chatForm from "@/views/busi/chatMain/chatForm";
|
||||
export default {
|
||||
name: "App",
|
||||
components: { ThemePicker },
|
||||
components: { ThemePicker,chatForm },
|
||||
data(){
|
||||
return{
|
||||
b:false,
|
||||
}
|
||||
},
|
||||
destroyed: function () { // 离开页面生命周期函数
|
||||
this.$websocket.dispatch('websocket_close');
|
||||
this.$store.dispatch('websocket_close')
|
||||
},
|
||||
created () {
|
||||
const username = Cookies.get('username')
|
||||
this.$store.dispatch('websocket_init', process.env.VUE_APP_WEBSOCKET+username)
|
||||
},
|
||||
mounted(){
|
||||
EventBus.$on('newMessage', (message) => {
|
||||
this.$refs.chatFrom.openForm()
|
||||
});
|
||||
},
|
||||
metaInfo() {
|
||||
return {
|
||||
title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title,
|
||||
@ -31,7 +39,8 @@ export default {
|
||||
return title ? `${title} - ${process.env.VUE_APP_TITLE}` : process.env.VUE_APP_TITLE
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
|
@ -37,7 +37,6 @@ import DictTag from '@/components/DictTag'
|
||||
import VueMeta from 'vue-meta'
|
||||
// 字典数据组件
|
||||
import DictData from '@/components/DictData'
|
||||
import websocket from "./store/websocket";
|
||||
|
||||
// 全局方法挂载
|
||||
Vue.prototype.getDicts = getDicts
|
||||
|
@ -1,4 +1,4 @@
|
||||
|
||||
import { EventBus } from '@/utils/eventBus';
|
||||
const websocket = {
|
||||
state: {
|
||||
socket:null,
|
||||
@ -9,25 +9,24 @@ const websocket = {
|
||||
|
||||
mutations: {
|
||||
WEBSOCKET_INIT(state,url){
|
||||
console.log(url);
|
||||
state.socket = new WebSocket(url);
|
||||
state.socket.onopen=function () {
|
||||
console.log("WebSocket连接成功");
|
||||
console.log("Websocket已连接")
|
||||
};
|
||||
state.socket.onmessage = function (e) {
|
||||
console.log(e,'接受到消息')
|
||||
if (e.data.startsWith("C")) {
|
||||
state.count = e.data;
|
||||
|
||||
}
|
||||
else if (e.data.startsWith("系统通知")){
|
||||
} else if (e.data.startsWith("系统通知")){
|
||||
state.notice.push(e.data);
|
||||
console.log(state.notice);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log(e.data,'消息内容')
|
||||
state.message.push(JSON.parse(e.data));
|
||||
// console.log(state.message);
|
||||
//这里捕获消息
|
||||
const messageData = JSON.parse(e.data)
|
||||
// 触发事件通知
|
||||
EventBus.$emit('newMessage', messageData);
|
||||
//存储消息
|
||||
state.message.push(messageData);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -1,64 +0,0 @@
|
||||
// import Vue from 'vue'
|
||||
// import Vuex from 'vuex'
|
||||
//
|
||||
// Vue.use(Vuex)
|
||||
//
|
||||
// export default new Vuex.Store({
|
||||
// //定义全局变量
|
||||
// state: {
|
||||
// websock:null,
|
||||
// message:[],
|
||||
// count:"0",
|
||||
// notice:[]
|
||||
// },
|
||||
// //改变state的值必须经过
|
||||
// mutations: {
|
||||
// WEBSOCKET_INIT(state,url){
|
||||
// console.log(url);
|
||||
// state.websock = new WebSocket(url);
|
||||
// state.websock.onopen=function () {
|
||||
// console.log("WebSocket连接成功");
|
||||
// };
|
||||
// state.websock.onmessage = function (e) {
|
||||
// if (e.data.startsWith("C")) {
|
||||
// state.count = e.data;
|
||||
//
|
||||
// }
|
||||
// else if (e.data.startsWith("系统通知")){
|
||||
// state.notice.push(e.data);
|
||||
// console.log(state.notice);
|
||||
// }
|
||||
// else {
|
||||
// state.message.push(JSON.parse(e.data));
|
||||
// // console.log(state.message);
|
||||
// }
|
||||
//
|
||||
// };
|
||||
// state.websock.onerror= function () {
|
||||
// console.log("WebSocket连接发生错误");
|
||||
// };
|
||||
// state.websock.onclose = function (e) {
|
||||
// console.log("connection closed (" + e.code + ")");
|
||||
// };
|
||||
// },
|
||||
// WEBSOCKET_SEND(state,msg){
|
||||
// state.websock.send(msg);
|
||||
// },
|
||||
// WEBSOCKET_CLOSE(state){
|
||||
// state.websock.close();
|
||||
// }
|
||||
// },
|
||||
// actions: {
|
||||
// websocket_init({commit}, url) {
|
||||
// commit('WEBSOCKET_INIT', url)
|
||||
// },
|
||||
// websocket_send({commit}, msg) {
|
||||
// commit('WEBSOCKET_SEND', msg)
|
||||
// },
|
||||
// websocket_close({commit}){
|
||||
// commit('WEBSOCKET_CLOSE')
|
||||
// }
|
||||
// },
|
||||
// modules: {
|
||||
// }
|
||||
// })
|
2
dl_vue/src/utils/eventBus.js
Normal file
2
dl_vue/src/utils/eventBus.js
Normal file
@ -0,0 +1,2 @@
|
||||
import Vue from 'vue';
|
||||
export const EventBus = new Vue();
|
@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<!-- 选择产品对话框 -->
|
||||
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
|
||||
<div class="dl-chat-box" v-infinite-scroll="nextPage" >
|
||||
<template v-for="(item,index) in chatItemList">
|
||||
<div class="dl-chat-box" >
|
||||
<template v-for="(item,index) in messages">
|
||||
<div v-if="item.dataFrom=='customer'" class="dl-customer-dom">
|
||||
<div class="dl-customer-photo">
|
||||
<img src="@/assets/images/customer.jpg" >
|
||||
@ -25,7 +25,12 @@
|
||||
|
||||
</div>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="cancelSelect">关 闭</el-button>
|
||||
<el-input type="textarea"
|
||||
class="inputT"
|
||||
placeholder="按 Enter 发送" v-model="text"
|
||||
@keyup.enter.native="sendToServer"
|
||||
></el-input>
|
||||
<el-button type="primary" icon="el-icon-s-promotion" @click="sendToServer"></el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
@ -42,9 +47,11 @@ export default {
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
// 在线聊天记录表格数据
|
||||
chatItemList: [],
|
||||
messages: [],
|
||||
//所有页数
|
||||
pages:0,
|
||||
//发送的消息
|
||||
text:'',
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
mainId: null,
|
||||
@ -62,6 +69,12 @@ export default {
|
||||
this.queryParams.mainId = id
|
||||
this.getList()
|
||||
},
|
||||
|
||||
openForm(){
|
||||
this.open = true
|
||||
this.messages = this.$store._modules.root.state.websocket.message
|
||||
},
|
||||
|
||||
reset(){
|
||||
this.chatItemList=[]
|
||||
},
|
||||
@ -76,6 +89,13 @@ export default {
|
||||
this.chatItemList = response.data;
|
||||
});
|
||||
},
|
||||
|
||||
/**发送消息*/
|
||||
sendToServer() {
|
||||
this.$store.dispatch('websocket_send',"platform," + this.text);
|
||||
this.messages = this.$store._modules.root.state.websocket.message
|
||||
this.text=''
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -157,7 +157,7 @@
|
||||
import chatForm from "@/views/busi/chatMain/chatForm";
|
||||
import { listChatMain, getChatMain, delChatMain, addChatMain, updateChatMain } from "@/api/busi/chatMain";
|
||||
import Treeselect from '@riophae/vue-treeselect'
|
||||
|
||||
import { EventBus } from '@/utils/eventBus';
|
||||
export default {
|
||||
name: "ChatMain",
|
||||
components: { chatForm},
|
||||
@ -204,6 +204,11 @@ export default {
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted(){
|
||||
EventBus.$on('newMessage', (message) => {
|
||||
this.$refs.chatFrom.openForm()
|
||||
});
|
||||
},
|
||||
created() {
|
||||
this.getList();
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user