finger-guide.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { defineComponent, onMounted, reactive, ref } from "vue";
  2. import styles from "./index.module.less";
  3. import { Button, Icon, Popup } from "vant";
  4. import icons from "./image/icons.json";
  5. import state from "/src/state";
  6. import { getQuery } from "/src/utils/queryString";
  7. export default defineComponent({
  8. name: "DetailGuide",
  9. emits: ["close"],
  10. setup(props, { emit }) {
  11. const query = getQuery();
  12. const data = reactive({
  13. box: {},
  14. show: true,
  15. steps: [
  16. {
  17. className: "boxItem1",
  18. des: `快点击下排按钮听听${state.fingeringInfo.code}的声音吧,按钮可以滑动哦~`,
  19. img: icons.icon_cursor_1,
  20. },
  21. {
  22. className: "boxItem2",
  23. des: "这里可以切换音调,查看不同音调的指法~",
  24. img: icons.icon_cursor_2,
  25. },
  26. {
  27. className: "boxItem3",
  28. des: "可以通过手势放大缩小乐器哦~",
  29. img: icons.icon_cursor_3,
  30. },
  31. ],
  32. step: 0,
  33. });
  34. const steps = ["finger-note-0", "finger-note-1", "finger-note-2"];
  35. const getStepELe = () => {
  36. const ele: HTMLElement = document.getElementById(steps[data.step])!;
  37. console.log(data.step, ele);
  38. if (ele) {
  39. const eleRect = ele.getBoundingClientRect();
  40. const increment = data.step === 2 ? eleRect.width : 0;
  41. data.box = {
  42. left: eleRect.x - increment + "px",
  43. top: eleRect.y + "px",
  44. width: (data.step === 2 ? 0 : eleRect.width) + "px",
  45. height: (data.step === 2 ? 0 : eleRect.height) + "px",
  46. };
  47. } else {
  48. handleNext();
  49. }
  50. };
  51. onMounted(() => {
  52. getStepELe();
  53. });
  54. const handleNext = () => {
  55. if (data.step >= 2) {
  56. endGuide();
  57. return;
  58. }
  59. data.step = data.step + 1;
  60. getStepELe();
  61. };
  62. const endGuide = () => {
  63. emit("close", true);
  64. };
  65. return () => (
  66. <Popup
  67. teleport="body"
  68. overlay={false}
  69. closeOnClickOverlay={false}
  70. class={["popup-custom", styles.fingerGuide]}
  71. v-model:show={data.show}
  72. >
  73. <div class={styles.content} onClick={() => handleNext()}>
  74. <div class={styles.box} style={data.box}>
  75. {data.steps.map((item, index) => (
  76. <div style={{ display: index === data.step ? "" : "none" }} class={styles[item.className]}>
  77. <img src={item.img} />
  78. </div>
  79. ))}
  80. </div>
  81. <div onClick={(e: Event) => e.stopPropagation()}>
  82. {data.steps.map((item, index) => (
  83. <div style={{ display: index === data.step ? "" : "none" }} class={[styles.item, ['Woodwind', 'Tenor Recorder'].includes(query.code) && styles.itemScale]}>
  84. <div class={styles.title}>
  85. <img src={icons.guide_2} />
  86. <div class={styles.des} style={{fontSize: index === 2 ? '0.34667rem' : ''}}>
  87. {item.des}
  88. </div>
  89. </div>
  90. <div class={styles.icon}>
  91. <img src={icons.guide_1} />
  92. </div>
  93. <Button class={styles.btn} round type="primary" onClick={() => handleNext()}>
  94. 我知道了
  95. </Button>
  96. </div>
  97. ))}
  98. </div>
  99. </div>
  100. </Popup>
  101. );
  102. },
  103. });