teacher-bootom.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 { headTopData } from "/src/page-instrument/header-top/index";
  9. import state, { IPlatform } from "/src/state";
  10. export default defineComponent({
  11. name: "aiTeacher-guide",
  12. emits: ["close"],
  13. setup(props, { emit }) {
  14. const data = reactive({
  15. box: {},
  16. show: false,
  17. steps: state.platform === IPlatform.PC ? [
  18. {
  19. img: getImage("aiTeacher2.png"),
  20. eleRect: {
  21. top: "-3rem",
  22. },
  23. imgStyle: {
  24. left: "-0.7rem",
  25. width: "6.48rem",
  26. height: "3.01rem",
  27. },
  28. btnsStyle: {
  29. bottom: ".9rem",
  30. left: ".9rem",
  31. transform: "scale(.83)",
  32. },
  33. boxStyle: {
  34. borderRadius: "40px",
  35. },
  36. },
  37. {
  38. img: getImage("aiTeacher3.png"),
  39. eleRect: {
  40. top: "-3rem",
  41. },
  42. imgStyle: {
  43. left: "-0.7rem",
  44. width: "6.48rem",
  45. height: "3rem",
  46. },
  47. btnsStyle: {
  48. bottom: ".9rem",
  49. left: ".8rem",
  50. transform: "scale(.83)",
  51. },
  52. boxStyle: {
  53. borderRadius: "40px",
  54. },
  55. }
  56. ] : [
  57. {
  58. eleRect: {
  59. left: "4.5rem",
  60. top: "-3.6rem",
  61. },
  62. img: getImage("aiTeacher1.png"),
  63. imgStyle: {
  64. width: "7.776rem",
  65. height: "3.6rem",
  66. },
  67. btnsStyle: {
  68. bottom: "1.3rem",
  69. left: "2.1rem",
  70. },
  71. boxStyle: {
  72. borderRadius: "40px",
  73. transform: "scale(1)",
  74. },
  75. eleRectPadding: {
  76. left: 14,
  77. top: 14,
  78. width: 28,
  79. height: 28,
  80. },
  81. },
  82. {
  83. img: getImage("aiTeacher2.png"),
  84. eleRect: {
  85. top: "-3rem",
  86. },
  87. imgStyle: {
  88. left: "-0.7rem",
  89. width: "6.48rem",
  90. height: "3.01rem",
  91. },
  92. btnsStyle: {
  93. bottom: ".9rem",
  94. left: ".9rem",
  95. transform: "scale(.83)",
  96. },
  97. boxStyle: {
  98. borderRadius: "40px",
  99. },
  100. },
  101. {
  102. img: getImage("aiTeacher3.png"),
  103. eleRect: {
  104. top: "-3rem",
  105. },
  106. imgStyle: {
  107. left: "-0.7rem",
  108. width: "6.48rem",
  109. height: "3rem",
  110. },
  111. btnsStyle: {
  112. bottom: ".9rem",
  113. left: ".8rem",
  114. transform: "scale(.83)",
  115. },
  116. boxStyle: {
  117. borderRadius: "40px",
  118. },
  119. },
  120. {
  121. img: getImage("aiTeacher4.png"),
  122. eleRect: {
  123. top: "-3rem",
  124. left: "-1rem",
  125. },
  126. imgStyle: {
  127. width: "6.48rem",
  128. height: "3.01rem",
  129. },
  130. btnsStyle: {
  131. bottom: ".9rem",
  132. left: "1.6rem",
  133. "justify-content": "center",
  134. padding: 0,
  135. transform: "scale(.83)",
  136. },
  137. boxStyle: {
  138. borderRadius: "40px",
  139. },
  140. },
  141. ],
  142. step: 0,
  143. });
  144. const tipShow = ref(false);
  145. // const guideInfo = localStorage.getItem("guideInfo");
  146. const query: any = getQuery();
  147. const guideInfo = ref({} as any)
  148. const getAllGuidance = async()=>{
  149. try{
  150. if (state.guideInfo) {
  151. guideInfo.value = state.guideInfo
  152. } else {
  153. const res = await getGuidance({guideTag:'guideInfo'})
  154. if(res.data){
  155. guideInfo.value = JSON.parse(res.data?.guideValue) || null
  156. }else{
  157. guideInfo.value = {}
  158. }
  159. }
  160. if (guideInfo.value && guideInfo.value.teacherBottom) {
  161. tipShow.value = false;
  162. } else {
  163. tipShow.value = headTopData.modeType === "init" ? true : false;
  164. }
  165. }catch(e){
  166. console.log(e)
  167. }
  168. // const guideInfo = localStorage.getItem('teacher-guideInfo');
  169. }
  170. getAllGuidance()
  171. // if ((guideInfo && JSON.parse(guideInfo).teacherBottom) || !query.showGuide) {
  172. // tipShow.value = false;
  173. // } else {
  174. // tipShow.value = true;
  175. // }
  176. const steps = state.platform === IPlatform.PC ? ["modeType-0", "modeType-1"] : ["modeType-box", "modeType-0", "modeType-1", "modeType-2"];
  177. const getStepELe = () => {
  178. console.log(steps[data.step]);
  179. const ele: HTMLElement = document.getElementById(steps[data.step])!;
  180. if (ele) {
  181. const eleRect = ele.getBoundingClientRect();
  182. const left = data.steps[data.step].eleRectPadding?.left || 0;
  183. const top = data.steps[data.step].eleRectPadding?.top || 0;
  184. const width = data.steps[data.step].eleRectPadding?.width || 0;
  185. const height = data.steps[data.step].eleRectPadding?.height || 0;
  186. data.box = {
  187. left: eleRect.x - left + "px",
  188. top: eleRect.y - top + "px",
  189. width: eleRect.width + width + "px",
  190. height: eleRect.height + height + "px",
  191. };
  192. console.log(`coai-${data.step}`, data.box);
  193. } else {
  194. handleNext();
  195. }
  196. };
  197. onMounted(() => {
  198. getStepELe();
  199. });
  200. const handleNext = () => {
  201. if (data.step >= 3 || (state.platform === IPlatform.PC && data.step >= 1)) {
  202. endGuide();
  203. return;
  204. }
  205. data.step = data.step + 1;
  206. getStepELe();
  207. };
  208. const endGuide = async() => {
  209. // let guideInfo = JSON.parse(localStorage.getItem("guideInfo") || "{}") || null;
  210. if (!guideInfo.value) {
  211. guideInfo.value = { teacherBottom: true };
  212. } else {
  213. guideInfo.value.teacherBottom = true;
  214. }
  215. try{
  216. const res = await setGuidance({guideTag:'guideInfo',guideValue:JSON.stringify(guideInfo.value)})
  217. }catch(e){
  218. console.log(e)
  219. }
  220. // localStorage.setItem("guideInfo", JSON.stringify(guideInfo));
  221. tipShow.value = false;
  222. // localStorage.setItem('endC')
  223. };
  224. return () => (
  225. <Popup
  226. teleport="body"
  227. overlay={false}
  228. closeOnClickOverlay={false}
  229. class={["popup-custom", styles.guidePopup]}
  230. v-model:show={tipShow.value}
  231. >
  232. <div class={styles.content} onClick={() => handleNext()}>
  233. <div
  234. class={styles.backBtn}
  235. onClick={(e: Event) => {
  236. e.stopPropagation();
  237. endGuide();
  238. }}
  239. >
  240. 跳过
  241. </div>
  242. <div
  243. class={styles.box}
  244. style={{ ...data.box, ...data.steps[data.step].boxStyle }}
  245. id={`modeType-${data.step}`}
  246. >
  247. {data.steps.map((item: any, index) => (
  248. <div
  249. onClick={(e: Event) => e.stopPropagation()}
  250. class={styles.item}
  251. style={{
  252. display: index === data.step ? "" : "none",
  253. left: `${item.eleRect?.left}`,
  254. top: `${item.eleRect?.top}`,
  255. }}
  256. >
  257. <img class={styles.img} style={item.imgStyle} src={item.img} />
  258. <div class={styles.btns} style={item.btnsStyle}>
  259. {data.step + 1 == data.steps.length ? (
  260. <>
  261. <div class={[styles.endBtn]} onClick={() => endGuide()}>
  262. 完成
  263. </div>
  264. <div
  265. class={[styles.nextBtn]}
  266. style={{ "border-color": "#fff" }}
  267. onClick={() => {
  268. data.step = 0;
  269. getStepELe();
  270. }}
  271. >
  272. 再看一遍
  273. </div>
  274. </>
  275. ) : (
  276. <Button class={styles.teacherBtn} round type="primary" onClick={() => handleNext()}>
  277. 下一步 ({data.step + 1}/{data.steps.length})
  278. </Button>
  279. )}
  280. </div>
  281. </div>
  282. ))}
  283. </div>
  284. </div>
  285. </Popup>
  286. );
  287. },
  288. });