index.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { computed, defineComponent, onMounted, reactive } from 'vue';
  2. import styles from './index.module.less';
  3. import { Button, showToast } from 'vant';
  4. import {
  5. barLineList,
  6. beatList,
  7. elementList,
  8. renderScore,
  9. setting,
  10. tempo4,
  11. tempo8
  12. } from '../setting';
  13. import { getImage } from '../images/music';
  14. import { hendleEndTick } from '../tick';
  15. import { hendleEndBeat } from '../beat-tick';
  16. import deepClone from '@/helpers/deep-clone';
  17. import { useRoute } from 'vue-router';
  18. export default defineComponent({
  19. emits: ['close'],
  20. name: 'setting-modal',
  21. setup(props, { emit }) {
  22. const route = useRoute();
  23. const state = reactive({
  24. win: route.query.win,
  25. element: 'jianpu' as 'jianpu' | 'staff', // 元素
  26. beat: '4-4' as '4-2' | '4-3' | '4-4' | '8-3' | '8-6', // 拍号
  27. barLine: '1' as '1' | '2' | '4', // 小节数
  28. tempo: ['1', '2', '3'] as any[] // 节奏形筛选
  29. });
  30. const tempoList = computed(() => {
  31. if (['4-2', '4-3', '4-4'].includes(state.beat)) {
  32. return tempo4;
  33. } else if (['8-3', '8-6'].includes(state.beat)) {
  34. return tempo8;
  35. }
  36. return tempo4;
  37. });
  38. const onChangeTempo = (item: any) => {
  39. const index = state.tempo.indexOf(item);
  40. if (index !== -1) {
  41. state.tempo.splice(index, 1);
  42. } else {
  43. state.tempo.push(item);
  44. }
  45. };
  46. const handleStop = () => {
  47. setting.playState = 'pause';
  48. if (setting.playType === 'beat') {
  49. hendleEndTick();
  50. } else {
  51. hendleEndBeat();
  52. }
  53. };
  54. const onSubmit = () => {
  55. if (state.tempo.length <= 0) {
  56. showToast('节奏型不能为空');
  57. return;
  58. }
  59. let status = false; // 是否有更改
  60. if (
  61. setting.element !== state.element ||
  62. setting.beat !== state.beat ||
  63. setting.barLine !== state.barLine ||
  64. setting.tempo.join(',') !== state.tempo.join(',')
  65. ) {
  66. status = true;
  67. }
  68. // 判断是否有数据变化
  69. handleStop();
  70. if (status) {
  71. setting.element = state.element;
  72. setting.beat = state.beat;
  73. setting.barLine = state.barLine;
  74. setting.tempo = state.tempo;
  75. renderScore();
  76. }
  77. emit('close');
  78. };
  79. return () => (
  80. <div
  81. class={[styles.settingContainer, state.win === 'pc' ? styles.pcS : '']}>
  82. <div class={styles.title}></div>
  83. <i
  84. class={styles.iconClose}
  85. onClick={() => {
  86. emit('close');
  87. setTimeout(() => {
  88. state.element = setting.element;
  89. state.beat = setting.beat;
  90. state.barLine = setting.barLine;
  91. state.tempo = setting.tempo;
  92. }, 300);
  93. }}></i>
  94. <div class={styles.settingContent}>
  95. <div class={styles.settingParams}>
  96. <div class={styles.parmaTitle}>元素</div>
  97. <div class={styles.paramContent}>
  98. {Object.keys(elementList).map((item: any) => (
  99. <Button
  100. round
  101. class={[styles.btn, state.element === item && styles.active]}
  102. onClick={() => {
  103. state.element = item;
  104. }}>
  105. {elementList[item]}
  106. </Button>
  107. ))}
  108. </div>
  109. <div class={styles.parmaTitle}>拍号</div>
  110. <div class={styles.paramContent}>
  111. {Object.keys(beatList).map((item: any) => (
  112. <Button
  113. round
  114. class={[styles.btn, state.beat === item && styles.active]}
  115. onClick={() => {
  116. state.beat = item;
  117. if (['4-2', '4-3', '4-4'].includes(state.beat)) {
  118. state.tempo = ['1', '2', '3'];
  119. } else if (['8-3', '8-6'].includes(state.beat)) {
  120. state.tempo = ['15', '16', '17'];
  121. }
  122. }}>
  123. {beatList[item]}
  124. </Button>
  125. ))}
  126. </div>
  127. <div class={styles.parmaTitle}>每页显示小节数量</div>
  128. <div class={styles.paramContent}>
  129. {Object.keys(barLineList).map((item: any) => (
  130. <Button
  131. round
  132. class={[styles.btn, state.barLine === item && styles.active]}
  133. onClick={() => {
  134. state.barLine = item;
  135. }}>
  136. {barLineList[item]}
  137. </Button>
  138. ))}
  139. </div>
  140. <div class={styles.parmaTitle}>节奏型筛选</div>
  141. <div class={[styles.paramContent, styles.tempo]}>
  142. {Object.keys(tempoList.value).map((item: any) => (
  143. <>
  144. <img
  145. onClick={() => onChangeTempo(item)}
  146. class={state.tempo.includes(item) && styles.active}
  147. src={getImage(
  148. (state.element === 'jianpu' ? 'j-' : 'f-') +
  149. tempoList.value[item]
  150. )}
  151. />
  152. </>
  153. ))}
  154. </div>
  155. </div>
  156. </div>
  157. <div class={styles.btnGroup}>
  158. <Button class={styles.btnSubmit} onClick={onSubmit}></Button>
  159. </div>
  160. </div>
  161. );
  162. }
  163. });