day14【首页课程和名师功能】-01 首页名师功能

01-名师页面静态效果整合

一、列表页面

创建 pages/teacher/index.vue

二、详情页面

创建 pages/teacher/_id.vue

修改资源路径为~/assets/



02-讲师列表页

一、后端

1、TeacherFrontController

//1 分页查询讲师的方法

    @ApiOperation(value = "分页讲师列表")

    @PostMapping("getTeacherFrontList/{page}/{limit}")

    public R getTeacherFrontList(@PathVariable long page,@PathVariable long limit){

        Page teacherPage = new Page(page,limit);

        Map map = teacherService.getTeacherFrontList(teacherPage);

        return R.ok().data(map);

    }

2、EduTeacherService

接口

//1 分页查询讲师的方法

    Map getTeacherFrontList(Page teacherPage);

实现

//1 分页查询讲师的方法

    @Override

    public Map getTeacherFrontList(Page teacherPage) {

        QueryWrapper wrapper = new QueryWrapper<>();

        wrapper.orderByDesc("id");

        //把分页数据封装到pageTeacher对象

        baseMapper.selectPage(teacherPage,wrapper);


        long total = teacherPage.getTotal();

        long current = teacherPage.getCurrent();

        List records = teacherPage.getRecords();

        long size = teacherPage.getSize();

        long pages = teacherPage.getPages();

        boolean hasNext = teacherPage.hasNext();

        boolean hasPrevious = teacherPage.hasPrevious();


        Map map = new HashMap<>();

        map.put("items", records);

        map.put("current", current);

        map.put("pages", pages);

        map.put("size", size);

        map.put("total", total);

        map.put("hasNext", hasNext);

        map.put("hasPrevious", hasPrevious);

        return map;

    }

3、swagger测试

二、前端列表js

1、创建api

创建文件夹api,api下创建teacher.js,用于封装讲师模块的请求

import request from '@/utils/request'

export default {

    //1 分页查询讲师的方法

    getTeacherList(page, limit){

        return request({

            url: `/eduservice/teacherfront/getTeacherFrontList/${page}/${limit}`,

            method: 'post'

        })

    }

}

2、讲师列表组件中调用api

pages/teacher/index.vue

三、页面渲染

1、无数据提示

添加:v-if="data.total==0"

        

          v-if="data.total==0">

             

            没有相关数据,小编正在努力整理中...

          

2、列表

        

           v-if="data.total>0" class="i-teacher-list">

            

               v-for="teacher in data.items" :key="teacher.id">

                

                  

                    :title="teacher.name" target="_blank">

                       :src="teacher.avatar" :alt="teacher.name">

                    

                  

                  

                    :title="teacher.name" target="_blank" class="fsize18 c-666">{{teacher.name}}

                  

                  

                    {{teacher.intro}}

                  

                  

                    {{teacher.career}}

                  

                

              

            

            

          

3、测试

四、分页

1、分页方法

2、分页页面渲染

        

        

          

            

            

              :class="{undisable: !data.hasPrevious}"

              href="#"

              title="首页"

              @click.prevent="gotoPage(1)">首页

            

              :class="{undisable: !data.hasPrevious}"

              href="#"

              title="前一页"

              @click.prevent="gotoPage(data.current-1)"><

            

              v-for="page in data.pages"

              :key="page"

              :class="{current: data.current == page, undisable: data.current == page}"

              :title="'第'+page+'页'"

              href="#"

              @click.prevent="gotoPage(page)">{{ page }}

            

              :class="{undisable: !data.hasNext}"

              href="#"

              title="后一页"

              @click.prevent="gotoPage(data.current+1)">>

            

              :class="{undisable: !data.hasNext}"

              href="#"

              title="末页"

              @click.prevent="gotoPage(data.pages)">末页

            

          

        

        

3、测试



03-讲师详情页

一、后端

1、修改讲师列表页面超链接,改成讲师id

2、编写讲师详情接口

(1)根据讲师id查询讲师基本信息

(2)根据讲师id查询讲师所讲课程

    @ApiOperation(value = "根据ID查询讲师")

    @GetMapping("getTeacherFrontInfo/{teacherId}")

    public R getTeacherFrontInfo(@PathVariable String teacherId){

        //(1)根据讲师id查询讲师基本信息

        EduTeacher teacher = teacherService.getById(teacherId);


        //(2)根据讲师id查询讲师所讲课程

        QueryWrapper wrapper = new QueryWrapper<>();

        wrapper.eq("teacher_id",teacherId);

        //按照最后更新时间倒序排列

        wrapper.orderByDesc("gmt_modified");

        List courseList = courseService.list(wrapper);

        return R.ok().data("teacher", teacher).data("courseList", courseList);

    }

3、swagger测试

二、前端详情js

1、teacher api

//讲师详情的方法

    getTeacherInfo(teacherId){

        return request({

            url: `/eduservice/teacherfront/getTeacherFrontInfo/${teacherId}`,

            method: 'get'

        })

    }

2、讲师详情页中调用api

三、页面渲染

1、讲师详情显示

     

        

          

            

              :src="teacher.avatar">

            

            

              {{teacher.name}} {{teacher.level===1?'高级讲师':'首席讲师'}}

            

            

              {{teacher.intro}}

            

            

              

                class="mt20">{{teacher.career}}

            

            

          

        

        

2、无数据提示

        

           v-if="courseList.length==0">

             

            没有相关数据,小编正在努力整理中...

          

          

3、当前讲师课程列表

        

          

            

              v-for="course in courseList" :key="course.id">

                

                  

                     :src="course.cover" class="img-responsive" >

                    

                       :href="'/course/'+course.id" title="开始学习" target="_blank" class="comm-btn c-btn-1">开始学习

                    

                  

                  

                     :href="'/course/'+course.id" :title="course.title" target="_blank" class="course-title fsize18 c-333">{{course.title}}

                  

                

              

            

            

          

          

4、测试

你可能感兴趣的:(day14【首页课程和名师功能】-01 首页名师功能)