index.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { defineComponent, reactive, ref, watch } from "vue";
  2. import { Popover, Icon } from "vant";
  3. import icons from "../icons/index.json";
  4. import iconChild from "./icons/child.png";
  5. import DotIcon from "./icons/dot.png";
  6. import DotActiveIcon from "./icons/dot-active.png";
  7. import DotErrorIcon from "./icons/dot-error.png";
  8. import styles from "./index.module.less";
  9. import state from "/src/state";
  10. import { evaluatingData } from "/src/view/evaluating";
  11. import { getScoreData } from "./data";
  12. export default defineComponent({
  13. name: "sound-effect",
  14. emits: ["close"],
  15. setup(props, { emit }) {
  16. const scoreData = getScoreData(state.subjectId);
  17. const soundEffectData = reactive({
  18. step: 0,
  19. tips: ["左边红灯表示吹奏的音过低", "吹奏时请保持中间绿灯亮起", "右边红灯表示吹奏的音过高"],
  20. time: 1,
  21. });
  22. watch(
  23. () => evaluatingData.soundEffectFrequency,
  24. () => {
  25. // console.log('吹奏',evaluatingData.soundEffectFrequency , scoreData.frequency)
  26. const trend =
  27. Math.abs(evaluatingData.soundEffectFrequency - scoreData.frequency) <= 10 ? 1 : evaluatingData.soundEffectFrequency > scoreData.frequency ? 2 : 0;
  28. soundEffectData.step = trend;
  29. if (trend !== 1) {
  30. soundEffectData.time = Date.now();
  31. }
  32. // 持续时间达到3秒钟,效音成功
  33. if (Date.now() - soundEffectData.time > 3000) {
  34. // console.log("效音完成");
  35. emit('close')
  36. }
  37. }
  38. );
  39. /** 跳过本次 */
  40. const handleSelect = (e: {text: string}) => {
  41. if (e.text === '关闭校音'){
  42. emit('close', true)
  43. return
  44. }
  45. emit('close')
  46. };
  47. return () => (
  48. <div class={styles["sound-effect"]}>
  49. <div class={styles.top}>
  50. <div class={styles.back} onClick={() => emit('close')}>
  51. <img src={icons["arrow-left-background"]} />
  52. </div>
  53. <Popover trigger="click" class={styles.skibtns} actions={[{ text: "跳过本次" }, { text: "关闭校音" }]} onSelect={handleSelect}>
  54. {{
  55. reference: () => (
  56. <div class={styles.rightSkipBtn}>
  57. <span>跳过本次</span>
  58. <Icon name="play" color="var(--van-primary-color)" class={styles.tran}/>
  59. </div>
  60. ),
  61. }}
  62. </Popover>
  63. </div>
  64. <div class={styles.content}>
  65. <div class={styles.heiban}>
  66. <img class={styles.iconChild} src={iconChild} />
  67. <div class={styles.scoreContent}>
  68. <img src={scoreData.src} />
  69. </div>
  70. <div class={styles.tips}>{soundEffectData.tips[soundEffectData.step]}</div>
  71. <div class={styles.steps}>
  72. <img src={soundEffectData.step === 0 ? DotErrorIcon : DotIcon} />
  73. <img src={soundEffectData.step === 1 ? DotActiveIcon : DotIcon} />
  74. <img src={soundEffectData.step === 2 ? DotErrorIcon : DotIcon} />
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. );
  80. },
  81. });