index.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. import ColSticky from '@/components/col-sticky'
  2. import request from '@/helpers/request'
  3. import { Button, Cell, CellGroup, Dialog, Image, Popup } from 'vant'
  4. import { defineComponent } from 'vue'
  5. import styles from './index.module.less'
  6. import dayjs from 'dayjs'
  7. import ShareModel from './share-model'
  8. import { postMessage } from '@/helpers/native-message'
  9. import { state } from '@/state'
  10. export const getAssetsHomeFile = (fileName: string) => {
  11. const path = `./images/${fileName}`
  12. const modules = import.meta.globEager('./images/*')
  13. return modules[path].default
  14. }
  15. export default defineComponent({
  16. name: 'track-review-activity',
  17. data() {
  18. const query = this.$route.query
  19. return {
  20. id: query.id,
  21. activeInfo: {} as any,
  22. shareStatus: false,
  23. shareUrl: ''
  24. }
  25. },
  26. computed: {
  27. activityMusic() {
  28. const activeInfo: any = this.activeInfo
  29. return activeInfo.activityMusicVoList || []
  30. }
  31. },
  32. async mounted() {
  33. await this.getMusicInfo()
  34. // 判断活动状态的活动时间
  35. this.checkActivityTime()
  36. },
  37. methods: {
  38. async getMusicInfo() {
  39. try {
  40. // 获取活动基本信息
  41. const res = await request.post(
  42. '/api-teacher/open/activity/info/' + this.id
  43. )
  44. this.activeInfo = res.data
  45. document.title = this.activeInfo.activityName
  46. // 设置连接
  47. this.shareUrl = `${location.origin}/student/#/track-review-activity?recomUserId=${state.user.data?.userId}&id=${this.activeInfo.id}`
  48. } catch {
  49. //
  50. }
  51. },
  52. checkActivityTime() {
  53. // 判断活动状态的活动时间
  54. try {
  55. const activeInfo = this.activeInfo
  56. if (activeInfo.activityState !== 1) {
  57. Dialog.alert({
  58. message: '活动已结束,感谢你的关注!',
  59. theme: 'round-button',
  60. confirmButtonColor: '#2dc7aa'
  61. })
  62. this.onBackDialog('活动已结束,感谢你的关注!')
  63. return false
  64. }
  65. const nowTime = dayjs()
  66. const startTime = dayjs(activeInfo.activityStart)
  67. const endTime = dayjs(activeInfo.activityEnd)
  68. if (dayjs(nowTime).isBefore(dayjs(startTime))) {
  69. this.onBackDialog('活动尚未开始,请您耐心等待!')
  70. return false
  71. } else if (!dayjs(nowTime).isBefore(dayjs(endTime))) {
  72. this.onBackDialog('活动已结束,感谢你的关注!')
  73. return false
  74. }
  75. return true
  76. } catch {
  77. //
  78. }
  79. },
  80. onBackDialog(str: string) {
  81. Dialog.alert({
  82. message: str,
  83. theme: 'round-button',
  84. confirmButtonColor: '#2dc7aa'
  85. }).then(() => {
  86. postMessage({ api: 'back' })
  87. })
  88. }
  89. },
  90. render() {
  91. return (
  92. <div
  93. class={styles.review}
  94. style={{
  95. background: `url(${this.activeInfo.subjectUrl}) no-repeat top center ${this.activeInfo.backgroundUrl}`,
  96. backgroundSize: 'contain'
  97. }}
  98. >
  99. <div class={styles.reviewContainer}>
  100. <div class={[styles.section, styles.activeTime]}>
  101. <div class={styles.activeBg}>
  102. <img src={getAssetsHomeFile('icon_time.png')} />
  103. <p>
  104. <span>活动时间:</span>
  105. {dayjs(this.activeInfo.activityStart).format(
  106. 'YYYY-MM-DD'
  107. )} ~ {dayjs(this.activeInfo.activityEnd).format('YYYY-MM-DD')}
  108. </p>
  109. </div>
  110. </div>
  111. <div class={[styles.section]}>
  112. <div class={styles.title}>
  113. <img src={getAssetsHomeFile('icon_arrow_left.png')} />
  114. <span>活动介绍</span>
  115. <img src={getAssetsHomeFile('icon_arrow_right.png')} />
  116. </div>
  117. <div class={styles.tips}>{this.activeInfo.describe}</div>
  118. </div>
  119. <div class={[styles.section]}>
  120. <h2 class={styles.title2}>
  121. <span>
  122. <i class={styles.titlePrefix}></i>
  123. 活动奖品
  124. </span>
  125. <img
  126. src={getAssetsHomeFile('star_bg.png')}
  127. class={styles.iconStar}
  128. />
  129. </h2>
  130. {this.activeInfo.activityRewardList &&
  131. this.activeInfo.activityRewardList.map((item: any) => (
  132. <div class={styles.prize}>
  133. <Image src={item.imgUrl} />
  134. <div class={styles.prizeContainer}>
  135. <div class={styles.prizeName}>{item.rewardName}</div>
  136. <div class={styles.prizeDesc}>{item.rewardDescribe}</div>
  137. </div>
  138. </div>
  139. ))}
  140. </div>
  141. <div class={[styles.section]} style={{ backgroundColor: '#fff' }}>
  142. <h2 class={styles.title2}>
  143. <span>
  144. <i class={styles.titlePrefix}></i>
  145. 活动曲目
  146. </span>
  147. <span class={styles.titleTips} onClick={() => this.$router.push({path: '/leaderboard', query:{id: this.id}})}>
  148. 查看挑战排行榜
  149. <img style={{width: '16px', marginLeft: '4px'}} src={getAssetsHomeFile('icon-lv.png')} />
  150. {/* 共{this.activityMusic.length || 0}
  151. 首曲目 */}
  152. </span>
  153. </h2>
  154. {this.activityMusic.map((item: any) => (
  155. <CellGroup class={styles.musicItem} border={false}>
  156. <Cell
  157. center
  158. titleClass={styles.musicTitle}
  159. v-slots={{
  160. icon: () => (
  161. <Image
  162. src={getAssetsHomeFile('icon_music.png')}
  163. class={styles.iconMusic}
  164. />
  165. ),
  166. title: () => (
  167. <span class={styles.musicName}>
  168. {item.musicSheetName}
  169. </span>
  170. ),
  171. value: () => <span>{item.musicSubject}</span>
  172. }}
  173. />
  174. <Cell
  175. center
  176. class={styles.cellLevel}
  177. v-slots={{
  178. icon: () => (
  179. <div class={styles.kingSection}>
  180. <Image
  181. src={getAssetsHomeFile('icon_king.png')}
  182. class={styles.iconKing}
  183. />
  184. <p class={styles.score}>
  185. {item.userId ? item.score : '--'}
  186. <span>分</span>
  187. </p>
  188. </div>
  189. ),
  190. title: () => (
  191. <div class={styles.users}>
  192. <div class={styles.userInfo}>
  193. <div class={styles.userImg}>
  194. {item.userId ? (
  195. <>
  196. <Image
  197. src={item.userAvatar}
  198. class={styles.userLogo}
  199. fit="cover"
  200. />
  201. <img
  202. src={getAssetsHomeFile('icon_level.png')}
  203. class={styles.iconLevel}
  204. />
  205. </>
  206. ) : (
  207. <div class={styles.userLogo}>
  208. <img
  209. class={styles.img}
  210. src={getAssetsHomeFile('icon_no_level.png')}
  211. />
  212. </div>
  213. )}
  214. </div>
  215. <div class={styles.userName}>
  216. {item.userId ? (
  217. <>
  218. <p class={styles.name}>{item.username}</p>
  219. <p>
  220. <span class={styles.subjectName}>
  221. {item.userSubject}
  222. </span>
  223. </p>{' '}
  224. </>
  225. ) : (
  226. <span class={styles.noText}>虚位以待</span>
  227. )}
  228. </div>
  229. </div>
  230. <div class={styles.userBtn}>
  231. <Button
  232. round
  233. style={{
  234. padding: '0 8px',
  235. height: '32px'
  236. }}
  237. color="linear-gradient(180deg, #FFA200 0%, #FF6900 100%)"
  238. disabled={
  239. // this.activeInfo.join === 0 ||
  240. // (this.userSelectMusic && item.join !== 1)
  241. true
  242. }
  243. >
  244. 立刻挑战
  245. </Button>
  246. </div>
  247. </div>
  248. )
  249. }}
  250. ></Cell>
  251. </CellGroup>
  252. ))}
  253. </div>
  254. <div class={[styles.section]}>
  255. <div class={styles.title}>
  256. <img src={getAssetsHomeFile('icon_arrow_left.png')} />
  257. <span>活动规则</span>
  258. <img src={getAssetsHomeFile('icon_arrow_right.png')} />
  259. </div>
  260. <div class={styles.tips}>{this.activeInfo.ruleDescribe}</div>
  261. </div>
  262. </div>
  263. <ColSticky position="bottom">
  264. <div class={styles.btnGroup}>
  265. <Button
  266. round
  267. class={styles.submit}
  268. block
  269. onClick={() => {
  270. if (!this.checkActivityTime()) {
  271. return
  272. }
  273. this.shareStatus = true
  274. }}
  275. >
  276. 立即分享
  277. </Button>
  278. </div>
  279. </ColSticky>
  280. <Popup
  281. v-model:show={this.shareStatus}
  282. style={{ background: 'transparent' }}
  283. >
  284. <ShareModel shareUrl={this.shareUrl} activeInfo={this.activeInfo} />
  285. </Popup>
  286. </div>
  287. )
  288. }
  289. })