EditVideo.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <el-row class="movie-list">
  3. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  4. <el-col :md="24" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  5. <el-card class="box-card">
  6. <div class="text item">
  7. <el-button style="float: left; padding: 3px 0" type="text" @click="onReturnVideo">返回视频稿件列表</el-button>
  8. </div>
  9. </el-card>
  10. </el-col>
  11. </el-row>
  12. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  13. <el-col :md="12" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  14. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  15. <el-card class="box-card">
  16. <div slot="header" class="clearfix">
  17. <span>更新视频封面</span>
  18. <el-button style="float: right; padding: 3px 0" type="text" @click="onUpdateVideoCover">更新</el-button>
  19. </div>
  20. <div class="text item">
  21. <el-tooltip class="item" effect="dark" content="点击上传图片" placement="top-end">
  22. <el-upload
  23. class="avatar-uploader"
  24. :action="actionUrl"
  25. :headers="imgHeaders"
  26. :data="imgData"
  27. :with-credentials="true"
  28. :show-file-list="false"
  29. :before-upload="beforeAvatarUpload"
  30. :on-success="handleAvatarSuccess"
  31. :on-change="handleOnChange"
  32. >
  33. <img :src="coverUrl" class="avatar">
  34. </el-upload>
  35. </el-tooltip>
  36. </div>
  37. </el-card>
  38. </el-row>
  39. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  40. <el-card class="box-card">
  41. <div slot="header" class="clearfix">
  42. <span>更新视频文件</span>
  43. <el-button style="float: right; padding: 3px 0" type="text" @click="onUpdateVideoFile">更新</el-button>
  44. </div>
  45. <div class="text item">
  46. <uploader
  47. class="uploader-example"
  48. :options="options"
  49. :auto-start="true"
  50. @file-added="onFileAdded"
  51. @file-success="onFileSuccess"
  52. @file-progress="onFileProgress"
  53. @file-error="onFileError"
  54. >
  55. <uploader-unsupport />
  56. <uploader-drop>
  57. <p>拖动视频文件到此处或</p>
  58. <uploader-btn :attrs="attrs">选择视频文件</uploader-btn>
  59. </uploader-drop>
  60. <uploader-list />
  61. </uploader>
  62. </div>
  63. </el-card>
  64. </el-row>
  65. </el-col>
  66. <el-col :md="12" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  67. <el-card class="box-card">
  68. <div slot="header" class="clearfix">
  69. <span>更新视频信息</span>
  70. <el-button style="float: right; padding: 3px 0" type="text" @click="onUpdateVideoInfo">更新</el-button>
  71. </div>
  72. <div class="text item">
  73. <el-form ref="form" :model="videoInfoForm" label-width="80px">
  74. <el-form-item label="标题">
  75. <el-input v-model="videoInfoForm.title" style="padding-right: 1px" placeholder="标题不能超过 50 个字符" />
  76. </el-form-item>
  77. <el-form-item label="描述">
  78. <el-input v-model="videoInfoForm.description" type="textarea" autosize style="padding-right: 1px;" />
  79. </el-form-item>
  80. <el-form-item label="发布时间">
  81. <el-date-picker
  82. v-model="videoInfoForm.pubDate"
  83. type="datetime"
  84. placeholder="选择发布的时间"
  85. />
  86. </el-form-item>
  87. </el-form>
  88. </div>
  89. </el-card>
  90. </el-col>
  91. </el-row>
  92. </el-row>
  93. </template>
  94. <script>
  95. import { getServerInfo } from '@/api/content'
  96. import { getVideoPost, updateVideoInfo, updateVideoCover, updateVideoFile } from '@/api/video'
  97. export default {
  98. name: 'EditVideo',
  99. data() {
  100. return {
  101. actionUrl: process.env.VUE_APP_OSS_URL,
  102. // ****************************************************************************************************************
  103. options: {
  104. target: process.env.VUE_APP_OSS_URL,
  105. chunkSize: 1024 * 1024 * 1024 * 5, // 5GiB
  106. fileParameterName: 'file',
  107. testChunks: false,
  108. query: (file, chunk) => {
  109. return {
  110. channelId: 2
  111. }
  112. },
  113. headers: {
  114. Authorization: ''
  115. },
  116. withCredentials: true
  117. },
  118. attrs: {
  119. accept: 'video/*'
  120. },
  121. imgHeaders: {
  122. Authorization: ''
  123. },
  124. imgData: {
  125. channelId: 5
  126. },
  127. // ****************************************************************************************************************
  128. coverUrl: null,
  129. coverUrl1: null,
  130. coverFileId: null,
  131. videoFileId: null,
  132. // 提交给后端的数据
  133. videoInfoForm: {
  134. videoId: null,
  135. title: null,
  136. description: null,
  137. pubDate: null
  138. },
  139. ossToken: null
  140. }
  141. },
  142. created() {
  143. document.title = '编辑视频稿件'
  144. const videoId = this.$route.params.videoId
  145. getVideoPost(videoId).then(res => {
  146. if (res.code === 0) {
  147. const userVideoPost = res.data
  148. this.coverUrl = userVideoPost.coverUrl
  149. this.videoInfoForm.videoId = userVideoPost.videoId
  150. this.videoInfoForm.title = userVideoPost.title
  151. this.videoInfoForm.description = userVideoPost.description
  152. this.videoInfoForm.pubDate = userVideoPost.pubDate
  153. } else {
  154. this.$notify({
  155. title: '提示',
  156. message: '获取 OSS 服务器地址失败, 暂时无法上传文件',
  157. type: 'error',
  158. duration: 3000
  159. })
  160. }
  161. }).catch(error => {
  162. this.$notify({
  163. title: '提示',
  164. message: error.message,
  165. type: 'warning',
  166. duration: 3000
  167. })
  168. })
  169. getServerInfo(2).then(res => {
  170. if (res.code === 0) {
  171. const resData = res.data
  172. this.options.target = resData.ossUrl
  173. this.options.chunkSize = resData.maxSize
  174. this.options.headers.Authorization = 'Bearer ' + resData.token
  175. } else {
  176. this.$notify({
  177. title: '提示',
  178. message: '获取 OSS 服务器地址失败, 暂时无法上传文件',
  179. type: 'error',
  180. duration: 3000
  181. })
  182. }
  183. }).catch(error => {
  184. this.$notify({
  185. title: '提示',
  186. message: '视频上传配置失败 ' + error.message,
  187. type: 'warning',
  188. duration: 3000
  189. })
  190. })
  191. getServerInfo(5).then(res => {
  192. if (res.code === 0) {
  193. const resData = res.data
  194. this.imgHeaders.Authorization = 'Bearer ' + resData.token
  195. } else {
  196. this.$notify({
  197. title: '提示',
  198. message: '获取 OSS 服务器地址失败, 暂时无法上传文件',
  199. type: 'error',
  200. duration: 3000
  201. })
  202. }
  203. }).catch(error => {
  204. this.$notify({
  205. title: '提示',
  206. message: '图片上传配置失败 ' + error.message,
  207. type: 'warning',
  208. duration: 3000
  209. })
  210. })
  211. },
  212. methods: {
  213. // ****************************************************************************************************************
  214. onFileAdded(file) {
  215. if (file.file.size > 1024 * 1024 * 1024 * 5) {
  216. file.cancel()
  217. this.$notify(
  218. {
  219. title: '提示',
  220. message: '视频文件应小于 5GiB',
  221. type: 'warning',
  222. duration: 3000
  223. }
  224. )
  225. return
  226. }
  227. },
  228. onFileProgress(rootFile, file, chunk) {
  229. },
  230. onFileSuccess(rootFile, file, response, chunk) {
  231. const res = JSON.parse(response)
  232. if (res.code === 0) {
  233. const resData = res.data
  234. this.videoFileId = resData.uploadId
  235. this.$notify(
  236. {
  237. title: '提示',
  238. message: '视频已上传',
  239. type: 'warning',
  240. duration: 3000
  241. }
  242. )
  243. }
  244. },
  245. onFileError(rootFile, file, response, chunk) {
  246. this.$notify(
  247. {
  248. title: '提示',
  249. message: '文件上传错误',
  250. type: 'warning',
  251. duration: 3000
  252. }
  253. )
  254. },
  255. // ****************************************************************************************************************
  256. beforeAvatarUpload(file) {
  257. const isJPG = file.type === 'image/jpeg'
  258. const isLt2M = file.size / 1024 / 1024 < 2
  259. if (!isJPG) {
  260. this.$message.error('上传头像图片只能是 JPG 格式!')
  261. }
  262. if (!isLt2M) {
  263. this.$message.error('上传头像图片大小不能超过 2MB!')
  264. }
  265. return isJPG && isLt2M
  266. },
  267. handleAvatarSuccess(res, file) {
  268. const localImageUrl = URL.createObjectURL(file.raw)
  269. if (res.code === 0) {
  270. const resData = res.data
  271. this.coverFileId = resData.uploadId
  272. this.coverUrl = localImageUrl
  273. this.coverUrl1 = resData.url
  274. } else {
  275. this.$notify({
  276. title: '提示',
  277. message: '视频封面上传失败,请重试!' + res.msg,
  278. type: 'warning',
  279. duration: 3000
  280. })
  281. }
  282. },
  283. handleOnChange(file, fileList) {
  284. },
  285. // ****************************************************************************************************************
  286. onReturnVideo() {
  287. this.$router.push('/my/post/list/video')
  288. },
  289. onUpdateVideoInfo() {
  290. updateVideoInfo(this.videoInfoForm).then(res => {
  291. if (res.code === 0) {
  292. this.$notify({
  293. title: '提示',
  294. message: '视频信息已更新',
  295. type: 'warning',
  296. duration: 3000
  297. })
  298. }
  299. }).catch(error => {
  300. this.$notify({
  301. title: '提示',
  302. message: error.message,
  303. type: 'warning',
  304. duration: 3000
  305. })
  306. })
  307. },
  308. onUpdateVideoCover() {
  309. if (this.coverUrl1 === null) {
  310. this.$notify({
  311. title: '提示',
  312. message: '你还没有上传视频封面',
  313. type: 'warning',
  314. duration: 3000
  315. })
  316. return
  317. }
  318. const videoCover = {
  319. videoId: this.videoInfoForm.videoId,
  320. coverUrl: this.coverUrl1,
  321. coverFileId: this.coverFileId
  322. }
  323. updateVideoCover(videoCover).then(res => {
  324. if (res.code === 0) {
  325. this.$notify({
  326. title: '提示',
  327. message: '视频封面已更新',
  328. type: 'warning',
  329. duration: 3000
  330. })
  331. }
  332. }).catch(error => {
  333. this.$notify({
  334. title: '提示',
  335. message: error.message,
  336. type: 'warning',
  337. duration: 3000
  338. })
  339. })
  340. },
  341. onUpdateVideoFile() {
  342. if (this.videoFileId === null) {
  343. this.$notify({
  344. title: '提示',
  345. message: '你还没有上传视频文件',
  346. type: 'warning',
  347. duration: 3000
  348. })
  349. return
  350. }
  351. const videoFile = {
  352. videoId: this.videoInfoForm.videoId,
  353. videoFileId: this.videoFileId
  354. }
  355. updateVideoFile(videoFile).then(res => {
  356. if (res.code === 0) {
  357. this.$notify({
  358. title: '提示',
  359. message: '视频文件已更新',
  360. type: 'warning',
  361. duration: 3000
  362. })
  363. }
  364. }).catch(error => {
  365. this.$notify({
  366. title: '提示',
  367. message: error.message,
  368. type: 'warning',
  369. duration: 3000
  370. })
  371. })
  372. }
  373. }
  374. }
  375. </script>
  376. <style>
  377. /*处于手机屏幕时*/
  378. @media screen and (max-width: 768px){
  379. .movie-list {
  380. padding-top: 8px;
  381. padding-left: 0.5%;
  382. padding-right: 0.5%;
  383. }
  384. .coverImg {
  385. height: 120px !important;
  386. }
  387. }
  388. .movie-list {
  389. padding-top: 15px;
  390. padding-left: 6%;
  391. padding-right: 6%;
  392. }
  393. .uploader-example {
  394. width: 500px;
  395. padding: 15px;
  396. margin: 40px auto 0;
  397. font-size: 12px;
  398. box-shadow: 0 0 10px rgba(0, 0, 0, .4);
  399. }
  400. .uploader-example .uploader-btn {
  401. margin-right: 4px;
  402. }
  403. .uploader-example .uploader-list {
  404. max-height: 440px;
  405. overflow: auto;
  406. overflow-x: hidden;
  407. overflow-y: auto;
  408. }
  409. .avatar-uploader .el-upload {
  410. border: 1px dashed #d9d9d9;
  411. border-radius: 6px;
  412. cursor: pointer;
  413. position: relative;
  414. overflow: hidden;
  415. }
  416. .avatar-uploader .el-upload:hover {
  417. border-color: #409EFF;
  418. }
  419. .avatar-uploader-icon {
  420. font-size: 28px;
  421. color: #8c939d;
  422. width: 320px;
  423. height: 240px;
  424. line-height: 178px;
  425. text-align: center;
  426. }
  427. .avatar {
  428. width: 320px;
  429. height: 240px;
  430. display: block;
  431. }
  432. </style>