Browse Source

update chat

luke 6 years ago
parent
commit
ae64159fe9
5 changed files with 126 additions and 109 deletions
  1. 10 10
      chat/config/index.js
  2. 55 48
      chat/src/api/https.js
  3. 14 13
      chat/src/components/index.vue
  4. 44 34
      chat/src/components/knowledgeLibrary.vue
  5. 3 4
      chat/src/main.js

+ 10 - 10
chat/config/index.js

@@ -9,16 +9,16 @@ module.exports = {
     // Paths
     assetsSubDirectory: 'static',
     assetsPublicPath: '/',
-    proxyTable: {
-      '/api': {
-        target:'http://103.108.43.176:8080',  // 线上地址
-        // target:'http://192.168.2.187:8090',  // 本地地址
-        changeOrigin: false,
-        pathRewrite: {
-          '^/api':''
-        }
-      }
-    },
+    // proxyTable: {
+    //   '/api': {
+    //     target:'http://kfadmin.bocai186.com',  // 线上地址
+    //     // target:'http://192.168.2.187:8090',  // 本地地址
+    //     changeOrigin: false,
+    //     pathRewrite: {
+    //       '^/api':''
+    //     }
+    //   }
+    // },
 
     // Various Dev Server settings
     host: 'localhost', // can be overwritten by process.env.HOST  localhost 192.168.2.195

+ 55 - 48
chat/src/api/https.js

@@ -1,55 +1,62 @@
 import axios from 'axios';
 import $qs from 'qs';
-
-//配置地址
-//axios.defaults.baseURL ='http://192.168.2.186:8090'  //'https://www.easy-mock.com/mock';
-
-//请求拦截器
-axios.interceptors.request.use(
-    config => {
-      config.data = JSON.stringify(config.data);
-      config.headers = {
-        'Content-Type':'application/x-www-form-urlencoded'
-      }
-      return config;
-    },
-    error => {
-      return Promise.reject(err);
-    }
-);
-axios.interceptors.response.use(
-    response => {
-      return response;
-    },
-    error => {
-      return Promise.reject(error)
-    }
-)
-
-//get\post封装
+// 请求超时时间
+axios.defaults.timeout = 10000
+// 线上
+let Base = 'http://kfadmin.bocai186.com'
+// 开发
+//let Base = 'http://sports.5gogo.com'
+function headerUrl (url) {
+    url = Base +  url
+    return url
+}
+// post请求头
+axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
 export default {
-    post(url,data){
-      return new Promise((resolve,reject) => {
-        console.log(data)
-        axios.post(url,$qs.stringify(data))
-          .then(response => {
-            resolve(response.data);
-          },err => {
-            reject(err)
-          })
-      })
+    /**
+     * get方法对应get请求
+     * @param {String}url 请求地址
+     * @param {Object}params 携带参数
+     * @returns {Promise}
+     */
+    get (url, params) {
+        return new Promise((resolve, reject) => {
+            axios.get(headerUrl(url),params)
+                .then(res => {
+                    resolve(res)
+                })
+                .catch(err => {
+                    reject(err)
+                })
+        })
+    },
+    /**
+     * post方法对应post请求
+     * @param {String} url 请求地址
+     * @param {Object} params 携带参数
+     * @returns {Promise}
+     */
+    post (url, params,headers) {
+        return new Promise((resolve, reject) => {
+            axios.post(headerUrl(url), params ? $qs.stringify(params):'',headers)
+                .then(res => {
+                    resolve(res)
+                })
+                .catch(err => {
+                    reject(err)
+                })
+        })
     },
-    get(url,params){
-      return new Promise((resolve,reject) => {
-        axios.get(url,{
-          params:params
+    uploadPost(url, params) {
+        return new Promise((resolve, reject) => {
+            // console.log(params);
+            axios.post(headerUrl(url), params)
+                .then(res => {
+                    resolve(res)
+                })
+                .catch(err => {
+                    reject(err)
+                })
         })
-          .then(response => {
-            resolve(response.data);
-          })
-          .catch(err => {
-            reject(err)
-          })
-      })
     }
 }

+ 14 - 13
chat/src/components/index.vue

@@ -337,9 +337,8 @@
 							</p>
 						</div>
 						<div class="row center">
-							<img style="width:1.8rem;height:1.8rem;" v-if="service_info.avatar == ''" :src="avatar_imgs">
-							<img style="width:1.8rem;height:1.8rem;" v-if="service_info.avatar != ''"
-								 :src="img_http + service_info.avatar">
+							<img style="width:1.8rem;height:1.8rem;" v-if="!trueImg" :src="avatar_imgs">
+							<img style="width:1.8rem;height:1.8rem;" v-if="trueImg" :src="img_http +service_info.avatar">
 						</div>
 					</div>
 					<div class="leftMain-chenter"
@@ -477,8 +476,8 @@
 	import "../css/index.css";
 	import knowledgeLibrary from './knowledgeLibrary'
 	import frce from "./frce.js";
-	import avatarImgs from "./../assets/user.png"
 	import defaultImgs from "./../assets/timg.jpg"
+	import headPortrait from "./../assets/headPortrait.png"
 
 	export default {
 		name: "service",
@@ -504,7 +503,7 @@
 				problem: [],//机器人问题
 				welcome: [],//欢迎语
 				advertisement: '', //广告
-				img_http: 'http://103.108.43.176:8080',//图片路径域
+				img_http: 'http://kfadmin.bocai186.com',//图片路径域
 				//img_http:'http://192.168.2.186:8090',//图片路径域
 
 				robot: [],//和机器人聊天临时数据
@@ -513,7 +512,7 @@
 				isConnection: true,//人工分组列表开关
 				//客服信息
 				service_info: {
-					avatar: '/static/customer/images/robot.png',
+					avatar: headPortrait,
 					job_name: '001',
 					name: '智能客服',
 					signature: ""
@@ -539,7 +538,7 @@
 				historyMsgtext: "", // 历史信息内容提示
 				hisSviceChat: [],
 				showHistory: true,
-				avatar_imgs: avatarImgs,
+				avatar_imgs: headPortrait,
 				webTime: '',//人工会话上一次发送消息时间
 				chatIndex: '',//人工会话上一次下标
 				/*****************websockt心跳变量*******************/
@@ -552,6 +551,7 @@
 				serviceNotOnlineText: '',
 				comtSuccess:false,
 				hisLength:0,
+				trueImg:false,
 			};
 		},
 		// 方法
@@ -666,6 +666,7 @@
 
 				//人工链接
 				if (redata.message_type == 'connect') {
+					this.trueImg = true
 					this.chat.splice(-1)
 					let server = {};
 					if (redata.data) {
@@ -1002,7 +1003,7 @@
 					}
 				}
 
-				this.post('api/index/register/autoReg', data, obj).then(res => {
+				this.$http.post('/index/register/autoReg', data, obj).then(res => {
 					if (res.data.code == 0) {
 						this.$dialog.alert({
 							mes: res.data.msg
@@ -1034,7 +1035,7 @@
 						"apiToken": this.setApiToken('index', 'robot', this.currentTime[0], 'index')
 					}
 				}
-				this.post('api/index/robot/index', {groups_id: 1, robotgroups_id: 1}, obj).then(res => {
+				this.$http.post('/index/robot/index', {groups_id: 1, robotgroups_id: 1}, obj).then(res => {
 					//console.log(res.data.data);
 					this.problem = res.data.data;
 				})
@@ -1152,7 +1153,7 @@
 				}
 				// this.isConnection = false;
 				//api
-				this.get('api/index/groups/index', obj).then(res => {
+				this.$http.get('/index/groups/index', obj).then(res => {
 					if (res.data.code == 1) {
 						this.robot.push({
 							type: 'artificial_service',
@@ -1211,7 +1212,7 @@
 						// let img = imgSrc;
 
 						// 数据结构请求
-						self.post('api/index/upload/uploadImg', formData).then(res => {
+						self.$http.uploadPost('/index/upload/uploadImg', formData).then(res => {
 							// console.log(res.data.code)
 							if (res.data.code == 1) {
 								let type = 'toRobot';
@@ -1416,7 +1417,7 @@
 
 			/* ****************获取聊天次数****************** */
 			getChatNum() {
-				this.get('/api/index/evaluate/minRound', {
+				this.$http.get('/index/evaluate/minRound', {
 					headers: {
 						'Content-Type': 'application/x-www-form-urlencoded',
 						'apiToken': this.setApiToken('minround', 'evaluate', this.currentTime[0], 'index')
@@ -1448,7 +1449,7 @@
 			//console.log(this.$md5('userwordscustomer-servicewords1562169600service'));
 			this.$dialog.loading.open('网络连接中...')
 
-			this.$axios.get('api/index/index/systime?t=' + 100).then(res => {
+			this.$http.get('/index/index/systime?t=' + 100).then(res => {
 				if (res.data.code == 1) {
 					this.logo = res.data.data.logo;
 					this.currentTime = res.data.data.time.split(' ')

+ 44 - 34
chat/src/components/knowledgeLibrary.vue

@@ -54,7 +54,7 @@
 								<div class="text">
 									{{item.content}}
 								</div>
-								<ul class="imgs" v-if="item.image" >
+								<ul class="imgs" v-if="item.image">
 									<li v-for="i in item.image">
 										<img :src="url + i" alt="">
 									</li>
@@ -113,7 +113,7 @@
             </span>
 						<b style="color:#F04992">{{formText.email}}</b>
 						<br/>
-						<input type="email" v-model="leave.email"/>
+						<input type="email" v-model="leave.email" @blur="emailBlur()"/>
 					</div>
 					<p>
             <span style="color:#666;">
@@ -226,16 +226,17 @@
 				imgSrcList: [], //上传图片列表
 				serchInputValue: "", //搜索输入框的值
 				setImgList: [],//上传图片
-				valTime:"week",
+				valTime: "week",
 				pages: 1,
 				imgs: [],
 				imgss: [],
 				url: 'http://kfadmin.bocai186.com', // 域名地址
 				// url: 'http://192.168.2.187:8090', // 域名地址
-				fileList:[],
-				filesImg:'',
-				showImg:false,
-				showImgs:false,
+				fileList: [],
+				filesImg: '',
+				showImg: false,
+				showImgs: false,
+				onSubmit:false
 			};
 		},
 		props: ["currentTime"],
@@ -267,6 +268,7 @@
 			/*******************************************/
 			// 用户留言上传图片
 			leaveFile(e) {
+
 				let self = this;
 				let files = e.target.files || e.dataTransfer.files;
 				if (!files.length) return;
@@ -289,9 +291,9 @@
 				//将图片转成base64格式
 				reader.readAsDataURL(picavalue);
 				//读取成功后的回调
-				reader.onloadend = function() {
+				reader.onloadend = function () {
 					let result = this.result;
-					_this.$set(picavalue,'src', result);
+					_this.$set(picavalue, 'src', result);
 					_this.imgSrcList.push(picavalue);
 					// console.log(_this.imgSrcList,'读取')
 					_this.$forceUpdate();
@@ -299,10 +301,10 @@
 			},
 
 			// 获取选择内容
-			getList(val){
+			getList(val) {
 				this.valTime = val;
 				let a = document.querySelector("#lists .yd-accordion-content")
-				a.style.height = 0 +"px";
+				a.style.height = 0 + "px";
 			},
 
 			// 留言知识库数据获取
@@ -313,12 +315,12 @@
 						apiToken: this.setApiToken("index", "message", this.currentTime[0], "index")
 					}
 				};
-				this.post("api/index/Message/index", {
-				        time: this.valTime,
+				this.$http.post("/index/Message/index", {
+						time: this.valTime,
 						key: this.serchInputValue,
 						type: this.mainTitle,
-						pageSize:size,
-						pageNumber:page
+						pageSize: size,
+						pageNumber: page
 					},
 					obj
 				).then(res => {
@@ -329,11 +331,11 @@
 						let _img;
 						let _imgs;
 						for (let i = 0; i < res.data.data.list.length; i++) {
-							if(res.data.data.list[i].image){
+							if (res.data.data.list[i].image) {
 								_img = res.data.data.list[i].image.split(",");
 								res.data.data.list[i].image = _img;
 							}
-							if(res.data.data.list[i].images){
+							if (res.data.data.list[i].images) {
 								_imgs = res.data.data.list[i].images.split(",");
 								res.data.data.list[i].images = _imgs;
 							}
@@ -353,7 +355,7 @@
 						apiToken: this.setApiToken("type", "message", this.currentTime[0], "index")
 					}
 				}
-				this.post('api/index/Message/type', {}, obj).then((res) => {
+				this.$http.post('/index/Message/type', {}, obj).then((res) => {
 					if (res.data.status == 1) {
 						this.typeList = res.data.data;
 					}
@@ -362,6 +364,10 @@
 			},
 			// 留言信息提交
 			leaveSubmit() {
+				if(this.onSubmit){
+					return false;
+				}
+				this.onSubmit = true;
 				let uid = localStorage.getItem('uid');
 				if (this.leave.call == '') {
 					this.$dialog.toast({mes: '请填写称呼', timeout: 1500});
@@ -371,15 +377,16 @@
 
 					for (let i = 0; i < this.imgSrcList.length; i++) {
 						var formData = new FormData();
-						formData.append('file',this.imgSrcList[i])
+						formData.append('file', this.imgSrcList[i]);
 						// 提交图片
-						this.post('api/index/upload/uploadImg',formData).then((res) => {
+						this.$http.uploadPost('/index/upload/uploadImg', formData).then((res) => {
+
 							this.filesImg = this.filesImg ? this.filesImg + "," + res.data.data.src : res.data.data.src;
 						})
 					}
 
 					// 提交表单
-					setTimeout(()=>{
+					setTimeout(() => {
 						let obj = {
 							headers: {
 								apiToken: this.setApiToken("LeavingMessage", "User", this.currentTime[0], "index")
@@ -393,20 +400,21 @@
 							'file': this.filesImg,
 							'account_id': uid,
 						}
-						this.post('api/index/User/LeavingMessage', params, obj).then((res) => {
+						this.$http.post('/index/User/LeavingMessage', params, obj).then((res) => {
 							if (res.data.code == 1) {
+								this.onSubmit = false;
 								this.$dialog.toast({mes: "留言成功", timeout: 1500});
 							}
 						})
 						this.flag = false;
-						this.fileList =[];
+						this.fileList = [];
 						this.leave.call = ''
 						this.leave.email = ''
 						this.leave.describe = ''
 						this.leave.phone = ''
 						this.leave.filesImg = ''
 						this.imgSrcList = []
-					},1000)
+					}, 1000)
 				}
 
 			},
@@ -429,12 +437,12 @@
 				}
 			},
 			// 验证邮箱
-			// emailBlur(){
-			//   if(!(/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(this.leave.email))){
-			//     this.leave.email = ''
-			//     this.formText.email = "邮箱格式错误,请重填"
-			//   }
-			// }
+			emailBlur() {
+				if (!(/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(this.leave.email))) {
+					this.leave.email = ''
+					this.formText.email = "邮箱格式错误,请重填"
+				}
+			}
 		},
 		mounted() {
 			this.getAjaxType()
@@ -829,19 +837,21 @@
 	}
 
 	.imgs li img {
-		width:1rem;
-		height:1rem;
+		width: 1rem;
+		height: 1rem;
 	}
 
 	.reply_title {
 		text-align: right;
 	}
+
 	.reply_text {
 		margin-top: 10px;
 		text-align: right;
-		word-wrap:break-word;
+		word-wrap: break-word;
 	}
+
 	.text {
-		word-wrap:break-word;
+		word-wrap: break-word;
 	}
 </style>

+ 3 - 4
chat/src/main.js

@@ -8,18 +8,17 @@ import publicMethods from './publicMethods';
 import md5 from 'js-md5';
 import YDUI from 'vue-ydui'; /* 相当于import YDUI from 'vue-ydui/ydui.rem.js' */
 import 'vue-ydui/dist/ydui.rem.css';
+import https from './api/https.js'; //api接口文档
 
 Vue.use(YDUI);
 Vue.config.productionTip = false;
 Vue.prototype.$public = publicMethods;
 Vue.prototype.$md5 = md5;
-Vue.prototype.post=axios.post;
-Vue.prototype.get=axios.get;
-Vue.prototype.$axios=axios;
+Vue.prototype.$http = https;
 
 /* eslint-disable no-new */
 new Vue({
   el: '#app',
   components: { App },
   template: '<App/>'
-})
+});