class-guide.tsx 6.4 KB

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