Parcourir la source

添加去练习的防抖

lex il y a 1 an
Parent
commit
a54eb7bed8
2 fichiers modifiés avec 31 ajouts et 26 suppressions
  1. 17 15
      src/tenant/music/music-detail/new-index.tsx
  2. 14 11
      src/views/music/music-detail/index.tsx

+ 17 - 15
src/tenant/music/music-detail/new-index.tsx

@@ -1,6 +1,6 @@
 import TheSticky from '@/components/the-sticky'
 import styles from './new-index.module.less'
-import { useEventListener, useWindowScroll } from '@vueuse/core'
+import { useEventListener, useThrottleFn, useWindowScroll } from '@vueuse/core'
 import { postMessage } from '@/helpers/native-message'
 import iconShare from '../../images/icon-share.png'
 import oStart from '../album-detail/icon-hart.png'
@@ -888,20 +888,22 @@ export default defineComponent({
                     type="primary"
                     color="linear-gradient(270deg, #FF3C81 0%, #FF76A6 100%)"
                     onClick={() => {
-                      player.value && player.value.stop()
-                      const item: any = partColumns.value.find(
-                        (c: any) => c.value === staffData.partIndex
-                      )
-                      const index = staffData.tempPartList.findIndex(
-                        (i: any) => i.track === item?.track
-                      )
-                      musicBuy(musicDetail.value, () => {}, {
-                        'part-index': index || 0,
-                        sett: staff.radio,
-                        // 1:忽略系统节拍器
-                        ignoreSysMetronome:
-                          route.query.subjectType === 'MUSIC' ? 1 : 0
-                      })
+                      useThrottleFn(() => {
+                        player.value && player.value.stop()
+                        const item: any = partColumns.value.find(
+                          (c: any) => c.value === staffData.partIndex
+                        )
+                        const index = staffData.tempPartList.findIndex(
+                          (i: any) => i.track === item?.track
+                        )
+                        musicBuy(musicDetail.value, () => {}, {
+                          'part-index': index || 0,
+                          sett: staff.radio,
+                          // 1:忽略系统节拍器
+                          ignoreSysMetronome:
+                            route.query.subjectType === 'MUSIC' ? 1 : 0
+                        })
+                      }, 500)
                     }}
                   >
                     立即练习

+ 14 - 11
src/views/music/music-detail/index.tsx

@@ -66,6 +66,7 @@ import Download from './download'
 import { getInstrumentName } from '@/constant/instruments'
 import { getUploadSign, onOnlyFileUpload } from '@/helpers/oss-file-upload'
 import { svgtopng } from '@/tenant/music/music-detail/formatSvgToImg'
+import { useThrottleFn } from '@vueuse/core'
 
 export const getAssetsHomeFile = (fileName: string) => {
   const path = `../component/images/${fileName}`
@@ -992,17 +993,19 @@ export default defineComponent({
                     type="primary"
                     color="linear-gradient(180deg, #59E5D5 0%, #2DC7AA 100%)"
                     onClick={() => {
-                      player.value && player.value.stop()
-                      const item: any = partColumns.value.find(
-                        (c: any) => c.value === staffData.partIndex
-                      )
-                      const index = staffData.tempPartList.findIndex(
-                        (i: any) => i.track === item?.track
-                      )
-                      musicBuy(musicDetail.value, () => {}, {
-                        'part-index': index || 0,
-                        sett: staff.radio
-                      })
+                      useThrottleFn(() => {
+                        player.value && player.value.stop()
+                        const item: any = partColumns.value.find(
+                          (c: any) => c.value === staffData.partIndex
+                        )
+                        const index = staffData.tempPartList.findIndex(
+                          (i: any) => i.track === item?.track
+                        )
+                        musicBuy(musicDetail.value, () => {}, {
+                          'part-index': index || 0,
+                          sett: staff.radio
+                        })
+                      }, 500)
                     }}
                   >
                     立即练习