index.tsx 6.4 KB

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