index.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. import request from '@/student/home-layout-orchestra/request-home'
  2. import { verifyUrl } from '@/helpers/toolsValidate'
  3. import { openDefaultWebView } from '@/student/home-layout-orchestra/state-orchestra'
  4. import { PullRefresh, Swipe, SwipeItem, Image, Tabs, Tab, Popup } from 'vant'
  5. import { defineComponent } from 'vue'
  6. import HotAlbum from './components/hot-album'
  7. import InfoList from './components/info-list'
  8. import MenuList from './components/menu-list'
  9. import Music from './components/music'
  10. import RecommendSage from './components/recommend-sage'
  11. import TalentStyle from './components/talent-style'
  12. import TheHomeHeader from './components/TheHomeHeader'
  13. import VideoClass from './components/video-class'
  14. import styles from './index.module.less'
  15. import Download from './model/download'
  16. import popupClose from './images/popup-close.png'
  17. import { postMessage } from '@/helpers/native-message'
  18. import { browser } from '@/helpers/utils'
  19. import { state } from '@/state'
  20. import event from './event'
  21. export default defineComponent({
  22. name: 'home-index',
  23. props: {
  24. album: {
  25. type: Array,
  26. default: () => {
  27. return []
  28. }
  29. }
  30. },
  31. data() {
  32. return {
  33. loading: false,
  34. height: 'auto' as any,
  35. banner: [], // BANNER列表
  36. appMenu: [], // 按钮列表
  37. albumList: [], // 热门专辑
  38. musicList: {
  39. topMusicSheet: [] as any,
  40. newMusicSheet: [] as any,
  41. hotMusicSheet: [] as any
  42. },
  43. sageList: [], // 推荐达人
  44. videoList: [], // 视频课
  45. headerHeight: 0,
  46. downloadStatus: false
  47. }
  48. },
  49. mounted() {
  50. this.headerHeight = (this as any).$refs.header?.getHeadeHeight()
  51. this.init()
  52. event.on('downloadApp', () => {
  53. this.downloadStatus = true
  54. })
  55. },
  56. methods: {
  57. async init() {
  58. try {
  59. const res = await request.post('/api-cms/news/app/home', {
  60. data: {
  61. clientType: 'STUDENT'
  62. }
  63. })
  64. const result = res.data || {}
  65. this.banner = result.banner || []
  66. this.appMenu = this.arrChange(5, result.appMenu || [])
  67. // 热门专辑
  68. const album = await request.post('/api-student/music/album/list', {
  69. data: {
  70. albumStatus: 1,
  71. clientId: 'STUDENT'
  72. }
  73. })
  74. this.albumList = album.data.rows || []
  75. // 曲谱
  76. const music = await request.post(
  77. '/api-student/music/sheet/appMusicSheet',
  78. {
  79. data: {}
  80. }
  81. )
  82. const musicData = music.data || []
  83. this.musicList = {
  84. topMusicSheet: this.arrChange(4, musicData.topMusicSheet || []),
  85. newMusicSheet: this.arrChange(4, musicData.newMusicSheet || []),
  86. hotMusicSheet: this.arrChange(4, musicData.hotMusicSheet || [])
  87. }
  88. const sage = await request.get(
  89. '/api-student/teacher/queryHotTeacherList'
  90. )
  91. this.sageList = sage.data || []
  92. const video = await request.get(
  93. '/api-student/courseSchedule/queryLiveAndVideo'
  94. )
  95. this.videoList = video.data.videoList || []
  96. } catch {
  97. //
  98. }
  99. setTimeout(() => {
  100. this.loading = false
  101. }, 500)
  102. },
  103. arrChange(num: number, arr: any) {
  104. const newArr = [] as any
  105. while (arr.length > 0) {
  106. newArr.push(arr.splice(0, num))
  107. }
  108. return newArr
  109. },
  110. async onRefresh() {
  111. await this.init()
  112. setTimeout(() => {
  113. this.loading = false
  114. }, 500)
  115. }
  116. },
  117. render() {
  118. return (
  119. <div class={styles.home}>
  120. <TheHomeHeader
  121. ref="header"
  122. onCart={() => {
  123. this.downloadStatus = true
  124. }}
  125. onSearch={() => {
  126. // 搜索详情
  127. this.downloadStatus = true
  128. }}
  129. onMore={() => {
  130. this.downloadStatus = true
  131. }}
  132. />
  133. <PullRefresh
  134. v-model={this.loading}
  135. loading-text="正在刷新..."
  136. success-text="刷新完成"
  137. onRefresh={() => this.onRefresh()}
  138. >
  139. <div class={styles.hotContent}>
  140. <Swipe class={styles.swipe} autoplay={3000}>
  141. {this.banner.map((item: any) => (
  142. <SwipeItem
  143. onClick={() => {
  144. // 判断url是否正常
  145. // if (verifyUrl(item.linkUrl)) {
  146. // openDefaultWebView(item.linkUrl, () => {
  147. // window.location.href = item.linkUrl
  148. // })
  149. // }
  150. this.downloadStatus = true
  151. }}
  152. >
  153. <Image
  154. class={styles.swipeItemImg}
  155. src={item.coverImage}
  156. fit="fill"
  157. />
  158. </SwipeItem>
  159. ))}
  160. </Swipe>
  161. <MenuList productList={this.appMenu} />
  162. </div>
  163. <HotAlbum album={this.albumList} />
  164. <Music title="推荐曲目" music={this.musicList?.topMusicSheet || []} />
  165. <Music title="最新曲目" music={this.musicList?.newMusicSheet || []} />
  166. <Music title="最热曲目" music={this.musicList?.hotMusicSheet || []} />
  167. {/* 推荐达人 */}
  168. <RecommendSage sage={this.sageList} />
  169. {/* 精品视频课 */}
  170. <VideoClass video={this.videoList} />
  171. <Tabs
  172. shrink
  173. background="#f6f8f9"
  174. class={styles.homeTabs}
  175. sticky
  176. offsetTop={this.headerHeight + 'px'}
  177. >
  178. <Tab title="达人风采" name="sage">
  179. <TalentStyle />
  180. </Tab>
  181. <Tab title="热门资讯" name="info">
  182. <InfoList />
  183. </Tab>
  184. </Tabs>
  185. </PullRefresh>
  186. <Popup
  187. v-model:show={this.downloadStatus}
  188. round
  189. style={{ width: '86%', background: 'transparent' }}
  190. closeable
  191. closeIcon={popupClose}
  192. >
  193. <Download
  194. buttonText={
  195. state.orchestraInfo.installStatus ? '唤起酷乐秀' : '下载酷乐秀'
  196. }
  197. onConfirm={() => {
  198. const type = browser().orchestraAndroid
  199. ? 'com.cooleshow.student'
  200. : 'ColexiuStudent://'
  201. if (state.orchestraInfo.installStatus) {
  202. postMessage({ api: 'openApp', content: { type: type } })
  203. } else {
  204. // const urlIos =
  205. // 'https://itunes.apple.com/cn/app/id1626971695?mt=8'
  206. // const urlAndroid =
  207. // 'https://appstore.ks3-cn-beijing.ksyuncs.com/clx-student-domain.apk'
  208. const url = browser().orchestraAndroid
  209. ? window.location.origin +
  210. window.location.pathname +
  211. '#/download'
  212. : 'https://itunes.apple.com/cn/app/id1626971695?mt=8'
  213. postMessage({
  214. api: 'downloadApp',
  215. content: { type: type, url: url }
  216. })
  217. }
  218. }}
  219. />
  220. </Popup>
  221. {/*
  222. ColexiuStudent IOS 学生端
  223. com.cooleshow.student ADNROID 学生端
  224. com.cooleshow.teacher ADNROID 老师端
  225. */}
  226. </div>
  227. )
  228. }
  229. })