index.tsx 6.6 KB

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