attent-guide.tsx 8.0 KB

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