myResources-guide.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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: 'myResources-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. eleRect: {} as DOMRect,
  31. img: getImage('myResourecs1.png'),
  32. handStyle: {
  33. top: '0.91rem'
  34. },
  35. imgStyle: {
  36. left: '-263px',
  37. width: '556px',
  38. height: '257px'
  39. },
  40. btnsStyle: {
  41. bottom:'30px',
  42. left: '-90px',
  43. },
  44. eleRectPadding:{
  45. left:14,
  46. top:14,
  47. width:28,
  48. height:28
  49. },
  50. boxStyle:{
  51. borderRadius: '30px'
  52. },
  53. },
  54. ],
  55. step: 0
  56. });
  57. const tipShow = ref(false);
  58. const guideInfo = localStorage.getItem('teacher-guideInfo');
  59. if (guideInfo && JSON.parse(guideInfo).myResourcesGuide) {
  60. tipShow.value = false;
  61. } else {
  62. tipShow.value = true;
  63. }
  64. const getStepELe = () => {
  65. const ele: HTMLElement = document.getElementById(`myResources-${data.step}`)!;
  66. if (ele) {
  67. const eleRect = ele.getBoundingClientRect();
  68. const left = data.steps[data.step].eleRectPadding?.left || 0;
  69. const top = data.steps[data.step].eleRectPadding?.top || 0;
  70. const width = data.steps[data.step].eleRectPadding?.width || 0;
  71. const height = data.steps[data.step].eleRectPadding?.height || 0
  72. data.box = {
  73. left: eleRect.x - left+ 'px',
  74. top: eleRect.y - top +'px',
  75. width: eleRect.width + width+'px',
  76. height: eleRect.height +height+ 'px'
  77. };
  78. console.log(`coai-${data.step}`,data.box);
  79. }
  80. };
  81. onMounted(() => {
  82. getStepELe();
  83. });
  84. const handleNext = () => {
  85. if (data.step >= 4) {
  86. endGuide();
  87. return;
  88. }
  89. data.step = data.step + 1;
  90. getStepELe();
  91. };
  92. const endGuide = () => {
  93. let guideInfo =
  94. JSON.parse(localStorage.getItem('teacher-guideInfo')) || null;
  95. if (!guideInfo) {
  96. guideInfo = { myResourcesGuide: true };
  97. } else {
  98. guideInfo.myResourcesGuide = true;
  99. }
  100. localStorage.setItem('teacher-guideInfo', JSON.stringify(guideInfo));
  101. tipShow.value = false;
  102. // localStorage.setItem('endC')
  103. };
  104. return () => (
  105. <>
  106. {tipShow.value ? (
  107. <div
  108. v-model:show={tipShow.value}
  109. class={['n-modal-mask', 'n-modal-mask-guide']}>
  110. <div class={styles.content} onClick={() => handleNext()}>
  111. <div
  112. class={styles.backBtn}
  113. onClick={(e: Event) => {
  114. e.stopPropagation();
  115. endGuide();
  116. }}>
  117. 跳过
  118. </div>
  119. <div
  120. class={styles.box}
  121. style={{...data.box,...data.steps[data.step].boxStyle}}
  122. id={`modeType-${data.step}`}>
  123. {data.steps.map((item: any, index) => (
  124. <div
  125. onClick={(e: Event) => e.stopPropagation()}
  126. class={styles.item}
  127. style={ item.type=='bottom'? {
  128. display: index === data.step ? '' : 'none',
  129. left: `${item.eleRect?.left}px`,
  130. top:`-${item.imgStyle?.height}`
  131. }:{
  132. display: index === data.step ? '' : 'none',
  133. left: `${item.eleRect?.left}px`,
  134. top: `${data.box?.height}`,
  135. }}>
  136. <img
  137. class={styles.img}
  138. style={item.imgStyle}
  139. src={item.img}
  140. />
  141. {/* <img
  142. class={styles.iconHead}
  143. style={item.handStyle}
  144. src={getImage('indexDot.png')}
  145. /> */}
  146. <div class={styles.btns} style={item.btnsStyle}>
  147. {data.step + 1 == data.steps.length ? (
  148. <>
  149. <div
  150. class={[styles.endBtn]}
  151. onClick={() => endGuide()}>
  152. 完成
  153. </div>
  154. {/* <div
  155. class={styles.nextBtn}
  156. onClick={() => {
  157. data.step = 0;
  158. getStepELe();
  159. }}>
  160. 再看一遍
  161. </div> */}
  162. </>
  163. ) : (
  164. <div class={styles.btn} onClick={() => handleNext()}>
  165. 下一步 ({data.step + 1}/{data.steps.length})
  166. </div>
  167. )}
  168. </div>
  169. </div>
  170. ))}
  171. </div>
  172. </div>
  173. </div>
  174. ) : null}
  175. </>
  176. );
  177. }
  178. });