|
@@ -3,109 +3,121 @@ import state, { handleSelection, skipNotePlay } from "/src/state";
|
|
|
import styles from "./index.module.less";
|
|
|
import { metronomeData } from "/src/helpers/metronome";
|
|
|
import { evaluatingData } from "../evaluating";
|
|
|
-import { getLeveByScoreMeasure, leveByScoreMeasureIcons } from "../evaluating/evaluatResult";
|
|
|
+import { leveByScoreMeasureIcons } from "../evaluating/evaluatResult";
|
|
|
import { Icon } from "vant";
|
|
|
|
|
|
-export default defineComponent({
|
|
|
- name: "selection",
|
|
|
- setup() {
|
|
|
- const selectData = reactive({
|
|
|
- notes: [] as any[],
|
|
|
- staves: [] as any[],
|
|
|
- });
|
|
|
- const calcNoteData = () => {
|
|
|
- const musicContainer = document.getElementById("musicAndSelection")?.getBoundingClientRect() || { x: 0, y: 0 };
|
|
|
- const parentLeft = musicContainer.x || 0;
|
|
|
- const parentTop = musicContainer.y || 0;
|
|
|
- const notes = state.times;
|
|
|
- const notesList: string[] = [];
|
|
|
- const MeasureNumberXMLList: number[] = [];
|
|
|
- for (let i = 0; i < notes.length; i++) {
|
|
|
- const item = notes[i];
|
|
|
- // console.log("🚀 ~ item:", item)
|
|
|
- const noteItem = {
|
|
|
- ...item,
|
|
|
- index: item.i,
|
|
|
- bbox: null as any,
|
|
|
- staveBox: null as any,
|
|
|
- };
|
|
|
- if (!notesList.includes(item.noteId)) {
|
|
|
- let staveBbox: any = {};
|
|
|
- if (item.stave?.attrs?.id) {
|
|
|
- const staveEle = document.querySelector(`#${item.stave.attrs.id}`);
|
|
|
- staveBbox = staveEle?.parentElement?.parentElement?.getBoundingClientRect?.() || { x: 0, width: 0 };
|
|
|
- // console.log("🚀 ~ staveBbox:", staveBbox)
|
|
|
- }
|
|
|
- if (item.svgElement) {
|
|
|
- const noteEle = document.querySelector(`#vf-${item.svgElement?.attrs?.id}`);
|
|
|
+const selectData = reactive({
|
|
|
+ notes: [] as any[],
|
|
|
+ staves: [] as any[],
|
|
|
+});
|
|
|
|
|
|
- if (noteEle) {
|
|
|
- const noteBbox = noteEle.getBoundingClientRect?.() || { x: 0, width: 0 };
|
|
|
- noteItem.bbox = {
|
|
|
- left: noteBbox.x - parentLeft - noteBbox.width / 4 + "px",
|
|
|
- top: staveBbox.y - parentTop + "px",
|
|
|
- width: noteBbox.width * 1.5 + "px",
|
|
|
- height: staveBbox.height + "px",
|
|
|
- };
|
|
|
- }
|
|
|
- selectData.notes.push(noteItem);
|
|
|
- notesList.push(item.noteId);
|
|
|
- }
|
|
|
- }
|
|
|
+/** 计算点击层数据 */
|
|
|
+const calcNoteData = () => {
|
|
|
+ const musicContainer = document.getElementById("musicAndSelection")?.getBoundingClientRect() || { x: 0, y: 0 };
|
|
|
+ console.log("🚀 ~ musicContainer:", musicContainer)
|
|
|
+ console.dir(document.getElementById("musicAndSelection"))
|
|
|
+ const parentLeft = musicContainer.x || 0;
|
|
|
+ const parentTop = musicContainer.y || 0;
|
|
|
+ const notes = state.times;
|
|
|
+ const notesList: string[] = [];
|
|
|
+ const MeasureNumberXMLList: number[] = [];
|
|
|
+ for (let i = 0; i < notes.length; i++) {
|
|
|
+ const item = notes[i];
|
|
|
+ // console.log("🚀 ~ item:", item)
|
|
|
+ const noteItem = {
|
|
|
+ ...item,
|
|
|
+ index: item.i,
|
|
|
+ bbox: null as any,
|
|
|
+ staveBox: null as any,
|
|
|
+ };
|
|
|
+ if (!notesList.includes(item.noteId)) {
|
|
|
+ let staveBbox: any = {};
|
|
|
+ if (item.stave?.attrs?.id) {
|
|
|
+ const staveEle = document.querySelector(`#${item.stave.attrs.id}`);
|
|
|
+ staveBbox = staveEle?.parentElement?.parentElement?.getBoundingClientRect?.() || { x: 0, width: 0 };
|
|
|
+ // console.log("🚀 ~ staveBbox:", staveBbox)
|
|
|
+ }
|
|
|
+ if (item.svgElement) {
|
|
|
+ const noteEle = document.querySelector(`#vf-${item.svgElement?.attrs?.id}`);
|
|
|
|
|
|
- if (!MeasureNumberXMLList.includes(item.MeasureNumberXML)) {
|
|
|
- if (item.stave) {
|
|
|
- if (item.stave?.attrs?.id) {
|
|
|
- const staveEle = document.querySelector(`#${item.stave.attrs.id}`);
|
|
|
- const list = [Array.from(staveEle?.querySelectorAll(".vf-clef") || []), Array.from(staveEle?.querySelectorAll(".vf-keysignature") || [])].flat();
|
|
|
- try {
|
|
|
- if (list.length) {
|
|
|
- // console.log("🚀 ~ list:", list)
|
|
|
- list.forEach((_el: any) => {
|
|
|
- _el?.style?.setProperty("display", "none");
|
|
|
- });
|
|
|
- }
|
|
|
- } catch (error) {}
|
|
|
+ if (noteEle) {
|
|
|
+ const noteBbox = noteEle.getBoundingClientRect?.() || { x: 0, width: 0 };
|
|
|
+ noteItem.bbox = {
|
|
|
+ left: noteBbox.x - parentLeft - noteBbox.width / 4 + "px",
|
|
|
+ top: staveBbox.y - parentTop + "px",
|
|
|
+ width: noteBbox.width * 1.5 + "px",
|
|
|
+ height: staveBbox.height + "px",
|
|
|
+ };
|
|
|
+ }
|
|
|
+ selectData.notes.push(noteItem);
|
|
|
+ notesList.push(item.noteId);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- const staveBbox = staveEle?.getBoundingClientRect?.() || { x: 0, width: 0, y: 0, height: 0 };
|
|
|
- try {
|
|
|
- if (list.length) {
|
|
|
- list.forEach((_el: any) => {
|
|
|
- _el?.style?.removeProperty("display");
|
|
|
- });
|
|
|
- }
|
|
|
- } catch (error) {}
|
|
|
+ if (!MeasureNumberXMLList.includes(item.MeasureNumberXML)) {
|
|
|
+ if (item.stave) {
|
|
|
+ if (item.stave?.attrs?.id) {
|
|
|
+ const staveEle = document.querySelector(`#${item.stave.attrs.id}`);
|
|
|
+ const list = [Array.from(staveEle?.querySelectorAll(".vf-clef") || []), Array.from(staveEle?.querySelectorAll(".vf-keysignature") || [])].flat();
|
|
|
+ try {
|
|
|
+ if (list.length) {
|
|
|
+ // console.log("🚀 ~ list:", list)
|
|
|
+ list.forEach((_el: any) => {
|
|
|
+ _el?.style?.setProperty("display", "none");
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (error) {}
|
|
|
|
|
|
- // console.log("🚀 ~ staveEle:", staveEle)
|
|
|
- noteItem.staveBox = {
|
|
|
- left: staveBbox.x - parentLeft + "px",
|
|
|
- // top: ((item.stave.y || 0) - 5) * state.zoom + "px",
|
|
|
- top: staveBbox.y - parentTop + "px",
|
|
|
- width: staveBbox.width + "px",
|
|
|
- height: staveBbox.height + "px",
|
|
|
- // background: 'rgba(0,0,0,.2)'
|
|
|
- };
|
|
|
- selectData.staves.push(noteItem);
|
|
|
+ const staveBbox = staveEle?.getBoundingClientRect?.() || { x: 0, width: 0, y: 0, height: 0 };
|
|
|
+ try {
|
|
|
+ if (list.length) {
|
|
|
+ list.forEach((_el: any) => {
|
|
|
+ _el?.style?.removeProperty("display");
|
|
|
+ });
|
|
|
}
|
|
|
+ } catch (error) {}
|
|
|
+
|
|
|
+ // console.log("🚀 ~ staveEle:", staveEle)
|
|
|
+ noteItem.staveBox = {
|
|
|
+ left: staveBbox.x - parentLeft + "px",
|
|
|
+ // top: ((item.stave.y || 0) - 5) * state.zoom + "px",
|
|
|
+ top: staveBbox.y - parentTop + "px",
|
|
|
+ width: staveBbox.width + "px",
|
|
|
+ height: staveBbox.height + "px",
|
|
|
+ // background: 'rgba(0,0,0,.2)'
|
|
|
+ };
|
|
|
+ selectData.staves.push(noteItem);
|
|
|
+ }
|
|
|
+ MeasureNumberXMLList.push(item.MeasureNumberXML);
|
|
|
+ } else {
|
|
|
+ if (item.multipleRestMeasures) {
|
|
|
+ const preItem = selectData.staves.find((n: any) => n.MeasureNumberXML === item.MeasureNumberXML - 1);
|
|
|
+ if (preItem?.staveBox) {
|
|
|
+ noteItem.staveBox = {
|
|
|
+ left: preItem.staveBox.left,
|
|
|
+ top: preItem.staveBox.top,
|
|
|
+ width: preItem.staveBox.width,
|
|
|
+ };
|
|
|
+ selectData.staves.push(noteItem);
|
|
|
MeasureNumberXMLList.push(item.MeasureNumberXML);
|
|
|
- } else {
|
|
|
- if (item.multipleRestMeasures) {
|
|
|
- const preItem = selectData.staves.find((n: any) => n.MeasureNumberXML === item.MeasureNumberXML - 1);
|
|
|
- if (preItem?.staveBox) {
|
|
|
- noteItem.staveBox = {
|
|
|
- left: preItem.staveBox.left,
|
|
|
- top: preItem.staveBox.top,
|
|
|
- width: preItem.staveBox.width,
|
|
|
- };
|
|
|
- selectData.staves.push(noteItem);
|
|
|
- MeasureNumberXMLList.push(item.MeasureNumberXML);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // console.log("🚀 ~ selectData.notes:", selectData.staves);
|
|
|
- };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // console.log("🚀 ~ selectData.notes:", selectData.staves);
|
|
|
+};
|
|
|
+
|
|
|
+/** 重新计算 */
|
|
|
+export const recalculateNoteData = () => {
|
|
|
+ selectData.notes = []
|
|
|
+ selectData.staves = []
|
|
|
+ calcNoteData()
|
|
|
+}
|
|
|
+
|
|
|
+export default defineComponent({
|
|
|
+ name: "selection",
|
|
|
+ setup() {
|
|
|
/** 是否可以点击音符 */
|
|
|
const disableClickNote = computed(() => {
|
|
|
return state.sectionStatus || state.modeType !== "practise";
|