index.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { defineComponent, onMounted, ref } from "vue"
  2. import styles from "./index.module.less"
  3. import { audioData, changeCombineAudio } from "/src/view/audio-list"
  4. import openImg from "./imgs/open.png"
  5. import lockImg from "./imgs/lock.png"
  6. import state from "/src/state"
  7. export default defineComponent({
  8. name: "combineAudio",
  9. setup(props, { emit }) {
  10. const elementsData = ref<{ index: number; top: number; left: number }[]>([])
  11. onMounted(() => {
  12. const parent = document.querySelector("#osmdCanvasPage1")
  13. const elements = document.querySelectorAll("g[data-trackIdx]")
  14. const combineMusicsIndexs = Object.keys(audioData.combineMusics)
  15. elements.forEach(element => {
  16. const dataTrackIdx = element.getAttribute("data-trackIdx")
  17. // 当有 dataTrackIdx 并且有原音的时候 显示
  18. if (dataTrackIdx && combineMusicsIndexs.includes(dataTrackIdx)) {
  19. const elementRect = element.getBoundingClientRect()
  20. const height = elementRect.height
  21. let top = elementRect.top + height / 2 - 11
  22. let left = elementRect.left - 22 - 10
  23. elementsData.value.push({
  24. index: parseInt(dataTrackIdx),
  25. top: top,
  26. left: left
  27. })
  28. }
  29. })
  30. })
  31. return () => (
  32. <>
  33. <div class={[styles.combineAudio, state.playState === "play" && styles.play]}>
  34. {elementsData.value.map(item => {
  35. return (
  36. <img
  37. class={styles.combineAudioImg}
  38. onClick={() => {
  39. changeCombineAudio(item.index)
  40. }}
  41. style={{
  42. top: item.top + "px",
  43. left: item.left + "px"
  44. }}
  45. src={audioData.combineIndex === item.index ? openImg : lockImg}
  46. />
  47. )
  48. })}
  49. </div>
  50. </>
  51. )
  52. }
  53. })