student-guide.tsx 5.9 KB

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