index.tsx 7.0 KB

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