import { Button, Popup } from "vant"; import { } from "vant"; import { defineComponent, nextTick, onMounted, onUnmounted, reactive, ref, watch } from "vue"; import styles from "./index.module.less"; import { getImage } from "./images"; import { useRect } from "@vant/use"; export default defineComponent({ name: "woring", emits: ["close"], setup(props, { emit }) { const data = reactive({ box: {height:''} as any, show: false, steps: [ { ele: "", eleRect: {} as DOMRect, img: getImage("woring1.png"), handStyle: { // top: "2.98rem", left:'4.5rem' }, // imgStyle: { // width:'5.46rem', // height:'2.6rem', // top: "1.2rem", // left:'2.1rem' // }, imgStyle: { width:'8.19rem', height:'3.9rem', top: "0.6rem", left:'0.8rem' }, btnsStyle: { top: "5.2rem", left:'3.5rem', }, // boxStyle:{ // transform: 'scale(1)' // }, type:'bottom' }, { ele: "", eleRect: {} as DOMRect, img: getImage("woring2.png"), handStyle: { // top: "2.98rem", left:'4.5rem' }, imgStyle: { width:'8.19rem', height:'3.9rem', top: "0.6rem", left:'0.8rem' }, btnsStyle: { top: "5.2rem", left:'3.5rem' }, // boxStyle:{ // transform: 'scale(1)' // }, type:'bottom' }, { ele: "", img: getImage("woring3.png"), handStyle: { top: "-1.39rem", left:'4.5rem', transform: 'rotate(180deg)' }, imgStyle: { width:'8.19rem', height:'3.9rem', top: "-7.4rem", left:'0.8rem' }, btnsStyle: { top: "-2.6rem", left:'2.11rem', }, // boxStyle:{ // transform: 'scale(1)' // }, }, ], step: 0, }); const tipShow = ref(false) const isPad = ref(true) const getStepELe = () => { const ele: HTMLElement = document.getElementById(`woring-${data.step}`)!; if (ele) { const eleRect = ele.getBoundingClientRect(); data.box = { left: eleRect.x + "px", top: eleRect.y + "px", width: eleRect.width + "px", height: eleRect.height + "px", }; console.log(data.box?.height) }else{ handleNext() } }; onMounted(() => { setTimeout(()=>{ const guideInfo = localStorage.getItem('guideInfo') if(guideInfo&&JSON.parse(guideInfo).woring){ tipShow.value =false }else { tipShow.value =true } var docEl = document.documentElement; var clientWidth = docEl.clientWidth; if(clientWidth>750){ console.log('PAD') isPad.value = true; }else{ isPad.value = false; console.log('PHONE') } getStepELe(); },500) window.addEventListener("resize", resetSize); }); const resetSize = ()=>{ getStepELe(); } onUnmounted(()=>{ window.removeEventListener("resize", resetSize); }) const handleNext = () => { if (data.step >= 3) { endGuide(); return; } data.step = data.step + 1; getStepELe(); }; const endGuide = ()=>{ let guideInfo = JSON.parse(localStorage.getItem('guideInfo') || '{}') if(!guideInfo){ guideInfo = {woring:true} }else{ guideInfo.woring = true } localStorage.setItem('guideInfo',JSON.stringify(guideInfo)) tipShow.value = false // localStorage.setItem('endC') } return () => (
handleNext()}> {data.step!=data.steps.length-1&&
{ e.stopPropagation(); endGuide() }} > 跳过
}
{data.steps.map((item: any, index) => ( // top: `${item.imgStyle?.height}` top: `${item.eleRect?.top}px`,
e.stopPropagation()} class={styles.item} style={ item.type == 'bottom'?{ display: index === data.step ? '' : 'none', left: `${item.eleRect?.left}px`, top: `${data.box?.height}`, }:{ display: index === data.step ? "" : "none", left: `${item.eleRect?.left}px`, top: `${item.eleRect?.top}px`, }} >
{data.step + 1 == data.steps.length ? ( <> ) : ( )}
))}
); }, });