theory.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import request from '@/helpers/request'
  2. import {
  3. Cell,
  4. List,
  5. Sticky,
  6. Image,
  7. CellGroup,
  8. Collapse,
  9. CollapseItem
  10. } from 'vant'
  11. import { defineComponent } from 'vue'
  12. import styles from './theory.module.less'
  13. import ColSearch from '@/components/col-search'
  14. import ColResult from '@/components/col-result'
  15. import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'
  16. import { state } from '@/state'
  17. import { useEventTracking } from '@/helpers/hooks'
  18. import ColHeader from '@/components/col-header'
  19. import ColSticky from '@/components/col-sticky'
  20. import { getHttpOrigin } from '@/helpers/utils'
  21. export default defineComponent({
  22. name: 'special',
  23. data() {
  24. const query = this.$route.query
  25. return {
  26. activeNames: [] as any,
  27. list: [],
  28. dataShow: true, // 判断是否有数据
  29. loading: false,
  30. finished: false,
  31. // 1热门资讯,2开屏广告,3闪页管理,4轮播图管理 5按钮管理 6 乐理章节
  32. params: {
  33. search: '',
  34. page: 1,
  35. rows: 20
  36. },
  37. theory: null as null
  38. }
  39. },
  40. mounted() {
  41. const theoryStr = sessionStorage.getItem('theoryCache')
  42. if (theoryStr) {
  43. const theory = JSON.parse(theoryStr)
  44. this.theory = theory
  45. const activeNames = theory.activeNames.split(',').map(item => item * 1)
  46. this.activeNames = activeNames
  47. this.params.search = theory.search || ''
  48. }
  49. this.getList()
  50. useEventTracking('热门资讯')
  51. },
  52. methods: {
  53. async getList() {
  54. try {
  55. const params = this.params
  56. const res = await request.post('/api-cms/music/theory/app/page', {
  57. data: {
  58. ...params
  59. }
  60. })
  61. this.loading = false
  62. const result = res.data || {}
  63. // 处理重复请求数据
  64. if (this.list.length > 0 && result.pageNo === 1) {
  65. return
  66. }
  67. this.list = this.list.concat(result.rows || [])
  68. this.finished = result.pageNo >= result.totalPage
  69. this.params.page = result.pageNo + 1
  70. this.dataShow = this.list.length > 0
  71. const tempList: any = this.list
  72. if (this.activeNames.length <= 0) {
  73. this.list.length > 0 && this.activeNames.push(tempList[0].id)
  74. }
  75. } catch {
  76. this.dataShow = false
  77. this.finished = true
  78. }
  79. // if(this.theory&&this.theory.scrollTop as never){
  80. // this.$nextTick(()=>{
  81. // window.scrollTo(0, this.theory.scrollTop as never)
  82. // })
  83. // //
  84. // }
  85. },
  86. onSearch(val: string) {
  87. this.params.search = val
  88. this.params.page = 1
  89. this.list = []
  90. this.dataShow = true // 判断是否有数据
  91. this.loading = false
  92. this.finished = false
  93. this.getList()
  94. },
  95. onDetail(item: any) {
  96. // let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  97. // console.log(scrollTop)
  98. // let obj = JSON.stringify({
  99. // search: this.params.search,
  100. // activeNames: this.activeNames.join(','),
  101. // scrollTop:scrollTop
  102. // })
  103. // sessionStorage.setItem('theoryCache', obj)
  104. if (item.linkUrl) {
  105. window.location.href = item.linkUrl
  106. } else {
  107. // this.$router.push({
  108. // path: 'theoryDetail',
  109. // query: {
  110. // id: item.id
  111. // }
  112. // })
  113. const client = state.platformType === 'STUDENT' ? 'student' : 'teacher'
  114. postMessage({
  115. api: 'openWebView',
  116. content: {
  117. url: `${getHttpOrigin()}/${client}/#/theoryDetail?id=${item.id}`,
  118. orientation: 1,
  119. isHideTitle: false
  120. }
  121. })
  122. }
  123. }
  124. },
  125. render() {
  126. return (
  127. <div class={[styles['theory'], 'theory']}>
  128. <ColSticky position="top" class={'mb12'}>
  129. <ColHeader border={false} />
  130. <ColSearch onSearch={this.onSearch} modelValue={this.params.search} />
  131. </ColSticky>
  132. {this.dataShow ? (
  133. <List
  134. class={styles.videoList}
  135. v-model:loading={this.loading}
  136. finished={this.finished}
  137. finishedText="没有更多了"
  138. immediateCheck={false}
  139. onLoad={this.getList}
  140. >
  141. {this.list.map((parent: any) => (
  142. <Collapse v-model={this.activeNames} border={false}>
  143. <CollapseItem
  144. title={parent.name}
  145. name={parent.id}
  146. center
  147. v-slots={{
  148. title: () => (
  149. <div class={[styles.groupTitle]}>
  150. {parent.url && (
  151. <Image
  152. src={parent.url}
  153. fit="cover"
  154. class={styles.groupImg}
  155. />
  156. )}
  157. <p class={['van-ellipsis', styles.musicTitle]}>
  158. {parent.name}
  159. </p>
  160. </div>
  161. )
  162. }}
  163. >
  164. {parent.newsInformationList.map((item: any) => (
  165. <Cell
  166. title={item.title}
  167. class={styles.cell}
  168. border={false}
  169. onClick={() => {
  170. this.onDetail(item)
  171. }}
  172. titleClass={['van-ellipsis', styles.title]}
  173. />
  174. ))}
  175. </CollapseItem>
  176. </Collapse>
  177. ))}
  178. </List>
  179. ) : (
  180. <ColResult btnStatus={false} classImgSize="SMALL" tips="暂无内容" />
  181. )}
  182. </div>
  183. )
  184. }
  185. })