案例修改、图片预览
This commit is contained in:
		| @@ -1,11 +1,35 @@ | ||||
| <template> | ||||
|   <div> | ||||
|   <!-- 多文件下载对话框 --> | ||||
|   <el-dialog :title="title" :visible.sync="open" @closed="cancel" width="600px" append-to-body> | ||||
|   <div class="app-container"> | ||||
|  | ||||
|   <el-dialog :title="title" :visible.sync="open" @closed="cancel" width="700px" append-to-body> | ||||
|   <div class="app-container" style="height: 400px; overflow: auto"> | ||||
|     <div style="margin: -20px auto 15px auto"> | ||||
|       <el-button type="primary" @click="lazyShow = true" plain>滚动下拉预览</el-button> | ||||
|     </div> | ||||
|     <el-table v-loading="loading" :data="fileList"> | ||||
|       <el-table-column label="文件名" align="center" prop="fileName" /> | ||||
|       <el-table-column label="上传时间" align="center" prop="createTime" /> | ||||
|       <el-table-column label="文件预览" align="center" prop="fileUrl"> | ||||
|       <template slot-scope="scope"> | ||||
|         <el-image v-if="scope.row.imageFlag" title="点击大图预览" | ||||
|           style="width: 80px; height: 80px" | ||||
|           :src="scope.row.downUrl" | ||||
|           :preview-src-list="imageList"> | ||||
|         </el-image> | ||||
|         <span v-else>不可预览</span> | ||||
|       </template> | ||||
|       </el-table-column> | ||||
|       <el-table-column label="文件名" align="center" prop="fileName"  width="200"> | ||||
|         <template slot-scope="scope"> | ||||
|           <AutoHideMessage :maxLength="10" :data="scope.row.fileName"></AutoHideMessage> | ||||
|         </template> | ||||
|       </el-table-column> | ||||
|  | ||||
|       <el-table-column label="上传时间" align="center" prop="createTime" > | ||||
|         <template slot-scope="scope"> | ||||
|         <span>{{ | ||||
|             parseTime(scope.row.createTime, "{y}-{m}-{d}") | ||||
|           }}</span> | ||||
|         </template> | ||||
|       </el-table-column> | ||||
|       <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ||||
|         <template slot-scope="scope"> | ||||
|           <el-button | ||||
| @@ -17,21 +41,30 @@ | ||||
|         </template> | ||||
|       </el-table-column> | ||||
|     </el-table> | ||||
|  | ||||
|   </div> | ||||
|     <div slot="footer" class="dialog-footer"> | ||||
|       <el-button @click="cancel">取 消</el-button> | ||||
|     </div> | ||||
|   </el-dialog> | ||||
|  | ||||
|   <el-dialog :title="'滚动下拉预览'" v-if="lazyShow" :visible.sync="lazyShow" width="600px" style="height: 90%; overflow: auto" append-to-body> | ||||
|     <div class="demo-image__lazy"> | ||||
|       <el-image v-for="(url,index) in imageList" :class="index !=0 ? 'top-10' : ''" :key="url" :src="url" lazy></el-image> | ||||
|     </div> | ||||
|     <div slot="footer" class="dialog-footer"> | ||||
|       <el-button @click="lazyShow = false">取 消</el-button> | ||||
|     </div> | ||||
|   </el-dialog> | ||||
|   </div> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| import { downCaseFile } from "@/api/custom/customerCase"; | ||||
|  | ||||
| import AutoHideMessage from "@/components/AutoHideMessage"; | ||||
| export default { | ||||
|   name: "MuchFileDown", | ||||
|   components: { | ||||
|  | ||||
|     AutoHideMessage | ||||
|   }, | ||||
|   data() { | ||||
|     return { | ||||
| @@ -43,8 +76,14 @@ export default { | ||||
|       open: false, | ||||
|       //案例id | ||||
|       caseId: null, | ||||
|       //支持预览的文件类型 | ||||
|       imgArr: ['jpg', 'jpeg', 'png', 'gif'], | ||||
|       //文件列表 | ||||
|       fileList: [] | ||||
|       fileList: [], | ||||
|       //图片文件列表 | ||||
|       imageList:[], | ||||
|       //懒加载 | ||||
|       lazyShow: false | ||||
|     }; | ||||
|   }, | ||||
|   created() { | ||||
| @@ -55,6 +94,13 @@ export default { | ||||
|   methods: { | ||||
|     showDialog(title, fileList) { | ||||
|       this.title = title ? title : "文件列表"; | ||||
|       fileList.forEach((item, index) => { | ||||
|         item["imageFlag"] = this.isImage(item.fileName); | ||||
|         if(item["imageFlag"]){ | ||||
|            //this.$set(this.imageList, this.imageList.length, item.downUrl) | ||||
|            this.imageList.push(item.downUrl); | ||||
|         } | ||||
|       }); | ||||
|       this.fileList = fileList; | ||||
|       this.loading = false; | ||||
|       this.open = true; | ||||
| @@ -64,10 +110,29 @@ export default { | ||||
|       this.open = false; | ||||
|       this.caseId = null; | ||||
|       this.fileList = []; | ||||
|       this.imageList = []; | ||||
|     }, | ||||
|     downloadFile(file){ | ||||
|       if(file == undefined || file == null || file.downUrl == null || file.downUrl == ""){ | ||||
|         this.$message({message: "文件不存在", type: "warning",}); | ||||
|         return; | ||||
|       } | ||||
|       downCaseFile(file.downUrl); | ||||
|     }, | ||||
|     isImage(name){ | ||||
|       var idx = name.indexOf('.'); | ||||
|       if (idx === -1) { | ||||
|         return false; | ||||
|       } | ||||
|       var type = name.substr(idx + 1); | ||||
|       return this.imgArr.indexOf(type) !== -1 ? true : false; | ||||
|     } | ||||
|   }, | ||||
| }; | ||||
| </script> | ||||
|  | ||||
| <style scoped> | ||||
|   .top-10{ | ||||
|     margin-top: 10px; | ||||
|   } | ||||
| </style> | ||||
|   | ||||
| @@ -9,6 +9,7 @@ | ||||
|              :file-list="upload.fileList" | ||||
|              :multiple="upload.multiple" | ||||
|              :on-change="handleFileChange" | ||||
|              :on-remove="handleFileRemove" | ||||
|              :on-exceed="handleFileexceed" | ||||
|              :on-progress="handleFileUploadProgress" | ||||
|              :on-success="handleFileSuccess" | ||||
| @@ -17,7 +18,7 @@ | ||||
|              :auto-upload="false"> | ||||
|     <i class="el-icon-upload"></i> | ||||
|     <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div> | ||||
|     <div class="el-upload__tip" slot="tip">每个案例最多上传5个文件,且每个文件不超过10M</div> | ||||
|     <div class="el-upload__tip" slot="tip">最多可上传{{upload.limit}}个文件,且每个文件不超过{{upload.fileSize/(1024*1024)}}M</div> | ||||
|   </el-upload> | ||||
| </template> | ||||
| <script> | ||||
| @@ -41,8 +42,8 @@ export default { | ||||
|         //文件列表 | ||||
|         fileList:[], | ||||
|         //同时上传文件上限 | ||||
|         limit: 5, | ||||
|         //每个文件大小 | ||||
|         limit: 10, | ||||
|         //每个文件大小(单位:byte) | ||||
|         fileSize: 1024 * 1024 * 10, | ||||
|         //是否支持同时选择多张 | ||||
|         multiple: true | ||||
| @@ -66,6 +67,10 @@ export default { | ||||
|       this.uploadResult["fileUrl"] = []; | ||||
|       this.uploadResult["fileName"] = []; | ||||
|     }, | ||||
|     //移除文件 | ||||
|     handleFileRemove(file, fileList){ | ||||
|       this.upload.fileList = fileList; | ||||
|     }, | ||||
|     //监控上传文件列表 | ||||
|     handleFileChange(file, fileList) { | ||||
|       let sizeFlag = file.size > this.upload.fileSize; | ||||
| @@ -110,9 +115,10 @@ export default { | ||||
|     } | ||||
|   }, | ||||
|   props: { | ||||
|  | ||||
|   }, | ||||
|   created() { | ||||
|  | ||||
|       this.uploadReset(); | ||||
|   }, | ||||
|  | ||||
| }; | ||||
|   | ||||
							
								
								
									
										165
									
								
								stdiet-ui/src/components/FileUpload/DragUploadEdit.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										165
									
								
								stdiet-ui/src/components/FileUpload/DragUploadEdit.vue
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,165 @@ | ||||
| <template> | ||||
|   <div> | ||||
|     <div v-for="(item, index) in oldCaseFileList"> | ||||
|       <span style="margin-right: 10px;"> | ||||
|         {{item.fileName ? (item.fileName.substring(0,15)+"..."): ""}} | ||||
|       </span> | ||||
|       <el-button style="margin-left: 10px;" type="danger" size="small" @click="removeOldFile(index)">移除该文件</el-button> | ||||
|     </div> | ||||
|     <el-upload class="upload-demo" style="margin-top: 10px;" | ||||
|                ref="upload" | ||||
|                drag | ||||
|                :headers="upload.headers" | ||||
|                :action="upload.url" | ||||
|                :limit="upload.limit" | ||||
|                :disabled="upload.isUploading" | ||||
|                :file-list="upload.fileList" | ||||
|                :multiple="upload.multiple" | ||||
|                :on-remove="handleFileRemove" | ||||
|                :on-change="handleFileChange" | ||||
|                :on-exceed="handleFileexceed" | ||||
|                :on-progress="handleFileUploadProgress" | ||||
|                :on-success="handleFileSuccess" | ||||
|                :on-error="handleFileFail" | ||||
|                :data="upload.data" | ||||
|                :auto-upload="false"> | ||||
|       <i class="el-icon-upload"></i> | ||||
|       <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div> | ||||
|       <div class="el-upload__tip" slot="tip">已存在{{oldCaseFileList.length}}个文件,还可上传{{upload.limit}}个文件,且每个文件不超过{{upload.fileSize/(1024*1024)}}M</div> | ||||
|     </el-upload> | ||||
|   </div> | ||||
| </template> | ||||
| <script> | ||||
|   import { getToken } from '@/utils/auth' | ||||
|   import AutoHideMessage from "@/components/AutoHideMessage"; | ||||
| export default { | ||||
|   name: "DragUploadEdit", | ||||
|   components: { | ||||
|       "AutoHideMessage":AutoHideMessage | ||||
|   }, | ||||
|   data() { | ||||
|     return { | ||||
|       upload: { | ||||
|         // 是否禁用上传 | ||||
|         isUploading: false, | ||||
|         // 上传的地址 | ||||
|         url: process.env.VUE_APP_BASE_API + "/custom/customerCase/uploadCaseFile", | ||||
|         // 设置上传的请求头部 | ||||
|         headers: {Authorization: 'Bearer ' + getToken()}, | ||||
|         // 其他需要携带的数据 | ||||
|         data:{}, | ||||
|         //文件列表 | ||||
|         fileList:[], | ||||
|         //同时上传文件上限 | ||||
|         limit: 10 - this.caseFileList.length, | ||||
|         //每个文件大小(单位:byte) | ||||
|         fileSize: 1024 * 1024 * 10, | ||||
|         //是否支持同时选择多张 | ||||
|         multiple: true | ||||
|       }, | ||||
|       oldCaseFileList: this.caseFileList, | ||||
|       uploadResult:{ | ||||
|         fileUrl:[], | ||||
|         fileName:[] | ||||
|       } | ||||
|     }; | ||||
|   }, | ||||
|   methods: { | ||||
|     uploadFile(){ | ||||
|       if(this.upload.fileList.length > 0 && this.uploadResult.fileUrl.length < this.upload.fileList.length){ | ||||
|         this.$refs.upload.submit(); | ||||
|       }else{ | ||||
|         //合并旧文件 | ||||
|         if(this.oldCaseFileList != null && this.oldCaseFileList.length > 0){ | ||||
|           this.oldCaseFileList.forEach((item, index) => { | ||||
|             this.uploadResult.fileUrl.unshift(item.fileUrl); | ||||
|             this.uploadResult.fileName.unshift(item.fileName); | ||||
|           }); | ||||
|         } | ||||
|         this.$emit('callbackMethod', this.uploadResult); | ||||
|       } | ||||
|     }, | ||||
|     removeOldFile(index){ | ||||
|       this.oldCaseFileList.splice(index,1); | ||||
|       this.upload.limit = 10 - this.oldCaseFileList.length; | ||||
|     }, | ||||
|     uploadReset(){ | ||||
|       this.upload.fileList = []; | ||||
|       this.uploadResult["fileUrl"] = []; | ||||
|       this.uploadResult["fileName"] = []; | ||||
|       this.oldCaseFileList = []; | ||||
|     }, | ||||
|     //移除文件 | ||||
|     handleFileRemove(file, fileList){ | ||||
|       this.upload.fileList = fileList; | ||||
|     }, | ||||
|     //监控上传文件列表 | ||||
|     handleFileChange(file, fileList) { | ||||
|       let sizeFlag = file.size > this.upload.fileSize; | ||||
|       if (sizeFlag) { | ||||
|         this.$message({ | ||||
|           message: "当前文件过大", | ||||
|           type: "warning", | ||||
|         }); | ||||
|         fileList.pop(); | ||||
|       } | ||||
|       this.upload.fileList = fileList; | ||||
|     }, | ||||
|     // 文件数量超过限度 | ||||
|     handleFileexceed(file, fileList){ | ||||
|       this.$message({ | ||||
|         message: "最多可上传"+ this.upload.limit +"份文件", | ||||
|         type: "warning", | ||||
|       }); | ||||
|     }, | ||||
|     // 文件上传中处理 | ||||
|     handleFileUploadProgress(event, file, fileList) { | ||||
|       //this.upload.isUploading = true; | ||||
|     }, | ||||
|     // 文件上传成功处理 | ||||
|     handleFileSuccess(response, file, fileList) { | ||||
|       if(response != null && response.code === 200){ | ||||
|         this.uploadResult.fileUrl.push(response.fileUrl); | ||||
|         this.uploadResult.fileName.push(response.fileName); | ||||
|         if(this.uploadResult.fileUrl.length === this.upload.fileList.length){ | ||||
|           //文件全部上传成功,则调用回调方法 | ||||
|           if(this.oldCaseFileList != null && this.oldCaseFileList.length > 0){ | ||||
|             this.oldCaseFileList.forEach((item, index) => { | ||||
|               this.uploadResult.fileUrl.unshift(item.fileUrl); | ||||
|               this.uploadResult.fileName.unshift(item.fileName); | ||||
|             }); | ||||
|           } | ||||
|           this.$emit('callbackMethod', this.uploadResult); | ||||
|         } | ||||
|       }else{ | ||||
|         this.upload.fileList = fileList.pop(); | ||||
|         this.$message.error('文件上传失败,请检查文件格式'); | ||||
|       } | ||||
|     }, | ||||
|     // 文件上传失败处理 | ||||
|     handleFileFail(err, file, fileList){ | ||||
|       this.$message.error('文件上传失败,请检查文件格式'); | ||||
|       this.upload.fileList = fileList.pop(); | ||||
|     } | ||||
|   }, | ||||
|   props: { | ||||
|     caseFileList:{ | ||||
|       type: Array, | ||||
|       default: function () { | ||||
|         return []; | ||||
|       } | ||||
|     } | ||||
|   }, | ||||
|   created() { | ||||
|  | ||||
|   }, | ||||
|  | ||||
| }; | ||||
| </script> | ||||
|  | ||||
| <style scoped> | ||||
|  | ||||
|  | ||||
|  | ||||
| </style> | ||||
|  | ||||
| @@ -66,8 +66,8 @@ export default { | ||||
|   }, | ||||
|   methods: { | ||||
|     removeOldFile(index){ | ||||
|       this.form.medicalReport = this.form.medicalReport.splice(index,index); | ||||
|       this.form.medicalReportName = this.form.medicalReportName.splice(index,index); | ||||
|       this.form.medicalReport.splice(index,1); | ||||
|       this.form.medicalReportName.splice(index,1); | ||||
|       this.upload.limit = 3 - this.form.medicalReport.length; | ||||
|     }, | ||||
|     getReportName(index){ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user