index.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. export default defineComponent({
  13. name: 'VideoClass',
  14. data() {
  15. const sessionSubjectId = sessionStorage.getItem('videoClassSubjectId')
  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. search: '',
  22. list: [],
  23. dataShow: true, // 判断是否有数据
  24. loading: false,
  25. finished: false,
  26. sessionSubjectId,
  27. params: {
  28. search: '',
  29. lessonSubject: (sessionSubjectId || subjectId || null) as any,
  30. subjectName: '',
  31. page: 1,
  32. rows: 20
  33. },
  34. searchStatus: false,
  35. openStatus: false,
  36. subjectList: []
  37. }
  38. },
  39. async mounted() {
  40. try {
  41. const res = await request.get(`${this.apiSuffix}/subject/subjectSelect`)
  42. this.subjectList = res.data || []
  43. } catch {
  44. //
  45. }
  46. let subjectName = ''
  47. console.log(this.params.lessonSubject)
  48. this.subjectList.forEach((item: any) => {
  49. item.subjects?.forEach((child: any) => {
  50. if (child.id === Number(this.params.lessonSubject)) {
  51. subjectName = child.name
  52. }
  53. if (!this.params.lessonSubject) {
  54. subjectName = child.name
  55. this.params.lessonSubject = child.id
  56. }
  57. })
  58. })
  59. console.log(subjectName)
  60. const subjectNameList = state.user.data?.subjectName || ''
  61. this.params.subjectName = subjectName || subjectNameList.split(',')[0] || ''
  62. sessionStorage.removeItem('videoClassSubjectId')
  63. },
  64. methods: {
  65. async getList() {
  66. try {
  67. const params: any = {
  68. ...this.params
  69. }
  70. // 只有学生端会有version
  71. if (state.version) {
  72. params.version = state.version || '' // 处理ios审核版本
  73. params.platform = 'ios-student'
  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. this.getList()
  111. },
  112. onSearch(val: string) {
  113. this.params.search = val
  114. this.onSort()
  115. },
  116. onDetail(item: any) {
  117. const params: any = {
  118. groupId: item.id
  119. }
  120. // 判断是否是老师端,如果是,则添加分享按钮
  121. if (state.platformType === 'TEACHER') {
  122. params.share = 1
  123. }
  124. this.$router.push({
  125. path: '/videoDetail',
  126. query: params
  127. })
  128. }
  129. },
  130. render() {
  131. return (
  132. <div class={styles.videoClass}>
  133. <Sticky offsetTop={0} position="top">
  134. <ColHeader
  135. class={styles.classHeader}
  136. border={false}
  137. isFixed={false}
  138. background="transparent"
  139. />
  140. <ColSearch
  141. placeholder="请输入老师名称/课程名称"
  142. onSearch={this.onSearch}
  143. v-slots={{
  144. left: () => (
  145. <div
  146. class={styles.label}
  147. onClick={() => {
  148. this.searchStatus = !this.searchStatus
  149. this.openStatus = !this.openStatus
  150. }}
  151. >
  152. {this.params.subjectName}
  153. <Icon
  154. classPrefix="iconfont"
  155. name="down"
  156. size={12}
  157. color="#333"
  158. />
  159. </div>
  160. )
  161. }}
  162. />
  163. </Sticky>
  164. {/* <div class={styles.banner}>
  165. <Image src={banner} />
  166. </div> */}
  167. <div>
  168. {this.dataShow ? (
  169. <List
  170. class={styles.videoList}
  171. v-model:loading={this.loading}
  172. finished={this.finished}
  173. finishedText="没有更多了"
  174. onLoad={this.getList}
  175. >
  176. {this.list.map(item => (
  177. <VideoItem item={item} onClick={this.onDetail} />
  178. ))}
  179. </List>
  180. ) : (
  181. <ColResult btnStatus={false} tips="暂无视频课" />
  182. )}
  183. </div>
  184. <Popup
  185. show={this.searchStatus}
  186. position="bottom"
  187. round
  188. closeable
  189. safe-area-inset-bottom
  190. onClose={() => (this.searchStatus = false)}
  191. onClosed={() => (this.openStatus = false)}
  192. >
  193. {this.openStatus && (
  194. <OrganSearch
  195. subjectList={this.subjectList}
  196. onSort={this.onSort}
  197. v-model={this.params.lessonSubject}
  198. v-model:subjectName={this.params.subjectName}
  199. />
  200. )}
  201. </Popup>
  202. </div>
  203. )
  204. }
  205. })