myResources-guide.tsx 5.7 KB

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