courseware-detail.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. export default defineComponent({
  7. name: "courseware-detail",
  8. emits: ["close"],
  9. setup(props, { emit }) {
  10. const data = reactive({
  11. box: {},
  12. show: false,
  13. steps: [
  14. {
  15. ele: "",
  16. eleRect: {} as DOMRect,
  17. img: getImage("courseware-detail1.png"),
  18. handStyle: {
  19. top: "-0.4rem",
  20. left:"1.1rem",
  21. transform: 'rotate(-90deg)'
  22. },
  23. imgStyle: {
  24. top: "-1.3rem",
  25. left:"2.2rem",
  26. },
  27. btnsStyle: {
  28. top: "1.5rem",
  29. left:"3.5rem",
  30. },
  31. },
  32. ],
  33. step: 0,
  34. });
  35. const tipShow = ref(false)
  36. const guideInfo = localStorage.getItem('guideInfo')
  37. if(guideInfo&&JSON.parse(guideInfo).coursewareDetail){
  38. tipShow.value =false
  39. }else {
  40. tipShow.value =true
  41. }
  42. const getStepELe = () => {
  43. console.log(`coursewareDetail-${data.step}`)
  44. const ele: HTMLElement = document.getElementById(`coursewareDetail-${data.step}`)!;
  45. if (ele) {
  46. const eleRect = ele.getBoundingClientRect();
  47. data.box = {
  48. left: eleRect.x + "px",
  49. top: eleRect.y + "px",
  50. width: eleRect.width + "px",
  51. height: eleRect.height + "px",
  52. };
  53. }else{
  54. handleNext()
  55. }
  56. };
  57. onMounted(() => {
  58. getStepELe();
  59. window.addEventListener("resize", resetSize);
  60. });
  61. const resetSize = ()=>{
  62. getStepELe();
  63. }
  64. onUnmounted(()=>{
  65. window.removeEventListener("resize", resetSize);
  66. })
  67. const handleNext = () => {
  68. if (data.step >= 2) {
  69. endGuide();
  70. return;
  71. }
  72. data.step = data.step + 1;
  73. getStepELe();
  74. };
  75. const endGuide = ()=>{
  76. let guideInfo = JSON.parse(localStorage.getItem('guideInfo')|| '{}') || null
  77. if(!guideInfo){
  78. guideInfo = {coursewareDetail:true}
  79. }else{
  80. guideInfo.coursewareDetail = true
  81. }
  82. localStorage.setItem('guideInfo',JSON.stringify(guideInfo))
  83. tipShow.value = false
  84. // localStorage.setItem('endC')
  85. }
  86. return () => (
  87. <Popup teleport="body" overlay={false} closeOnClickOverlay={false} class={["popup-custom", styles.guidePopup]} v-model:show={tipShow.value}>
  88. <div class={styles.content} onClick={() => handleNext()}>
  89. <div
  90. class={styles.backBtn}
  91. onClick={(e: Event) => {
  92. e.stopPropagation();
  93. endGuide()
  94. }}
  95. >
  96. 跳过
  97. </div>
  98. <div class={styles.box} style={data.box} id={`modeType-${data.step}`}>
  99. {data.steps.map((item: any, index) => (
  100. <div
  101. onClick={(e: Event) => e.stopPropagation()}
  102. class={styles.item}
  103. style={{
  104. display: index === data.step ? "" : "none",
  105. left: `${item.eleRect?.left}px`,
  106. top: `${item.eleRect?.top}px`,
  107. }}
  108. >
  109. <img class={styles.img} style={item.imgStyle} src={item.img} />
  110. <img class={styles.iconHead} style={item.handStyle} src={getImage("indexDot.png")} />
  111. <div class={styles.btns} style={item.btnsStyle}>
  112. {data.step + 1 == data.steps.length ? (
  113. <>
  114. {/* <Button
  115. class={styles.btn}
  116. round
  117. color="transparent"
  118. style={{ "border-color": "#fff" }}
  119. type="primary"
  120. onClick={() => {
  121. data.step = 0;
  122. getStepELe();
  123. }}
  124. >
  125. 再看一遍
  126. </Button> */}
  127. <Button class={[styles.btn,styles.endBtn]} round type="primary" onClick={() =>endGuide()}>
  128. 完成
  129. </Button>
  130. </>
  131. ) : (
  132. <Button class={styles.btn} round type="primary" onClick={() => handleNext()}>
  133. 下一步 ({data.step + 1}/{data.steps.length})
  134. </Button>
  135. )}
  136. </div>
  137. </div>
  138. ))}
  139. </div>
  140. </div>
  141. </Popup>
  142. );
  143. },
  144. });