|
@@ -1,4 +1,4 @@
|
|
|
-import { computed, defineComponent, nextTick, onBeforeMount, reactive, ref } from "vue";
|
|
|
+import { computed, defineComponent, onMounted, reactive, ref } from "vue";
|
|
|
import { formatXML, onlyVisible } from "../../helpers/formateMusic";
|
|
|
// // @ts-ignore
|
|
|
import { OpenSheetMusicDisplay } from "/osmd-extended/src";
|
|
@@ -14,20 +14,13 @@ const musicData = reactive({
|
|
|
showSelection: false, // 可以加载点击浮层
|
|
|
isRenderLoading: true,
|
|
|
score: "",
|
|
|
+ containerWidth: 0
|
|
|
});
|
|
|
|
|
|
/** 重新计算曲谱渲染比例 */
|
|
|
export const resetMusicScore = () => {
|
|
|
- const svgEL = document.querySelector("#osmdSvgPage1");
|
|
|
- const svgContainer = document.getElementById("osmdCanvasPage1");
|
|
|
- if (svgEL && svgContainer) {
|
|
|
- let width: any = svgEL?.getAttribute("width");
|
|
|
- width = isNaN(Number(width)) ? 0 : Number(width);
|
|
|
- if (width) {
|
|
|
- const zoom = svgContainer.offsetWidth / width;
|
|
|
- document.getElementById("musicAndSelection")?.style.setProperty("--music-zoom", zoom + "");
|
|
|
- }
|
|
|
- }
|
|
|
+ const contaienrWidth = document.getElementById('musicAndSelection')?.offsetWidth || 625
|
|
|
+ state.musicZoom = contaienrWidth / musicData.containerWidth
|
|
|
};
|
|
|
|
|
|
/** 重新渲染曲谱 */
|
|
@@ -59,7 +52,7 @@ export default defineComponent({
|
|
|
};
|
|
|
const init = async () => {
|
|
|
const container = document.getElementById("musicAndSelection");
|
|
|
- // console.log("🚀 ~ container:", container);
|
|
|
+ console.log("🚀 ~ container:", container);
|
|
|
if (!container || !musicData.score) return;
|
|
|
const osmd = new OpenSheetMusicDisplay(container, {
|
|
|
drawTitle: false,
|
|
@@ -94,7 +87,13 @@ export default defineComponent({
|
|
|
emit("rendered", osmd);
|
|
|
musicData.showSelection = true;
|
|
|
};
|
|
|
- onBeforeMount(async () => {
|
|
|
+ /** 获取渲染容器的宽度 */
|
|
|
+ const getContainerWidth = () => {
|
|
|
+ musicData.containerWidth = document.getElementById('musicAndSelection')?.offsetWidth || 625
|
|
|
+ // console.log(musicData.containerWidth)
|
|
|
+ }
|
|
|
+ onMounted(async () => {
|
|
|
+ getContainerWidth()
|
|
|
setRenderType();
|
|
|
await getXML();
|
|
|
await init();
|
|
@@ -115,7 +114,7 @@ export default defineComponent({
|
|
|
return result;
|
|
|
});
|
|
|
return () => (
|
|
|
- <div id="musicAndSelection" class={[isInTheGradualRange.value && styles.inGradualRange]}>
|
|
|
+ <div id="musicAndSelection" style={{"--music-zoom" : state.musicZoom}} class={[isInTheGradualRange.value && styles.inGradualRange]}>
|
|
|
{musicData.showSelection && <Selection />}
|
|
|
</div>
|
|
|
);
|