student-bottom.tsx 5.2 KB

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