courseware-detail.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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","changeShowGuide"],
  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. console.log('调用')
  42. // setGuidance({guideTag:'guideInfo',guideValue:'{}'})
  43. const getAllGuidance = async()=>{
  44. try{
  45. const res = await getGuidance({guideTag:'guideInfo'})
  46. if(res.data){
  47. guideInfo.value = JSON.parse(res.data?.guideValue) || null
  48. }else{
  49. guideInfo.value = {}
  50. }
  51. if (guideInfo.value &&guideInfo.value.coursewareDetail) {
  52. tipShow.value = false;
  53. emit('changeShowGuide',tipShow.value)
  54. } else {
  55. tipShow.value = true;
  56. }
  57. }catch(e){
  58. console.log(e)
  59. }
  60. // const guideInfo = localStorage.getItem('teacher-guideInfo');
  61. }
  62. watch(()=>tipShow.value,(value)=>{
  63. emit('changeShowGuide',tipShow.value)
  64. },{
  65. })
  66. getAllGuidance()
  67. // const guideInfo = localStorage.getItem('guideInfo')
  68. // if(guideInfo&&JSON.parse(guideInfo).coursewareDetail){
  69. // tipShow.value =false
  70. // }else {
  71. // tipShow.value =true
  72. // }
  73. const getStepELe = () => {
  74. const ele: HTMLElement = document.getElementById(`coursewareDetail-${data.step}`)!;
  75. if (ele) {
  76. const eleRect = ele.getBoundingClientRect();
  77. data.box = {
  78. left: eleRect.x + "px",
  79. top: eleRect.y + "px",
  80. width: eleRect.width + "px",
  81. height: eleRect.height + "px",
  82. };
  83. }else{
  84. handleNext()
  85. }
  86. };
  87. onMounted(() => {
  88. getStepELe();
  89. window.addEventListener("resize", resetSize);
  90. });
  91. const resetSize = ()=>{
  92. getStepELe();
  93. }
  94. onUnmounted(()=>{
  95. window.removeEventListener("resize", resetSize);
  96. })
  97. const handleNext = () => {
  98. if (data.step >= 0) {
  99. endGuide();
  100. return;
  101. }
  102. data.step = data.step + 1;
  103. getStepELe();
  104. };
  105. const endGuide = async()=>{
  106. // console.log(`handleNext-${data.step}`)
  107. // if(!tipShow.value){
  108. // return
  109. // }
  110. // let guideInfo = JSON.parse(localStorage.getItem('guideInfo')|| '{}') || null
  111. if(!guideInfo.value){
  112. guideInfo.value = {coursewareDetail:true}
  113. }else{
  114. guideInfo.value.coursewareDetail = true
  115. }
  116. try{
  117. const res = await setGuidance({guideTag:'guideInfo',guideValue:JSON.stringify(guideInfo.value)})
  118. }catch(e){
  119. console.log(e)
  120. }
  121. console.log('调用detail完成')
  122. tipShow.value = false
  123. // localStorage.setItem('endC')
  124. }
  125. return () => (<>
  126. {tipShow.value? <Popup teleport="body" overlay={false} closeOnClickOverlay={false} class={["popup-custom", styles.guidePopup]} v-model:show={tipShow.value}>
  127. <div class={styles.content} onClick={() => handleNext()}>
  128. {data.step!=data.steps.length-1&&<div
  129. class={styles.backBtn}
  130. onClick={(e: Event) => {
  131. e.stopPropagation();
  132. endGuide()
  133. }}
  134. >
  135. 跳过
  136. </div>}
  137. <div class={styles.box} style={{...data.box,...data.steps[data.step]?.boxStyle}} id={`modeType-${data.step}`}>
  138. {data.steps.map((item: any, index) => (
  139. <div
  140. onClick={(e: Event) => e.stopPropagation()}
  141. class={styles.item}
  142. style={{
  143. display: index === data.step ? "" : "none",
  144. left: `${item.eleRect?.left}px`,
  145. top: `${item.eleRect?.top}px`,
  146. }}
  147. >
  148. <img class={styles.img} style={item.imgStyle} src={item.img} />
  149. <img class={styles.iconHead} style={item.handStyle} src={getImage("indexDot.png")} />
  150. <div class={styles.btns} style={item.btnsStyle}>
  151. {data.step + 1 == data.steps.length ? (
  152. <>
  153. {/* <Button
  154. class={styles.btn}
  155. round
  156. color="transparent"
  157. style={{ "border-color": "#fff" }}
  158. type="primary"
  159. onClick={() => {
  160. data.step = 0;
  161. getStepELe();
  162. }}
  163. >
  164. 再看一遍
  165. </Button> */}
  166. <Button class={[styles.btn,styles.endBtn]} round type="primary" onClick={() =>endGuide()}>
  167. 完成
  168. </Button>
  169. </>
  170. ) : (
  171. <Button class={styles.btn} round type="primary" onClick={() => handleNext()}>
  172. 下一步 ({data.step + 1}/{data.steps.length})
  173. </Button>
  174. )}
  175. </div>
  176. </div>
  177. ))}
  178. </div>
  179. </div>
  180. </Popup>:null}
  181. </>
  182. );
  183. },
  184. });