增加附加视频预览功能,并对不支持预览的缩略图做不支持处理

pull/3445/head
guqing 2019-06-26 19:58:08 +08:00
parent 7b8a468ccf
commit 17ffe87f81
3 changed files with 82 additions and 12 deletions

View File

@ -21,12 +21,13 @@
"vue": "^2.6.10", "vue": "^2.6.10",
"vue-clipboard2": "^0.3.0", "vue-clipboard2": "^0.3.0",
"vue-codemirror-lite": "^1.0.4", "vue-codemirror-lite": "^1.0.4",
"vue-count-to": "^1.0.13",
"vue-cropper": "0.4.9", "vue-cropper": "0.4.9",
"vue-ls": "^3.2.1", "vue-ls": "^3.2.1",
"vue-router": "^3.0.6", "vue-router": "^3.0.6",
"vue-video-player": "^5.0.2",
"vuejs-logger": "^1.5.3", "vuejs-logger": "^1.5.3",
"vuex": "^3.1.1", "vuex": "^3.1.1"
"vue-count-to": "^1.0.13"
}, },
"devDependencies": { "devDependencies": {
"@babel/polyfill": "^7.4.4", "@babel/polyfill": "^7.4.4",

View File

@ -99,7 +99,8 @@
@click="handleShowDetailDrawer(item)" @click="handleShowDetailDrawer(item)"
> >
<div class="attach-thumb"> <div class="attach-thumb">
<img :src="item.thumbPath"> <span v-show="!handleJudgeMediaType(item)"></span>
<img :src="item.thumbPath" v-show="handleJudgeMediaType(item)">
</div> </div>
<a-card-meta> <a-card-meta>
<ellipsis <ellipsis
@ -242,6 +243,23 @@ export default {
onUploadClose() { onUploadClose() {
this.loadAttachments() this.loadAttachments()
this.loadMediaTypes() this.loadMediaTypes()
},
handleJudgeMediaType(attachment) {
var mediaType = attachment.mediaType
//
if(mediaType) {
var prefix = mediaType.split('/')[0]
if(prefix === 'image') {
//
return true
} else {
//
return false
}
}
//false
return false
} }
} }
} }
@ -262,13 +280,20 @@ export default {
position: relative; position: relative;
padding-bottom: 56%; padding-bottom: 56%;
overflow: hidden; overflow: hidden;
img { img, span{
width: 100%; width: 100%;
height: 100%; height: 100%;
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
} }
span {
display: flex;
font-size: 12px;
align-items: center;
justify-content: center;
color: #9b9ea0;
}
} }
.ant-card-meta { .ant-card-meta {

View File

@ -19,7 +19,12 @@
> >
<div class="attach-detail-img"> <div class="attach-detail-img">
<div v-show="nonsupportPreviewVisible"></div> <div v-show="nonsupportPreviewVisible"></div>
<img :src="attachment.path" v-if="photoPreviewVisible"> <img :src="attachment.path" v-show="photoPreviewVisible">
<video-player class="video-player-box" v-show="videoPreviewVisible"
ref="videoPlayer"
:options="playerOptions"
:playsinline="true">
</video-player>
</div> </div>
</a-skeleton> </a-skeleton>
</a-col> </a-col>
@ -149,18 +154,41 @@
import { mixin, mixinDevice } from '@/utils/mixin.js' import { mixin, mixinDevice } from '@/utils/mixin.js'
import attachmentApi from '@/api/attachment' import attachmentApi from '@/api/attachment'
import photoApi from '@/api/photo' import photoApi from '@/api/photo'
import 'video.js/dist/video-js.css'
import { videoPlayer } from 'vue-video-player'
export default { export default {
name: 'AttachmentDetailDrawer', name: 'AttachmentDetailDrawer',
mixins: [mixin, mixinDevice], mixins: [mixin, mixinDevice],
components: {
videoPlayer
},
data() { data() {
return { return {
detailLoading: true, detailLoading: true,
editable: false, editable: false,
photo: {}, photo: {},
photoPreviewVisible: false, photoPreviewVisible: false,
vedioPreviewVisible: false, videoPreviewVisible: false,
nonsupportPreviewVisible: false nonsupportPreviewVisible: false,
playerOptions: {
// videojs options
muted: true,
language: 'zh-CN',
aspectRatio: '16:9',
fluid: true,
controls: true,
loop: false,
muted: false,
playbackRates: [0.7, 1.0, 1.5, 2.0],
sources: [{
type: "video/mp4",
src: "https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm"
}],
poster: "/static/images/author.jpg",
width: document.documentElement.clientWidth,
notSupportedMessage: '此视频暂无法播放,请稍后再试'
}
} }
}, },
model: { model: {
@ -186,6 +214,11 @@ export default {
created() { created() {
this.loadSkeleton() this.loadSkeleton()
}, },
computed: {
player() {
return this.$refs.videoPlayer.player
}
},
watch: { watch: {
visiable: function(newValue, oldValue) { visiable: function(newValue, oldValue) {
this.$log.debug('old value', oldValue) this.$log.debug('old value', oldValue)
@ -197,8 +230,7 @@ export default {
attachment: function(newValue, oldValue) { attachment: function(newValue, oldValue) {
if (newValue) { if (newValue) {
var attachment = newValue var attachment = newValue
var mediaType = attachment.mediaType this.handleJudgeMediaType(attachment)
this.handleJudgeMediaType(mediaType)
} }
} }
}, },
@ -262,20 +294,29 @@ export default {
onClose() { onClose() {
this.$emit('close', false) this.$emit('close', false)
}, },
handleJudgeMediaType(mediaType) { handleJudgeMediaType(attachment) {
var mediaType = attachment.mediaType
// //
if(mediaType) { if(mediaType) {
var prefix = mediaType.split('/')[0] var prefix = mediaType.split('/')[0]
if(prefix === 'video' || prefix==='flv') { if(prefix === 'video' || prefix==='flv') {
this.vedioPreviewVisible = true this.videoPreviewVisible = true
this.photoPreviewVisible = false
this.nonsupportPreviewVisible = false this.nonsupportPreviewVisible = false
//
this.$set(this.playerOptions.sources, 0, {
type: mediaType,
src: attachment.path
})
console.log(this.playerOptions.sources)
} else if(prefix === 'image') { } else if(prefix === 'image') {
this.photoPreviewVisible = true this.photoPreviewVisible = true
this.videoPreviewVisible = false
this.nonsupportPreviewVisible = false this.nonsupportPreviewVisible = false
} else { } else {
this.nonsupportPreviewVisible = true this.nonsupportPreviewVisible = true
this.vedioPreviewVisible = false this.videoPreviewVisible = false
this.photoPreviewVisible = false this.photoPreviewVisible = false
} }
} }
@ -288,4 +329,7 @@ export default {
.attach-detail-img img { .attach-detail-img img {
width: 100%; width: 100%;
} }
.video-player-box {
width: 100%;
}
</style> </style>