luke 6 жил өмнө
parent
commit
8cfb4dad3d

+ 26 - 21
service/src/pages/LeaveMessage.vue

@@ -271,17 +271,21 @@
 			beforeAvatarUpload(file) {
 				// console.log(file, '上传之前')
 				const isJPG = file.type == 'image/jpeg' || 'image/jpg' || 'image/png' || 'image/svg';
+				const isLt1M = file.size / 1024 / 1024 < 2;
 				if (!isJPG) {
 					this.$message.error('上传只能是图片格式!');
 				}
-				return isJPG
+				if (!isLt1M) {
+					this.$message.error('上传文件大小不能超过 2MB!');
+				}
+				return isJPG && isLt1M;
 			},
 			// 上传成功时的回调
-			uploadSuccess(res, file) {
-				// console.log('res',file)
-				this.uploadImg.push(URL.createObjectURL(file.raw))
-				// console.log(this.uploadImg)
-				return this.uploadImg
+			uploadSuccess(res, file, fileList) {
+				console.log(res)
+				console.log(file)
+				console.log(fileList)
+
 			},
 			// 发送中
 			onProgress() {
@@ -291,12 +295,11 @@
 			uploadError() {
 				this.$message.error('上传失败,请重新上传')
 			},
-			handleRemove(file, fileList) {
-				// this.uploadImg = []
-				// fileList.forEach((res,index) => {
-				//   this.uploadImg.push(URL.createObjectURL(res.raw))
-				// });
-				// console.log(this.uploadImg)
+			handleRemove(res, file, fileList) {
+				this.uploadImg = []
+				fileList.forEach((res,index) => {
+				  this.uploadImg.push(URL.createObjectURL(res.raw))
+				});
 			},
 			// 每次改变图片状态返回的回调
 			uploadChange(file, fileList) {
@@ -306,16 +309,18 @@
 				this.$message.error(`图片上传数量最多4张`);
 			},
 			sendMessage() {
-				console.log(this.uploadImg)
+				console.log(this.uploadImg,"上传的图片")
 				this.$refs.upload.submit();
-				let formData = new FormData();
-				formData.append("user_id",this.users.id);
-				formData.append("message_id", this.uid);
-				formData.append("reply_content", this.leaveInfor);
-				formData.append("images",this.uploadImg);
-				this.post('/api/service/Message/dealmessage', formData).then(res => {
-					this.$message.success(res.data.msg);
-				})
+				// let parmas = {
+				// 	"user_id":this.users.id,
+				// 	"message_id":this.uid,
+				// 	"reply_content":this.leaveInfor,
+				// 	"images":this.uploadImg,
+				// }
+				// this.post('/api/service/Message/dealmessage', parmas).then(res => {
+				// 	console.log(res);
+				// 	this.$message.success(res.data.msg);
+				// })
 			},
 
 			/*****************获取当前聊天用户信息****************/