课程发布页面整合

36 阅读1分钟

1、添加隐藏路由

{
        path: 'add/:id',
        name: 'EduCourseInfoEdit',
        component: () => import('@/views/course/add'),
        meta: { title: '编辑课程基本信息', noCache: true },
        hidden: true
      },
      {
        path: 'chapter/:id',
        name: 'EduCourseChapterEdit',
        component: () => import('@/views/course/chapter'),
        meta: { title: '编辑课程大纲', noCache: true },
        hidden: true
      },
      {
        path: 'publish/:id',
        name: 'EduCoursePublishEdit',
        component: () => import('@/views/course/publish'),
        meta: { title: '发布课程', noCache: true },
        hidden: true
      },

2、创建课程大纲、最终发布页面

(1)复制页面内容、拷贝到对应页面

Course/chapter.vue

<template>
  <div class="app-container">
    <h2 style="text-align: center;">发布新课程</h2>

    <el-steps :active="2" process-status="wait" align-center style="margin-bottom: 40px;">
      <el-step title="填写课程基本信息"/>
      <el-step title="创建课程大纲"/>
      <el-step title="提交审核"/>
    </el-steps>

    <el-form label-width="120px">
      <el-button type="text" @click="dialogChapterFormVisible = true">添加章节</el-button>
      <!--章节-->
      <ul class="chanpterList">
        <li v-for="chapter in allChapterVideo" :key="chapter.id">
          <p>
            {{ chapter.title }}
            <span class="acts">
              <el-button type="text">添加课时</el-button>
              <el-button style type="text">编辑</el-button>
              <el-button type="text" @click="removeChapter(chapter.id)">删除</el-button>
            </span>
          </p>
          <!--小节(视频)-->
          <ul class="chanpterList videoList">
            <li v-for="video in chapter.children" :key="video.id">
              <p>{{ video.title }}</p>
            </li>
          </ul>
        </li>
      </ul>

      <el-button @click="previous">上一步</el-button>
      <el-button :disabled="saveBtnDisabled" type="primary" @click="next">下一步</el-button>

    </el-form>
    <!-- 添加和修改章节表单 -->
    <el-dialog :visible.sync="dialogChapterFormVisible" title="添加章节">
      <el-form :model="chapter" label-width="120px">
        <el-form-item label="章节标题">
          <el-input v-model="chapter.title"/>
        </el-form-item>
        <el-form-item label="章节排序">
          <el-input-number v-model="chapter.sort" :min="0" controls-position="right"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogChapterFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveOrUpdate">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import chapter from '@/api/chapter'
export default {
  data() {
    return {
      courseId: '',
      saveBtnDisabled: false, // 保存按钮是否禁用
      allChapterVideo: [], // 章节小节数据集合
      dialogChapterFormVisible: false, // 章节添加修改表单是否展示
      chapter: {} // 章节信息
    }
  },

  created() {
    console.log('chapter created')
    if (this.$route.params && this.$route.params.id) {
      this.courseId = this.$route.params.id
      console.log('this.courseId=' + this.courseId)
      this.getChapterVideoList()
    }
  },
  methods: {
    // 新增获取修改章节
    saveOrUpdate() {
      this.saveChapter()
    },
    // 保存章节
    saveChapter() {
      this.chapter.courseId = this.courseId
      chapter.addChapter(this.chapter).then(response => {
        // 关闭添加章节对话框
        this.dialogChapterFormVisible = false
        // 提示
        this.$message({
          type: 'success',
          message: '添加章节成功!'
        })
        // 刷新页面
        this.getChapterVideoList()
      })
    },
    // 删除章节
    removeChapter(chapterId) {
      this.$confirm('此操作将永久删除该章节, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // 调用接口删除数据
          chapter.deleteChapter(chapterId).then(response => {
            this.$message({
              type: 'success',
              message: '删除章节成功!'
            })
            // 刷新数据
            this.getChapterVideoList()
          })
        })
    },

    // 根据课程id查询章节小节信息
    getChapterVideoList() {
      chapter.getChapterVideoById(this.courseId).then(response => {
        this.allChapterVideo = response.data.allChapterVideo
      })
    },
    previous() {
      console.log('previous')
      this.$router.push({ path: `/course/add/${this.courseId}` })
    },

    next() {
      console.log('next')
      this.$router.push({ path: '/edu/course/publish/1' })
    }
  }
}
</script>

<style scoped>
.chanpterList {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
}
.chanpterList li {
  position: relative;
}
.chanpterList p {
  float: left;
  font-size: 20px;
  margin: 10px 0;
  padding: 10px;
  height: 70px;
  line-height: 50px;
  width: 100%;
  border: 1px solid #ddd;
}
.chanpterList .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 dotted #ddd;
}
</style>

Course/publish.vue

<template>

  <div class="app-container">

    <h2 style="text-align: center;">发布新课程</h2>

    <el-steps :active="3" process-status="wait" align-center style="margin-bottom: 40px;">
      <el-step title="填写课程基本信息"/>
      <el-step title="创建课程大纲"/>
      <el-step title="提交审核"/>
    </el-steps>

    <el-form label-width="120px">

      <el-form-item>
        <el-button @click="previous">返回修改</el-button>
        <el-button :disabled="saveBtnDisabled" type="primary" @click="publish">发布课程</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

export default {
  data() {
    return {
      saveBtnDisabled: false // 保存按钮是否禁用
    }
  },

  created() {
    console.log('publish created')
  },

  methods: {
    previous() {
      console.log('previous')
      this.$router.push({ path: '/edu/course/chapter/1' })
    },

    publish() {
      console.log('publish')
      this.$router.push({ path: '/edu/course/list' })
    }
  }
}
</script>

最后效果:

在这里插入图片描述