Day07-添加课程信息前端部分(1)---p109、110

1、添加路由

在这里插入图片描述
在这里插入图片描述路由代码:

{
    path: '/course',
    component: Layout,
    redirect: '/course/list',
    name: '课程管理',
    meta: { title: '课程管理', icon: 'example' },
    children: [
      {
        path: 'list',
        name: '课程列表',
        component: () => import('@/views/edu/course/list'),
        meta: { title: '课程列表', icon: 'table' }
      },
      {
        path: 'info',
        name: '添加课程',  
        component: () => import('@/views/edu/course/info'),
        meta: { title: '添加课程', icon: 'tree' }
      },
      {
        path: 'info/:id',
        name: 'EduCourseInfoEdit',
        component: () => import('@/views/edu/course/info'),
        meta: { title: '编辑课程基本信息', noCache: true },
        hidden: true
      },
      {
        path: 'chapter/:id',
        name: 'EduCourseChapterEdit',
        component: () => import('@/views/edu/course/chapter'),
        meta: { title: '编辑课程大纲', noCache: true },
        hidden: true
      },
      {
        path: 'publish/:id',
        name: 'EduCoursePublishEdit',
        component: () => import('@/views/edu/course/publish'),
        meta: { title: '发布课程', noCache: true },
        hidden: true
      }
    ]
  },

2、添加组件—新建前端页面

在这里插入图片描述
使用的是element-ui前端步骤条组件:https://element.eleme.cn/#/zh-CN/component/steps

2.1、完善前端info.vue(课程信息页面)

页面效果:
在这里插入图片描述

2.2.1、前端代码:

<template>

  <div class="app-container">

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

    <el-steps :active="1" 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 :disabled="saveBtnDisabled" type="primary" @click="saveOrUpdate">保存并下一步</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

2.1.2、js代码

<script>
export default {
    data(){
        return {
            saveBtnDisabled:false
        }
    },
    created(){

    },
    methods:{
        saveOrUpdate(){
            //跳转到下一步
            this.$router.push({path:'/course/chapter/1'})
        }
    }
}
</script>

2.2、完善前端chapter.vue(完善大纲信息页面)

效果图:
在这里插入图片描述

2.2.1、前端代码:

<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-form-item>
        <el-button @click="previous">上一步</el-button>
        <el-button :disabled="saveBtnDisabled" type="primary" @click="next">下一步</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

2.2.2、js代码

<script>
export default {
    data(){
        return {
            saveBtnDisabled:false
        }
    },
    created(){

    },
    methods:{
        previous(){
            this.$router.push({path:'course/info/:id'})
        },
        next(){
            this.$router.push({path:'/course/publish/:id'})
        }
    }
}
</script>

2.3、完善前端publish.vue(课程发布页面)

效果:
在这里插入图片描述

2.3.1、前端代码:

<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>

2.3.2、js代码

<script>
export default {
    data(){
        return {
            saveBtnDisabled:false
        }
    },
    created(){

    },
    methods:{
        previous(){
            this.$router.push({path:'/course/chapter/:id'})
        },
        publish(){
            this.$router.push({path:'/course/list'})
        }
    }
}
</script>

3、添加api接口course.js,在前端页面中调用后端接口

在这里插入图片描述

3.1、定义course.js 接口中的代码

import request from '@/utils/request'

export default {
    //1、添加课程信息
    addCourseInfo(courseInfo){
        return request({
            url:'eduservice/course/addCourseInfo',
            method:'post',
            data:courseInfo
        })
    }
}

3.2、完善前端info.vue的页面:

3.2.1、完善表单:

在这里插入图片描述完善后效果图:
在这里插入图片描述

3.2.2、定义表单中数据

在这里插入图片描述

courseInfo:{
        title: '',
         subjectId: '',
         teacherId: '',
         lessonNum: 0,
         description: '',
         cover: '',
         price: 0
}

3.2.3、引入api

在这里插入图片描述

import course from '@/api/edu/course'

3.2.4、完善方法:

在这里插入图片描述

	course.addCourseInfo(this.courseInfo)
                .then(response=>{
                    //提示
                    this.$message({
                        type:'success',
                        message:'添加课程信息成功'
                    });
                    //跳转到下一步
                    this.$router.push({path:'/course/chapter/1'})
                })

完善后info.vue页面代码:

<template>

  <div class="app-container">

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

    <el-steps :active="1" 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 label="课程标题">
            <el-input v-model="courseInfo.title" placeholder=" 示例:机器学习项目课:从基础到搭建项目视频课程。专业名称注意大小写"/>
        </el-form-item>

        <!-- 所属分类 TODO -->

        <!-- 课程讲师 TODO -->

        <el-form-item label="总课时">
            <el-input-number :min="0" v-model="courseInfo.lessonNum" controls-position="right" placeholder="请填写课程的总课时数"/>
        </el-form-item>

        <!-- 课程简介 TODO -->
        <el-form-item label="课程简介">
            <el-input v-model="courseInfo.description" placeholder=" 请输入课程简介信息"/>
        </el-form-item>

        <!-- 课程封面 TODO -->

        <el-form-item label="课程价格">
            <el-input-number :min="0" v-model="courseInfo.price" controls-position="right" placeholder="免费课程请设置为0元"/></el-form-item>

        <el-form-item>
            <el-button :disabled="saveBtnDisabled" type="primary" @click="saveOrUpdate">保存并下一步</el-button>
        </el-form-item>
    </el-form>

  </div>
</template>

<script>
import course from '@/api/edu/course'
export default {
    data(){
        return {
            saveBtnDisabled:false,
            courseInfo:{
                title: '',
                subjectId: '',
                teacherId: '',
                lessonNum: 0,
                description: '',
                cover: '',
                price: 0
            }
        }
    },
    created(){

    },
    methods:{
        saveOrUpdate(){
             course.addCourseInfo(this.courseInfo)
                .then(response=>{
                    //提示
                    this.$message({
                        type:'success',
                        message:'添加课程信息成功'
                    });
                    //跳转到下一步
                    this.$router.push({path:'/course/chapter/1'})
                })
        }  
    }
}
</script>

4、完善后端接口

在EduCourseCourse中完善:
在这里插入图片描述

//返回添加之后的课程id,为了后面添加大纲使用
String id = courseService.saveCourseInfo(courseInfoVo);
return R.ok().data("courseId",id);

业务层接口
在这里插入图片描述业务层接口实现类
在这里插入图片描述

5、完善info.vue

在这里插入图片描述
下一节:添加课程信息(2)实现讲师下拉列表

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值