index.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { Cell, Icon, Swipe, SwipeItem } from 'vant'
  2. import styles from './index.module.less'
  3. import { defineComponent, onMounted, ref } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. import TheSong from '../TheSong'
  6. import TheTitle from '../the-title'
  7. import { openDefaultWebView } from '@/state'
  8. import item from '@/views/coupons/item'
  9. export default defineComponent({
  10. name: 'music-list',
  11. props: {
  12. title: {
  13. type: String,
  14. default: '最热曲目'
  15. },
  16. music: {
  17. type: Array,
  18. default: () => {
  19. return []
  20. }
  21. }
  22. },
  23. setup(props) {
  24. const router = useRouter()
  25. onMounted(() => {
  26. getWidth()
  27. })
  28. const swipeWidth = ref(312)
  29. const swipeShow = ref(false)
  30. const getWidth = () => {
  31. swipeShow.value = false
  32. const clientWidth =
  33. document.body.clientWidth > 750 ? 750 : document.body.clientWidth
  34. swipeWidth.value = clientWidth - 63
  35. swipeShow.value = true
  36. }
  37. return () => (
  38. <>
  39. {props.music.length > 0 && (
  40. <TheTitle
  41. title={props.title}
  42. onDetail={() => {
  43. const url = location.origin + location.pathname + '#/music-list'
  44. openDefaultWebView(url, () => {
  45. router.push('/music-list')
  46. })
  47. }}
  48. />
  49. )}
  50. <div class={styles.hotMusic}>
  51. {swipeShow.value && (
  52. <Swipe showIndicators={false} loop={false} width={swipeWidth.value}>
  53. {props.music.map((n: any) => (
  54. <SwipeItem class={styles.swipeItem}>
  55. <div class={styles.swipeChild}>
  56. <TheSong
  57. list={n}
  58. onDetail={(item: any) => {
  59. const url =
  60. location.origin +
  61. location.pathname +
  62. '#/music-detail?id=' +
  63. item.id
  64. openDefaultWebView(url, () => {
  65. router.push({
  66. path: '/music-detail',
  67. query: {
  68. id: item.id
  69. }
  70. })
  71. })
  72. }}
  73. />
  74. </div>
  75. </SwipeItem>
  76. ))}
  77. </Swipe>
  78. )}
  79. </div>
  80. </>
  81. )
  82. }
  83. })