index.tsx 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 {
  18. listenerMessage,
  19. postMessage,
  20. promisefiyPostMessage,
  21. removeListenerMessage
  22. } from '@/helpers/native-message'
  23. import { browser } from '@/helpers/utils'
  24. import { setLogout, state } from '@/state'
  25. import event from './event'
  26. export default defineComponent({
  27. name: 'home-index',
  28. props: {
  29. album: {
  30. type: Array,
  31. default: () => {
  32. return []
  33. }
  34. }
  35. },
  36. data() {
  37. return {
  38. loading: false,
  39. height: 'auto' as any,
  40. banner: [], // BANNER列表
  41. appMenu: [], // 按钮列表
  42. albumList: [], // 热门专辑
  43. musicList: {
  44. topMusicSheet: [] as any,
  45. newMusicSheet: [] as any,
  46. hotMusicSheet: [] as any
  47. },
  48. sageList: [], // 推荐达人
  49. videoList: [], // 视频课
  50. headerHeight: 0,
  51. downloadStatus: false
  52. }
  53. },
  54. async mounted() {
  55. await this.init()
  56. event.on('downloadApp', async () => {
  57. // 管乐团里面,获取是否已安装酷乐秀
  58. const type = browser().orchestraAndroid
  59. ? 'com.cooleshow.student'
  60. : 'ColexiuStudent://'
  61. await promisefiyPostMessage({
  62. api: 'isInstall',
  63. content: { type: type }
  64. }).then((res: any) => {
  65. const content = res.content
  66. state.orchestraInfo.installStatus = content.installStatus
  67. })
  68. this.downloadStatus = true
  69. })
  70. listenerMessage('webViewOnResume', () => {
  71. promisefiyPostMessage({ api: 'getUserAccount' }).then((res: any) => {
  72. const content = res.content
  73. // console.log(state.orchestraInfo, 'state.orchestraInfo')
  74. // console.log(content, 'content')
  75. if (content.phone !== state.orchestraInfo.phone) {
  76. // 判断是否已经有关联编号
  77. if (content.unionId) {
  78. window.location.reload()
  79. } else {
  80. state.orchestraInfo.token = content.token.split(' ')[1]
  81. state.orchestraInfo.phone = content.phone
  82. state.orchestraInfo.nickname = content.nickname
  83. state.orchestraInfo.avatar = content.avatar
  84. state.orchestraInfo.unionId = content.unionId || 0
  85. // 13310106048
  86. // 15088666723
  87. setLogout()
  88. // window.location.reload()
  89. this.$router.push({
  90. path: '/home-auth'
  91. })
  92. }
  93. }
  94. })
  95. })
  96. postMessage({ api: 'setBarStatus', content: { status: 0 } })
  97. },
  98. unmounted() {
  99. removeListenerMessage('webViewOnResume', () => {
  100. //
  101. })
  102. },
  103. methods: {
  104. async init() {
  105. try {
  106. const res = await request.post('/api-cms/news/app/home', {
  107. data: {
  108. clientType: 'STUDENT'
  109. }
  110. })
  111. const result = res.data || {}
  112. this.banner = result.banner || []
  113. this.appMenu = this.arrChange(5, result.appMenu || [])
  114. // 热门专辑
  115. const album = await request.post('/api-student/music/album/list', {
  116. data: {
  117. albumStatus: 1,
  118. clientId: 'STUDENT'
  119. }
  120. })
  121. this.albumList = album.data.rows || []
  122. // 曲谱
  123. const music = await request.post(
  124. '/api-student/music/sheet/appMusicSheet',
  125. {
  126. data: {}
  127. }
  128. )
  129. const musicData = music.data || []
  130. this.musicList = {
  131. topMusicSheet: this.arrChange(4, musicData.topMusicSheet || []),
  132. newMusicSheet: this.arrChange(4, musicData.newMusicSheet || []),
  133. hotMusicSheet: this.arrChange(4, musicData.hotMusicSheet || [])
  134. }
  135. const sage = await request.get(
  136. '/api-student/teacher/queryHotTeacherList'
  137. )
  138. this.sageList = sage.data || []
  139. const video = await request.get(
  140. '/api-student/courseSchedule/queryLiveAndVideo'
  141. )
  142. this.videoList = video.data.videoList || []
  143. } catch {
  144. //
  145. }
  146. setTimeout(() => {
  147. this.loading = false
  148. }, 500)
  149. },
  150. arrChange(num: number, arr: any) {
  151. const newArr = [] as any
  152. while (arr.length > 0) {
  153. newArr.push(arr.splice(0, num))
  154. }
  155. return newArr
  156. },
  157. async onRefresh() {
  158. await this.init()
  159. setTimeout(() => {
  160. this.loading = false
  161. }, 500)
  162. }
  163. },
  164. render() {
  165. return (
  166. <div class={styles.home}>
  167. <TheHomeHeader
  168. ref="header"
  169. onHeaderDom={(height: number) => {
  170. console.log(height, 'height')
  171. this.headerHeight = height
  172. }}
  173. onCart={() => {
  174. this.downloadStatus = true
  175. }}
  176. onSearch={() => {
  177. // 搜索详情
  178. this.downloadStatus = true
  179. }}
  180. onMore={() => {
  181. this.downloadStatus = true
  182. }}
  183. />
  184. <PullRefresh
  185. v-model={this.loading}
  186. loading-text="正在刷新..."
  187. success-text="刷新完成"
  188. onRefresh={() => this.onRefresh()}
  189. >
  190. <div class={styles.hotContent}>
  191. <Swipe class={styles.swipe} autoplay={3000}>
  192. {this.banner.map((item: any) => (
  193. <SwipeItem
  194. onClick={() => {
  195. // 判断url是否正常
  196. // if (verifyUrl(item.linkUrl)) {
  197. // openDefaultWebView(item.linkUrl, () => {
  198. // window.location.href = item.linkUrl
  199. // })
  200. // }
  201. this.downloadStatus = true
  202. }}
  203. >
  204. <Image
  205. class={styles.swipeItemImg}
  206. src={item.coverImage}
  207. fit="fill"
  208. />
  209. </SwipeItem>
  210. ))}
  211. </Swipe>
  212. <MenuList productList={this.appMenu} />
  213. </div>
  214. <HotAlbum album={this.albumList} />
  215. <Music title="推荐曲目" music={this.musicList?.topMusicSheet || []} />
  216. <Music title="最新曲目" music={this.musicList?.newMusicSheet || []} />
  217. <Music title="最热曲目" music={this.musicList?.hotMusicSheet || []} />
  218. {/* 推荐达人 */}
  219. <RecommendSage sage={this.sageList} />
  220. {/* 精品视频课 */}
  221. <VideoClass video={this.videoList} />
  222. <Tabs
  223. shrink
  224. background="#f6f8f9"
  225. class={styles.homeTabs}
  226. sticky
  227. offsetTop={this.headerHeight + 'px'}
  228. >
  229. <Tab title="达人风采" name="sage">
  230. <TalentStyle />
  231. </Tab>
  232. <Tab title="热门资讯" name="info">
  233. <InfoList />
  234. </Tab>
  235. </Tabs>
  236. </PullRefresh>
  237. <Popup
  238. v-model:show={this.downloadStatus}
  239. round
  240. style={{ width: '86%', background: 'transparent' }}
  241. closeable
  242. closeIcon={popupClose}
  243. >
  244. <Download
  245. buttonText={
  246. state.orchestraInfo.installStatus ? '唤起酷乐秀' : '下载酷乐秀'
  247. }
  248. onConfirm={() => {
  249. const type = browser().orchestraAndroid
  250. ? 'com.cooleshow.student'
  251. : 'ColexiuStudent://'
  252. if (state.orchestraInfo.installStatus) {
  253. postMessage({ api: 'openApp', content: { type: type } })
  254. } else {
  255. // const urlIos =
  256. // 'https://itunes.apple.com/cn/app/id1626971695?mt=8'
  257. // const urlAndroid =
  258. // 'https://appstore.ks3-cn-beijing.ksyuncs.com/clx-student-domain.apk'
  259. const url = browser().orchestraAndroid
  260. ? window.location.origin +
  261. window.location.pathname +
  262. '#/download'
  263. : 'https://itunes.apple.com/cn/app/id1626971695?mt=8'
  264. postMessage({
  265. api: 'downloadApp',
  266. content: { type: type, url: url }
  267. })
  268. }
  269. }}
  270. />
  271. </Popup>
  272. {/*
  273. ColexiuStudent IOS 学生端
  274. com.cooleshow.student ADNROID 学生端
  275. com.cooleshow.teacher ADNROID 老师端
  276. */}
  277. </div>
  278. )
  279. }
  280. })