finger-guide.tsx 3.6 KB

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