courseware-detail.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import { Button, Popup } from "vant";
  2. import { } from "vant";
  3. import { defineComponent, nextTick, onMounted, onUnmounted, reactive, ref, watch } from "vue";
  4. import styles from "./index.module.less";
  5. import { getImage } from "./images";
  6. import {getGuidance,setGuidance} from './api'
  7. export default defineComponent({
  8. name: "courseware-detail",
  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("courseware-detail1.png"),
  19. handStyle: {
  20. top: "-0.4rem",
  21. left:"0.98rem",
  22. transform: 'rotate(-90deg)'
  23. },
  24. boxStyle:{
  25. 'borderRadius':'0.1rem'
  26. },
  27. imgStyle: {
  28. top: "-1.3rem",
  29. left:"2.2rem",
  30. },
  31. btnsStyle: {
  32. top: "1.5rem",
  33. left:"3.5rem",
  34. },
  35. },
  36. ],
  37. step: 0,
  38. });
  39. const tipShow = ref(false)
  40. const guideInfo = ref({} as any)
  41. const getAllGuidance = async()=>{
  42. try{
  43. const res = await getGuidance({guideTag:'guideInfo'})
  44. if(res.data){
  45. guideInfo.value = JSON.parse(res.data?.guideValue) || null
  46. }else{
  47. guideInfo.value = {}
  48. }
  49. if (guideInfo.value &&guideInfo.value.coursewareDetail) {
  50. tipShow.value = false;
  51. } else {
  52. tipShow.value = true;
  53. }
  54. }catch(e){
  55. console.log(e)
  56. }
  57. // const guideInfo = localStorage.getItem('teacher-guideInfo');
  58. }
  59. getAllGuidance()
  60. // const guideInfo = localStorage.getItem('guideInfo')
  61. // if(guideInfo&&JSON.parse(guideInfo).coursewareDetail){
  62. // tipShow.value =false
  63. // }else {
  64. // tipShow.value =true
  65. // }
  66. const getStepELe = () => {
  67. console.log(`coursewareDetail-${data.step}`)
  68. const ele: HTMLElement = document.getElementById(`coursewareDetail-${data.step}`)!;
  69. if (ele) {
  70. const eleRect = ele.getBoundingClientRect();
  71. data.box = {
  72. left: eleRect.x + "px",
  73. top: eleRect.y + "px",
  74. width: eleRect.width + "px",
  75. height: eleRect.height + "px",
  76. };
  77. }else{
  78. handleNext()
  79. }
  80. };
  81. onMounted(() => {
  82. getStepELe();
  83. window.addEventListener("resize", resetSize);
  84. });
  85. const resetSize = ()=>{
  86. getStepELe();
  87. }
  88. onUnmounted(()=>{
  89. window.removeEventListener("resize", resetSize);
  90. })
  91. const handleNext = () => {
  92. if (data.step >= 2) {
  93. endGuide();
  94. return;
  95. }
  96. data.step = data.step + 1;
  97. getStepELe();
  98. };
  99. const endGuide = async()=>{
  100. // let guideInfo = JSON.parse(localStorage.getItem('guideInfo')|| '{}') || null
  101. if(!guideInfo.value){
  102. guideInfo.value = {coursewareDetail:true}
  103. }else{
  104. guideInfo.value.coursewareDetail = true
  105. }
  106. try{
  107. const res = await setGuidance({guideTag:'guideInfo',guideValue:JSON.stringify(guideInfo.value)})
  108. }catch(e){
  109. console.log(e)
  110. }
  111. tipShow.value = false
  112. // localStorage.setItem('endC')
  113. }
  114. return () => (
  115. <Popup teleport="body" overlay={false} closeOnClickOverlay={false} class={["popup-custom", styles.guidePopup]} v-model:show={tipShow.value}>
  116. <div class={styles.content} onClick={() => handleNext()}>
  117. {data.step!=data.steps.length-1&&<div
  118. class={styles.backBtn}
  119. onClick={(e: Event) => {
  120. e.stopPropagation();
  121. endGuide()
  122. }}
  123. >
  124. 跳过
  125. </div>}
  126. <div class={styles.box} style={{...data.box,...data.steps[data.step].boxStyle}} id={`modeType-${data.step}`}>
  127. {data.steps.map((item: any, index) => (
  128. <div
  129. onClick={(e: Event) => e.stopPropagation()}
  130. class={styles.item}
  131. style={{
  132. display: index === data.step ? "" : "none",
  133. left: `${item.eleRect?.left}px`,
  134. top: `${item.eleRect?.top}px`,
  135. }}
  136. >
  137. <img class={styles.img} style={item.imgStyle} src={item.img} />
  138. <img class={styles.iconHead} style={item.handStyle} src={getImage("indexDot.png")} />
  139. <div class={styles.btns} style={item.btnsStyle}>
  140. {data.step + 1 == data.steps.length ? (
  141. <>
  142. {/* <Button
  143. class={styles.btn}
  144. round
  145. color="transparent"
  146. style={{ "border-color": "#fff" }}
  147. type="primary"
  148. onClick={() => {
  149. data.step = 0;
  150. getStepELe();
  151. }}
  152. >
  153. 再看一遍
  154. </Button> */}
  155. <Button class={[styles.btn,styles.endBtn]} round type="primary" onClick={() =>endGuide()}>
  156. 完成
  157. </Button>
  158. </>
  159. ) : (
  160. <Button class={styles.btn} round type="primary" onClick={() => handleNext()}>
  161. 下一步 ({data.step + 1}/{data.steps.length})
  162. </Button>
  163. )}
  164. </div>
  165. </div>
  166. ))}
  167. </div>
  168. </div>
  169. </Popup>
  170. );
  171. },
  172. });