home-guide.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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: 'coai-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('home1.png'),
  33. handStyle: {
  34. top: '0.91rem'
  35. },
  36. imgStyle: {
  37. top: px2vw(-150),
  38. left: px2vw(563),
  39. width: px2vw(734),
  40. height: px2vw(295)
  41. },
  42. btnsStyle: {
  43. bottom:px2vw(188),
  44. left: px2vw(805),
  45. },
  46. boxStyle:{
  47. border:'none',
  48. width:'0px',
  49. height:'0px',
  50. backgroundColor: 'transparent'
  51. // visibility: 'hidden'
  52. },
  53. eleRectPadding:{
  54. left:7,
  55. top:7,
  56. width:14,
  57. height:14
  58. }
  59. },
  60. // {
  61. // ele: '',
  62. // img: getImage('home2.png'),
  63. // imgStyle: {
  64. // top: '100%',
  65. // left: px2vw(-250),
  66. // width: px2vw(401),
  67. // height: px2vw(227)
  68. // },
  69. // btnsStyle: {
  70. // bottom: '30px',
  71. // left: px2vw(-90),
  72. // },
  73. // boxStyle:{
  74. // borderRadius:'25px'
  75. // },
  76. // eleRectPadding:{
  77. // left:7,
  78. // top:7,
  79. // width:14,
  80. // height:14
  81. // }
  82. // },
  83. {
  84. ele: '',
  85. img: getImage('home3.png'),
  86. handStyle: {
  87. top: '-1.39rem',
  88. left: '0.17rem',
  89. transform: 'rotate(180deg)'
  90. },
  91. imgStyle: {
  92. top: px2vw(-4),
  93. width: px2vw(454),
  94. height: px2vw(227),
  95. left:px2vw(282)
  96. },
  97. btnsStyle: {
  98. bottom: '30px',
  99. left:px2vw(450)
  100. },
  101. boxStyle:{
  102. borderRadius: '20px'
  103. },
  104. eleRectPadding:{
  105. left:44,
  106. top:44,
  107. width:88,
  108. height:88
  109. }
  110. },
  111. {
  112. ele: '',
  113. img: getImage('home4.png'),
  114. handStyle: {
  115. top: '-1.39rem',
  116. left: '1.4rem',
  117. transform: 'rotate(180deg)'
  118. },
  119. imgStyle: {
  120. top: px2vw(-4),
  121. left: px2vw(-310),
  122. width: px2vw(477),
  123. height: px2vw(227),
  124. },
  125. btnsStyle: {
  126. bottom: '30px',
  127. },
  128. eleRectPadding:{
  129. left:7,
  130. top:7,
  131. width:14,
  132. height:14
  133. }
  134. },
  135. {
  136. ele: '',
  137. img: getImage('home5.png'),
  138. handStyle: {
  139. top: '-1.39rem',
  140. left: '1.4rem',
  141. transform: 'rotate(180deg)'
  142. },
  143. imgStyle: {
  144. top: '0',
  145. width: px2vw(600),
  146. height: px2vw(290),
  147. left: px2vw(18)
  148. },
  149. btnsStyle: {
  150. bottom: px2vw(80),
  151. left: px2vw(185),
  152. 'justify-content': 'center',
  153. padding: 0
  154. },
  155. eleRectPadding:{
  156. left:7,
  157. top:7,
  158. width:14,
  159. height:14
  160. },
  161. type:'bottom'
  162. }
  163. ],
  164. step: 0
  165. });
  166. const tipShow = ref(false);
  167. const guideInfo = localStorage.getItem('teacher-guideInfo');
  168. if (guideInfo && JSON.parse(guideInfo).homeGuide) {
  169. tipShow.value = false;
  170. } else {
  171. tipShow.value = true;
  172. }
  173. const getStepELe = () => {
  174. const ele: HTMLElement = document.getElementById(`home-${data.step}`)!;
  175. console.log(`coai-${data.step}`,data.steps[data.step].eleRectPadding);
  176. if (ele) {
  177. const eleRect = ele.getBoundingClientRect();
  178. const left = data.steps[data.step].eleRectPadding?.left || 0;
  179. const top = data.steps[data.step].eleRectPadding?.top || 0;
  180. const width = data.steps[data.step].eleRectPadding?.width || 0;
  181. const height = data.steps[data.step].eleRectPadding?.height || 0
  182. data.box = {
  183. left: eleRect.x - left+ 'px',
  184. top: eleRect.y - top +'px',
  185. width: eleRect.width + width+'px',
  186. height: eleRect.height +height+ 'px'
  187. };
  188. }else{
  189. handleNext()
  190. }
  191. };
  192. onMounted(() => {
  193. getStepELe();
  194. window.addEventListener("resize", resetSize);
  195. });
  196. const resetSize = ()=>{
  197. getStepELe();
  198. }
  199. onUnmounted(()=>{
  200. window.removeEventListener("resize", resetSize);
  201. })
  202. const handleNext = () => {
  203. if (data.step >= 4) {
  204. endGuide();
  205. return;
  206. }
  207. data.step = data.step + 1;
  208. getStepELe();
  209. }
  210. const endGuide = () => {
  211. let guideInfo =
  212. JSON.parse(localStorage.getItem('teacher-guideInfo') || '{}') || null;
  213. if (!guideInfo) {
  214. guideInfo = { homeGuide: true };
  215. } else {
  216. guideInfo.homeGuide = true;
  217. }
  218. localStorage.setItem('teacher-guideInfo', JSON.stringify(guideInfo));
  219. tipShow.value = false;
  220. // localStorage.setItem('endC')
  221. };
  222. return () => (
  223. <>
  224. {tipShow.value ? (
  225. <div
  226. v-model:show={tipShow.value}
  227. class={['n-modal-mask', 'n-modal-mask-guide']}>
  228. <div class={styles.content} onClick={() => handleNext()}>
  229. <div
  230. class={styles.backBtn}
  231. onClick={(e: Event) => {
  232. e.stopPropagation();
  233. endGuide();
  234. }}>
  235. 跳过
  236. </div>
  237. <div
  238. class={styles.box}
  239. style={{...data.box,...data.steps[data.step].boxStyle}}
  240. id={`modeType-${data.step}`}>
  241. {data.steps.map((item: any, index) => (
  242. <div
  243. onClick={(e: Event) => e.stopPropagation()}
  244. class={styles.item}
  245. style={ item.type=='bottom'? {
  246. display: index === data.step ? '' : 'none',
  247. left: `${item.eleRect?.left}px`,
  248. top:`-${item.imgStyle?.height}`
  249. }:{
  250. display: index === data.step ? '' : 'none',
  251. left: `${item.eleRect?.left}px`,
  252. top: `${data.box?.height}`,
  253. }}>
  254. <img
  255. class={styles.img}
  256. style={item.imgStyle}
  257. src={item.img}
  258. />
  259. {/* <img
  260. class={styles.iconHead}
  261. style={item.handStyle}
  262. src={getImage('indexDot.png')}
  263. /> */}
  264. <div class={styles.btns} style={item.btnsStyle}>
  265. {data.step + 1 == data.steps.length ? (
  266. <>
  267. <div
  268. class={[styles.endBtn]}
  269. onClick={() => endGuide()}>
  270. 完成
  271. </div>
  272. <div
  273. class={styles.nextBtn}
  274. onClick={() => {
  275. data.step = 0;
  276. getStepELe();
  277. }}>
  278. 再看一遍
  279. </div>
  280. </>
  281. ) : (
  282. <div class={styles.btn} onClick={() => handleNext()}>
  283. 下一步 ({data.step + 1}/{data.steps.length})
  284. </div>
  285. )}
  286. </div>
  287. </div>
  288. ))}
  289. </div>
  290. </div>
  291. </div>
  292. ) : null}
  293. </>
  294. );
  295. }
  296. });