student-guide.tsx 7.0 KB

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