|
@@ -1,6 +1,7 @@
|
|
|
-import { defineComponent, onMounted, Ref, ref, toRefs } from "vue";
|
|
|
+import { computed, defineComponent, onBeforeMount, onMounted, reactive, Ref, ref, toRefs } from "vue";
|
|
|
import styles from "./index.module.less";
|
|
|
import state from "/src/state";
|
|
|
+import { getFingeringConfig, ITypeFingering } from "./fingering-config";
|
|
|
|
|
|
export const getImageSize = (src: string): Promise<HTMLImageElement> => {
|
|
|
return new Promise((resolve, reject) => {
|
|
@@ -45,127 +46,46 @@ export const useFingeringSrc = (activeType: any, fingeringName: string, formatFi
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: "fingering",
|
|
|
- props: {
|
|
|
- type: {
|
|
|
- type: String,
|
|
|
- default: "",
|
|
|
- },
|
|
|
- fixedKey: {
|
|
|
- type: Number,
|
|
|
- default: 0,
|
|
|
- },
|
|
|
- fingeringInfo: {
|
|
|
- type: Object,
|
|
|
- },
|
|
|
- loaded: {
|
|
|
- type: Function,
|
|
|
- default: () => {},
|
|
|
- },
|
|
|
- viewInfo: {
|
|
|
- type: Object,
|
|
|
- },
|
|
|
- },
|
|
|
setup(props, { expose }) {
|
|
|
- const fingeringInfo = state.fingeringInfo;
|
|
|
- console.log("🚀 ~ fingeringInfo:", fingeringInfo)
|
|
|
- const refProps = toRefs(props);
|
|
|
- const container: Ref<HTMLDivElement | null> = ref(null);
|
|
|
- const imgRef: Ref<HTMLImageElement | null> = ref(null);
|
|
|
- const containerWidth = ref(0);
|
|
|
- const index = ref(0);
|
|
|
-
|
|
|
- // 横向具体指法样式
|
|
|
- const ItemImgStyleTransverse = {
|
|
|
- top: "50%",
|
|
|
- left: "50%",
|
|
|
- transform: "translate(-50%, -50%)",
|
|
|
- };
|
|
|
-
|
|
|
- // 竖向具体指法样式
|
|
|
- const ItemImgStyleVertical = {
|
|
|
- top: "50%",
|
|
|
- left: 0,
|
|
|
- // transform: 'translateY(-50%)',
|
|
|
+ const fingerData = reactive({
|
|
|
+ relationshipIndex: 0,
|
|
|
+ subject: null as unknown as ITypeFingering,
|
|
|
+ });
|
|
|
+ const getFingeringData = async () => {
|
|
|
+ fingerData.subject = await getFingeringConfig(state.fingeringInfo.name);
|
|
|
+ console.log("🚀 ~ fingerData.relationship:", fingerData.subject);
|
|
|
};
|
|
|
+ onBeforeMount(() => {
|
|
|
+ getFingeringData();
|
|
|
+ });
|
|
|
|
|
|
- expose({
|
|
|
- container,
|
|
|
- containerWidth,
|
|
|
+ /** 当前音域 */
|
|
|
+ const realKey = computed(() => {
|
|
|
+ return state.times[state.activeNoteIndex]?.realKey || -1;
|
|
|
});
|
|
|
|
|
|
return () => {
|
|
|
- if (!refProps.viewInfo.value?.activeType) return null;
|
|
|
- const usedFixedKey = formatFixedKey(props.fingeringInfo?.name, refProps.fixedKey.value).value;
|
|
|
- // console.log(refProps.fixedKey.value, usedFixedKey)
|
|
|
- const relationshipGroup = formatRelationship(refProps.viewInfo.value?.activeType?.relationship, usedFixedKey || 0);
|
|
|
-
|
|
|
- // console.log(imgRef.value?.width, imgRef.value?.offsetLeft, imgRef.value?.offsetTop)
|
|
|
-
|
|
|
- const changeIndex = () => {
|
|
|
- let nextIndex = index.value === relationshipGroup.length - 1 ? 0 : index.value + 1;
|
|
|
- index.value = nextIndex;
|
|
|
- };
|
|
|
-
|
|
|
- const rs = relationshipGroup[index.value] || [];
|
|
|
+ const relationship = fingerData.subject?.relationship?.[realKey.value] || [];
|
|
|
+ const rs: number[] = Array.isArray(relationship[1]) ? relationship[fingerData.relationshipIndex] : relationship;
|
|
|
+ const canTizhi = Array.isArray(relationship[1]);
|
|
|
return (
|
|
|
- <div
|
|
|
- ref={container}
|
|
|
- class={[props.fingeringInfo?.name, styles.container]}
|
|
|
- style={{
|
|
|
- width: props.fingeringInfo?.direction === "vertical" ? props.fingeringInfo?.width : "",
|
|
|
- height: "100%",
|
|
|
- display: "flex",
|
|
|
- paddingLeft: props.fingeringInfo?.direction === "vertical" ? props.fingeringInfo?.paddingLeft : "",
|
|
|
- paddingRight: props.fingeringInfo?.direction === "vertical" ? props.fingeringInfo?.paddingRight : "",
|
|
|
- }}
|
|
|
- >
|
|
|
- {rs.includes(0) ? (
|
|
|
- <span
|
|
|
- style={{
|
|
|
- position: "absolute",
|
|
|
- top: ".5vh",
|
|
|
- right: ".5vw",
|
|
|
- color: "rgb(1, 193, 181)",
|
|
|
- fontWeight: "bold",
|
|
|
- }}
|
|
|
- >
|
|
|
- 转调
|
|
|
- </span>
|
|
|
- ) : null}
|
|
|
- <img
|
|
|
- ref={imgRef}
|
|
|
- src={refProps.viewInfo.value?.fullsrc}
|
|
|
- style={{
|
|
|
- width: "auto",
|
|
|
- maxWidth: "100%",
|
|
|
- maxHeight: "100%",
|
|
|
- }}
|
|
|
- />
|
|
|
- {rs.map((key: number | string, index: number) => {
|
|
|
- const nk: string = typeof key === "string" ? key.replace("active-", "") : String(key);
|
|
|
- return (
|
|
|
- <img
|
|
|
- data-index={nk}
|
|
|
- style={{
|
|
|
- position: "absolute",
|
|
|
- top: imgRef.value?.offsetTop + "px",
|
|
|
- left: imgRef.value?.offsetLeft + "px",
|
|
|
- zIndex: index,
|
|
|
- height: imgRef.value?.height + "px",
|
|
|
- width: imgRef.value?.width + "px",
|
|
|
- maxWidth: "100%",
|
|
|
- maxHeight: "100%",
|
|
|
- }}
|
|
|
- src={refProps.viewInfo.value?.activeType?.json?.[nk]}
|
|
|
- />
|
|
|
- );
|
|
|
- })}
|
|
|
+ <div class={[styles.fingeringContainer]}>
|
|
|
+ <span class={[styles.yidiao, !rs.includes(0) && styles.canDisplay]}>转调</span>
|
|
|
+
|
|
|
+ <div class={styles.imgs}>
|
|
|
+ <img src={fingerData.subject?.json?.full} />
|
|
|
+ {rs.map((key: number | string, index: number) => {
|
|
|
+ const nk: string = typeof key === "string" ? key.replace("active-", "") : String(key);
|
|
|
+ return <img data-index={nk} src={fingerData.subject?.json?.[nk]} />;
|
|
|
+ })}
|
|
|
+ </div>
|
|
|
|
|
|
- {relationshipGroup.length > 1 ? (
|
|
|
- <div onClick={changeIndex} class={styles.changeIndex}>
|
|
|
- 替指
|
|
|
- </div>
|
|
|
- ) : null}
|
|
|
+ <div
|
|
|
+ class={[styles.tizhi, canTizhi && styles.canDisplay]}
|
|
|
+ onClick={() => (fingerData.relationshipIndex = fingerData.relationshipIndex === 0 ? 1 : 0)}
|
|
|
+ >
|
|
|
+ 替指
|
|
|
+ </div>
|
|
|
</div>
|
|
|
);
|
|
|
};
|