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} from '@/utils/index' import {getGuidance,setGuidance} from './api' export default defineComponent({ name: 'shareResources-guide', emits: ['close'], setup(props, { emit }) { const data = reactive({ box: { height:'0px', } as any, show: false, /** * width: px2vw(840), height: px2vw(295) */ steps: [ { ele: '', eleRect: {} as DOMRect, img: getImage('shareResources1.png'), handStyle: { top: '0.91rem' }, imgStyle: { top: px2vw(-4), left: px2vw(-263), width: px2vw(553), height: px2vw(229) }, btnsStyle: { bottom:px2vw(30), left: px2vw(-102), }, eleRectPadding:{ left:14, top:14, width:28, height:28 }, boxStyle:{ borderRadius: '30px', }, }, { ele: '', img: getImage('shareResources2.png'), imgStyle: { left: px2vw(99), width: px2vw(618), height:px2vw(273) }, btnsStyle: { bottom: px2vw(88), left: px2vw(240), }, eleRectPadding:{ left:7, top:7, width:14, height:14 }, boxStyle:{ borderRadius: '15px' }, type:'bottom' }, ], step: 0 }); const tipShow = ref(false); const guideInfo = ref({} as any) const getAllGuidance = async()=>{ try{ const res = await getGuidance({guideTag:'teacher-guideInfo'}) guideInfo.value = JSON.parse(res.data?.guideValue) if (guideInfo.value && guideInfo.value.shareResourcesGuide) { tipShow.value = false; } else { tipShow.value = true; } }catch(e){ console.log(e) } // const guideInfo = localStorage.getItem('teacher-guideInfo'); } getAllGuidance() // const guideInfo = localStorage.getItem('teacher-guideInfo'); // if (guideInfo && JSON.parse(guideInfo).shareResourcesGuide) { // tipShow.value = false; // } else { // tipShow.value = true; // } const getStepELe = () => { const ele: HTMLElement = document.getElementById(`shareResources-${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 if(`shareResources-${data.step}`=='shareResources-1'){ data.box = { left: eleRect.x - left+ 'px', top: eleRect.y - top +'px', width: (eleRect.width + width)*2+width+'px', height: eleRect.height +height+ 'px' }; console.log( data.box.width,'---',eleRect.width) }else{ 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 >= 4) { endGuide(); return; } data.step = data.step + 1; getStepELe(); }; const endGuide = async() => { // let guideInfo = // JSON.parse(localStorage.getItem('teacher-guideInfo')||'{}') || null; if (!guideInfo.value) { guideInfo.value = { shareResourcesGuide: true }; } else { guideInfo.value.shareResourcesGuide = true; } localStorage.setItem('teacher-guideInfo', JSON.stringify(guideInfo)); tipShow.value = false; // localStorage.setItem('endC') }; return () => ( <> {tipShow.value ? (