index.tsx 5.8 KB

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