index.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import ColHeader from '@/components/col-header'
  2. import ColSearch from '@/components/col-search'
  3. import { Sticky, Image, List, Icon, Popup } from 'vant'
  4. import { defineComponent } from 'vue'
  5. import styles from './index.module.less'
  6. import request from '@/helpers/request'
  7. import ColResult from '@/components/col-result'
  8. import LiveItem from './live-item'
  9. import banner from '../video-class/images/banner.png'
  10. import { state } from '@/state'
  11. import OrganSearch from '@/student/practice-class/model/organ-search'
  12. export default defineComponent({
  13. name: 'liveClass',
  14. data() {
  15. const sessionSubjectId = sessionStorage.getItem('liveClassSubjectId')
  16. const subjectIds = state.user.data?.subjectId || ''
  17. const subjectId = subjectIds ? Number(subjectIds.split(',')[0]) : null
  18. return {
  19. apiSuffix:
  20. state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher',
  21. list: [],
  22. dataShow: true, // 判断是否有数据
  23. loading: false,
  24. finished: false,
  25. searchStatus: false,
  26. openStatus: false,
  27. subjectList: [],
  28. sessionSubjectId,
  29. params: {
  30. search: '',
  31. subjectId: (sessionSubjectId || subjectId || null) as any,
  32. subjectName: '全部',
  33. groupStatus: 'APPLY',
  34. page: 1,
  35. rows: 20
  36. }
  37. }
  38. },
  39. async mounted() {
  40. try {
  41. const res = await request.get(`${this.apiSuffix}/subject/subjectSelect?type=LIVE`)
  42. this.subjectList = res.data || []
  43. } catch {
  44. //
  45. }
  46. const list = this.subjectList.map((n: any) => n.subjects).flat().filter(n => typeof n === 'object').sort((a,b) => a.id - b.id)
  47. const userSubjectId = state.user.data?.subjectId.split(',').map(n => parseInt(n)) || [this.params.subjectId]
  48. let isRest = true
  49. for(let i = 0; i < list.length; i++){
  50. if (userSubjectId.includes(list[i].id)) {
  51. this.params.subjectId = list[i].id
  52. this.params.subjectName = list[i].name
  53. isRest = false
  54. break;
  55. }
  56. }
  57. if (isRest && list.length){
  58. this.params.subjectId = list[0].id
  59. this.params.subjectName = list[0].name
  60. }
  61. sessionStorage.removeItem('liveClassSubjectId')
  62. this.getList()
  63. },
  64. methods: {
  65. onSort() {
  66. this.params.page = 1
  67. this.list = []
  68. this.dataShow = true // 判断是否有数据
  69. this.loading = false
  70. this.finished = false
  71. this.searchStatus = false
  72. this.getList()
  73. },
  74. onSearch(value: string) {
  75. this.params.search = value
  76. this.onSort()
  77. },
  78. async getList() {
  79. try {
  80. const params: any = {
  81. ...this.params
  82. }
  83. // 只有学生端会有version
  84. if (state.version) {
  85. params.version = state.version || '' // 处理ios审核版本
  86. params.platform = 'ios-student'
  87. }
  88. // 判断是哪个端
  89. const url =
  90. state.platformType === 'STUDENT'
  91. ? '/api-student/courseGroup/queryPageCourseGroup'
  92. : '/api-teacher/courseGroup/queryPageCourseGroup'
  93. // 处理搜索,老师端分享用
  94. if (state.platformType === 'TEACHER') {
  95. params.myself = false
  96. }
  97. const res = await request.post(url, {
  98. data: {
  99. ...params
  100. }
  101. })
  102. this.loading = false
  103. const result = res.data || {}
  104. // 处理重复请求数据
  105. if (this.list.length > 0 && result.pageNo === 1) {
  106. return
  107. }
  108. this.list = this.list.concat(result.rows || [])
  109. this.finished = result.pageNo >= result.totalPage
  110. this.params.page = result.pageNo + 1
  111. this.dataShow = this.list.length > 0
  112. } catch {
  113. this.dataShow = false
  114. this.finished = true
  115. }
  116. },
  117. onDetail(item: any) {
  118. this.params.subjectId &&
  119. sessionStorage.setItem('liveClassSubjectId', this.params.subjectId)
  120. const params: any = {
  121. groupId: item.courseGroupId
  122. }
  123. // 判断是否是老师端,如果是,则添加分享按钮
  124. if (state.platformType === 'TEACHER') {
  125. params.share = 1
  126. }
  127. this.$router.push({
  128. path: '/liveDetail',
  129. query: params
  130. })
  131. }
  132. },
  133. render() {
  134. return (
  135. <div class={styles.liveClass}>
  136. <Sticky offsetTop={0} position="top">
  137. <ColHeader
  138. class={styles.classHeader}
  139. border={false}
  140. isFixed={false}
  141. background="transparent"
  142. />
  143. <ColSearch
  144. placeholder="请输入老师名称/课程名称"
  145. onSearch={this.onSearch}
  146. v-slots={{
  147. left: () => (
  148. <div
  149. class={styles.label}
  150. onClick={() => {
  151. this.searchStatus = !this.searchStatus
  152. this.openStatus = !this.openStatus
  153. }}
  154. >
  155. {this.params.subjectName}
  156. <Icon
  157. classPrefix="iconfont"
  158. name="down"
  159. size={12}
  160. color="#333"
  161. />
  162. </div>
  163. )
  164. }}
  165. />
  166. </Sticky>
  167. {/* <div class={styles.banner}>
  168. <Image src={banner} />
  169. </div> */}
  170. {this.dataShow ? (
  171. <List
  172. v-model:loading={this.loading}
  173. finished={this.finished}
  174. finishedText=" "
  175. class={[styles.liveList]}
  176. onLoad={this.getList}
  177. immediateCheck={false}
  178. >
  179. {this.list.map((item: any) => (
  180. <LiveItem onClick={this.onDetail} liveInfo={item} />
  181. ))}
  182. </List>
  183. ) : (
  184. <ColResult btnStatus={false} classImgSize="SMALL" tips="暂无直播课" />
  185. )}
  186. <Popup
  187. show={this.searchStatus}
  188. position="bottom"
  189. round
  190. closeable
  191. safe-area-inset-bottom
  192. onClose={() => (this.searchStatus = false)}
  193. onClosed={() => (this.openStatus = false)}
  194. >
  195. {this.openStatus && (
  196. <OrganSearch
  197. subjectList={this.subjectList}
  198. onSort={this.onSort}
  199. v-model={this.params.subjectId}
  200. v-model:subjectName={this.params.subjectName}
  201. />
  202. )}
  203. </Popup>
  204. </div>
  205. )
  206. }
  207. })