|
@@ -1,4 +1,4 @@
|
|
|
-import { computed, defineComponent, onBeforeMount, ref } from "vue"
|
|
|
+import { computed, defineComponent, onMounted, ref } from "vue"
|
|
|
import styles from "./index.module.less"
|
|
|
import state from "/src/state"
|
|
|
import { headTopData } from "/src/page-instrument/header-top"
|
|
@@ -27,12 +27,12 @@ export default defineComponent({
|
|
|
"1/32.": "6",
|
|
|
rest: "7"
|
|
|
}
|
|
|
- const rhythmData = ref<rhythmData[]>([])
|
|
|
+ const rhythmData = ref<rhythmData[][]>([])
|
|
|
const actRhythmData = computed<rhythmData[]>(() => {
|
|
|
- return rhythmData.value.slice(state.activeNoteIndex, state.activeNoteIndex + 7)
|
|
|
+ return rhythmData.value[Math.floor(state.activeNoteIndex / 6)]
|
|
|
})
|
|
|
function initRhythmData() {
|
|
|
- rhythmData.value = state.times.map(item => {
|
|
|
+ const rhythmArr = state.times.map(item => {
|
|
|
const noteElement = item.noteElement
|
|
|
const isDot = !!noteElement?.DotsXml
|
|
|
const denominator = noteElement?.typeLength?.denominator || 4
|
|
@@ -44,16 +44,54 @@ export default defineComponent({
|
|
|
rhythmImg: isRestFlag ? "rest" : `1/${denominator}${isDot ? "." : ""}`
|
|
|
}
|
|
|
})
|
|
|
+ rhythmData.value = splitArrayWithReduce(rhythmArr, 6)
|
|
|
+ }
|
|
|
+ function splitArrayWithReduce(arr: any[], chunkSize: number) {
|
|
|
+ return arr.reduce((result, item, index) => {
|
|
|
+ const chunkIndex = Math.floor(index / chunkSize)
|
|
|
+ if (!result[chunkIndex]) {
|
|
|
+ result[chunkIndex] = [] // 初始化一个新组
|
|
|
+ }
|
|
|
+ result[chunkIndex].push(item)
|
|
|
+ return result
|
|
|
+ }, [])
|
|
|
}
|
|
|
initRhythmData()
|
|
|
+ onMounted(() => {
|
|
|
+ // 横屏的时候 当宽度大于屏幕的时候缩小一点
|
|
|
+ if (headTopData.rhythmModeDirection !== "vertical") {
|
|
|
+ const element = document.querySelector(".rhythmBox-scale-element") as HTMLElement | null
|
|
|
+ if (element) {
|
|
|
+ const screenWidth = document.documentElement.clientWidth
|
|
|
+ const originalWidth = element.offsetWidth
|
|
|
+ // 保留一位小数
|
|
|
+ const scale = screenWidth < originalWidth ? Math.floor((screenWidth / originalWidth) * 10) / 10 : 1
|
|
|
+ element.style.transform = `translate(-50%, -50%) scale(${scale})`
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
return () => {
|
|
|
return (
|
|
|
<>
|
|
|
<div class={[styles.rhythm, headTopData.rhythmModeDirection === "vertical" && styles.vertical]}>
|
|
|
- <div class={styles.titImg}></div>
|
|
|
- <div class={styles.rhythmBox}>
|
|
|
- {actRhythmData.value.map(item => {
|
|
|
- return <div class={[styles.rhythmImg, styles[`rhythm${rhythmImgObj[item.rhythmImg]}`]]}></div>
|
|
|
+ {headTopData.rhythmModeDirection === "vertical" && <div class={styles.titImg}></div>}
|
|
|
+ <div class={[styles.rhythmBox, "rhythmBox-scale-element"]}>
|
|
|
+ {headTopData.rhythmModeDirection !== "vertical" && <div class={styles.titImg}></div>}
|
|
|
+ {headTopData.rhythmModeDirection === "vertical" && (
|
|
|
+ <div
|
|
|
+ class={[styles.rhythmImg, styles[`rhythm${rhythmImgObj[actRhythmData.value[state.activeNoteIndex % 6].rhythmImg]}`]]}
|
|
|
+ ></div>
|
|
|
+ )}
|
|
|
+ {actRhythmData.value.map((item, index) => {
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ class={[
|
|
|
+ styles.rhythmImg,
|
|
|
+ styles[`rhythm${rhythmImgObj[item.rhythmImg]}`],
|
|
|
+ state.activeNoteIndex % 6 === index && styles.active
|
|
|
+ ]}
|
|
|
+ ></div>
|
|
|
+ )
|
|
|
})}
|
|
|
</div>
|
|
|
</div>
|