denghaoyue il y a 6 ans
Parent
commit
c73af2ec64

+ 8 - 2
service/src/App.vue

@@ -81,6 +81,9 @@
 			websocketonmessage(e){
 				this.heatBeat();//收到消息会刷新心跳检测,如果一直收到消息,就推迟心跳发送
 				const redata = JSON.parse(e.data);//接收数据源
+				if(!redata) {
+					return
+				}
 				//
 				if(redata.message_type == "ping"){
 					this.$websocket.send('{"type":"pong"}')
@@ -90,6 +93,9 @@
 				if(redata.type == "pong") return false;
 				if(redata.type != "pong" || redata.message_type != "ping"){
 					console.log(redata);
+					if(redata.message_type === 'connct') {
+						this.$store.dispatch("SET_SESSSION_USER", redata.data.user_info);
+					}
 				}
 				let getters = this.$store.getters;
 				//获取vuex数据
@@ -99,7 +105,6 @@
 				let dataIndex  = getters.get_num;//列表下标
 				let current_session  = getters.get_current;//当前会话
 				let session_name  = getters.get_session_name;//当前用户名
-
 				this.$store.dispatch("SET_SESSION_MESSAGE",JSON.parse(e.data));
 
 				// 用户接入数据
@@ -330,7 +335,8 @@
 		},
 		destroyed() {
 			this.lockReconnect = true;
-			this.websock.close()                   //离开路由之后断开websocket连接
+			this.$websocket.close();
+			// this.websock.close()                   //离开路由之后断开websocket连接
 			clearTimeout(this.reconnectData);      //离开清除 timeout
 			clearTimeout(this.timeoutObj);         //离开清除 timeout
 			clearTimeout(this.serverTimeoutObj);   //离开清除 timeout

+ 5 - 0
service/src/api/ports.js

@@ -37,6 +37,7 @@ export default {
   history:{
     historyList:'/service/history/historyList',
     historyInfo:"/service/history/historyInfo",
+    userHistory: "/service/history/userHistory"
   },
 
   //留言 
@@ -55,6 +56,10 @@ export default {
   overview:{
     allConversation:"/service/history/allConversation",
     chatByTime:'/service/history/chatByTime',
+  },
+  // 验证码权限
+  securityCode: {
+    getconfigs: '/index/index/getconfigs'
   }
 
 }

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

@@ -15,7 +15,7 @@
 							</template>
 							<div :class="{session_choose:dataIndex ==index &&  sessionType ==1}"
 								 class="user session_style" @click="chooseDialogue(1,index)"
-								 v-for="(item,index) in sessionList">
+								 v-for="(item,index) in sessionList" :key="index">
 								<div class="row allAlignment item-center">
 									<span style="font-weight:bold;color:#666;font-size:14px;">{{item.name}}</span>
 									<span style="color:#999;font-size:.12px;">{{item.intime}}</span>
@@ -34,7 +34,7 @@
 							</template>
 							<div :class="{session_choose:dataIndex == index &&  sessionType ==2}"
 								 class="user session_style" @click="chooseDialogue(2,index)"
-								 v-for="(item,index) in offlineList">
+								 v-for="(item,index) in offlineList" :key="index">
 								<div class="row allAlignment item-center">
 									<span style="font-weight:bold;color:#999;font-size:14px;">{{item.name}}</span>
 									<span style="color:#999;font-size:12px;">{{item.intime}}</span>
@@ -95,6 +95,10 @@
 					</div>
 
 					<div class="chat-box scroll" id='chat_box'>
+						<div class="history-info">
+							<el-button type="text" size="small" :loading="historyLoading" 
+							@click="getHistoryInfo">{{historyProcess}}</el-button>
+						</div>
 						<div v-for="(item,index) in data" :key="index">
 							<!-- 系统转接 -->
 							<!-- <div class="row center" v-if="item.type == 'system'">
@@ -169,7 +173,7 @@
 						<textarea draggable="false" class="input scroll" id="input" v-model.trim="inputValue"
 								  @keyup.enter="listenEnter($event)" @keyup.ctrl.enter="lineFeed()"></textarea>
 						<div class="row rightAlignment" style="width: 100%;">
-							<div @click="sendMessage()" class="msgInputBtn row center">发送</div>
+							<div @click="sendMessage()" @keyup.enter="sendMessage" class="msgInputBtn row center">发送</div>
 						</div>
 					</div>
 					<!-- 发送消息音频提示 -->
@@ -333,6 +337,7 @@
 	import leftNav from "@/components/leftNav";
 	import hader from "@/components/hader";
 	import messageCenter from "@/components/messageCenter";
+	import historicalRecord from "@/components/historicalRecord";
 
 	export default {
 		name: "TheCurrentSession",
@@ -375,6 +380,9 @@
 				showHistoryList: false,
 				historyList: [],
 				historyTime:'',
+				historyLoading: false, // 历史记录加载
+				historyProcess: '更多历史记录', // 查看历史历史记录或者加载中
+				historyPage: 1 // 当前的历史记录页
 			}
 		},
 		methods: {
@@ -692,6 +700,7 @@
 			/***************关闭当前和用户聊天对话***************/
 			open() {
 				let _this = this;
+				console.log(this.sessionList)
 				if (this.sessionType == 1) {
 					if (this.sessionList.length < 1) return
 				} else {
@@ -708,7 +717,7 @@
 					let data = {
 						"type": "kfCloseUser",
 						data: {
-							to_id,
+							to_id: '',
 							kf_id: "KF" + _this.user_info.id,
 							group_id: _this.user_info.group_id,
 							conversationId: conversationId,
@@ -756,6 +765,11 @@
 
 			/*********************发送消息*********************/
 			sendMessage() {
+				console.log('websocket',this.$websocket.readyState)
+				console.log('sessionType', this.sessionType)
+				if(this.sessionType == 1) {
+					console.log("???")
+				}
 				console.log(this.inputValue);
 				if (!this.inputValue) return;
 				if (this.sessionType == 2) {
@@ -805,7 +819,8 @@
 						type: 'service', content: {
 							text: this.$public.turnFace(this.inputValue, this.$frce),
 							img: '',
-						}, time: this.time[1]
+						}, 
+						// time: this.time[1]
 					});
 					//this.data = [];
 					//标记当前会话位置
@@ -824,7 +839,7 @@
 					//计算关键词次数
 					this.sensitiveNumber = this.sensitiveNumber + sensitive_data.num;
 				}
-
+				this.historyProcess = '更多历史消息' // 发送信息成功后改变说明
 
 			},
 
@@ -1123,7 +1138,9 @@
 			/****************访问信息和评价状态***************/
 			accessTerminal(data) {
 				if (this.sessionType == 1) {
+					console.log('dataIndex', this.dataIndex)
 					let List = this.sessionList[this.dataIndex];
+					console.log('list', List)
 					if (data == 'eva') {
 						if (!List) return false
 						// console.log(List,'对话信息');
@@ -1164,8 +1181,64 @@
 					}
 					// }
 				}
+			},
+			getHistoryInfo() { // 获取历史数据
+				let obj = {
+					headers: {
+						apiToken: this.$md5("userhistory" + "customer-service" + "history" + "service"),
+						// 'apiToken': this.$md5("historylist" + "customer-service" + "history" + "service"),
+						userToken: this.token
+					},
+					params: {
+						// user_name: this.user_info.account_name,
+						account_id: 'KF' + this.user_info.id,
+						currentPage: this.historyPage,
+						pageSize: 10
+					}
+				};
+				this.historyLoading = true
+				this.historyProcess = '加载中'
+				this.$http.get(this.$ports.history.userHistory,obj).then(res => {
+					if(res.data.code == 1) {
+						if(!res.data.data.total ) { // 历史记录总数
+							this.historyProcess = '没有更多历史记录'
+							this.historyLoading = false
+						} else {
+							// 遍历封装数据
+							if(this.historyPage > res.data.data.countPage) {
+								this.historyProcess = '没有更多历史记录'
+							    this.historyLoading = false
+							} else {
+								let list = res.data.data.list
+								if(list) {
+									for(let item of list) {
+										let historyItem = {
+											type: item.from_id.substr(0, 2) === 'KF' ? 'service' : 'user',
+											time: this.$public.customFormatDateTime(item.time_line),
+											content: JSON.parse(item.content)
+										}
+										this.data.unshift(historyItem)
+									}
+									this.historyPage ++ ;
+									this.historyProcess = '更多历史记录'
+									this.historyLoading = false;
+								} else {
+									this.historyProcess = '没有更多历史记录'
+							    	this.historyLoading = false
+								}
+							}
+						}
+					}
+				}).catch(err => {
+					this.$message.error(err.message)
+					this.historyLoading = false;
+					this.historyProcess = '更多历史记录'
+				})
 			}
 		},
+		created() {
+			this.get_vuex_info();
+		},
 		/**
 		 * 挂载前执行
 		 */
@@ -1206,8 +1279,14 @@
 				this.chatMessage(e)
 			},
 
-			sessionList(e) {
-				this.accessTerminal(e)
+			// sessionList(e) {
+			// 	this.accessTerminal(e)
+			// },
+			sessionList: {
+				handler(val) {
+					this.accessTerminal(val)
+				},
+				deep: true
 			},
 			offlineList(e) {
 				this.accessTerminal(e)
@@ -1229,7 +1308,7 @@
 				offlineList: 'get_offline',
 				dataIndex: 'get_num',
 				sessionType: 'get_type',
-				get_user_info: 'get_session_user',
+				get_user_info: 'get_session_user', // 会话人详细信息
 				// is_eva_btn:'get_is_eva_btn',
 			}),
 
@@ -1247,7 +1326,8 @@
 		components: {
 			leftNav,
 			hader,
-			messageCenter
+			messageCenter,
+			historicalRecord
 		}
 	};
 </script>
@@ -1680,4 +1760,9 @@
 	.rightAlignment .el-button {
 		border: none;
 	}
+	.history-info {
+		color: #5399f5;
+		text-align: center;
+		margin-top: 5px;
+	}
 </style>

+ 35 - 12
service/src/pages/login.vue

@@ -24,7 +24,7 @@
 							<p v-if="0" style="color:#f60;font-size:14px;margin-top:5px;margin-left:3px;">密码错误,请重新输入</p>
 						</div>
 					</div>
-					<div class="box row center" v-if="showSecurityCode">
+					<div class="box row center" v-if="needCode && showSecurityCode">
 						<div class="boxData" :class="0?'errBd':''">
 							<input maxlength="6" @keyup.enter="loginBtn()" @blur="testCode()" type="text" v-model="securityCode" placeholder="验证码">
 							<img src="@/assets/img/password.png">
@@ -54,6 +54,7 @@
 				time:'',
 				loading:false,
 				showSecurityCode:false,
+				needCode: 1, // 是否需要验证码验证
 				logo: '',
 				verifySystem:"",
 				verifySystemId:"",
@@ -63,10 +64,12 @@
 		},
 		methods:{
 			testCode(){
-				if(this.showSecurityCode){
-					if (!(/^[0-9]+$/.test(this.securityCode))) {
-						this.$message.error('验证码错误!')
-						this.securityCode = '';
+				if(this.needCode) {
+					if(this.showSecurityCode){
+						if (!(/^[0-9]+$/.test(this.securityCode))) {
+							this.$message.error('验证码错误!')
+							this.securityCode = '';
+						}
 					}
 				}
 			},
@@ -87,7 +90,7 @@
 						// console.log(this.verifySystem)
 						// console.log(this.securityCode)
 						let parmas;
-						if(this.showSecurityCode){
+						if(this.needCode && this.showSecurityCode){
 							 parmas = {
 								username:this.account,
 								password:this.password,
@@ -97,12 +100,11 @@
 							parmas = {
 								username:this.account,
 								password:this.password,
-								verifySystemId:this.verifySystemId,
-								verifySystem:this.verifySystem,
+								verifySystemId:this.verifySystemId ? this.verifySystemId : '',
+								verifySystem:this.verifySystem ? this.verifySystem : '',
 							}
 						}
 						this.$http.post(this.$ports.login, parmas).then((res)=>{
-
 							if(res.data.code == 1){
 								this.$store.dispatch("SET_USER",res.data.data.user);
 								this.$store.dispatch("SET_IS_INIT",true);
@@ -157,6 +159,28 @@
 				this.$websocket.onopen();
 				//console.log('已经链接')
 			},
+			getSecurityCode() { // 获取登录是否需要验证码
+				let obj = {
+					headers: {
+						// 公共接口只需要传apitoken
+						apiToken: this.$md5('getconfigs' + "customer-service" + 'index' + 'index'),
+					}
+				}
+				this.$http.get(this.$ports.securityCode.getconfigs, obj).then(res => {
+					if(res.data.code == 1) {
+						this.needCode = res.data.data.checkcodeflag
+					}
+					else {
+						this.$message.error(err.message)
+					}
+				})
+				.catch(err => {
+					this.$message.error(err.message)
+				})
+			}
+		},
+		created() {
+			this.getSecurityCode();
 		},
 		mounted(){
 			// 判断验证码参数
@@ -171,7 +195,6 @@
 				localStorage.clear();
 				sessionStorage.clear();
 			}
-
 			this.$http.get(this.$ports.TIME).then(res => {
 				if (res.data.code == 1) {
 					let time = res.data.data.time.split(' ');
@@ -181,11 +204,11 @@
 					sessionStorage.setItem("logo",res.data.data.logo);
 					
 				}
-			});
+			})
 			// this.logo = sessionStorage.getItem('logo');
 			//console.log(this.logo, '========logo')
 		}
-	};
+	}
 </script>
 
 <style scoped>

+ 1 - 1
service/src/store/index.js

@@ -8,7 +8,7 @@ Vue.use(Vuex);
  store
  */
 const state = {
-	user_info: localStorage.getItem('user'), //用户信息
+	user_info: localStorage.getItem('user'), //用户(客服)信息
 	sessionList: [],//会话列表
 	offlineList: [],//离线列表
 	current_session: [],//当前会话详情信息