| | |
| | | :footer="null" |
| | | cancelText="关闭"> |
| | | <a-spin :spinning="confirmLoading"> |
| | | <img v-if="isImage" :src="fileUrl" width="100%" height="100%" alt="图片预览" /> |
| | | <iframe v-else-if="isPdf" :src="fileUrl" width="100%" height="600px"></iframe> |
| | | <img v-if="isImage" :src="localFileUrl" width="100%" height="100%" alt="图片预览" /> |
| | | <iframe v-else-if="isPdf" :src="localFileUrl" width="100%" height="600px"></iframe> |
| | | <video v-else-if="isVideo" controls> |
| | | <source :src="fileUrl" type="video/mp4"> |
| | | <source :src="localFileUrl" type="video/mp4"> |
| | | 您的浏览器不支持 video 标签。 |
| | | </video> |
| | | <pre v-else-if="isText">{{ textContent }}</pre> |
| | |
| | | title: '预览', |
| | | textContent: '', |
| | | confirmLoading: false, |
| | | visible: false |
| | | visible: false, |
| | | localFileUrl: this.fileUrl, |
| | | } |
| | | }, |
| | | computed: { |
| | | isImage() { |
| | | return /\.(jpeg|jpg|png|gif|bmp|webp)$/i.test(this.fileUrl) |
| | | return /\.(jpeg|jpg|png|gif|bmp|webp)$/i.test(this.localFileUrl) |
| | | }, |
| | | isPdf() { |
| | | return /\.pdf$/i.test(this.fileUrl) |
| | | return /\.pdf$/i.test(this.localFileUrl) |
| | | }, |
| | | isVideo() { |
| | | return /\.(mp4|webm|ogg)$/i.test(this.fileUrl) |
| | | return /\.(mp4|webm|ogg)$/i.test(this.localFileUrl) |
| | | }, |
| | | isText() { |
| | | return /\.(txt|md|json|xml|yaml|yml)$/i.test(this.fileUrl) |
| | | return /\.(txt|md|json|xml|yaml|yml)$/i.test(this.localFileUrl) |
| | | } |
| | | }, |
| | | watch: { |
| | | fileUrl: 'fetchTextContent' |
| | | localFileUrl: 'fetchTextContent' |
| | | }, |
| | | mounted() { |
| | | if (this.isText) { |
| | |
| | | preview(fileUrl) { |
| | | let url = getFileAccessHttpUrl(fileUrl) |
| | | this.visible = true |
| | | this.fileUrl = url |
| | | this.localFileUrl = url |
| | | }, |
| | | handleOk() { |
| | | this.close() |