diff --git a/package.json b/package.json index 1689866e..18eb587f 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,13 @@ "vue": "^2.6.10", "vue-clipboard2": "^0.3.0", "vue-codemirror-lite": "^1.0.4", + "vue-count-to": "^1.0.13", "vue-cropper": "0.4.9", "vue-ls": "^3.2.1", "vue-router": "^3.0.6", + "vue-video-player": "^5.0.2", "vuejs-logger": "^1.5.3", - "vuex": "^3.1.1", - "vue-count-to": "^1.0.13" + "vuex": "^3.1.1" }, "devDependencies": { "@babel/polyfill": "^7.4.4", diff --git a/src/components/Upload/UploadPhoto.vue b/src/components/Upload/UploadPhoto.vue new file mode 100644 index 00000000..86bec4ed --- /dev/null +++ b/src/components/Upload/UploadPhoto.vue @@ -0,0 +1,139 @@ + + + diff --git a/src/views/attachment/AttachmentList.vue b/src/views/attachment/AttachmentList.vue index 689c85ac..3626e3bf 100644 --- a/src/views/attachment/AttachmentList.vue +++ b/src/views/attachment/AttachmentList.vue @@ -99,7 +99,8 @@ @click="handleShowDetailDrawer(item)" >
- + 当前格式不支持预览 +
- +
此文件不支持预览
+ + +
@@ -74,7 +82,7 @@ 附件大小: - + 图片尺寸: @@ -100,7 +108,7 @@ - + ![{{ attachment.name }}]({{ attachment.path }}) @@ -148,15 +156,40 @@ import { mixin, mixinDevice } from '@/utils/mixin.js' import attachmentApi from '@/api/attachment' import photoApi from '@/api/photo' +import 'video.js/dist/video-js.css' +import { videoPlayer } from 'vue-video-player' export default { name: 'AttachmentDetailDrawer', mixins: [mixin, mixinDevice], + components: { + videoPlayer + }, data() { return { detailLoading: true, editable: false, - photo: {} + photo: {}, + photoPreviewVisible: false, + videoPreviewVisible: false, + nonsupportPreviewVisible: false, + playerOptions: { + // videojs options + muted: true, + language: 'zh-CN', + aspectRatio: '16:9', + fluid: true, + controls: true, + loop: 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: { @@ -182,6 +215,11 @@ export default { created() { this.loadSkeleton() }, + computed: { + player() { + return this.$refs.videoPlayer.player + } + }, watch: { visiable: function(newValue, oldValue) { this.$log.debug('old value', oldValue) @@ -189,6 +227,12 @@ export default { if (newValue) { this.loadSkeleton() } + }, + attachment: function(newValue, oldValue) { + if (newValue) { + var attachment = newValue + this.handleJudgeMediaType(attachment) + } } }, methods: { @@ -250,7 +294,47 @@ export default { }, onClose() { this.$emit('close', false) + }, + handleJudgeMediaType(attachment) { + var mediaType = attachment.mediaType + // 判断文件类型 + if (mediaType) { + var prefix = mediaType.split('/')[0] + + if (prefix === 'video' || prefix === 'flv') { + this.videoPreviewVisible = true + this.photoPreviewVisible = false + this.nonsupportPreviewVisible = false + // 设置视频地址 + this.$set(this.playerOptions.sources, 0, { + type: mediaType, + src: attachment.path + }) + console.log(this.playerOptions.sources) + } else if (prefix === 'image') { + this.photoPreviewVisible = true + this.videoPreviewVisible = false + this.nonsupportPreviewVisible = false + } else { + this.nonsupportPreviewVisible = true + this.videoPreviewVisible = false + this.photoPreviewVisible = false + } + } } + // handleDownLoadPhoto(attachment) { + // var path = attachment.path + + // var index = path.lastIndexOf('/') + // var filename = path.substr(index+1, path.length) + // // chrome/firefox + // var aTag = document.createElement('a') + // aTag.download = filename + // aTag.href = path//URL.createObjectURL(blob) + // aTag.target = '_blank' + // aTag.click() + // URL.revokeObjectURL(aTag.href) + // } } } @@ -259,4 +343,7 @@ export default { .attach-detail-img img { width: 100%; } +.video-player-box { + width: 100%; +} diff --git a/src/views/dashboard/Dashboard.vue b/src/views/dashboard/Dashboard.vue index 8e3016ed..2c31458d 100644 --- a/src/views/dashboard/Dashboard.vue +++ b/src/views/dashboard/Dashboard.vue @@ -200,11 +200,26 @@ placeholder="写点什么吧..." /> + + + + + + 保存 + 更多选项 @@ -318,6 +333,7 @@ import logApi from '@/api/log' import adminApi from '@/api/admin' import journalApi from '@/api/journal' import countTo from 'vue-count-to' +import UploadPhoto from '../../components/Upload/UploadPhoto.vue' export default { name: 'Dashboard', mixins: [mixin, mixinDevice], @@ -325,10 +341,13 @@ export default { PageView, AnalysisCard, RecentCommentTab, - countTo + countTo, + UploadPhoto }, data() { return { + photoList: [], + showMoreOptions: false, startVal: 0, logType: logApi.logType, activityLoading: true, @@ -339,7 +358,11 @@ export default { postData: [], logData: [], countsData: {}, - journal: {}, + journal: { + content: '', + photos: [] + }, + journalPhotos: [], // 日志图片集合最多九张 logs: [], options: [], keys: ['blog_url'], @@ -398,6 +421,18 @@ export default { next() }, methods: { + handlerPhotoUploadSuccess(response, file) { + var callData = response.data.data + var photo = { + name: callData.name, + url: callData.path, + thumbnail: callData.thumbPath, + suffix: callData.suffix, + width: callData.width, + height: callData.height + } + this.journalPhotos.push(photo) + }, loadOptions() { optionApi.listAll(this.keys).then(response => { this.options = response.data.data @@ -426,11 +461,20 @@ export default { this.$router.push({ name: 'PostEdit', query: { postId: post.id } }) }, handleCreateJournalClick() { + // 给属性填充数据 + this.journal.photos = this.journalPhotos + journalApi.create(this.journal).then(response => { this.$message.success('发表成功!') this.journal = {} + this.photoList = [] + this.showMoreOptions = false }) }, + handleUploadPhotoWallClick() { + // 是否显示上传照片墙组件 + this.showMoreOptions = !this.showMoreOptions + }, handleShowLogDrawer() { this.logDrawerVisiable = true this.loadLogs() @@ -458,3 +502,10 @@ export default { } } + + diff --git a/src/views/sheet/internal/JournalList.vue b/src/views/sheet/internal/JournalList.vue index 5bcfa814..fb89bac0 100644 --- a/src/views/sheet/internal/JournalList.vue +++ b/src/views/sheet/internal/JournalList.vue @@ -6,18 +6,12 @@
- + - + - + 公开 @@ -25,32 +19,19 @@ - + - 查询 - 重置 + 查询 + 重置
- 写日志 + 写日志
- +
- + + + + example + + + + + + + {{ item.createTime | moment }} - +
@@ -132,29 +114,35 @@ - + + + + + + + + 更多选项 + + @@ -166,21 +154,11 @@ v-model="selectCommentVisible" > - + @@ -194,23 +172,16 @@ destroyOnClose @close="()=>this.commentVisiable = false" > - + - +

{{ journal.content }}

{{ journal.createTime | moment }}
- + { @@ -330,6 +348,9 @@ export default { }) }, createOrUpdateJournal() { + // 给属性填充数据 + this.journal.photos = this.journalPhotos + if (this.journal.id) { journalApi.update(this.journal.id, this.journal).then(response => { this.$message.success('更新成功!') @@ -339,6 +360,7 @@ export default { journalApi.create(this.journal).then(response => { this.$message.success('发表成功!') this.loadJournals() + this.photoList = [] }) } this.visible = false @@ -356,3 +378,16 @@ export default { } } +