luke 6 lat temu
rodzic
commit
8f328485f3
1 zmienionych plików z 92 dodań i 77 usunięć
  1. 92 77
      pc_chat/src/components/chat.vue

+ 92 - 77
pc_chat/src/components/chat.vue

@@ -202,7 +202,8 @@
 						<div v-if="machineAndAtl == 100">
 							<!--历史消息-->
 							<div v-for="(item,index) in hisSviceChat" :key="index">
-								<div class="conversationBox">
+								<!-- 客服信息 -->
+								<div class="conversationBox" v-if="item.to_id.startsWith('KF')">
 									<div class="timer">{{item.time_line | formatDate}}</div>
 									<div class="row">
 										<div class="conversation row">
@@ -210,19 +211,42 @@
 												<img :src="serviceImg?url+serviceImg:require('@/assets/st-img/kf.png')"
 													 alt="">
 											</div>
-											<div class="cont left" >
+											<div class="cont left">
 												<div v-if="item.content != ''" v-html="item.content.text"></div>
 												<div v-else slot="file">
 													<img class="el-upload-list__item-thumbnail"
-														 @click="handlePictureCardPreview(url+item.imgUrl)"
+														 @click="handlePictureCardPreview(url+item.content.img)"
 														 style="width:100%;height:auto;border-radius: 10px;"
-														 :src="url+item.imgUrl" alt="">
+														 :src="url+item.content.img" alt="">
 												</div>
 											</div>
 										</div>
 										<div style="width:66px;"></div>
 									</div>
 								</div>
+								<!-- 用户信息 -->
+								<div class="conversationBox" v-else>
+									<div>
+										<div class="timer">{{item.time_line | formatDate}}</div>
+										<div class="customer row allAlignment">
+											<div style="width:66px;"></div>
+											<div class="row">
+												<div class="cont right">
+													<div v-if="item.content != ''" v-html="item.content.text"></div>
+													<div v-else slot="file">
+														<img class="el-upload-list__item-thumbnail"
+															 @click="handlePictureCardPreview(url+item.content.img)"
+															 style="width:100%;height:auto;border-radius: 10px;"
+															 :src="url+item.content.img" alt="">
+													</div>
+												</div>
+												<div class="headImg">
+													<img :src="user_info.avatar" alt="">
+												</div>
+											</div>
+										</div>
+									</div>
+								</div>
 							</div>
 
 							<!-- 人工客服回复消息 -->
@@ -533,8 +557,8 @@
 				userConversation: {}, //用户当前会话
 				machineAndAtl: 10, //默认为机器人,100为人工
 				satisfaction: 1, //评价满意度,1为满意,2为一般,3为不满意
-				url: 'http://kfadmin.bocai186.com', // 域名地址
-				// url: 'http://192.168.2.187:8090', // 域名地址
+				// url: 'http://kfadmin.bocai186.com', // 域名地址
+				url: 'http://192.168.2.187:8090', // 域名地址
 				user_info: '', // 用户信息
 				// 人工客服信息
 				service: '',
@@ -588,8 +612,9 @@
 		},
 		filters: {
 			formatDate: function (value) {
-				console.log(value);
-				let date = new Date(value);
+				let val = parseInt(value);
+				// console.log(val);
+				let date = new Date(val);
 				let y = date.getFullYear();
 				let MM = date.getMonth() + 1;
 				 MM = MM < 10 ? ('0' + MM) : MM;
@@ -940,8 +965,8 @@
 			initWebSocket() {
 				let _this = this;
 				let apiToken = this.$md5.hex_md5('customer-service' + this.currTime + window.location.origin);
-				this.websock = new WebSocket('ws://103.108.43.176:9101?apiToken=' + apiToken);
-				// this.websock = new WebSocket('ws://192.168.2.187:9101?apiToken=' + apiToken);
+				// this.websock = new WebSocket('ws://103.108.43.176:9101?apiToken=' + apiToken);
+				this.websock = new WebSocket('ws://192.168.2.187:9101?apiToken=' + apiToken);
 				this.websock.debug = true;
 				// 数据接收
 				this.websock.onmessage = this.websocketonmessage;
@@ -1051,56 +1076,6 @@
 					this.comtSuccess = false;
 					this.showleaveIcon = false;
 					this.waitingMsg = false;
-					// let obj = {
-					// 	message_type: "toOld",
-					// 	data: {
-					// 		chatLog: [{
-					// 			id: "1020",
-					// 			from_id: "14",
-					// 			from_name: "c_c1001",
-					// 			from_avatar: "",
-					// 			to_id: "KF15",
-					// 			to_name: "9090950",
-					// 			content: {'text':222222},
-					// 			time_line: 1565423525,
-					// 			servicelog_id: "720"
-					// 		},
-					// 			{
-					// 				id: "1020",
-					// 				from_id: "14",
-					// 				from_name: "c_c1001",
-					// 				from_avatar: "",
-					// 				to_id: "KF15",
-					// 				to_name: "9090950",
-					// 				content: {'text':222222},
-					// 				time_line: 1565423525,
-					// 				servicelog_id: "720"
-					// 			},
-					// 			{
-					// 				id: "1020",
-					// 				from_id: "14",
-					// 				from_name: "c_c1001",
-					// 				from_avatar: "",
-					// 				to_id: "KF15",
-					// 				to_name: "9090950",
-					// 				content: {'text':222222},
-					// 				time_line: 1565423525,
-					// 				servicelog_id: "720"
-					// 			}
-					// 		],
-					// 		"content": "接入至未结束的会话"
-					// 	}
-					// };
-					//
-					// this.historyMsgtext = obj.data.content;
-					//
-					// obj.data.chatLog.forEach(res => {
-					// 	console.log(res,'每一个')
-					// 	this.hisSviceChat.push(res)
-					// })
-					//
-					// this.customerSviceChat.push({type: 'system', str: 'historyMsg'})
-
 				}
 				// 暂无客服
 				if (redata.message_type == 'wait') {
@@ -1232,14 +1207,53 @@
 				}
 				// 历史信息
 				if(redata.message_type == 'toOld'){
-					// console.log(redata,'历史信息');
-					// let obj = redata
-					// this.historyMsg = true;
-					// this.historyMsgtext = obj.data.content;
-					// obj.data.chatLog.forEach(res => {
-					// 	console.log(res,'每一个')
-					// 	this.hisSviceChat.push(res)
-					// })
+					console.log(redata,'历史信息');
+					let obj = {
+						"message_type": "toOld",
+						"data": {
+							"chatLog": [
+								{
+									"id": "1020",
+									"from_id": "14",
+									"from_name": "c_c1001",
+									"from_avatar": "",
+									"to_id": "KF15",
+									"to_name": "9090950",
+									"content": "{\"text\":\"222222\",\"img\":\"\",\"type\":\"user\"}",
+									"time_line": "1565423525",
+									"servicelog_id": "720"
+								},
+								{
+									"id": "1021",
+									"from_id": "KF15",
+									"from_name": "tank",
+									"from_avatar": "",
+									"to_id": "14",
+									"to_name": "c_c1001",
+									"content": "{\"text\":\"444444\",\"img\":\"\"}",
+									"time_line": "1565423528",
+									"servicelog_id": "720"
+								},
+								{
+									"id": "1022",
+									"from_id": "14",
+									"from_name": "c_c1001",
+									"from_avatar": "",
+									"to_id": "KF15",
+									"to_name": "9090950",
+									"content": "{\"text\":\"3333333\",\"img\":\"\",\"type\":\"user\"}",
+									"time_line": "1565423530",
+									"servicelog_id": "720"
+								}
+							],
+							"content": "接入至未结束的会话"
+						}
+					};
+					this.historyMsgtext = obj.data.content;
+					obj.data.chatLog.forEach(res => {
+						res.content = JSON.parse(res.content)
+						this.hisSviceChat.push(res)
+					})
 					this.customerSviceChat.push({type: 'system', str: 'historyMsg'})
 				}
 			},
@@ -1401,20 +1415,20 @@
 			registered() {
 				let token = localStorage.getItem('token');
 				let appuid = this.$public.getQueryString('appuid');
-				// 有会员账号
-				// if (appuid) {
-				// 	token = localStorage.setItem('xx');
-				//
-				// }else {
-				// 无会员账号
-				// 	token = localStorage.setItem('xx');
-				// }
-
+				let tutype = this.$public.getQueryString('tutype');
+				if (appuid && tutype >= 1) {
+					token = localStorage.getItem('token');
+				} else if (!appuid && tutype < 1) {
+					token = localStorage.getItem('token');
+				} else {
+					token = '';
+				}
 				let data = {
 					token: token != null ? token : '',
 					appid: this.$public.getQueryString('appid'),
 					appuid: this.$public.getQueryString('appuid'),
 				}
+				console.log(data,'参数')
 				let obj = {
 					headers: {
 						"apiToken": this.setApiToken('autoreg', 'register', this.currTime, 'index')
@@ -1426,6 +1440,7 @@
 						console.log(this.user_info,"用户信息")
 						// 游客 token
 						localStorage.setItem("token", res.data.data.token);
+						localStorage.setItem("tutype", res.data.tutype);
 						setTimeout(() => {
 							//关闭加载条
 							this.allLoadingClose();