| | |
| | | :before-upload="handleAttachmentBeforeUpload" |
| | | :on-error="handleAttachmentUploadError" |
| | | :on-success="handleAttachmentUploadSuccess" |
| | | :on-preview="handleAttachmentPreview" |
| | | :on-remove="handleAttachmentRemove" |
| | | list-type="picture-card" |
| | | :limit="9" |
| | |
| | | <template #footer> |
| | | <el-button @click="attachment.visible = false">关闭</el-button> |
| | | </template> |
| | | </el-dialog> |
| | | |
| | | <el-dialog |
| | | v-model="attachment.previewVisible" |
| | | title="图片预览" |
| | | width="70%" |
| | | append-to-body |
| | | > |
| | | <div class="attachment-preview-wrap"> |
| | | <img |
| | | v-if="attachment.previewUrl" |
| | | :src="attachment.previewUrl" |
| | | alt="preview" |
| | | class="attachment-preview-img" |
| | | /> |
| | | </div> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | |
| | | deviceRepairId: undefined, |
| | | files: [], |
| | | fileList: [], |
| | | previewVisible: false, |
| | | previewUrl: "", |
| | | }); |
| | | |
| | | const normalizeFileUrl = (rawUrl = '') => { |
| | |
| | | attachment.deviceRepairId = undefined; |
| | | attachment.files = []; |
| | | attachment.fileList = []; |
| | | attachment.previewVisible = false; |
| | | attachment.previewUrl = ""; |
| | | }; |
| | | |
| | | const handleAttachmentBeforeUpload = (file) => { |
| | |
| | | |
| | | const handleAttachmentUploadError = () => { |
| | | ElMessage.error("上传失败"); |
| | | }; |
| | | |
| | | const handleAttachmentPreview = (file) => { |
| | | const rawUrl = file?.url || file?.response?.data?.url || ""; |
| | | if (!rawUrl) { |
| | | ElMessage.warning("图片地址无效,无法预览"); |
| | | return; |
| | | } |
| | | attachment.previewUrl = normalizeFileUrl(rawUrl); |
| | | attachment.previewVisible = true; |
| | | }; |
| | | |
| | | const handleAttachmentRemove = async (file) => { |
| | |
| | | margin-bottom: 12px; |
| | | } |
| | | |
| | | .attachment-preview-wrap { |
| | | display: flex; |
| | | justify-content: center; |
| | | align-items: center; |
| | | min-height: 360px; |
| | | } |
| | | |
| | | .attachment-preview-img { |
| | | max-width: 100%; |
| | | max-height: 70vh; |
| | | object-fit: contain; |
| | | } |
| | | |
| | | </style> |