addVideo.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="video-list-container">
  3. <draggable v-model="videoListComputed" handle=".drag-handle" @end="onDragEnd">
  4. <div
  5. v-for="(item, index) in videoListComputed"
  6. :key="index"
  7. :class="['video-item', item.videoError ? 'error-video' : '']"
  8. v-loading="item.videoLoading"
  9. element-loading-text="上传中,请稍后..."
  10. element-loading-spinner="el-icon-loading"
  11. element-loading-background="rgba(0, 0, 0, 0.8)"
  12. element-loading-customClass="loadingTextClolr"
  13. >
  14. <el-row :gutter="20">
  15. <el-col :span="1">
  16. <i class="el-icon-rank drag-handle" style="cursor: move; line-height: 32px;"></i>
  17. </el-col>
  18. <el-col :span="6">
  19. <el-input v-model="item.videoName" size="small" placeholder="请输入视频名称"></el-input>
  20. </el-col>
  21. <el-col :span="4">
  22. <el-select v-model="item.videoLecturerId" placeholder="请选择教师" size="small" style="width: 100%">
  23. <el-option
  24. v-for="type in videoTypes"
  25. :key="type.id"
  26. :label="type.teacherName"
  27. :value="type.id"
  28. ></el-option>
  29. </el-select>
  30. </el-col>
  31. <el-col :span="8" style="display: flex; align-items: center;">
  32. <div>试看时间(分钟)</div>
  33. <el-input-number
  34. size="small"
  35. v-model="item.videoPreviewTime"
  36. :min="0"
  37. :max="600"
  38. placeholder="试看时间(秒)"
  39. ></el-input-number>
  40. </el-col>
  41. <el-col :span="5">
  42. <el-button size="small" type="primary" @click="previewingVideoSrc(item)">预览视频</el-button>
  43. <el-button size="small" type="danger" @click="removeRow(index)">删除</el-button>
  44. </el-col>
  45. </el-row>
  46. </div>
  47. </draggable>
  48. <!-- 预览视频 -->
  49. <el-dialog title="预览视频" append-to-body :visible.sync="previewingVideoVisable" width="900px" top="6.5vh" :before-close="handleClose">
  50. <div class="previewingVideo">
  51. <video :src="previewVideoSrc" :poster="require('../../assets/image/yunketang.png')" controls></video>
  52. </div>
  53. </el-dialog>
  54. </div>
  55. </template>
  56. <script>
  57. import draggable from 'vuedraggable'
  58. export default {
  59. name: 'VideoListEditor',
  60. components: {
  61. draggable
  62. },
  63. props: {
  64. value: {
  65. type: Array,
  66. required: true
  67. }
  68. },
  69. computed: {
  70. videoListComputed: {
  71. get() {
  72. return this.value
  73. },
  74. set(val) {
  75. this.$emit('input', val)
  76. }
  77. }
  78. },
  79. data() {
  80. return {
  81. videoTypes: [],
  82. previewVideoSrc: '',
  83. previewingVideoVisable: false
  84. }
  85. },
  86. methods: {
  87. previewingVideoSrc(row) {
  88. console.log(row)
  89. this.previewVideoSrc = row.videoUrl
  90. this.previewingVideoVisable = true
  91. },
  92. getAllTeachers() {
  93. this.http.post(`/course-teacher/list`, {}, res => {
  94. this.videoTypes = res.data || []
  95. })
  96. },
  97. removeRow(index) {
  98. const list = [...this.videoListComputed]
  99. const row = list[index]
  100. this.$confirm(`此操作将删除【${row.videoName}】视频, 是否继续?`, '删除视频', {
  101. confirmButtonText: '确定',
  102. cancelButtonText: '取消',
  103. type: 'warning'
  104. }).then(() => {
  105. const { id, videoUrl, coursePreviousUrl } = row
  106. this.http.post(`/course-sub-info/remove`, {
  107. id,
  108. courseUrl: videoUrl,
  109. coursePreviousUrl: coursePreviousUrl
  110. }, res => {
  111. if(res.code === 'ok') {
  112. this.$message({
  113. type: 'success',
  114. message: '删除成功!'
  115. });
  116. list.splice(index, 1)
  117. this.videoListComputed = list
  118. }
  119. })
  120. })
  121. },
  122. onDragEnd() {
  123. console.log('排序完成', this.videoListComputed)
  124. },
  125. handleClose(done) {
  126. // 清除 video 的 src,释放资源
  127. const videoEl = this.$refs.previewVideo
  128. if (videoEl) {
  129. videoEl.pause()
  130. videoEl.removeAttribute('src')
  131. videoEl.load()
  132. }
  133. this.previewingVideoVisable = false
  134. this.previewVideoSrc = ''
  135. done()
  136. }
  137. },
  138. mounted() {
  139. this.getAllTeachers()
  140. }
  141. }
  142. </script>
  143. <style scoped>
  144. .video-list-container {
  145. padding: 20px;
  146. }
  147. .video-item {
  148. margin-bottom: 15px;
  149. padding: 10px;
  150. background: #f5f7fa;
  151. border-radius: 4px;
  152. position: relative;
  153. }
  154. .error-video {
  155. background: #e6a23c;
  156. }
  157. </style>
  158. <style lang="scss">
  159. .video-list-container {
  160. .el-loading-spinner i {
  161. color: #fff !important;
  162. }
  163. .el-loading-text {
  164. color: #fff !important;
  165. }
  166. }
  167. .previewingVideo {
  168. display: flex;
  169. align-items: center;
  170. justify-content: center;
  171. width: 100%;
  172. height: 68vh;
  173. }
  174. .previewingVideo video {
  175. width: 100%;
  176. height: 100%;
  177. }
  178. </style>