index.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { computed, defineComponent, onMounted, reactive } from "vue";
  2. import state, { gotoCustomNote, skipNotePlay } from "/src/state";
  3. import styles from "./index.module.less";
  4. export default defineComponent({
  5. name: "selection",
  6. setup() {
  7. const selectData = reactive({
  8. notes: [] as any[],
  9. });
  10. const calcNoteData = () => {
  11. const musicContainer = document.getElementById("musicContainer")?.getBoundingClientRect() || { x: 0, y: 0 };
  12. const parentLeft = musicContainer.x || 0;
  13. const parentTop = musicContainer.y || 0;
  14. const notes = state.times;
  15. const notesList: string[] = []
  16. const MeasureNumberXMLList: number[] = [];
  17. for (let i = 0; i < notes.length; i++) {
  18. const item = notes[i];
  19. // console.log("🚀 ~ item:", item)
  20. const noteItem = {
  21. index: i,
  22. MeasureNumberXML: item.MeasureNumberXML,
  23. bbox: null as any,
  24. staveBox: null as any,
  25. };
  26. if (item.svgElement) {
  27. const noteEle = document.querySelector(`#vf-${item.svgElement?.attrs?.id}`);
  28. const noteEleBox = item.svgElement.getBoundingBox?.() || { h: 40 };
  29. // console.log("🚀 ~ noteEle:", noteEle, item.svgElement, noteEleBox.h)
  30. if (noteEle) {
  31. const noteBbox = noteEle.getBoundingClientRect?.() || { x: 0, width: 0 };
  32. noteItem.bbox = {
  33. left: noteBbox.x - parentLeft + "px",
  34. top: noteBbox.y - parentTop + "px",
  35. width: noteBbox.width + "px",
  36. height: noteEleBox.h * state.zoom + "px",
  37. };
  38. }
  39. }
  40. if (!MeasureNumberXMLList.includes(item.MeasureNumberXML)) {
  41. // console.log(item);
  42. if (item.stave) {
  43. if (item.stave?.attrs?.id) {
  44. const staveEle = document.querySelector(`#${item.stave.attrs.id}`);
  45. const staveBbox = staveEle?.getBoundingClientRect?.() || { x: 0, width: 0 };
  46. noteItem.staveBox = {
  47. left: staveBbox.x - parentLeft + "px",
  48. top: ((item.stave.y || 0) - 5) * state.zoom + "px",
  49. width: staveBbox.width + "px",
  50. height: 50 * state.zoom + "px",
  51. };
  52. }
  53. MeasureNumberXMLList.push(item.MeasureNumberXML);
  54. }
  55. }
  56. if (!notesList.includes(item.id)) {
  57. selectData.notes.push(noteItem);
  58. notesList.push(item.id)
  59. }
  60. }
  61. console.log("🚀 ~ selectData.notes:", selectData.notes);
  62. };
  63. const staveBoxList = computed(() => {
  64. return selectData.notes.filter((item) => item.staveBox);
  65. });
  66. onMounted(() => {
  67. calcNoteData();
  68. });
  69. return () => (
  70. <div class={styles.selectionContainer}>
  71. <button onClick={() => gotoCustomNote(4)}>next</button>
  72. <button onClick={() => state.osmd.cursor.next()}>next</button>
  73. {staveBoxList.value.map((item: any) => {
  74. // console.log(state.activeMeasureIndex , item.MeasureNumberXML, '')
  75. return (
  76. <>
  77. {/* <div class={styles.note} style={item.bbox}></div> */}
  78. {item.staveBox && <div class={[styles.position, state.activeMeasureIndex == item.MeasureNumberXML && styles.staveBox]} style={item.staveBox}></div>}
  79. </>
  80. );
  81. })}
  82. {selectData.notes.map((item: any) => {
  83. return <div class={[styles.position, styles.note]} style={item.bbox} onClick={() => skipNotePlay(item.index)}></div>;
  84. })}
  85. </div>
  86. );
  87. },
  88. });