提交 b4645f11 authored 作者: 王鹏飞's avatar 王鹏飞

新增图片预览器

上级 2393322f
...@@ -5743,7 +5743,7 @@ ...@@ -5743,7 +5743,7 @@
}, },
"html-tags": { "html-tags": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/html-tags/-/html-tags-2.0.0.tgz", "resolved": "https://registry.npm.taobao.org/html-tags/download/html-tags-2.0.0.tgz",
"integrity": "sha1-ELMKOGCF9Dzt41PMj6fLDe7qZos=" "integrity": "sha1-ELMKOGCF9Dzt41PMj6fLDe7qZos="
}, },
"html-webpack-plugin": { "html-webpack-plugin": {
...@@ -6708,7 +6708,7 @@ ...@@ -6708,7 +6708,7 @@
}, },
"lodash.kebabcase": { "lodash.kebabcase": {
"version": "4.1.1", "version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz", "resolved": "https://registry.npm.taobao.org/lodash.kebabcase/download/lodash.kebabcase-4.1.1.tgz",
"integrity": "sha1-hImxyw0p/4gZXM7KRI/21swpXDY=" "integrity": "sha1-hImxyw0p/4gZXM7KRI/21swpXDY="
}, },
"loglevel": { "loglevel": {
...@@ -13580,7 +13580,7 @@ ...@@ -13580,7 +13580,7 @@
}, },
"svg-tags": { "svg-tags": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/svg-tags/-/svg-tags-1.0.0.tgz", "resolved": "https://registry.npm.taobao.org/svg-tags/download/svg-tags-1.0.0.tgz",
"integrity": "sha1-WPcc7jvVGbWdSyqEO2x95krAR2Q=" "integrity": "sha1-WPcc7jvVGbWdSyqEO2x95krAR2Q="
}, },
"swiper": { "swiper": {
...@@ -14363,6 +14363,11 @@ ...@@ -14363,6 +14363,11 @@
"extsprintf": "^1.2.0" "extsprintf": "^1.2.0"
} }
}, },
"viewerjs": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/viewerjs/-/viewerjs-1.9.0.tgz",
"integrity": "sha512-2D1OdGatb5aCZbZvaCdbJYuoDObjD9ITe7GZp0SoG7rgw3arOIZoIO1ygmfG+I4+RvEuDo+aZ75kNgwmYS9j3w=="
},
"vlq": { "vlq": {
"version": "0.2.3", "version": "0.2.3",
"resolved": "https://registry.npm.taobao.org/vlq/download/vlq-0.2.3.tgz", "resolved": "https://registry.npm.taobao.org/vlq/download/vlq-0.2.3.tgz",
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
"@ezijing/vue-form": "^2.1.9", "@ezijing/vue-form": "^2.1.9",
"animate.css": "^4.1.0", "animate.css": "^4.1.0",
"axios": "^0.19.2", "axios": "^0.19.2",
"core-js": "^3.6.5",
"cross-env": "^7.0.2", "cross-env": "^7.0.2",
"element-ui": "^2.13.0", "element-ui": "^2.13.0",
"install": "^0.13.0", "install": "^0.13.0",
...@@ -83,6 +84,7 @@ ...@@ -83,6 +84,7 @@
"qrcode.vue": "^1.7.0", "qrcode.vue": "^1.7.0",
"swiper": "^5.4.5", "swiper": "^5.4.5",
"tween.js": "^16.6.0", "tween.js": "^16.6.0",
"viewerjs": "^1.9.0",
"vue": "^2.6.11", "vue": "^2.6.11",
"vue-awesome-swiper": "^4.1.1", "vue-awesome-swiper": "^4.1.1",
"vue-i18n": "^8.16.0", "vue-i18n": "^8.16.0",
...@@ -91,8 +93,7 @@ ...@@ -91,8 +93,7 @@
"vue-router": "^3.1.6", "vue-router": "^3.1.6",
"vue-scrollmagic": "^1.2.0", "vue-scrollmagic": "^1.2.0",
"vue-template-compiler": "^2.6.11", "vue-template-compiler": "^2.6.11",
"vuex": "^3.1.3", "vuex": "^3.1.3"
"core-js": "^3.6.5"
}, },
"engines": { "engines": {
"node": ">=8.9" "node": ">=8.9"
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
<template v-if="material.attachments"> <template v-if="material.attachments">
<ul class="attachments"> <ul class="attachments">
<li class="attachments-item" v-for="(item, index) in material.attachments" :key="index"> <li class="attachments-item" v-for="(item, index) in material.attachments" :key="index">
<a class="inner" :href="item.oss_sign_url" target="_blank"> <div class="inner" @click="handlePreview(item)">
<el-image :src="item.oss_sign_url" class="pic"> <el-image :src="item.oss_sign_url" class="pic">
<template #error> <template #error>
<i class="el-icon-document"></i> <i class="el-icon-document"></i>
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
<div v-if="item.status_desc"> <div v-if="item.status_desc">
<el-tag size="mini">{{ item.status_desc }}</el-tag> <el-tag size="mini">{{ item.status_desc }}</el-tag>
</div> </div>
</a> </div>
<el-button-group v-if="hasButton" style="margin-left: 40px"> <el-button-group v-if="hasButton" style="margin-left: 40px">
<el-button size="mini" :disabled="item.status === 'INACTIVE'" @click="handleRemove(item)" <el-button size="mini" :disabled="item.status === 'INACTIVE'" @click="handleRemove(item)"
>删除</el-button >删除</el-button
...@@ -112,9 +112,12 @@ ...@@ -112,9 +112,12 @@
</div> </div>
</div> </div>
</template> </template>
<img :src="previewImageUrl" :alt="previewImageTitle" id="image" style="display: none" />
</div> </div>
</template> </template>
<script> <script>
import 'viewerjs/dist/viewer.css'
import Viewer from 'viewerjs'
import * as api from '@/api/my' import * as api from '@/api/my'
// 行业类别 // 行业类别
...@@ -175,6 +178,9 @@ export default { ...@@ -175,6 +178,9 @@ export default {
data() { data() {
return { return {
loading: false, loading: false,
previewImageUrl: '',
previewImageTitle: '',
viewer: null,
material: {}, material: {},
progress: {}, progress: {},
options: [ options: [
...@@ -333,10 +339,10 @@ export default { ...@@ -333,10 +339,10 @@ export default {
computed: { computed: {
right() { right() {
const { right = '' } = this.$route.query const { right = '' } = this.$route.query
return right return right.toUpperCase()
}, },
hasButton() { hasButton() {
return this.right.includes('x') return this.right.includes('X')
} }
}, },
methods: { methods: {
...@@ -373,10 +379,52 @@ export default { ...@@ -373,10 +379,52 @@ export default {
api.changeFileStatus(this.material.user_id, data.id, status).then(response => { api.changeFileStatus(this.material.user_id, data.id, status).then(response => {
this.getApplication() this.getApplication()
}) })
},
// 预览
handlePreview(file) {
let url = file.oss_sign_url
if (!url) {
this.$message({ type: 'warning', message: '无法查看' })
return
}
url = url.includes('?') ? url.split('?').shift() : url
const names = ['jpg', 'jpeg', 'png', 'gif']
const name = url.split('.').pop() || ''
if (names.includes(name.toLocaleLowerCase())) {
this.previewImageUrl = file.oss_sign_url
this.previewImageTitle = file.file_type_label
this.$nextTick(() => {
this.viewer.update()
this.viewer.show(true)
})
} else {
this.newWindowPreview(file.oss_sign_url)
}
},
// 新窗口预览
newWindowPreview(url) {
const a = document.createElement('a')
a.href = url
a.target = '_blank'
document.body.appendChild(a)
a.click()
a.remove()
},
createViewer() {
this.viewer = new Viewer(document.getElementById('image'), {
navbar: false,
toolbar: { zoomIn: true, zoomOut: true, rotateLeft: true, rotateRight: true }
})
} }
}, },
beforeMount() { beforeMount() {
this.getApplication() this.getApplication()
},
mounted() {
this.createViewer()
},
destroyed() {
this.viewer && this.viewer.destroy()
} }
} }
</script> </script>
...@@ -483,6 +531,7 @@ export default { ...@@ -483,6 +531,7 @@ export default {
display: flex; display: flex;
align-items: center; align-items: center;
color: #222; color: #222;
cursor: pointer;
} }
.pic { .pic {
width: 40px; width: 40px;
...@@ -508,4 +557,7 @@ export default { ...@@ -508,4 +557,7 @@ export default {
border-top: 1px solid #ebeef5; border-top: 1px solid #ebeef5;
} }
} }
.viewer-toolbar > ul {
margin-bottom: 20px;
}
</style> </style>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论