class-guide.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. });
  123. const handleNext = () => {
  124. if (data.step >= 4) {
  125. endGuide();
  126. return;
  127. }
  128. data.step = data.step + 1;
  129. getStepELe();
  130. };
  131. const endGuide = () => {
  132. let guideInfo =
  133. JSON.parse(localStorage.getItem('teacher-guideInfo')||'{}') || null;
  134. if (!guideInfo) {
  135. guideInfo = { classGuide: true };
  136. } else {
  137. guideInfo.classGuide = true;
  138. }
  139. localStorage.setItem('teacher-guideInfo', JSON.stringify(guideInfo));
  140. tipShow.value = false;
  141. // localStorage.setItem('endC')
  142. };
  143. return () => (
  144. <>
  145. {tipShow.value ? (
  146. <div
  147. v-model:show={tipShow.value}
  148. class={['n-modal-mask', 'n-modal-mask-guide']}>
  149. <div class={styles.content} onClick={() => handleNext()}>
  150. <div
  151. class={styles.backBtn}
  152. onClick={(e: Event) => {
  153. e.stopPropagation();
  154. endGuide();
  155. }}>
  156. 跳过
  157. </div>
  158. <div
  159. class={styles.box}
  160. style={{...data.box,...data.steps[data.step].boxStyle}}
  161. id={`modeType-${data.step}`}>
  162. {data.steps.map((item: any, index) => (
  163. <div
  164. onClick={(e: Event) => e.stopPropagation()}
  165. class={styles.item}
  166. style={ item.type=='bottom'? {
  167. display: index === data.step ? '' : 'none',
  168. left: `${item.eleRect?.left}px`,
  169. top:`-${item.imgStyle?.height}`
  170. }:{
  171. display: index === data.step ? '' : 'none',
  172. left: `${item.eleRect?.left}px`,
  173. top: `${data.box?.height}`,
  174. }}>
  175. <img
  176. class={styles.img}
  177. style={item.imgStyle}
  178. src={item.img}
  179. />
  180. {/* <img
  181. class={styles.iconHead}
  182. style={item.handStyle}
  183. src={getImage('indexDot.png')}
  184. /> */}
  185. <div class={styles.btns} style={item.btnsStyle}>
  186. {data.step + 1 == data.steps.length ? (
  187. <>
  188. <div
  189. class={[styles.endBtn]}
  190. onClick={() => endGuide()}>
  191. 完成
  192. </div>
  193. <div
  194. class={styles.nextBtn}
  195. onClick={() => {
  196. data.step = 0;
  197. getStepELe();
  198. }}>
  199. 再看一遍
  200. </div>
  201. </>
  202. ) : (
  203. <div class={styles.btn} onClick={() => handleNext()}>
  204. 下一步 ({data.step + 1}/{data.steps.length})
  205. </div>
  206. )}
  207. </div>
  208. </div>
  209. ))}
  210. </div>
  211. </div>
  212. </div>
  213. ) : null}
  214. </>
  215. );
  216. }
  217. });