李昌恒 пре 6 година
родитељ
комит
76ab40d436

+ 148 - 8
service/src/App.vue

@@ -19,7 +19,9 @@ export default {
       timeout:10000,          //10s一次心跳检测
       timeoutObj:null,
       serverTimeoutObj:null,
-      apiToken:''
+      apiToken:'',
+      linkfailure:true,
+
     }
   },
   methods:{
@@ -50,24 +52,152 @@ export default {
     //连接关闭触发
     socket_close(e){  
       console.log('断开连接',e);
-      this.init()
+      //this.init()
+      this.reconnect();
     },
 
     /******************************************/
     //数据接收
     websocketonmessage(e){
       this.heatBeat();//收到消息会刷新心跳检测,如果一直收到消息,就推迟心跳发送
-      console.log('消息',JSON.parse(e.data));
+      const redata = JSON.parse(e.data);//接收数据源
+      if(redata.type != "pong"){
+        console.log(redata);
+      }
+      let  getters = this.$store.getters;
+      //获取vuex数据
+      let session = getters.get_session;//会话列表
+      let offline  = getters.get_offline;//离线列表
+      let sessionType  = getters.get_type;//选择状态(会话/离线)
+      let dataIndex  = getters.get_num;//列表下标
+      let current_session  = getters.get_current;//当前会话
+      let session_name  = getters.get_session_name;//当前用户名
+      
       if(e.data.type == "pong" ) return
       this.$store.dispatch("SET_SESSION_MESSAGE",JSON.parse(e.data));
+
+      	// 用户接入数据
+				if(redata.message_type == "connect"){
+					let _this  = this;
+					let arr =[
+						redata.data,
+						offline,
+						session,
+						sessionType,
+						dataIndex,
+						current_session,
+						session_name
+					]
+					_this.$public.visitorsConnect(arr,function(data){
+						//离线匹配列表访客链接回调
+            _this.$store.dispatch("SET_OFFLINE",data);
+            
+					},function(data,session,offline,type,num,dataList,name){
+						//将用户添加到会话列表中
+						session.push(data.user_info);
+						//获取接入的用户信息
+						//_this.get_user_info(list);
+						//获取接入的用户信息写入vuex
+						_this.$store.dispatch("SET_SESSION",session);//会话列表
+						_this.$store.dispatch("SET_OFFLINE",offline);//离线列表
+						_this.$store.dispatch("SET_TYPE",type);//选择类型(会话/离线)
+						_this.$store.dispatch("SET_NUM",num);//列表下标
+						_this.$store.dispatch("SET_CURRENT",dataList);//当前会话数据
+						_this.$store.dispatch("SET_SESSION_NAME",name);//当前会话对象名
+						
+					})
+				}
+				
+
+				//用户离线后会话窗口切换
+				if(redata.message_type == "userClose"){
+					let _this =this;
+					let	arr= [
+						redata.data,
+						session,
+            offline,
+						sessionType,
+						dataIndex,
+						session_name,
+						current_session,
+					]
+					_this.$public.userOffline(arr,function(session,offline,type,index,name,list,userInfo){
+            _this.$store.dispatch("SET_CURRENT",list);//当前会话数据
+						_this.$store.dispatch("SET_SESSION_NAME",name);//当前会话对象名
+						_this.$store.dispatch("SET_NUM",index);
+						_this.$store.dispatch("SET_TYPE",type);
+						_this.$store.dispatch("SET_SESSION",session);
+						_this.$store.dispatch("SET_OFFLINE",offline);
+						// _this.get_user_info(userInfo);
+					})
+				}
+
+
+				//用户会话结束窗口切换
+				if(redata.message_type == "delUser"){
+					let _this =this;
+					let	arr= [
+						redata.data,
+						session,
+            offline,
+						sessionType,
+						dataIndex,
+						session_name,
+						current_session,
+					]
+					_this.$public.sessionEnd(arr,function(session,offline,type,index,name,list,userInfo){
+            _this.$store.dispatch("SET_CURRENT",list);//当前会话数据
+						_this.$store.dispatch("SET_SESSION_NAME",name);//当前会话对象名
+						_this.$store.dispatch("SET_NUM",index);
+						_this.$store.dispatch("SET_TYPE",type);
+						_this.$store.dispatch("SET_SESSION",session);
+						_this.$store.dispatch("SET_OFFLINE",offline);
+					//	_this.get_user_info(userInfo);
+					})
+				}
+
+				//接收用户消息数据
+				if(redata.message_type == "chatMessage"){
+					let _this =this;
+					this.$public.receivesMessage(redata.data,session,this.$frce,function(data,chatList,index){
+						//判断是否是当前对话信息
+						if(dataIndex == index){
+						    // _this.data =[];
+                // _this.data = chatList.data;
+                _this.$store.dispatch("SET_CURRENT",chatList.data);//当前会话数据
+						}else{
+						    let num = Number.isInteger(chatList.num) ? chatList.num : 0;
+                // _this.$set(chatList,'num',num+1)
+                session[index].num = num+1
+						}
+						//更新会话时间
+            // _this.$set(chatList,'intime',data.time);
+            session[index].intime =data.time
+				
+						//更新会话列表中最新回复消息
+						if(data.content.text){
+              // _this.$set(chatList,'text',data.content.text)
+              session[index].text =data.content.text
+            }
+             _this.$store.dispatch("SET_SESSION",session);
+					})
+				}
       
+        //reLoginErr
+        if(redata.message_type == "reLoginErr"){
+          console.log('haha');
+          this.init()
+        }
 
     },   
 
     /**************************************/
     //连接断开,失败
-    websocketonerror() {
-      // this.init()
+    websocketonerror(e) {
+      console.log('失败',e);
+      if(this.linkfailure){
+        this.init()
+      }
     },
 
     /******************************************/
@@ -76,15 +206,24 @@ export default {
       this.$store.dispatch("SET_STATEVALUE",'隐身');
       this.$store.dispatch("SET_SESSION",[]);
       this.$store.dispatch("SET_OFFLINE",[]);
+      this.$store.dispatch("SET_SESSION",[]);//会话列表
+			this.$store.dispatch("SET_OFFLINE",[]);//离线列表
+		  this.$store.dispatch("SET_TYPE",1);//选择类型(会话/离线)
+			this.$store.dispatch("SET_NUM",0);//列表下标
+			this.$store.dispatch("SET_CURRENT",[]);//当前会话数据
+      this.$store.dispatch("SET_SESSION_NAME",'');//当前会话对象名
+      this.$store.dispatch("SET_SESSION_MESSAGE",{});
+      this.$store.dispatch("SET_IS_INIT",false);
       this.$token = '';
       this.$router.push('/login')
-      this.reconnect();
+      this.linkfailure = true;
+      //this.reconnect();
     },
 
     /***************************************/
     //socket重连
     reconnect(){
-      if(this.lockReconnect){       //这里很关键,因为连接失败之后之后会相继触发 连接关闭,不然会连接上两个 WebSocket
+      if(this.lockReconnect){   //这里很关键,因为连接失败之后之后会相继触发 连接关闭,不然会连接上两个 WebSocket
           return
       }
       this.lockReconnect = true;
@@ -92,7 +231,7 @@ export default {
       this.reconnectData = setTimeout(()=>{
           this.initWebSocket(this.apiToken);
           this.lockReconnect = false;
-      },5000)
+      },3000)
     },  
 
     /*************************************/
@@ -121,6 +260,7 @@ export default {
         let time = res.data.data.time.split(' ');
         time[0] =(new Date( time[0].replace(/-/g,'/')).getTime()) /1000;
         sessionStorage.setItem("time",JSON.stringify(time));
+        sessionStorage.setItem("logo",res.data.data.logo);
         this.apiToken = this.$md5('customer-service'+time[0]+window.location.origin)
         this.initWebSocket(this.apiToken);
       }

+ 7 - 2
service/src/components/hader.vue

@@ -86,8 +86,13 @@
 			//退出系统
 			isExit() {
 				this.$store.dispatch("SET_STATEVALUE", '隐身');
-				this.$store.dispatch("SET_SESSION", []);
-				this.$store.dispatch("SET_OFFLINE", []);
+				this.$store.dispatch("SET_SESSION",[]);//会话列表
+				this.$store.dispatch("SET_OFFLINE",[]);//离线列表
+		  		this.$store.dispatch("SET_TYPE",1);//选择类型(会话/离线)
+				this.$store.dispatch("SET_NUM",0);//列表下标
+				this.$store.dispatch("SET_CURRENT",[]);//当前会话数据
+      			this.$store.dispatch("SET_SESSION_NAME",'');//当前会话对象名
+      			this.$store.dispatch("SET_SESSION_MESSAGE",{});
 				this.$websocket.close();
 				this.$token = '';
 				this.$router.push('/login')

+ 1 - 0
service/src/components/leftNav.vue

@@ -71,6 +71,7 @@ export default {
       }
       
       this.$store.dispatch("SET_NAVSTATE",str);
+      // this.$store.dispatch("SET_DRAWER",false);
       this.$router.push(path);
     }
   },

+ 88 - 34
service/src/components/messageCenter.vue

@@ -6,6 +6,7 @@
 			:visible.sync="drawer"
 			:modal="false"
 			:show-close="false"
+			:before-close="handleClose"
 			size="90%">
 		<div>
 			<el-col :span="6" class="left-list">
@@ -21,7 +22,7 @@
 
 				</div>
 				<ul class="message-list" v-if="switchMessageType == 'unread'">
-					<li class="list-item"  v-for="item in unreadList" :key="item.id" @click="toReading(item)">
+					<li class="list-item"  :class="{active:markupCode == index}"  v-for="(item,index) in unreadList" :key="item.id" @click="toReading(item,index)">
 						<p class="item-info">
 							<span class="name">{{item.title}}</span>
 							<span class="time">{{item.sendtime}}</span>
@@ -31,7 +32,7 @@
 				</ul>
 
 				<ul class="message-list" v-if="switchMessageType == 'read'">
-					<li class="list-item" v-for="item in readList" :key="item.id"  @click="toReading(item)">
+					<li class="list-item" :class="{active:markupCode == index}" v-for="(item,index) in readList" :key="item.id"  @click="toReading(item,index)">
 						<p class="item-info">
 							<span class="name">{{item.title}}</span>
 							<span class="time">{{item.sendtime}}</span>
@@ -48,21 +49,25 @@
 					<strong>客服满意度调查!</strong>
 					<i @click="handleClose" class="el-icon-close"></i>
 				</el-row>
-				<el-row class="messageBox" v-if="nomessage">
-					<ul>
-						<li><p>发件人:{{unreadListOne.admin_name}}</p></li>
-						<li><p>收件人:{{userName}}</p></li>
-						<li><p>时 间:{{unreadListOne.sendtime}}</p></li>
-					</ul>
-					<div class="message-content">{{unreadListOne.atext}}</div>
+				<el-row class="messageBox" v-if="switchMessageType == 'unread'">
+					<div v-if="unreadList.length > 0">
+						<ul >
+							<li><p>发件人:{{unreadListOne.admin_name}}</p></li>
+							<li><p>收件人:{{userName}}</p></li>
+							<li><p>时 间:{{unreadListOne.sendtime}}</p></li>
+						</ul>
+						<div class="message-content">{{unreadListOne.atext}}</div>
+					</div>
 				</el-row>
-				<el-row class="messageBox" v-if="nomessage == false">
-					<ul>
-						<li><p>发件人:{{messageBox.admin_name}}</p></li>
-						<li><p>收件人:{{userName}}</p></li>
-						<li><p>时 间:{{messageBox.sendtime}}</p></li>
-					</ul>
-					<div class="message-content">{{messageBox.atext}}</div>
+				<el-row class="messageBox" v-if="switchMessageType == 'read'">
+					<div  v-if="readList.length > 0">
+						<ul>
+							<li><p>发件人:{{messageBox.admin_name}}</p></li>
+							<li><p>收件人:{{userName}}</p></li>
+							<li><p>时 间:{{messageBox.sendtime}}</p></li>
+						</ul>
+						<div class="message-content">{{messageBox.atext}}</div>
+					</div>
 				</el-row>
 			</el-col>
 		</div>
@@ -87,11 +92,13 @@
 				//未读列表
 				unreadList:[],
 				//未读第一个
-				unreadListOne:[],
+				unreadListOne:{},
 				//未读数量
 				unreadNum:null,
 				// 详情
-				messageBox:[],
+				messageBox:{},
+				//标记代码
+				markupCode:0,
 
 			}
 		},
@@ -103,12 +110,14 @@
 		},
 		watch: {
 			get_drawer(data) {
-				console.log(data)
+				// console.log('22',data)
 				this.drawer = data;
 				this.userID = this.$store.getters.get_user_info.id;
 				this.userName = this.$store.getters.get_user_info.user_name;
-				this.readnotice();
-				this.unreadnotice();
+				if(data){
+					this.readnotice();
+					this.unreadnotice();
+				}
 			},
 		},
 		methods: {
@@ -117,6 +126,12 @@
 			},
 			switchMessage(num) {
 				this.switchMessageType = num;
+				this.markupCode = 0 ;
+				if(this.switchMessageType == 'unread'){
+					this.unreadnotice();
+				}else if(this.switchMessageType=='read'){
+					this.readnotice();	
+				}
 			},
 			// 已读信息
 			readnotice(){
@@ -130,10 +145,13 @@
 					user_id: this.userID
 				};
 				this.post("api/service/index/readnotice", obj).then(res => {
-					console.log(res)
+					// console.log(res)
 					if(res.data.code === 1){
 						console.log("已读",res.data.data)
 						this.readList =  res.data.data;
+						if(res.data.data.length > 0){
+							this.messageBox = res.data.data[0];
+						}
 					}
 				});
 			},
@@ -153,19 +171,53 @@
 					if(res.data.code === 1){
 						console.log("未读",res.data.data)
 						this.unreadList = res.data.data;
-						this.unreadListOne = res.data.data[0];
-						console.log(this.unreadListOne,'第一个')
-						this.unreadNum =  res.data.data.length;
+						// console.log(this.unreadListOne,'第一个')
+						this.unreadNum =res.data.data.length >0 ? res.data.data.length-1 : 0;
+						if(res.data.data.length > 0){
+							this.unreadListOne = res.data.data[0];
+							this.readInfo(res.data.data[0].id)
+						}
+
+					}
+				});
+			},
+
+			//读取信息
+			readInfo(id){
+				//this.messageBox.id
+				let str = "updatenotice" + "customer-service" + "index" + this.time + "service";
+				let obj = {
+					headers: {
+						"Content-Type": "application/x-www-form-urlencoded",
+						apiToken: this.$md5(str),
+						userToken: this.token
+					},
+					servicenotice_id: id
+				};
+				this.post("api/service/index/updatenotice", obj).then(res => {
+					console.log(res)
+					if(res.data.code === 1){
+						console.log("已读",res.data.data)
+						// this.unreadList = res.data.data;
+						// this.unreadListOne = res.data.data[0];
+						// // console.log(this.unreadListOne,'第一个')
+						// this.unreadNum =  res.data.data.length;
 
 					}
 				});
 			},
+			
 
 			// 点击显示当前详细内容
-			toReading(item){
-				console.log(item);
+			toReading(item,index){
+				// console.log(item,index);
+				if( this.markupCode == index) return
+				this.markupCode = index;
 				this.nomessage = false;
 				this.messageBox = item;
+				if(this.switchMessageType == 'unread'){
+					this.readInfo(item.id)
+				}
 			}
 		},
 
@@ -198,15 +250,17 @@
 
 	.message-list {
 		margin: 0;
-		/* 奇数背景色 */
-		.list-item:nth-of-type(odd) {
+		// /* 奇数背景色 */
+		// .list-item:nth-of-type(odd) {
+		// 	background: #F6F8FF;
+		// }
+		// /* 偶数背景色 */
+		// .list-item:nth-of-type(even) {
+		// 	background: #fff;
+		// }
+		.active{
 			background: #F6F8FF;
 		}
-		/* 偶数背景色 */
-		.list-item:nth-of-type(even) {
-			background: #fff;
-		}
-
 		.list-item {
 			padding: 10px 20px;
 

+ 95 - 88
service/src/pages/TheCurrentSession.vue

@@ -248,6 +248,7 @@
 
 <script>
 	import "@/css/index.css";
+	import {mapState,mapGetters} from 'vuex'; //先要引入
 	import leftNav from "@/components/leftNav";
 	import hader from "@/components/hader";
 	import messageCenter from "@/components/messageCenter";
@@ -260,8 +261,8 @@
 				inputValue: "", //输入框内容
 				isFrce: false, //表情包开关
 				frceArr: [], //表情包数组
-				data: [], //当前对话数据
-				dataIndex:0,//定位当前会话,默认是0
+				// data: [], //当前对话数据
+				// dataIndex:0,//定位当前会话,默认是0
 				FastReply: "", //快捷回复
 				FastReplySwitch: "one", //快捷回复开关
 				user_info:'',//用户信息
@@ -270,10 +271,10 @@
 				sessionList:[],//会话列表
 				offlineList:[],//离线列表
 				transferList:[],//转接列表
-				sessionType:1,//选择列表状态默认未1(1是会话中,2是离线)
+				// sessionType:1,//选择列表状态默认未1(1是会话中,2是离线)
 				lineUp:[],//排队列表
 				conversationId:'',//会话工单
-				sessionName:'',//当前会话用户名字
+				// sessionName:'',//当前会话用户名字
 				session_user_info:{},//当前会话用户信息
 				img_http:'http://kfadmin.bocai186.com',//图片路径域
 				//img_http:'http://192.168.2.186:8090',//图片路径域
@@ -284,6 +285,7 @@
 				session_marked:'',//客服当前会话标记
 				sensitive:[],//客服敏感词数据
 				userSensitiveWords:[],//用户敏感词
+				sensitiveNumber:0,//关键词次数
 			};
 		},
 		/**
@@ -323,14 +325,10 @@
 						//离线匹配列表访客链接回调
 						_this.$store.dispatch("SET_OFFLINE",data);
 					},function(data,list,offline,type,num,dataList,name){
+						// console.log(name)
 						//新访客链接回调
 						_this.sessionType = type;
 						_this.dataIndex = num;
-						_this.data = [];
-						if( dataList.length >0 ){
-							_this.data = dataList;
-						}
-						_this.sessionName = name;
 						//将用户添加到会话列表中
 						_this.sessionList.push(data.user_info);
 						//获取接入的用户信息
@@ -338,6 +336,12 @@
 						//获取接入的用户信息写入vuex
 						_this.$store.dispatch("SET_SESSION",list);
 						_this.$store.dispatch("SET_OFFLINE",offline);
+						_this.$store.dispatch("SET_TYPE",type);//选择类型(会话/离线)
+						_this.$store.dispatch("SET_NUM",num);//列表下标
+						_this.$store.dispatch("SET_CURRENT",dataList);//当前会话数据
+						if(name){
+							_this.$store.dispatch("SET_SESSION_NAME",name);//当前会话对象名
+						}
 					})
 				}
 				
@@ -361,9 +365,7 @@
 						_this.offlineList = offline;
 						_this.sessionType = type;
 						_this.dataIndex = index;
-						_this.sessionName = name;
-						_this.data = [];
-						_this.data = list;
+						this.$store.dispatch("SET_CURRENT",list);//当前会话数据
 						_this.$store.dispatch("SET_NUM",index);
 						_this.$store.dispatch("SET_TYPE",type);
 						_this.$store.dispatch("SET_SESSION",session);
@@ -392,8 +394,7 @@
 						_this.offlineList = offline;
 						_this.sessionType = type;
 						_this.dataIndex = index;
-						_this.sessionName = name;
-						_this.data = [];
+						_this.$store.dispatch("SET_CURRENT",list);//当前会话数据
 						_this.$store.dispatch("SET_NUM",index);
 						_this.$store.dispatch("SET_TYPE",type);
 						_this.$store.dispatch("SET_SESSION",session);
@@ -402,29 +403,30 @@
 					})
 				}
 
-				//接收用户消息数据
-				if(redata.message_type == "chatMessage"){
-					let _this =this;
-					this.$public.receivesMessage(redata.data,this.sessionList,this.$frce,
-					function(data,chatList,dataIndex){
-
-						//判断是否是当前对话信息
-						if(dataIndex == _this.dataIndex){
-						    _this.data =[];
-						    _this.data = chatList.data;
-						}else{
-						    let num = Number.isInteger(chatList.num) ? chatList.num : 0;
-						    _this.$set(chatList,'num',num+1)
-						}
-						//更新会话时间
-						_this.$set(chatList,'intime',data.time);
+				// //接收用户消息数据
+				// if(redata.message_type == "chatMessage"){
+				// 	let _this =this;
+				// 	this.$public.receivesMessage(redata.data,this.sessionList,this.$frce,
+				// 	function(data,chatList,dataIndex){
+
+				// 		//判断是否是当前对话信息
+				// 		if(dataIndex == _this.dataIndex){
+				// 		    _this.data =[];
+				// 		    _this.data = chatList.data;
+				// 		}else{
+				// 		    let num = Number.isInteger(chatList.num) ? chatList.num : 0;
+				// 		    _this.$set(chatList,'num',num+1)
+				// 		}
+				// 		//更新会话时间
+				// 		_this.$set(chatList,'intime',data.time);
 				
-						//更新会话列表中最新回复消息
-						if(data.content.text){
-							_this.$set(chatList,'text',data.content.text)
-						}
-					})
-				}
+				// 		//更新会话列表中最新回复消息
+				// 		if(data.content.text){
+				// 			_this.$set(chatList,'text',data.content.text)
+				// 		}
+				// 	})
+				// 	console.log(_this.data);
+				// }
 
 				//接收系统操作信息状态在线客服列表
 				if(redata.message_type == "onlinekfs"){
@@ -434,7 +436,6 @@
 
 				//接收会话时间
 				if(redata.message_type == "webTime"){
-					// this.webTime = redata.data.webTime
 					this.$set(this.data[this.session_marked],'time',redata.data.webTime);
 				}
 
@@ -451,15 +452,9 @@
 						// this.data = []
 
 					}else{
-						this.data = [];
-						this.sessionName ='';
-						// if(this.offlineList.length >0){
-						//   this.data = [];
-						//   this.sessionName ='';
-						// }else{
-						//   this.data = [];
-						//   this.sessionName ='';
-						// }
+						// this.data = [];
+						this.$store.dispatch("SET_CURRENT",[]);//当前会话数据
+						this.$store.dispatch("SET_SESSION_NAME",'');
 					}
 				}
 				this.automaticRolling();
@@ -495,7 +490,6 @@
 										}
 									}
 								}
-
 								let obj = {
 									text:'',
 									img:res.data.data.src,
@@ -576,13 +570,14 @@
 					data = this.sessionList[index].data;
 					this.session_user_info = this.sessionList[index];
 					this.$set(this.sessionList[index],'num',0);
-					this.sessionName = this.sessionList[index].name
+					this.$store.dispatch("SET_SESSION_NAME",this.sessionList[index].name);
 				}else if(type == 2){
 					data = this.offlineList[index].data;
-					this.sessionName = this.offlineList[index].name;
+					this.$store.dispatch("SET_SESSION_NAME",this.offlineList[index].name);
 					this.session_user_info = this.offlineList[index];
 				}
-				this.data = data;
+				//this.data = data;
+				this.$store.dispatch("SET_CURRENT",data);//当前会话数据
 			},
 
 			/***************关闭当前和用户聊天对话***************/
@@ -612,16 +607,16 @@
 					if(this.sessionType  == 1){
 						this.sessionList.splice(this.dataIndex,1);
 						if(this.sessionList.length> 0){
-							this.data = this.sessionList[0];
-							this.sessionName = this.sessionList[0].name;
+							this.$store.dispatch("SET_CURRENT",this.sessionList[0]);//当前会话数据
+							this.$store.dispatch("SET_SESSION_NAME",this.sessionList[0].name);
 						}else{
-							this.data = [];
-							this.sessionName = '';
+							this.$store.dispatch("SET_CURRENT",[]);//当前会话数据
+							this.$store.dispatch("SET_SESSION_NAME",'');
 						}
 					}else{
 						this.offlineList.splice(this.dataIndex,1);
-						this.data = [];
-						this.sessionName = '';
+						this.$store.dispatch("SET_CURRENT",[]);//当前会话数据
+						this.$store.dispatch("SET_SESSION_NAME",'');
 					}
 
 					this.websocketsend(JSON.stringify(data))
@@ -641,7 +636,6 @@
 
 			/*********************发送消息*********************/
 			sendMessage(){
-				console.log();
 				if(!this.inputValue) return
 				if(this.sessionList.length == 0) {
 					this.$message({
@@ -662,48 +656,49 @@
 						}
 					}
 				}
-				//判断客服敏感词报警次数
-				let obj = {
-					text: this.inputValue,
-					img:'',
-					type:false,
-				}
-				let type ='chatMessage';
+				//检测发送信息是否含有敏感词
+				let  sensitive_data= this.$public.shieldingKeyword(this.$public.turnFace(this.inputValue,this.$frce),this.sensitive);
+				//组合发送数据
 				let data = {
 					from_name:this.user_info.user_name,//发送者
 					from_avatar:this.user_info.avatar,//发送者头像
 					from_id:"KF"+this.user_info.id,//发送者id
-					content:JSON.stringify(obj),
+					content:JSON.stringify({
+						text: this.inputValue,
+						img:'',
+					}),
 					to_id: this.sessionList[this.dataIndex].id,
 					to_name:this.sessionList[this.dataIndex].name,
 					conversationId:this.sessionList[this.dataIndex].conversationId,
 					isFirst:isFirst,//是否是第一句话
-					sensitiveNumber:sensitiveNumber,//敏感词次数
+					sensitiveNumber:this.sensitiveNumber,//敏感词次数
 				}
 				let chatList = this.sessionList[this.dataIndex];
-				//检测发送信息是否含有敏感词
-				let  sensitive_data= this.$public.shieldingKeyword(this.$public.turnFace(this.inputValue,this.$frce),this.sensitive);
+
 
 				//有敏感词提示并且禁止发送
 				if(sensitive_data.num == 0 ){
 					// 本地储存
 					chatList.data.push({type:'service', content:{
-							text:this.$public.turnFace(this.inputValue,this.$frce),
-							img:'',
-							type:false,
-						} ,time:this.time[1]});
+						text:this.$public.turnFace(this.inputValue,this.$frce),
+						img:'',
+					} ,time:this.time[1]});
 
-					this.data = [];
+					//this.data = [];
 					//标记当前会话位置
 					this.session_marked = chatList.data.length -1;
-					this.data = chatList.data;
-					this.websocketsend(JSON.stringify({type,data}))
+					//this.data = chatList.data;
+					this.$store.dispatch("SET_CURRENT",chatList.data);//当前会话数据
+					this.websocketsend(JSON.stringify({type:'chatMessage',data}))
 					this.inputValue = '';
+					this.sensitiveNumber = 0;
 				}else{
 					this.$message({
 						message: '敏感词'+sensitive_data.text,
 						type: 'warning'
 					});
+					//计算关键词次数
+					this.sensitiveNumber = this.sensitiveNumber +sensitive_data.num;
 				}
 
 
@@ -716,7 +711,6 @@
 
 			/*******************发送评价指令*******************/
 			evaluation(){
-				console.log(this.sessionList[this.dataIndex]);
 				if(!this.is_eva_btn && this.sessionType == 1){
 					this.$message({
 						message: '评价指令已发送',
@@ -773,10 +767,9 @@
 			get_user_info(type){
 				if(type.length > 0 ){
 					this. session_user_info  = {};
-					if(this.dataIndex !=100){
+					if(this.dataIndex <= type.length){
 						this.session_user_info = type[this.dataIndex];
 					}
-					// console.log(this.session_user_info);
 				}else{
 					this.session_user_info = {};
 				}
@@ -826,22 +819,30 @@
 				})
 			},
 
+			/********************获取vuex数据***********************/
+			get_vuex_info(){
+				let  getters = this.$store.getters
+				this.token =getters.get_user_info.token ;//token
+				this.user_info = getters.get_user_info;//用户消息
+				this.sessionList = getters.get_session ;//会话
+				this.offlineList = getters.get_offline ;//离线
+				this.dataIndex = getters.get_num; //getters.get_num;列表下标
+				this.sessionType = getters.get_type;//选择类型
+				// this.data = getters.get_current;//当前会话数据
+				// this.sessionName = getters.get_session_name;//会话对象名字
+				this.time =JSON.parse(sessionStorage.getItem("time"));
+			}
 		},
 		/**
 		 * 挂载前执行
 		 */
 		mounted() {
-			//获取vuex数据
-			let  getters = this.$store.getters
-			this.sessionList = getters.get_session ? getters.get_session :[] ;
-			this.offlineList = getters.get_offline ? getters.get_offline :[] ;
-			this.token =getters.get_user_info.token ;
-			this.user_info = getters.get_user_info;
-			this.dataIndex =100; //getters.get_num;
-			this.sessionType = getters.get_type;
-			this.time =JSON.parse(sessionStorage.getItem("time"));
+			//获取vuex里面数据
+			this.get_vuex_info();
 			let _this = this;
 			this.get_config_info();
+
+			//客服人员登陆会话
 			if(this.$store.getters.get_is_init){
 				// this.$websocket.onmessage = this.;
 				_this.websocketsend(JSON.stringify({
@@ -870,7 +871,6 @@
 			get_session_message(e){
 				this.chatMessage(e)
 			},
-
 			/*****************评价按钮显示隐藏处理*****************/
 			get_is_eva_btn(data){
 				if(this.sessionType != 2){
@@ -894,9 +894,16 @@
 		 * 计算属性
 		 */
 		computed:{
+			...mapGetters({
+				data:'get_current',
+				sessionName:'get_session_name',
+			}),
+
 			get_session_message(){
 				return this.$store.getters.get_session_message;
 			},
+			
+
 			/****************判断是否可以点击评价*****************/
 			get_is_eva_btn(){
 				return this.data;

+ 2 - 1
service/src/pages/login.vue

@@ -49,6 +49,7 @@
 		},
 		methods:{
 			loginBtn(){
+				this.time = sessionStorage.getItem('time');
 				if(this.$socket_open != undefined ){
 					let apiToken = this.$md5('customer-service'+this.time[0]+window.location.origin)
 					if(this.account && this.password){
@@ -104,7 +105,7 @@
 			},
 		},
 		mounted(){
-			this.time = sessionStorage.getItem('time')
+			
 		}
 	};
 </script>

+ 0 - 74
service/src/pages/websocht.js

@@ -1,74 +0,0 @@
-data(){
-    return{
-        websock: null,
-        reconnectData:null,
-        lockReconnect:false,    //避免重复连接,因为onerror之后会立即触发 onclose
-        timeout:10000,          //10s一次心跳检测
-        timeoutObj:null,
-        serverTimeoutObj:null,
-    }
-},
-created(){
-    this.initWebSocket();
-},
-methods:{
-    initWebSocket(){
-        console.log('启动中')
-        let wsurl = '你的websockt url';
-        this.websock = new WebSocket(wsurl);
-        this.websock.onopen = this.websocketonopen;          //连接成功
-        this.websock.onmessage = this.websocketonmessage;    //广播成功
-        this.websock.onerror = this.websocketonerror;        //连接断开,失败
-        this.websock.onclose = this.websocketclose;          //连接关闭
-    },             //初始化weosocket
-    websocketonopen(){
-        console.log('连接成功')
-        this.heatBeat();
-    },           //连接成功
-    websocketonerror(){
-        console.log('连接失败')
-        this.reconnect();
-    },          //连接失败
-    websocketclose(){
-        console.log('断开连接');
-        this.reconnect();
-    },            //各种问题导致的 连接关闭
-    websocketonmessage(data){
-        this.heatBeat();      //收到消息会刷新心跳检测,如果一直收到消息,就推迟心跳发送
-        let msgData = JSON.parse(data);
-    },    //数据接收
-    websocketsend(data){
-        this.websock.send(JSON.stringify(data));
-    },  
-    
-    
-    //数据发送
-    reconnect(){
-        if(this.lockReconnect){       //这里很关键,因为连接失败之后之后会相继触发 连接关闭,不然会连接上两个 WebSocket
-            return
-        }
-        this.lockReconnect = true;
-        this.reconnectData && clearTimeout(this.reconnectData);
-        this.reconnectData = setTimeout(()=>{
-            this.initWebSocket();
-            this.lockReconnect = false;
-        },5000)
-    },                 //socket重连
-    heatBeat(){
-        this.timeoutObj && clearTimeout(this.timeoutObj);
-        this.serverTimeoutObj && clearTimeout(this.serverTimeoutObj);
-        this.timeoutObj = setTimeout(()=>{
-            this.websocketsend({type:'ping'})   //根据后台要求发送
-            this.serverTimeoutObj = setTimeout(()=> {
-                this.websock.close();       //如果  5秒之后我们没有收到 后台返回的心跳检测数据 断开socket,断开后会启动重连机制
-            }, 5000);
-        }, this.timeout)
-    },                  
-},
-destroyed() {
-    this.lockReconnect = true;
-    this.websock.close()                   //离开路由之后断开websocket连接
-    clearTimeout(this.reconnectData);      //离开清除 timeout
-    clearTimeout(this.timeoutObj);         //离开清除 timeout
-    clearTimeout(this.serverTimeoutObj);   //离开清除 timeout
-}

+ 17 - 3
service/src/store/index.js

@@ -11,14 +11,16 @@ const state = {
 	user_info: '', //用户信息
 	sessionList: [],//会话列表
 	offlineList: [],//离线列表
-	current_session:{},//当前会话详情信息
+	current_session:[],//当前会话详情信息
 	sessionType: 1,//选择列表状态默认未1(1是会话中,2是离线)
 	data_num: 0,//定位当前会话,默认是0
 	navState: 'TheCurrentSession',//导航状态
-	session_message: '',//会话消息
+	session_name: '',//当前会话用户名
+	session_message:'',//接收会话信息
 	stateValue: '',//状态值
 	is_init: false,//初始化,
 	new_drawer: false, //显示消息中心
+	session_user_info:{},//当前会话用户信息
 }
 
 /**
@@ -46,6 +48,9 @@ const getters = {
 	get_navState(state) {
 		return state.navState;
 	},
+	get_session_name(state) {
+		return state.session_name;
+	},
 	get_session_message(state) {
 		return state.session_message;
 	},
@@ -57,7 +62,10 @@ const getters = {
 	},
     get_drawer(state) {
         return state.new_drawer;
-    },
+	},
+	get_session_user(state){
+		return state.session_user_info;
+	}
 }
 /**
  * 设置对外可调用的方法
@@ -85,6 +93,9 @@ const mutations = {
 	new_navState(state, val) {
 		state.navState = val;
 	},
+	new_session_name(state, val) {
+		state.session_name = val;
+	},
 	new_session_message(state, val) {
 		state.session_message = val;
 	},
@@ -124,6 +135,9 @@ const actions = {
 	SET_NAVSTATE(context, val) {
 		context.commit('new_navState', val);
 	},
+	SET_SESSION_NAME(context, val) {
+		context.commit('new_session_name', val);
+	},
 	SET_SESSION_MESSAGE(context, val) {
 		context.commit('new_session_message', val);
 	},