home-guide.tsx 8.1 KB

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