index.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { defineComponent, onMounted, ref, computed } 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 musicContainerPos = document.getElementById("musicAndSelection")?.getBoundingClientRect() || {
  15. top: 0,
  16. left: 0
  17. }
  18. const combineMusicsIndexs = Object.keys(audioData.combineMusics)
  19. elements.forEach(element => {
  20. const dataTrackIdx = element.getAttribute("data-trackIdx")
  21. // 当有 dataTrackIdx 并且有原音的时候 显示
  22. if (dataTrackIdx && combineMusicsIndexs.includes(dataTrackIdx)) {
  23. const elementRect = element.getBoundingClientRect()
  24. const height = elementRect.height
  25. let top = elementRect.top + height / 2 - 11 - musicContainerPos.top
  26. let left = elementRect.left - 22 - 10 - musicContainerPos.left
  27. elementsData.value.push({
  28. index: parseInt(dataTrackIdx),
  29. top: top,
  30. left: left
  31. })
  32. }
  33. })
  34. })
  35. const combineZoom = computed(() => {
  36. let zoom = state.zoom
  37. if (zoom < 1) {
  38. zoom = 1
  39. } else if (zoom > 1.5) {
  40. zoom = 1.5
  41. }
  42. return zoom
  43. })
  44. return () => (
  45. <>
  46. <div class={[styles.combineAudio, state.playState === "play" && styles.play]}>
  47. {elementsData.value.map(item => {
  48. return (
  49. <img
  50. class={styles.combineAudioImg}
  51. onClick={() => {
  52. changeCombineAudio(item.index)
  53. }}
  54. style={{
  55. top: item.top + "px",
  56. left: item.left - (combineZoom.value - 1) * 22 + "px",
  57. "--combineZoom": combineZoom.value
  58. }}
  59. src={audioData.combineIndex === item.index ? openImg : lockImg}
  60. />
  61. )
  62. })}
  63. </div>
  64. </>
  65. )
  66. }
  67. })