123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- import ColHeader from '@/components/col-header'
- import ColSearch from '@/components/col-search'
- import { Sticky, Image, List, Icon, Popup } from 'vant'
- import { defineComponent } from 'vue'
- import styles from './index.module.less'
- import request from '@/helpers/request'
- import ColResult from '@/components/col-result'
- import LiveItem from './live-item'
- import banner from '../video-class/images/banner.png'
- import { state } from '@/state'
- import OrganSearch from '@/student/practice-class/model/organ-search'
- export default defineComponent({
- name: 'liveClass',
- data() {
- const sessionSubjectId = sessionStorage.getItem('liveClassSubjectId')
- const subjectIds = state.user.data?.subjectId || ''
- const subjectId = subjectIds ? Number(subjectIds.split(',')[0]) : null
- return {
- apiSuffix:
- state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher',
- list: [],
- dataShow: true, // 判断是否有数据
- loading: false,
- finished: false,
- searchStatus: false,
- openStatus: false,
- subjectList: [],
- sessionSubjectId,
- params: {
- search: '',
- subjectId: (sessionSubjectId || subjectId || null) as any,
- subjectName: '全部',
- groupStatus: 'APPLY',
- page: 1,
- rows: 20
- }
- }
- },
- async mounted() {
- try {
- const res = await request.get(
- `${this.apiSuffix}/subject/subjectSelect?type=LIVE`
- )
- this.subjectList = res.data || []
- } catch {
- //
- }
- const list = this.subjectList.map((n: any) => n.subjects).flat().filter(n => typeof n === 'object').sort((a,b) => a.id - b.id)
- const userSubjectId = state.user.data?.subjectId.split(',').map(n => parseInt(n)) || [this.params.subjectId]
- let isRest = true
- for(let i = 0; i < list.length; i++){
- if (userSubjectId.includes(list[i].id)) {
- this.params.subjectId = list[i].id
- this.params.subjectName = list[i].name
- isRest = false
- break;
- }
- }
- if (isRest && list.length){
- this.params.subjectId = list[0].id
- this.params.subjectName = list[0].name
- }
- sessionStorage.removeItem('liveClassSubjectId')
- this.getList()
- },
- methods: {
- onSort() {
- this.params.page = 1
- this.list = []
- this.dataShow = true // 判断是否有数据
- this.loading = false
- this.finished = false
- this.searchStatus = false
- this.getList()
- },
- onSearch(value: string) {
- this.params.search = value
- this.onSort()
- },
- async getList() {
- try {
- const params: any = {
- ...this.params
- }
- // 只有学生端会有version
- if (state.version) {
- params.version = state.version || '' // 处理ios审核版本
- params.platform =
- state.platformType === 'STUDENT' ? 'ios-student' : 'ios-teacher'
- }
- // 判断是哪个端
- const url =
- state.platformType === 'STUDENT'
- ? '/api-student/courseGroup/queryPageCourseGroup'
- : '/api-teacher/courseGroup/queryPageCourseGroup'
- // 处理搜索,老师端分享用
- if (state.platformType === 'TEACHER') {
- params.myself = false
- }
- const res = await request.post(url, {
- data: {
- ...params
- }
- })
- this.loading = false
- const result = res.data || {}
- // 处理重复请求数据
- if (this.list.length > 0 && result.pageNo === 1) {
- return
- }
- this.list = this.list.concat(result.rows || [])
- this.finished = result.pageNo >= result.totalPage
- this.params.page = result.pageNo + 1
- this.dataShow = this.list.length > 0
- } catch {
- this.dataShow = false
- this.finished = true
- }
- },
- onDetail(item: any) {
- this.params.subjectId &&
- sessionStorage.setItem('liveClassSubjectId', this.params.subjectId)
- const params: any = {
- groupId: item.courseGroupId
- }
- // 判断是否是老师端,如果是,则添加分享按钮
- if (state.platformType === 'TEACHER') {
- params.share = 1
- }
- this.$router.push({
- path: '/liveDetail',
- query: params
- })
- }
- },
- render() {
- return (
- <div class={styles.liveClass}>
- <Sticky offsetTop={0} position="top">
- <ColHeader
- class={styles.classHeader}
- border={false}
- isFixed={false}
- background="transparent"
- />
- <ColSearch
- placeholder="请输入老师名称/课程名称"
- onSearch={this.onSearch}
- v-slots={{
- left: () => (
- <div
- class={styles.label}
- onClick={() => {
- this.searchStatus = !this.searchStatus
- this.openStatus = !this.openStatus
- }}
- >
- {this.params.subjectName}
- <Icon
- classPrefix="iconfont"
- name="down"
- size={12}
- color="#333"
- />
- </div>
- )
- }}
- />
- </Sticky>
- {/* <div class={styles.banner}>
- <Image src={banner} />
- </div> */}
- {this.dataShow ? (
- <List
- v-model:loading={this.loading}
- finished={this.finished}
- finishedText=" "
- class={[styles.liveList]}
- onLoad={this.getList}
- immediateCheck={false}
- >
- {this.list.map((item: any) => (
- <LiveItem onClick={this.onDetail} liveInfo={item} />
- ))}
- </List>
- ) : (
- <ColResult btnStatus={false} classImgSize="SMALL" tips="暂无直播课" />
- )}
- <Popup
- show={this.searchStatus}
- position="bottom"
- round
- closeable
- safe-area-inset-bottom
- onClose={() => (this.searchStatus = false)}
- onClosed={() => (this.openStatus = false)}
- >
- {this.openStatus && (
- <OrganSearch
- subjectList={this.subjectList}
- onSort={this.onSort}
- v-model={this.params.subjectId}
- v-model:subjectName={this.params.subjectName}
- />
- )}
- </Popup>
- </div>
- )
- }
- })
|