attent-guide.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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, px2vwH } from '@/utils/index';
  13. export default defineComponent({
  14. name: 'attent-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('attent1.png'),
  32. handStyle: {
  33. top: '0.91rem'
  34. },
  35. imgStyle: {
  36. width: px2vw(647),
  37. height: px2vw(223),
  38. left:px2vw(-647),
  39. top:px2vw(-150)
  40. },
  41. btnsStyle: {
  42. bottom:px2vw(180),
  43. left: px2vw(-490)
  44. },
  45. eleRectPadding: {
  46. left: 7,
  47. top: 7,
  48. width: 14,
  49. height: 14
  50. },
  51. type: 'left'
  52. },
  53. {
  54. ele: '',
  55. img: getImage('attent2.png'),
  56. imgStyle: {
  57. left: px2vw(-290),
  58. top: px2vw(20),
  59. width:px2vw(477),
  60. height: px2vw(277)
  61. },
  62. btnsStyle: {
  63. bottom: px2vw(70),
  64. left: px2vw(-135)
  65. },
  66. boxStyle:{
  67. borderRadius: '50%'
  68. },
  69. eleRectPadding: {
  70. left: 7,
  71. top: 7,
  72. width: 14,
  73. height: 14
  74. },type:'bottom'
  75. },
  76. {
  77. ele: '',
  78. img: getImage('attent3.png'),
  79. imgStyle: {
  80. left:px2vw(-290),
  81. top: px2vw(20),
  82. width:px2vw(382),
  83. height: px2vw(277)
  84. },
  85. btnsStyle: {
  86. bottom: px2vw(70),
  87. left: px2vw(-135)
  88. },
  89. boxStyle:{
  90. borderRadius: '50%'
  91. },
  92. eleRectPadding: {
  93. left: 7,
  94. top: 7,
  95. width: 14,
  96. height: 14
  97. },type:'bottom'
  98. },
  99. {
  100. ele: '',
  101. img: getImage('attent4.png'),
  102. imgStyle: {
  103. top: '100%',
  104. left: px2vw(-2),
  105. width: px2vw(515),
  106. height: px2vw(227)
  107. },
  108. btnsStyle: {
  109. bottom: px2vw(30),
  110. left: px2vw(-20)
  111. },
  112. boxStyle:{
  113. borderRadius: '50px'
  114. },
  115. eleRectPadding: {
  116. left: 7,
  117. top: 7,
  118. width: 14,
  119. height: 14
  120. }
  121. }
  122. ],
  123. step: 0
  124. });
  125. const tipShow = ref(false);
  126. const guideInfo = localStorage.getItem('teacher-guideInfo');
  127. if (guideInfo && JSON.parse(guideInfo).attentGuide) {
  128. tipShow.value = false;
  129. } else {
  130. tipShow.value = true;
  131. }
  132. const getStepELe = () => {
  133. const ele: HTMLElement = document.getElementById(`attent-${data.step}`)!;
  134. if (ele) {
  135. const eleRect = ele.getBoundingClientRect();
  136. const left = data.steps[data.step].eleRectPadding?.left || 0;
  137. const top = data.steps[data.step].eleRectPadding?.top || 0;
  138. const width = data.steps[data.step].eleRectPadding?.width || 0;
  139. const height = data.steps[data.step].eleRectPadding?.height || 0;
  140. data.box = {
  141. left: eleRect.x - left + 'px',
  142. top: eleRect.y - top + 'px',
  143. width: eleRect.width + width + 'px',
  144. height: eleRect.height + height + 'px'
  145. };
  146. console.log(`coai-${data.step}`, data.box);
  147. }
  148. };
  149. onMounted(() => {
  150. getStepELe();
  151. });
  152. const handleNext = () => {
  153. if (data.step >= 4) {
  154. endGuide();
  155. return;
  156. }
  157. data.step = data.step + 1;
  158. getStepELe();
  159. };
  160. const endGuide = () => {
  161. let guideInfo =
  162. JSON.parse(localStorage.getItem('teacher-guideInfo') || '{}') || null;
  163. if (!guideInfo) {
  164. guideInfo = { attentGuide: true };
  165. } else {
  166. guideInfo.attentGuide = true;
  167. }
  168. localStorage.setItem('teacher-guideInfo', JSON.stringify(guideInfo));
  169. tipShow.value = false;
  170. // localStorage.setItem('endC')
  171. };
  172. return () => (
  173. <>
  174. {tipShow.value ? (
  175. <div
  176. v-model:show={tipShow.value}
  177. class={['n-modal-mask', 'n-modal-mask-guide']}>
  178. <div class={styles.content} onClick={() => handleNext()}>
  179. <div
  180. class={styles.backBtn}
  181. onClick={(e: Event) => {
  182. e.stopPropagation();
  183. endGuide();
  184. }}>
  185. 跳过
  186. </div>
  187. <div
  188. class={styles.box}
  189. style={{ ...data.box, ...data.steps[data.step].boxStyle }}
  190. id={`modeType-${data.step}`}>
  191. {data.steps.map((item: any, index) => (
  192. <div
  193. onClick={(e: Event) => e.stopPropagation()}
  194. class={styles.item}
  195. style={
  196. item.type == 'bottom'
  197. ? {
  198. display: index === data.step ? '' : 'none',
  199. left: `${item.eleRect?.left}px`,
  200. top: `-${item.imgStyle?.height}`
  201. }
  202. : item.type == 'left'
  203. ? {
  204. display: index === data.step ? '' : 'none',
  205. left: `${item.eleRect?.left}px`,
  206. top: `${
  207. parseFloat(data.box?.height) / 2 -
  208. parseFloat(item.imgStyle?.height) / 20 +
  209. 14
  210. }px`
  211. }
  212. : {
  213. display: index === data.step ? '' : 'none',
  214. left: `${item.eleRect?.left}px`,
  215. top: `${data.box?.height}`
  216. }
  217. }>
  218. <img
  219. class={styles.img}
  220. style={item.imgStyle}
  221. src={item.img}
  222. />
  223. {/* <img
  224. class={styles.iconHead}
  225. style={item.handStyle}
  226. src={getImage('indexDot.png')}
  227. /> */}
  228. <div class={styles.btns} style={item.btnsStyle}>
  229. {data.step + 1 == data.steps.length ? (
  230. <>
  231. <div
  232. class={[styles.endBtn]}
  233. onClick={() => endGuide()}>
  234. 完成
  235. </div>
  236. <div
  237. class={styles.nextBtn}
  238. onClick={() => {
  239. data.step = 0;
  240. getStepELe();
  241. }}>
  242. 再看一遍
  243. </div>
  244. </>
  245. ) : (
  246. <div class={styles.btn} onClick={() => handleNext()}>
  247. 下一步 ({data.step + 1}/{data.steps.length})
  248. </div>
  249. )}
  250. </div>
  251. </div>
  252. ))}
  253. </div>
  254. </div>
  255. </div>
  256. ) : null}
  257. </>
  258. );
  259. }
  260. });