|
@@ -40,11 +40,13 @@
|
|
|
action="//oss.reghao.cn/"
|
|
action="//oss.reghao.cn/"
|
|
|
:headers="imgHeaders"
|
|
:headers="imgHeaders"
|
|
|
:data="imgData"
|
|
:data="imgData"
|
|
|
|
|
+ :with-credentials="true"
|
|
|
:show-file-list="false"
|
|
:show-file-list="false"
|
|
|
:before-upload="beforeAvatarUpload"
|
|
:before-upload="beforeAvatarUpload"
|
|
|
:on-success="handleAvatarSuccess"
|
|
:on-success="handleAvatarSuccess"
|
|
|
|
|
+ :on-change="handleOnChange"
|
|
|
>
|
|
>
|
|
|
- <img v-if="form.coverUrl" :src="form.coverUrl" class="avatar">
|
|
|
|
|
|
|
+ <img v-if="coverUrl" :src="coverUrl" class="avatar">
|
|
|
<i v-else class="el-icon-plus avatar-uploader-icon" />
|
|
<i v-else class="el-icon-plus avatar-uploader-icon" />
|
|
|
</el-upload>
|
|
</el-upload>
|
|
|
</el-tooltip>
|
|
</el-tooltip>
|
|
@@ -144,6 +146,7 @@ export default {
|
|
|
imgData: {
|
|
imgData: {
|
|
|
channelId: 5
|
|
channelId: 5
|
|
|
},
|
|
},
|
|
|
|
|
+ coverUrl: null,
|
|
|
/***********************************************************************/
|
|
/***********************************************************************/
|
|
|
categoryMap: {
|
|
categoryMap: {
|
|
|
Set: function(key, value) { this[key] = value },
|
|
Set: function(key, value) { this[key] = value },
|
|
@@ -158,7 +161,7 @@ export default {
|
|
|
],
|
|
],
|
|
|
form: {
|
|
form: {
|
|
|
videoFileId: null,
|
|
videoFileId: null,
|
|
|
- coverUrl: null,
|
|
|
|
|
|
|
+ coverFileId: null,
|
|
|
title: null,
|
|
title: null,
|
|
|
description: null,
|
|
description: null,
|
|
|
categoryPid: null,
|
|
categoryPid: null,
|
|
@@ -271,28 +274,6 @@ export default {
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
/***********************************************************************/
|
|
/***********************************************************************/
|
|
|
- beforeAvatarUpload(file) {
|
|
|
|
|
- const isJPG = file.type === 'image/jpeg'
|
|
|
|
|
- const isLt2M = file.size / 1024 / 1024 < 2
|
|
|
|
|
- if (!isJPG) {
|
|
|
|
|
- this.$message.error('上传头像图片只能是 JPG 格式!')
|
|
|
|
|
- }
|
|
|
|
|
- if (!isLt2M) {
|
|
|
|
|
- this.$message.error('上传头像图片大小不能超过 2MB!')
|
|
|
|
|
- }
|
|
|
|
|
- return isJPG && isLt2M
|
|
|
|
|
- },
|
|
|
|
|
- handleAvatarSuccess(res, file) {
|
|
|
|
|
- const localUrl = URL.createObjectURL(file.raw)
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- const resData = res.data
|
|
|
|
|
- const uploadId = resData.uploadId
|
|
|
|
|
- this.form.coverUrl = resData.url
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- /***********************************************************************/
|
|
|
|
|
// 选择视频后获取视频的分辨率和时长, 并截取第一秒的内容作为封面
|
|
// 选择视频后获取视频的分辨率和时长, 并截取第一秒的内容作为封面
|
|
|
processVideo(file) {
|
|
processVideo(file) {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
@@ -346,6 +327,8 @@ export default {
|
|
|
|
|
|
|
|
const coverFile = new File([u8arr], 'cover.jpg', { type: 'image/jpeg' })
|
|
const coverFile = new File([u8arr], 'cover.jpg', { type: 'image/jpeg' })
|
|
|
if (coverFile instanceof File) {
|
|
if (coverFile instanceof File) {
|
|
|
|
|
+ const localImageUrl = URL.createObjectURL(coverFile)
|
|
|
|
|
+
|
|
|
const formData = new FormData()
|
|
const formData = new FormData()
|
|
|
formData.append('file', coverFile)
|
|
formData.append('file', coverFile)
|
|
|
formData.append('channelId', 5)
|
|
formData.append('channelId', 5)
|
|
@@ -356,8 +339,9 @@ export default {
|
|
|
body: formData
|
|
body: formData
|
|
|
}).then(response => response.json()).then(json => {
|
|
}).then(response => response.json()).then(json => {
|
|
|
if (json.code === 0) {
|
|
if (json.code === 0) {
|
|
|
|
|
+ this.coverUrl = localImageUrl
|
|
|
const resData = json.data
|
|
const resData = json.data
|
|
|
- this.form.coverUrl = resData.url
|
|
|
|
|
|
|
+ this.form.coverFileId = resData.uploadId
|
|
|
} else {
|
|
} else {
|
|
|
this.$notify({
|
|
this.$notify({
|
|
|
title: '提示',
|
|
title: '提示',
|
|
@@ -375,6 +359,36 @@ export default {
|
|
|
// videoElem.removeEventListener('canplay', arguments.callee)
|
|
// videoElem.removeEventListener('canplay', arguments.callee)
|
|
|
},
|
|
},
|
|
|
/***********************************************************************/
|
|
/***********************************************************************/
|
|
|
|
|
+ beforeAvatarUpload(file) {
|
|
|
|
|
+ const isJPG = file.type === 'image/jpeg'
|
|
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 2
|
|
|
|
|
+ if (!isJPG) {
|
|
|
|
|
+ this.$message.error('上传头像图片只能是 JPG 格式!')
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!isLt2M) {
|
|
|
|
|
+ this.$message.error('上传头像图片大小不能超过 2MB!')
|
|
|
|
|
+ }
|
|
|
|
|
+ return isJPG && isLt2M
|
|
|
|
|
+ },
|
|
|
|
|
+ handleAvatarSuccess(res, file) {
|
|
|
|
|
+ const localImageUrl = URL.createObjectURL(file.raw)
|
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
|
+ const resData = res.data
|
|
|
|
|
+ this.coverUrl = localImageUrl;
|
|
|
|
|
+ this.form.coverFileId = resData.uploadId
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.$notify({
|
|
|
|
|
+ title: '提示',
|
|
|
|
|
+ message: '视频封面上传失败,请重试!' + res.msg,
|
|
|
|
|
+ type: 'warning',
|
|
|
|
|
+ duration: 3000
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ handleOnChange(file, fileList) {
|
|
|
|
|
+ console.log('封面改变')
|
|
|
|
|
+ },
|
|
|
|
|
+ /***********************************************************************/
|
|
|
setTitle(title) {
|
|
setTitle(title) {
|
|
|
if (title.length > 50) {
|
|
if (title.length > 50) {
|
|
|
this.form.title = title.substring(0, 50)
|
|
this.form.title = title.substring(0, 50)
|
|
@@ -435,7 +449,7 @@ export default {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!this.form.coverUrl) {
|
|
|
|
|
|
|
+ if (!this.form.coverFileId) {
|
|
|
this.$notify({
|
|
this.$notify({
|
|
|
title: '提示',
|
|
title: '提示',
|
|
|
message: '你还没有上传视频封面',
|
|
message: '你还没有上传视频封面',
|