Skip to content

Commit f3d7347

Browse files
committed
feat(editor): 添加和弦线显示选项及高度设置功能
- 在 SnOptions 组件中新增和弦线显示选项及和弦线高度设置功能,允许用户自定义和弦线的显示与高度。 - 更新 editorStore,增加 showChordLine 和 chordLineHeight 属性以支持新功能。 - 在 SNScore 类中调整计算逻辑,考虑和弦线高度的影响。 - 增强代码注释,符合jsdoc规范,提升可读性和维护性。
1 parent d4d65cb commit f3d7347

File tree

9 files changed

+59
-4
lines changed

9 files changed

+59
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"score": {
3+
"showChordLine": true,
4+
"chordLineHeight": 50
5+
}
6+
}

examples/src/App.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ const initSn = (container: HTMLDivElement) => {
191191
contextMenuX.value = event.detail.e.pageX + 20;
192192
contextMenuY.value = event.detail.e.pageY + 10;
193193
});
194-
sn.value?.loadData(editorStore.formData);
195194
};
196195
197196
onMounted(() => {

examples/src/components/PanelExample.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ import { defineEmits, ref, computed } from 'vue';
110110
import { examples } from './examples';
111111
import { Example } from '../model';
112112
113-
// 示例列表
114-
115113
const emits = defineEmits(['load-example']);
116114
117115
const handleClick = (example: Example) => {
118116
emits('load-example', example);
119117
};
120118
119+
handleClick(examples[0]);
120+
121121
// 筛选相关状态
122122
const filterName = ref('');
123123
const filterType = ref('');

examples/src/components/editor/SnOptions.vue

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,43 @@
222222
min="0"
223223
/>
224224
</div>
225+
<!-- 显示和弦线 -->
226+
<div class="input-group flex flex-col gap-2">
227+
<!--
228+
* @description 是否显示和弦线
229+
-->
230+
<label
231+
for="show-chord-line-input"
232+
class="font-medium text-[#333] whitespace-nowrap"
233+
>显示和弦线</label
234+
>
235+
<select
236+
id="show-chord-line-input"
237+
v-model="editorStore.snOptions.score!.showChordLine"
238+
class="flex-1 p-2 px-3 border border-[#ddd] rounded text-sm bg-white bg-opacity-80"
239+
>
240+
<option :value="true">开启</option>
241+
<option :value="false">关闭</option>
242+
</select>
243+
</div>
244+
<!-- 和弦线高度 -->
245+
<div class="input-group flex flex-col gap-2">
246+
<!--
247+
* @description 和弦线的高度
248+
-->
249+
<label
250+
for="chord-line-height-input"
251+
class="font-medium text-[#333] whitespace-nowrap"
252+
>和弦线高度</label
253+
>
254+
<input
255+
id="chord-line-height-input"
256+
type="number"
257+
v-model.number="editorStore.snOptions.score!.chordLineHeight"
258+
class="flex-1 p-2 px-3 border border-[#ddd] rounded text-sm bg-white bg-opacity-80"
259+
min="0"
260+
/>
261+
</div>
225262
</div>
226263
</div>
227264
</div>

examples/src/components/examples.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Example } from '../model';
44
export const examples: Example[] = [
55
{
66
name: '小星星',
7-
hasConf: false,
7+
hasConf: true,
88
type: SNDataType.TEMPLATE,
99
isFinished: true,
1010
},

examples/src/stores/editor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export const useEditorStore = defineStore('editor', () => {
4343
allowOverWeight: 40,
4444
chordType: SNChordType.Default,
4545
scoreType: SNScoreType.Simple,
46+
showChordLine: false,
47+
chordLineHeight: 0,
4648
},
4749
});
4850

@@ -130,6 +132,8 @@ export const useEditorStore = defineStore('editor', () => {
130132
allowOverWeight: 40,
131133
chordType: SNChordType.Default,
132134
scoreType: SNScoreType.Simple,
135+
showChordLine: false,
136+
chordLineHeight: 0,
133137
},
134138
};
135139
}

lib/src/components/score.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class SNScore extends SNBox {
9292
totalY +=
9393
SNConfig.score.chordHeight +
9494
SNConfig.score.lineHeight +
95+
(SNConfig.score.showChordLine ? SNConfig.score.chordLineHeight : 0) +
9596
SNConfig.score.lineSpace +
9697
(SNRuntime.lyric ? SNConfig.score.lyricHeight : 0);
9798
});

lib/src/config/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class SNConfig {
4242
allowOverWeight: 40,
4343
chordType: SNChordType.Default,
4444
scoreType: SNScoreType.Simple,
45+
showChordLine: false,
46+
chordLineHeight: 0,
4547
...options?.score,
4648
};
4749
SNConfig.debug = options?.debug ? DEBUG_OPTIONS : {};
@@ -89,6 +91,8 @@ export class SNConfig {
8991
allowOverWeight: 40,
9092
chordType: SNChordType.Default,
9193
scoreType: SNScoreType.Simple,
94+
showChordLine: false,
95+
chordLineHeight: 0,
9296
...options?.score,
9397
};
9498
SNConfig.debug = options?.debug ? DEBUG_OPTIONS : {};

lib/src/types/options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export interface SNContentOptions {
4949
* @property {number} allowOverWeight - 每行歌词允许的溢出权重。
5050
* @property {SNChordType} chordType - 和弦显示类型。
5151
* @property {SNScoreType} scoreType - 总谱显示类型。
52+
* @property {boolean} showChordLine - 是否显示和弦线。
53+
* @property {number} chordLineHeight - 和弦线高度。
5254
*/
5355
export interface SNScoreOptions {
5456
padding: number;
@@ -60,6 +62,8 @@ export interface SNScoreOptions {
6062
allowOverWeight: number;
6163
chordType: SNChordType;
6264
scoreType: SNScoreType;
65+
showChordLine: boolean;
66+
chordLineHeight: number;
6367
}
6468

6569
export enum SNChordType {

0 commit comments

Comments
 (0)