index.tsx 7.4 KB

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