teacher-bootom.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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: "aiTeacher-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("aiTeacher1.png"),
  19. handStyle: {
  20. top: "0.91rem",
  21. },
  22. imgStyle: {
  23. top: "-3.01rem",
  24. width: "6.48rem",
  25. height: "3.01rem",
  26. left: "4.67rem",
  27. },
  28. btnsStyle: {
  29. top: "-1.61rem",
  30. left: "6rem",
  31. },
  32. },
  33. {
  34. ele: "",
  35. img: getImage("aiTeacher2.png"),
  36. handStyle: {
  37. top: "-1.39rem",
  38. left: "0.15rem",
  39. transform: "rotate(180deg)",
  40. },
  41. imgStyle: {
  42. top: "-3.01rem",
  43. width: "6.48rem",
  44. height: "3.01rem",
  45. },
  46. btnsStyle: {
  47. top: "-1.61rem",
  48. left: "1.3rem",
  49. },
  50. },
  51. {
  52. ele: "",
  53. img: getImage("aiTeacher3.png"),
  54. handStyle: {
  55. top: "-1.39rem",
  56. left: "0.17rem",
  57. transform: "rotate(180deg)",
  58. },
  59. imgStyle: {
  60. top: "-3.01rem",
  61. width: "6.48rem",
  62. height: "3.01rem",
  63. },
  64. btnsStyle: {
  65. top: "-1.61rem",
  66. left: "1.3rem",
  67. },
  68. },
  69. {
  70. ele: "",
  71. img: getImage("aiTeacher4.png"),
  72. handStyle: {
  73. top: "-1.39rem",
  74. left: "1.4rem",
  75. transform: "rotate(180deg)",
  76. },
  77. imgStyle: {
  78. top: "-3.01rem",
  79. width: "6.48rem",
  80. height: "3.01rem",
  81. },
  82. btnsStyle: {
  83. top: "-1.61rem",
  84. left: "0.8rem",
  85. "justify-content": "center",
  86. padding: 0,
  87. },
  88. },
  89. ],
  90. step: 0,
  91. });
  92. const tipShow = ref(false);
  93. const guideInfo = localStorage.getItem("guideInfo");
  94. const query: any = getQuery();
  95. if ((guideInfo && JSON.parse(guideInfo).teacherBottom) || !query.showGuide) {
  96. tipShow.value = false;
  97. } else {
  98. tipShow.value = true;
  99. }
  100. const getStepELe = () => {
  101. console.log(`modeType${data.step}`);
  102. const ele: HTMLElement = document.getElementById(`modeType-${data.step}`)!;
  103. if (ele) {
  104. const eleRect = ele.getBoundingClientRect();
  105. data.box = {
  106. left: eleRect.x + "px",
  107. top: eleRect.y + "px",
  108. width: eleRect.width + "px",
  109. height: eleRect.height + "px",
  110. };
  111. }
  112. };
  113. onMounted(() => {
  114. getStepELe();
  115. });
  116. const handleNext = () => {
  117. if (data.step >= 3) {
  118. endGuide();
  119. return;
  120. }
  121. data.step = data.step + 1;
  122. getStepELe();
  123. };
  124. const endGuide = () => {
  125. let guideInfo = JSON.parse(localStorage.getItem("guideInfo") || "{}") || null;
  126. if (!guideInfo) {
  127. guideInfo = { teacherBottom: true };
  128. } else {
  129. guideInfo.teacherBottom = true;
  130. }
  131. localStorage.setItem("guideInfo", JSON.stringify(guideInfo));
  132. tipShow.value = false;
  133. // localStorage.setItem('endC')
  134. };
  135. return () => (
  136. <Popup
  137. teleport="body"
  138. overlay={false}
  139. closeOnClickOverlay={false}
  140. class={["popup-custom", styles.guidePopup]}
  141. v-model:show={tipShow.value}
  142. >
  143. <div class={styles.content} onClick={() => handleNext()}>
  144. <div
  145. class={styles.backBtn}
  146. onClick={(e: Event) => {
  147. e.stopPropagation();
  148. endGuide();
  149. }}
  150. >
  151. 跳过
  152. </div>
  153. <div class={styles.box} style={data.box} id={`modeType-${data.step}`}>
  154. {data.steps.map((item: any, index) => (
  155. <div
  156. onClick={(e: Event) => e.stopPropagation()}
  157. class={styles.item}
  158. style={{
  159. display: index === data.step ? "" : "none",
  160. left: `${item.eleRect?.left}px`,
  161. top: `${item.eleRect?.top}px`,
  162. }}
  163. >
  164. <img class={styles.img} style={item.imgStyle} src={item.img} />
  165. <div class={styles.btns} style={item.btnsStyle}>
  166. {data.step + 1 == data.steps.length ? (
  167. <>
  168. <div class={[styles.endBtn]} onClick={() => endGuide()}>
  169. 完成
  170. </div>
  171. <div
  172. class={[styles.nextBtn]}
  173. style={{ "border-color": "#fff" }}
  174. onClick={() => {
  175. data.step = 0;
  176. getStepELe();
  177. }}
  178. >
  179. 再看一遍
  180. </div>
  181. </>
  182. ) : (
  183. <Button class={styles.teacherBtn} round type="primary" onClick={() => handleNext()}>
  184. 下一步 ({data.step + 1}/{data.steps.length})
  185. </Button>
  186. )}
  187. </div>
  188. </div>
  189. ))}
  190. </div>
  191. </div>
  192. </Popup>
  193. );
  194. },
  195. });