index.tsx 6.7 KB

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