theory.tsx 5.4 KB

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