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