student-bottom.tsx 5.3 KB

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