import { NButton } from 'naive-ui'; import { defineComponent, nextTick, onMounted, onUnmounted, reactive, ref, watch } from 'vue'; import styles from './index.module.less'; import { getImage } from './images'; import {px2vw,px2vwH} from '@/utils/index' export default defineComponent({ name: 'coai-guide', emits: ['close'], setup(props, { emit }) { const data = reactive({ box: { height:'0px', } as any, show: false, /** * width: px2vw(840), height: px2vw(295) left: '-80px', width: '518px', height: '256px' */ steps: [ { ele: '', eleRect: {} as DOMRect, img: getImage('student1.png'), handStyle: { top: '0.91rem' }, imgStyle: { top:px2vw(-4), left: px2vw(-64), width: px2vw(518), height: px2vw(256) }, btnsStyle: { bottom: px2vw(30), left: px2vw(-74), }, eleRectPadding:{ left:7, top:7, width:14, height:14 } }, { ele: '', img: getImage('student2.png'), imgStyle: { top: px2vw(-4), left: px2vw(-261), width: px2vw(515), height:px2vw(227) }, btnsStyle: { bottom:px2vw(30), left: px2vw(-120), }, eleRectPadding:{ left:7, top:7, width:14, height:14 } }, ], step: 0 }); const tipShow = ref(false); const guideInfo = localStorage.getItem('teacher-guideInfo'); if (guideInfo && JSON.parse(guideInfo).studentGuide) { tipShow.value = false; } else { tipShow.value = true; } const getStepELe = () => { const ele: HTMLElement = document.getElementById(`student-${data.step}`)!; if (ele) { const eleRect = ele.getBoundingClientRect(); const left = data.steps[data.step].eleRectPadding?.left || 0; const top = data.steps[data.step].eleRectPadding?.top || 0; const width = data.steps[data.step].eleRectPadding?.width || 0; const height = data.steps[data.step].eleRectPadding?.height || 0 data.box = { left: eleRect.x - left+ 'px', top: eleRect.y - top +'px', width: eleRect.width + width+'px', height: eleRect.height +height+ 'px' }; console.log(`coai-${data.step}`,data.box); }else{ handleNext() } }; onMounted(() => { getStepELe(); window.addEventListener("resize", resetSize); }); const resetSize = ()=>{ getStepELe(); } onUnmounted(()=>{ window.removeEventListener("resize", resetSize); }) const handleNext = () => { if (data.step >= 2) { endGuide(); return; } data.step = data.step + 1; getStepELe(); }; const endGuide = () => { let guideInfo = JSON.parse(localStorage.getItem('teacher-guideInfo') || '{}') || null; if (!guideInfo) { guideInfo = { studentGuide: true }; } else { guideInfo.studentGuide = true; } localStorage.setItem('teacher-guideInfo', JSON.stringify(guideInfo)); tipShow.value = false; // localStorage.setItem('endC') }; return () => ( <> {tipShow.value ? (
handleNext()}>
{ e.stopPropagation(); endGuide(); }}> 跳过
{data.steps.map((item: any, index) => (
e.stopPropagation()} class={styles.item} style={ item.type=='bottom'? { display: index === data.step ? '' : 'none', left: `${item.eleRect?.left}px`, top:`-${item.imgStyle?.height}` }:{ display: index === data.step ? '' : 'none', left: `${item.eleRect?.left}px`, top: `${data.box?.height}`, }}> {/* */}
{data.step + 1 == data.steps.length ? ( <>
endGuide()}> 完成
{ data.step = 0; getStepELe(); }}> 再看一遍
) : (
handleNext()}> 下一步 ({data.step + 1}/{data.steps.length})
)}
))}
) : null} ); } });