theory.tsx 5.6 KB

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