123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <template>
- <div class="video-list-container">
- <draggable v-model="videoListComputed" handle=".drag-handle" @end="onDragEnd">
- <div
- v-for="(item, index) in videoListComputed"
- :key="index"
- :class="['video-item', item.videoError ? 'error-video' : '']"
- v-loading="item.videoLoading"
- element-loading-text="上传中,请稍后..."
- element-loading-spinner="el-icon-loading"
- element-loading-background="rgba(0, 0, 0, 0.8)"
- element-loading-customClass="loadingTextClolr"
- >
- <el-row :gutter="20">
- <el-col :span="1">
- <i class="el-icon-rank drag-handle" style="cursor: move; line-height: 32px;"></i>
- </el-col>
- <el-col :span="6">
- <el-input v-model="item.videoName" size="small" placeholder="请输入视频名称"></el-input>
- </el-col>
- <el-col :span="4">
- <el-select v-model="item.videoLecturerId" placeholder="请选择教师" size="small" style="width: 100%">
- <el-option
- v-for="type in videoTypes"
- :key="type.id"
- :label="type.teacherName"
- :value="type.id"
- ></el-option>
- </el-select>
- </el-col>
- <el-col :span="8" style="display: flex; align-items: center;">
- <div>试看时间(分钟)</div>
- <el-input-number
- size="small"
- v-model="item.videoPreviewTime"
- :min="0"
- :max="600"
- placeholder="试看时间(秒)"
- :disabled="item.coursePreviousUrl"
- ></el-input-number>
- </el-col>
- <el-col :span="5">
- <el-button size="small" type="primary" @click="previewingVideoSrc(item)">预览视频</el-button>
- <el-button size="small" type="danger" @click="removeRow(index)">删除</el-button>
- </el-col>
- </el-row>
- </div>
- </draggable>
- <!-- 预览视频 -->
- <el-dialog title="预览视频" append-to-body :visible.sync="previewingVideoVisable" width="900px" top="6.5vh" :before-close="handleClose">
- <div class="previewingVideo">
- <!-- <video :src="previewVideoSrc" :poster="require('../../assets/image/yunketang.png')" controls></video> -->
- <video :src="previewVideoSrc" controls></video>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import draggable from 'vuedraggable'
- export default {
- name: 'VideoListEditor',
- components: {
- draggable
- },
- props: {
- value: {
- type: Array,
- required: true
- }
- },
- computed: {
- videoListComputed: {
- get() {
- return this.value
- },
- set(val) {
- this.$emit('input', val)
- }
- }
- },
- data() {
- return {
- videoTypes: [],
- previewVideoSrc: '',
- previewingVideoVisable: false
- }
- },
- methods: {
- previewingVideoSrc(row) {
- console.log(row)
- this.previewVideoSrc = row.videoUrl
- this.previewingVideoVisable = true
- },
- getAllTeachers() {
- this.http.post(`/course-teacher/list`, {}, res => {
- this.videoTypes = res.data || []
- })
- },
- removeRow(index) {
- const list = [...this.videoListComputed]
- const row = list[index]
- this.$confirm(`此操作将删除【${row.videoName}】视频, 是否继续?`, '删除视频', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- const { id, videoUrl, coursePreviousUrl } = row
- this.http.post(`/course-sub-info/remove`, {
- id,
- courseUrl: videoUrl,
- coursePreviousUrl: coursePreviousUrl
- }, res => {
- if(res.code === 'ok') {
- this.$message({
- type: 'success',
- message: '删除成功!'
- });
- list.splice(index, 1)
- this.videoListComputed = list
- }
- })
- })
- },
- onDragEnd() {
- console.log('排序完成', this.videoListComputed)
- },
- handleClose(done) {
- // 清除 video 的 src,释放资源
- const videoEl = this.$refs.previewVideo
- if (videoEl) {
- videoEl.pause()
- videoEl.removeAttribute('src')
- videoEl.load()
- }
- this.previewingVideoVisable = false
- this.previewVideoSrc = ''
- done()
- }
- },
- mounted() {
- this.getAllTeachers()
- }
- }
- </script>
- <style scoped>
- .video-list-container {
- padding: 20px;
- }
- .video-item {
- margin-bottom: 15px;
- padding: 10px;
- background: #f5f7fa;
- border-radius: 4px;
- position: relative;
- }
- .error-video {
- background: #e6a23c;
- }
- </style>
- <style lang="scss">
- .video-list-container {
- .el-loading-spinner i {
- color: #fff !important;
- }
- .el-loading-text {
- color: #fff !important;
- }
- }
- .previewingVideo {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 68vh;
- }
- .previewingVideo video {
- width: 100%;
- height: 100%;
- }
- </style>
|