From af029bdfb645bd2b75fbab687c1a5f45b428d801 Mon Sep 17 00:00:00 2001
From: inleft <inleft@qq.com>
Date: Thu, 11 Aug 2022 18:53:48 +0800
Subject: [PATCH] 优化上传逻辑,月台添加mini播放弹窗

---
 src/components/mini/box10-add.vue |   79 +++++++++++++++++++++++----------------
 1 files changed, 46 insertions(+), 33 deletions(-)

diff --git a/src/components/mini/box10-add.vue b/src/components/mini/box10-add.vue
index 705e398..ef07260 100644
--- a/src/components/mini/box10-add.vue
+++ b/src/components/mini/box10-add.vue
@@ -22,11 +22,9 @@
 			</a-form-model-item>
 
 			<a-form-model-item label="日志文件" v-show="!form.online">
-
-				<a-upload :customRequest="customRequest" name="file" :showUploadList="true" @change="handleChange"
-					:default-file-list="form.blogFileList" :beforeUpload="beforeUpload"
-					:data="{'fileType':fileTypeMarkDown}">
-
+				<a-upload ref="blogFileUpload" :customRequest="customRequest" name="file" :showUploadList="true"
+					@change="handleChange" :default-file-list="form.blogFileList" :beforeUpload="beforeUpload"
+					:data="{'fileType':fileTypeMarkDown}" accept=".md,.html,.htm,.txt">
 					<a-button>
 						<a-icon type="upload" />限 markdown/html
 					</a-button>
@@ -104,8 +102,10 @@
 
 				<a-form-model-item label="封面">
 					<a-upload :customRequest="customRequest" name="file" :showUploadList="true" list-type="picture"
-						@change="handleChangeCoverFile" :default-file-list="form.coverFileList" 
-						:beforeUpload="beforeUploadCover" :data="{'fileType':fileTypeCover}">
+						:data="{'fileType':fileTypeCover}" @change="handleChangeCoverFile"
+						:default-file-list="form.coverFileList" :beforeUpload="beforeUploadCover"
+						accept=".jpg,.png,.jpeg">
+						<!-- :disabled="form.coverFileList.length>=1" -->
 						<a-button>
 							<a-icon type="upload" />jpg/png/jpeg..
 						</a-button>
@@ -195,18 +195,16 @@
 			})
 		},
 		data() {
-
+			let _this = this;
 			let validateContent = (rule, value, callback) => {
-				if (this.form.online) {
-					console.log("内容未填");
-					this.$refs.myForm.validateField('content')
-					if (this.form.content == null || this.form.content == "") {
+				if (_this.form.online) {
+					//this.$refs.myForm.validateField('content')
+					if (_this.form.content == null || _this.form.content == "") {
 						callback(new Error('内容未填'));
 					}
 				} else {
-					console.log("文件未传");
-					this.$refs.myForm.validateField('blogFileList')
-					if (this.form.fileId == null) {
+					//this.$refs.myForm.validateField('blogFileList')
+					if (_this.form.fileId == null) {
 						callback(new Error('文件未传'));
 					}
 				}
@@ -289,28 +287,31 @@
 			};
 		},
 		methods: {
-
-			beforeUploadCover(file, fileList) {
-				if (this.form.coverFileList.length > 1) {
-					this.$message.error('这里最多上传一个文件');
-					return false;
-				}
+			reset() {
+				// this.form.blogFileList = [];
+				// this.form.coverFileList = [];
 			},
-			beforeUpload(file, fileList) {
+			beforeUploadCover(file, fileList) {
 				return new Promise((resolve, reject) => {
-					if (this.form.fileId != null) {
+					if (this.form.coverFileList.length >= 1) {
 						this.$message.error('这里最多上传一个文件');
 						return reject(false);
 					}
-					// var testmsg=/^image\/(jpeg|png|jpg)$/.test(file.type)
-					// // var testmsg=/^image\/(md|html|markdown)$/.test(file.type)
-					// if (!testmsg) {
-					//   this.$message.error('上传文件格式不对!');
-					//   return reject(false);
-					// }
+					if (file.size > myConstant.uploadFileSizeLimit) {
+						this.$message.error('上传文件大小不能超过 2M!');
+						return reject(false);
+					}
+					return resolve(true)
+				});
+			},
+			beforeUpload(file, fileList) {
+				return new Promise((resolve, reject) => {
+					if (this.form.blogFileList.length >= 1) {
+						this.$message.error('这里最多上传一个文件');
+						return reject(false);
+					}
 
-					const isLt2M = file.size / 1024 / 1024 <= 2 //图片大小不超过2MB
-					if (!isLt2M) {
+					if (file.size > myConstant.uploadFileSizeLimit) {
 						this.$message.error('上传文件大小不能超过 2M!');
 						return reject(false);
 					}
@@ -319,6 +320,8 @@
 
 			},
 			handleChange(info) {
+				this.form.blogFileList = info.fileList;
+
 				if (info.file.status !== 'uploading') {
 					console.log(info.file, info.fileList);
 				}
@@ -328,8 +331,14 @@
 				} else if (info.file.status === 'error') {
 					this.$message.error(`${info.file.name} file upload failed.`);
 				}
+
+				if (this.form.blogFileList == null || this.form.blogFileList.length == 0) {
+					this.form.fileId = null
+				}
 			},
 			handleChangeCoverFile(info) {
+				this.form.coverFileList = info.fileList;
+
 				if (info.file.status !== 'uploading') {
 					console.log(info.file, info.fileList);
 				}
@@ -338,6 +347,10 @@
 					this.$message.success(`${info.file.name} file uploaded successfully`);
 				} else if (info.file.status === 'error') {
 					this.$message.error(`${info.file.name} file upload failed.`);
+				}
+
+				if (this.form.coverFileList == null || this.form.coverFileList.length == 0) {
+					this.form.coverFile = null
 				}
 			},
 			/**
@@ -365,9 +378,9 @@
 				return trigger => trigger.parentNode;
 			},
 			handleClose(removedTag) {
-				const tags = this.tags.filter(tag => tag !== removedTag);
+				// const tags = this.tags.filter(tag => tag !== removedTag);
 				//console.log(tags);
-				this.tags = tags;
+				this.tags = this.tags.filter(tag => tag !== removedTag);
 			},
 
 			showInput() {

--
Gitblit v1.9.1