myColloge-guide.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import { NButton } from 'naive-ui';
  2. import {
  3. defineComponent,
  4. nextTick,
  5. onMounted,
  6. reactive,
  7. ref,
  8. watch
  9. } from 'vue';
  10. import styles from './index.module.less';
  11. import { getImage } from './images';
  12. import {px2vw} from '@/utils/index'
  13. export default defineComponent({
  14. name: 'myColloge-guide',
  15. emits: ['close'],
  16. setup(props, { emit }) {
  17. const data = reactive({
  18. box: {
  19. height:'0px',
  20. } as any,
  21. show: false,
  22. /**
  23. *
  24. width: px2vw(840),
  25. height: px2vw(295)
  26. */
  27. steps: [
  28. {
  29. ele: '',
  30. img: getImage('myColloge1.png'),
  31. imgStyle: {
  32. top: '100%',
  33. left: '630px',
  34. width: '458px',
  35. height:'291px'
  36. },
  37. btnsStyle: {
  38. bottom: '96px',
  39. left: '780px',
  40. },
  41. eleRectPadding:{
  42. left:7,
  43. top:7,
  44. width:14,
  45. height:14
  46. },
  47. type:'bottom'
  48. },
  49. ],
  50. step: 0
  51. });
  52. const tipShow = ref(false);
  53. const guideInfo = localStorage.getItem('teacher-guideInfo');
  54. if (guideInfo && JSON.parse(guideInfo).myColloge) {
  55. tipShow.value = false;
  56. } else {
  57. tipShow.value = true;
  58. }
  59. const getStepELe = () => {
  60. const ele: HTMLElement = document.getElementById(`myColloge-${data.step}`)!;
  61. if (ele) {
  62. const eleRect = ele.getBoundingClientRect();
  63. const left = data.steps[data.step].eleRectPadding?.left || 0;
  64. const top = data.steps[data.step].eleRectPadding?.top || 0;
  65. const width = data.steps[data.step].eleRectPadding?.width || 0;
  66. const height = data.steps[data.step].eleRectPadding?.height || 0
  67. data.box = {
  68. left: eleRect.x - left+ 'px',
  69. top: eleRect.y - top +'px',
  70. width: eleRect.width + width+'px',
  71. height: eleRect.height +height+ 'px'
  72. };
  73. console.log(`coai-${data.step}`,data.box);
  74. }
  75. };
  76. onMounted(() => {
  77. getStepELe();
  78. });
  79. const handleNext = () => {
  80. if (data.step >= 4) {
  81. endGuide();
  82. return;
  83. }
  84. data.step = data.step + 1;
  85. getStepELe();
  86. };
  87. const endGuide = () => {
  88. let guideInfo =
  89. JSON.parse(localStorage.getItem('teacher-guideInfo') || '') || null;
  90. if (!guideInfo) {
  91. guideInfo = { myColloge: true };
  92. } else {
  93. guideInfo.myColloge = true;
  94. }
  95. localStorage.setItem('teacher-guideInfo', JSON.stringify(guideInfo));
  96. tipShow.value = false;
  97. // localStorage.setItem('endC')
  98. };
  99. return () => (
  100. <>
  101. {tipShow.value ? (
  102. <div
  103. v-model:show={tipShow.value}
  104. class={['n-modal-mask', 'n-modal-mask-guide']}>
  105. <div class={styles.content} onClick={() => handleNext()}>
  106. <div
  107. class={styles.backBtn}
  108. onClick={(e: Event) => {
  109. e.stopPropagation();
  110. endGuide();
  111. }}>
  112. 跳过
  113. </div>
  114. <div
  115. class={styles.box}
  116. style={{...data.box,...data.steps[data.step].boxStyle}}
  117. id={`modeType-${data.step}`}>
  118. {data.steps.map((item: any, index) => (
  119. <div
  120. onClick={(e: Event) => e.stopPropagation()}
  121. class={styles.item}
  122. style={ item.type=='bottom'? {
  123. display: index === data.step ? '' : 'none',
  124. left: `${item.eleRect?.left}px`,
  125. top:`-${item.imgStyle?.height}`
  126. }:{
  127. display: index === data.step ? '' : 'none',
  128. left: `${item.eleRect?.left}px`,
  129. top: `${data.box?.height}`,
  130. }}>
  131. <img
  132. class={styles.img}
  133. style={item.imgStyle}
  134. src={item.img}
  135. />
  136. {/* <img
  137. class={styles.iconHead}
  138. style={item.handStyle}
  139. src={getImage('indexDot.png')}
  140. /> */}
  141. <div class={styles.btns} style={item.btnsStyle}>
  142. {data.step + 1 == data.steps.length ? (
  143. <>
  144. <div
  145. class={[styles.endBtn]}
  146. onClick={() => endGuide()}>
  147. 完成
  148. </div>
  149. {/* <div
  150. class={styles.nextBtn}
  151. onClick={() => {
  152. data.step = 0;
  153. getStepELe();
  154. }}>
  155. 再看一遍
  156. </div> */}
  157. </>
  158. ) : (
  159. <div class={styles.btn} onClick={() => handleNext()}>
  160. 下一步 ({data.step + 1}/{data.steps.length})
  161. </div>
  162. )}
  163. </div>
  164. </div>
  165. ))}
  166. </div>
  167. </div>
  168. </div>
  169. ) : null}
  170. </>
  171. );
  172. }
  173. });