index.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. import { SubjectEnum, useSubjectId } from '@/helpers/hooks'
  13. export default defineComponent({
  14. name: 'liveClass',
  15. data() {
  16. return {
  17. apiSuffix:
  18. state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher',
  19. list: [],
  20. dataShow: true, // 判断是否有数据
  21. loading: false,
  22. finished: false,
  23. searchStatus: false,
  24. openStatus: false,
  25. subjectList: [],
  26. lockLoading: false,
  27. params: {
  28. search: '',
  29. subjectId: null as any,
  30. subjectName: '全部声部',
  31. groupStatus: 'APPLY',
  32. page: 1,
  33. rows: 20
  34. }
  35. }
  36. },
  37. async mounted() {
  38. try {
  39. const res = await request.get(
  40. `${this.apiSuffix}/subject/subjectSelect?type=LIVE`
  41. )
  42. this.subjectList = res.data || []
  43. } catch {
  44. //
  45. }
  46. // 判断是否在缓存
  47. const subjects: any = useSubjectId(SubjectEnum.LIVE)
  48. if (subjects.id) {
  49. this.params.subjectId = Number(subjects.id)
  50. this.params.subjectName = subjects.name
  51. } else {
  52. const list = this.subjectList
  53. const subjectIds = state.user.data?.subjectId || ''
  54. const subjectId = subjectIds ? Number(subjectIds.split(',')[0]) : null
  55. list.forEach((subject: any) => {
  56. const child = subject.subjects || []
  57. child.forEach((sub: any) => {
  58. if (sub.id === Number(subjectId)) {
  59. this.params.subjectId = sub.id
  60. this.params.subjectName = sub.name
  61. }
  62. })
  63. })
  64. }
  65. this.getList()
  66. },
  67. methods: {
  68. onSort() {
  69. this.params.page = 1
  70. this.list = []
  71. this.dataShow = true // 判断是否有数据
  72. this.loading = false
  73. this.finished = false
  74. this.searchStatus = false
  75. if (this.params.subjectId) {
  76. useSubjectId(
  77. SubjectEnum.LIVE,
  78. JSON.stringify({
  79. id: this.params.subjectId,
  80. name: this.params.subjectName
  81. }),
  82. 'set'
  83. )
  84. }
  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. const params: any = {
  137. groupId: item.courseGroupId
  138. }
  139. // 判断是否是老师端,如果是,则添加分享按钮
  140. if (state.platformType === 'TEACHER') {
  141. params.share = 1
  142. }
  143. this.$router.push({
  144. path: '/liveDetail',
  145. query: params
  146. })
  147. }
  148. },
  149. render() {
  150. return (
  151. <div class={styles.liveClass}>
  152. <Sticky offsetTop={0} position="top">
  153. <ColHeader
  154. class={styles.classHeader}
  155. border={false}
  156. isFixed={false}
  157. background="transparent"
  158. />
  159. <ColSearch
  160. placeholder="请输入老师名称/课程名称"
  161. onSearch={this.onSearch}
  162. v-slots={{
  163. left: () => (
  164. <div
  165. class={styles.label}
  166. onClick={() => {
  167. this.searchStatus = !this.searchStatus
  168. this.openStatus = !this.openStatus
  169. }}
  170. >
  171. {this.params.subjectName}
  172. <Icon
  173. classPrefix="iconfont"
  174. name="down"
  175. size={12}
  176. color="#333"
  177. />
  178. </div>
  179. )
  180. }}
  181. />
  182. </Sticky>
  183. {/* <div class={styles.banner}>
  184. <Image src={banner} />
  185. </div> */}
  186. {this.dataShow ? (
  187. <List
  188. v-model:loading={this.loading}
  189. finished={this.finished}
  190. finishedText=" "
  191. class={[styles.liveList]}
  192. onLoad={this.getList}
  193. immediateCheck={false}
  194. >
  195. {this.list.map((item: any) => (
  196. <LiveItem onClick={this.onDetail} liveInfo={item} />
  197. ))}
  198. </List>
  199. ) : (
  200. <ColResult btnStatus={false} classImgSize="SMALL" tips="暂无直播课" />
  201. )}
  202. <Popup
  203. show={this.searchStatus}
  204. position="bottom"
  205. round
  206. closeable
  207. safe-area-inset-bottom
  208. onClose={() => (this.searchStatus = false)}
  209. onClosed={() => (this.openStatus = false)}
  210. >
  211. {this.openStatus && (
  212. <OrganSearch
  213. subjectList={this.subjectList}
  214. onSort={this.onSort}
  215. v-model={this.params.subjectId}
  216. v-model:subjectName={this.params.subjectName}
  217. />
  218. )}
  219. </Popup>
  220. </div>
  221. )
  222. }
  223. })