addVideo.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. <video :src="previewVideoSrc" controls></video>
  53. </div>
  54. </el-dialog>
  55. </div>
  56. </template>
  57. <script>
  58. import draggable from 'vuedraggable'
  59. export default {
  60. name: 'VideoListEditor',
  61. components: {
  62. draggable
  63. },
  64. props: {
  65. value: {
  66. type: Array,
  67. required: true
  68. }
  69. },
  70. computed: {
  71. videoListComputed: {
  72. get() {
  73. return this.value
  74. },
  75. set(val) {
  76. this.$emit('input', val)
  77. }
  78. }
  79. },
  80. data() {
  81. return {
  82. videoTypes: [],
  83. previewVideoSrc: '',
  84. previewingVideoVisable: false
  85. }
  86. },
  87. methods: {
  88. previewingVideoSrc(row) {
  89. console.log(row)
  90. this.previewVideoSrc = row.videoUrl
  91. this.previewingVideoVisable = true
  92. },
  93. getAllTeachers() {
  94. this.http.post(`/course-teacher/list`, {}, res => {
  95. this.videoTypes = res.data || []
  96. })
  97. },
  98. removeRow(index) {
  99. const list = [...this.videoListComputed]
  100. const row = list[index]
  101. this.$confirm(`此操作将删除【${row.videoName}】视频, 是否继续?`, '删除视频', {
  102. confirmButtonText: '确定',
  103. cancelButtonText: '取消',
  104. type: 'warning'
  105. }).then(() => {
  106. const { id, videoUrl, coursePreviousUrl } = row
  107. this.http.post(`/course-sub-info/remove`, {
  108. id,
  109. courseUrl: videoUrl,
  110. coursePreviousUrl: coursePreviousUrl
  111. }, res => {
  112. if(res.code === 'ok') {
  113. this.$message({
  114. type: 'success',
  115. message: '删除成功!'
  116. });
  117. list.splice(index, 1)
  118. this.videoListComputed = list
  119. }
  120. })
  121. })
  122. },
  123. onDragEnd() {
  124. console.log('排序完成', this.videoListComputed)
  125. },
  126. handleClose(done) {
  127. // 清除 video 的 src,释放资源
  128. const videoEl = this.$refs.previewVideo
  129. if (videoEl) {
  130. videoEl.pause()
  131. videoEl.removeAttribute('src')
  132. videoEl.load()
  133. }
  134. this.previewingVideoVisable = false
  135. this.previewVideoSrc = ''
  136. done()
  137. }
  138. },
  139. mounted() {
  140. this.getAllTeachers()
  141. }
  142. }
  143. </script>
  144. <style scoped>
  145. .video-list-container {
  146. padding: 20px;
  147. }
  148. .video-item {
  149. margin-bottom: 15px;
  150. padding: 10px;
  151. background: #f5f7fa;
  152. border-radius: 4px;
  153. position: relative;
  154. }
  155. .error-video {
  156. background: #e6a23c;
  157. }
  158. </style>
  159. <style lang="scss">
  160. .video-list-container {
  161. .el-loading-spinner i {
  162. color: #fff !important;
  163. }
  164. .el-loading-text {
  165. color: #fff !important;
  166. }
  167. }
  168. .previewingVideo {
  169. display: flex;
  170. align-items: center;
  171. justify-content: center;
  172. width: 100%;
  173. height: 68vh;
  174. }
  175. .previewingVideo video {
  176. width: 100%;
  177. height: 100%;
  178. }
  179. </style>