train-guide.tsx 5.5 KB

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