1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
| <template> <div class="app-container">
<!-- 添加章节按钮 --> <div> <el-button type="primary" @click="addChapter()">添加章节</el-button> </div>
<!-- 章节列表 --> <ul class="chapterList"> <li v-for="chapter in chapterList" :key="chapter.id"> <p> {{ chapter.title }} <span class="acts"> <el-button type="text" @click="addVideo(chapter.id)">添加课时</el-button> <el-button type="text" @click="editChapter(chapter.id)">编辑</el-button> <el-button type="text" @click="removeChapterById(chapter.id)">删除</el-button> </span> </p> <!-- 视频 --> <ul class="chapterList videoList"> <li v-for="video in chapter.children" :key="video.id"> <p> {{ video.title }} <el-tag v-if="!video.videoSourceId" size="mini" type="danger"> {{ '尚未上传视频' }} </el-tag> <span class="acts"> <el-tag v-if="video.isFree" size="mini" type="success">{{ '免费观看' }}</el-tag> <el-button type="text" @click="editVideo(chapter.id, video.id)">编辑</el-button> <el-button type="text" @click="removeVideoById(video.id)">删除</el-button> </span> </p> </li> </ul> </li> </ul> <!-- 章节表单对话框 --> <chapter-form ref="chapterForm" /> <!-- 课时表单对话框 --> <video-form ref="videoForm" /> <div style="text-align:center"> <el-button type="primary" @click="prev()">上一步</el-button> <el-button type="primary" @click="next()">下一步</el-button> </div> </div> </template> <script> import chapterApi from '@/api/vod/chapter' import videoApi from '@/api/vod/video'
// 引入组件 import ChapterForm from '@/views/vod/course/components/Chapter/Form' import VideoForm from '@/views/vod/course/components/Video/Form'
export default { // 注册组件 components: { ChapterForm, VideoForm }, data() { return { chapterList: [] // 章节嵌套列表 } }, created() { this.fetchNodeList() }, methods: { // 获取章节小节数据 fetchNodeList() { chapterApi.getNestedTreeList(this.$parent.courseId).then(response => { this.chapterList = response.data }) }, //删除章节 removeChapterById(chapterId) { this.$confirm('此操作将永久删除该章节,是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { return chapterApi.removeById(chapterId) }).then(response => { this.fetchNodeList() this.$message.success(response.message) }).catch((response) => { if (response === 'cancel') { this.$message.info('取消删除') } }) }, // 添加章节 addChapter() { this.$refs.chapterForm.open() }, // 编辑章节 editChapter(chapterId) { this.$refs.chapterForm.open(chapterId) }, // 添加课时 addVideo(chapterId) { this.$refs.videoForm.open(chapterId) }, // 编辑课时 editVideo(chapterId, videoId) { this.$refs.videoForm.open(chapterId, videoId) }, // 删除课时 removeVideoById(videoId) { this.$confirm('此操作将永久删除该课时, 是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { return videoApi.removeById(videoId) }).then(response => { this.fetchNodeList() this.$message.success(response.message) }).catch((response) => { if (response === 'cancel') { this.$message.info('取消删除') } }) }, // 上一步 prev() { this.$parent.active = 0 }, // 下一步 next() { this.$parent.active = 2 } } } </script> <style scoped> .chapterList{ position: relative; list-style: none; margin: 0; padding: 0; } .chapterList li{ position: relative; } .chapterList p{ float: left; font-size: 20px; margin: 10px 0; padding: 10px; height: 70px; line-height: 50px; width: 100%; border: 1px solid #DDD; } .chapterList .acts { float: right; font-size: 14px; }
.videoList{ padding-left: 50px; } .videoList p{ float: left; font-size: 14px; margin: 10px 0; padding: 10px; height: 50px; line-height: 30px; width: 100%; border: 1px dashed #DDD; } </style>
|