student-bottom.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import { Button, Popup } from "vant";
  2. import {} from "vant";
  3. import { defineComponent, nextTick, onMounted, reactive, ref, watch } from "vue";
  4. import styles from "./index.module.less";
  5. import { getImage } from "./images";
  6. import { getQuery } from "/src/utils/queryString";
  7. export default defineComponent({
  8. name: "studentB-guide",
  9. emits: ["close"],
  10. setup(props, { emit }) {
  11. const data = reactive({
  12. box: {},
  13. show: false,
  14. steps: [
  15. {
  16. ele: "",
  17. eleRect: {} as DOMRect,
  18. img: getImage("studentB1.png"),
  19. handStyle: {
  20. top: "-1.41rem",
  21. left: "1.4rem",
  22. transform: "rotate(180deg)",
  23. },
  24. imgStyle: {
  25. top: "-5.01rem",
  26. width: "6.48rem",
  27. height: "3.01rem",
  28. left: "1.2rem",
  29. },
  30. btnsStyle: {
  31. top: "-1.61rem",
  32. left: "3.2rem",
  33. },
  34. },
  35. {
  36. ele: "",
  37. img: getImage("studentB2.png"),
  38. handStyle: {
  39. top: "-1.39rem",
  40. left: "0.15rem",
  41. transform: "rotate(180deg)",
  42. },
  43. imgStyle: {
  44. top: "-5.01rem",
  45. width: "6.48rem",
  46. height: "3.01rem",
  47. },
  48. btnsStyle: {
  49. top: "-1.61rem",
  50. left: "1.3rem",
  51. },
  52. },
  53. {
  54. ele: "",
  55. img: getImage("studentB3.png"),
  56. handStyle: {
  57. top: "-1.39rem",
  58. left: "2.8rem",
  59. transform: "rotate(180deg)",
  60. },
  61. imgStyle: {
  62. top: "-4.5rem",
  63. width: "6.48rem",
  64. height: "3.01rem",
  65. left: "-2.9rem",
  66. },
  67. btnsStyle: {
  68. top: "-1.1rem",
  69. left: "-1.8rem",
  70. },
  71. },
  72. ],
  73. step: 0,
  74. });
  75. const tipShow = ref(false);
  76. const query: any = getQuery();
  77. const guideInfo = localStorage.getItem("guideInfo");
  78. if ((guideInfo && JSON.parse(guideInfo).studentB) || !query.showGuide) {
  79. tipShow.value = false;
  80. } else {
  81. tipShow.value = true;
  82. }
  83. const getStepELe = () => {
  84. console.log(`modeType${data.step}`);
  85. const ele: HTMLElement = document.getElementById(`modeType-${data.step}`)!;
  86. if (ele) {
  87. const eleRect = ele.getBoundingClientRect();
  88. data.box = {
  89. left: eleRect.x + "px",
  90. top: eleRect.y + "px",
  91. width: eleRect.width + "px",
  92. height: eleRect.height + "px",
  93. };
  94. }
  95. };
  96. onMounted(() => {
  97. getStepELe();
  98. });
  99. const handleNext = () => {
  100. if (data.step >= 2) {
  101. endGuide();
  102. return;
  103. }
  104. data.step = data.step + 1;
  105. getStepELe();
  106. };
  107. const endGuide = () => {
  108. let guideInfo = JSON.parse(localStorage.getItem("guideInfo") || "{}") || null;
  109. if (!guideInfo) {
  110. guideInfo = { studentB: true };
  111. } else {
  112. guideInfo.studentB = true;
  113. }
  114. localStorage.setItem("guideInfo", JSON.stringify(guideInfo));
  115. tipShow.value = false;
  116. // localStorage.setItem('endC')
  117. };
  118. return () => (
  119. <Popup
  120. teleport="body"
  121. overlay={false}
  122. closeOnClickOverlay={false}
  123. class={["popup-custom", styles.guidePopup]}
  124. v-model:show={tipShow.value}
  125. >
  126. <div class={styles.content} onClick={() => handleNext()}>
  127. <div
  128. class={styles.backBtn}
  129. onClick={(e: Event) => {
  130. e.stopPropagation();
  131. endGuide();
  132. }}
  133. >
  134. 跳过
  135. </div>
  136. <div class={styles.box} style={data.box} id={`modeType-${data.step}`}>
  137. {data.steps.map((item: any, index) => (
  138. <div
  139. onClick={(e: Event) => e.stopPropagation()}
  140. class={styles.item}
  141. style={{
  142. display: index === data.step ? "" : "none",
  143. left: `${item.eleRect?.left}px`,
  144. top: `${item.eleRect?.top}px`,
  145. }}
  146. >
  147. <img class={styles.img} style={item.imgStyle} src={item.img} />
  148. <img class={styles.iconHead} style={item.handStyle} src={getImage("indexDot.png")} />
  149. <div class={styles.btns} style={item.btnsStyle}>
  150. {data.step + 1 == data.steps.length ? (
  151. <>
  152. <div class={[styles.studentNext]} onClick={() => endGuide()}>
  153. 完成
  154. </div>
  155. <div
  156. class={[styles.nextBtn]}
  157. style={{ "border-color": "#fff" }}
  158. onClick={() => {
  159. data.step = 0;
  160. getStepELe();
  161. }}
  162. >
  163. 再看一遍
  164. </div>
  165. </>
  166. ) : (
  167. <Button class={styles.studentNext} round type="primary" onClick={() => handleNext()}>
  168. 下一步 ({data.step + 1}/{data.steps.length})
  169. </Button>
  170. )}
  171. </div>
  172. </div>
  173. ))}
  174. </div>
  175. </div>
  176. </Popup>
  177. );
  178. },
  179. });