一 定义api
复制代码
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
39export default { // 课程章节列表 getNestedTreeList(courseId) { return request({ url: `/admin/edu/chapter/nested-list/${courseId}`, method: 'get' }) }, // 删除章节 removeById(id) { return request({ url: `/admin/edu/chapter/remove/${id}`, method: 'delete' }) }, // 保存章节信息 save(chapter) { return request({ url: '/admin/edu/chapter/save', method: 'post', data: chapter }) }, // 根据章节id获得章节信息 getById(id) { return request({ url: `/admin/edu/chapter/get/${id}`, method: 'get' }) }, // 更新章节信息 updateById(chapter) { return request({ url: '/admin/edu/chapter/update', method: 'put', data: chapter }) } }
二 显示章节列表
1 组件脚本
复制代码
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
51export default { components: { ChapterForm, VideoForm }, // 2、注册组件 data() { return { chapterList: [] // 章节嵌套列表 } }, created() { this.fetchNodeList() }, methods: { // 获取后端章节列表数据 fetchNodeList() { chapterApi.getNestedTreeList(this.$parent.courseId).then(response => { this.chapterList = response.data.items }) }, // 根据id删除章节信息 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) }, }
2 组件模板
复制代码
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<!-- 章节列表 --> <!-- 添加章节按钮 --> <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.free" 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>
3 定义样式
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23.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; }
三 测试
最后
以上就是默默月饼最近收集整理的关于章节列表前端实现一 定义api二 显示章节列表三 测试的全部内容,更多相关章节列表前端实现一 定义api二 显示章节列表三 测试内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复