class-guide.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. import {getGuidance,setGuidance} from './api'
  15. export default defineComponent({
  16. name: 'coai-guide',
  17. emits: ['close'],
  18. setup(props, { emit }) {
  19. const data = reactive({
  20. box: {
  21. height: '0px'
  22. } as any,
  23. show: false,
  24. /**
  25. *
  26. width: px2vw(840),
  27. height: px2vw(295)
  28. */
  29. steps: [
  30. {
  31. ele: '',
  32. eleRect: {} as DOMRect,
  33. img: getImage('class1.png'),
  34. handStyle: {
  35. top: '0.91rem'
  36. },
  37. imgStyle: {
  38. top: px2vw(-4),
  39. left: px2vw(-294),
  40. width: px2vw(648),
  41. height: px2vw(227)
  42. },
  43. btnsStyle: {
  44. bottom: px2vw(30),
  45. left: px2vw(-130)
  46. },
  47. eleRectPadding: {
  48. left: 7,
  49. top: 7,
  50. width: 14,
  51. height: 14
  52. }
  53. },
  54. {
  55. ele: '',
  56. img: getImage('class2.png'),
  57. imgStyle: {
  58. top: px2vw(-4),
  59. left: px2vw(-276),
  60. width: px2vw(515),
  61. height: px2vw(227)
  62. },
  63. btnsStyle: {
  64. bottom: px2vw(30),
  65. left: px2vw(-110)
  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. top: px2vw(-4),
  79. width: px2vw(437),
  80. height: px2vw(227),
  81. left: px2vw(-276)
  82. },
  83. btnsStyle: {
  84. bottom: px2vw(30),
  85. left: px2vw(-113)
  86. },
  87. eleRectPadding: {
  88. left: 7,
  89. top: 7,
  90. width: 14,
  91. height: 14
  92. }
  93. }
  94. ],
  95. step: 0
  96. });
  97. const tipShow = ref(false);
  98. const guideInfo = ref({} as any)
  99. const getAllGuidance = async()=>{
  100. try{
  101. const res = await getGuidance({guideTag:'teacher-guideInfo'})
  102. if(res.data){
  103. guideInfo.value = JSON.parse(res.data?.guideValue) || null
  104. }else{
  105. guideInfo.value = {}
  106. }
  107. if (guideInfo.value && guideInfo.value.classGuide) {
  108. tipShow.value = false;
  109. } else {
  110. tipShow.value = true;
  111. }
  112. }catch(e){
  113. console.log(e)
  114. }
  115. // const guideInfo = localStorage.getItem('teacher-guideInfo');
  116. }
  117. getAllGuidance()
  118. // const guideInfo = localStorage.getItem('teacher-guideInfo');
  119. // if (guideInfo && JSON.parse(guideInfo).classGuide) {
  120. // tipShow.value = false;
  121. // } else {
  122. // tipShow.value = true;
  123. // }
  124. const getStepELe = () => {
  125. const ele: HTMLElement = document.getElementById(`class-${data.step}`)!;
  126. if (ele) {
  127. const eleRect = ele.getBoundingClientRect();
  128. const left = data.steps[data.step].eleRectPadding?.left || 0;
  129. const top = data.steps[data.step].eleRectPadding?.top || 0;
  130. const width = data.steps[data.step].eleRectPadding?.width || 0;
  131. const height = data.steps[data.step].eleRectPadding?.height || 0;
  132. data.box = {
  133. left: eleRect.x - left + 'px',
  134. top: eleRect.y - top + 'px',
  135. width: eleRect.width + width + 'px',
  136. height: eleRect.height + height + 'px'
  137. };
  138. // console.log(`coai-${data.step}`,data.box);
  139. } else {
  140. handleNext();
  141. }
  142. };
  143. onMounted(() => {
  144. getStepELe();
  145. window.addEventListener('resize', resetSize);
  146. });
  147. const resetSize = () => {
  148. getStepELe();
  149. };
  150. onUnmounted(() => {
  151. window.removeEventListener('resize', resetSize);
  152. });
  153. const handleNext = () => {
  154. if (data.step >= 4) {
  155. endGuide();
  156. return;
  157. }
  158. data.step = data.step + 1;
  159. getStepELe();
  160. };
  161. const endGuide = async() => {
  162. if (!guideInfo.value) {
  163. guideInfo.value = { classGuide: true };
  164. } else {
  165. guideInfo.value.classGuide = true;
  166. }
  167. try{
  168. const res = await setGuidance({guideTag:'teacher-guideInfo',guideValue:JSON.stringify(guideInfo.value)})
  169. }catch(e){
  170. console.log(e)
  171. }
  172. tipShow.value = false;
  173. // localStorage.setItem('endC')
  174. };
  175. return () => (
  176. <>
  177. {tipShow.value ? (
  178. <div
  179. v-model:show={tipShow.value}
  180. class={['n-modal-mask', 'n-modal-mask-guide']}>
  181. <div class={styles.content} onClick={() => handleNext()}>
  182. <div
  183. class={styles.backBtn}
  184. onClick={(e: Event) => {
  185. e.stopPropagation();
  186. endGuide();
  187. }}>
  188. 跳过
  189. </div>
  190. <div
  191. class={styles.box}
  192. style={{ ...data.box, ...data.steps[data.step].boxStyle }}
  193. id={`modeType-${data.step}`}>
  194. {data.steps.map((item: any, index) => (
  195. <div
  196. onClick={(e: Event) => e.stopPropagation()}
  197. class={styles.item}
  198. style={
  199. item.type == 'bottom'
  200. ? {
  201. display: index === data.step ? '' : 'none',
  202. left: `${item.eleRect?.left}px`,
  203. top: `-${item.imgStyle?.height}`
  204. }
  205. : {
  206. display: index === data.step ? '' : 'none',
  207. left: `${item.eleRect?.left}px`,
  208. top: `${data.box?.height}`
  209. }
  210. }>
  211. <img
  212. class={styles.img}
  213. style={item.imgStyle}
  214. src={item.img}
  215. />
  216. {/* <img
  217. class={styles.iconHead}
  218. style={item.handStyle}
  219. src={getImage('indexDot.png')}
  220. /> */}
  221. <div class={styles.btns} style={item.btnsStyle}>
  222. {data.step + 1 == data.steps.length ? (
  223. <>
  224. <div
  225. class={[styles.endBtn]}
  226. onClick={() => endGuide()}>
  227. 完成
  228. </div>
  229. <div
  230. class={styles.nextBtn}
  231. onClick={() => {
  232. data.step = 0;
  233. getStepELe();
  234. }}>
  235. 再看一遍
  236. </div>
  237. </>
  238. ) : (
  239. <div class={styles.btn} onClick={() => handleNext()}>
  240. 下一步 ({data.step + 1}/{data.steps.length})
  241. </div>
  242. )}
  243. </div>
  244. </div>
  245. ))}
  246. </div>
  247. </div>
  248. </div>
  249. ) : null}
  250. </>
  251. );
  252. }
  253. });