|
@@ -1,7 +1,6 @@
|
|
-import { Button, Popup } from 'vant'
|
|
|
|
|
|
+import { Button } from 'vant'
|
|
import {} from 'vant'
|
|
import {} from 'vant'
|
|
import { defineComponent, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
|
import { defineComponent, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
|
-import state from '/src/pages/detail/state'
|
|
|
|
import styles from './index.module.less'
|
|
import styles from './index.module.less'
|
|
import { getImage } from './images'
|
|
import { getImage } from './images'
|
|
|
|
|
|
@@ -9,150 +8,145 @@ export default defineComponent({
|
|
name: 'tips-tip1',
|
|
name: 'tips-tip1',
|
|
emits: ['hanldeStop'],
|
|
emits: ['hanldeStop'],
|
|
setup(props, { emit }) {
|
|
setup(props, { emit }) {
|
|
- const steps = [
|
|
|
|
- {
|
|
|
|
- img: getImage('step0.png'),
|
|
|
|
- btnsStyle: {
|
|
|
|
- top: '-2.13333rem',
|
|
|
|
- },
|
|
|
|
- handStyle: {
|
|
|
|
- top: '-0.42667rem',
|
|
|
|
- },
|
|
|
|
- imgStyle: {
|
|
|
|
- top: '-2.4rem',
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- img: getImage('step1.png'),
|
|
|
|
- btnsStyle: {
|
|
|
|
- top: '-2.2rem',
|
|
|
|
- },
|
|
|
|
- handStyle: {
|
|
|
|
- top: '-0.42667rem',
|
|
|
|
- },
|
|
|
|
- imgStyle: {
|
|
|
|
- top: '-2.4rem',
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- img: getImage('step2.png'),
|
|
|
|
- btnsStyle: {
|
|
|
|
- top: '-0.7rem',
|
|
|
|
- left: '-2.5rem',
|
|
|
|
- 'justify-content': 'space-evenly',
|
|
|
|
- padding: 0,
|
|
|
|
- },
|
|
|
|
- handStyle: {
|
|
|
|
- top: '-0.42667rem',
|
|
|
|
- },
|
|
|
|
- imgStyle: {
|
|
|
|
- top: '-2.7rem',
|
|
|
|
- left: '-2.3rem',
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- ]
|
|
|
|
const contentRef = ref<HTMLElement>()
|
|
const contentRef = ref<HTMLElement>()
|
|
const data = reactive({
|
|
const data = reactive({
|
|
show: false,
|
|
show: false,
|
|
|
|
+ steps: [
|
|
|
|
+ {
|
|
|
|
+ ele: '',
|
|
|
|
+ eleRect: {} as DOMRect,
|
|
|
|
+ img: getImage('step0.png'),
|
|
|
|
+ btnsStyle: {
|
|
|
|
+ top: '-2.13333rem',
|
|
|
|
+ },
|
|
|
|
+ handStyle: {
|
|
|
|
+ top: '-0.42667rem',
|
|
|
|
+ },
|
|
|
|
+ imgStyle: {
|
|
|
|
+ top: '-2.4rem',
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ ele: '',
|
|
|
|
+ img: getImage('step1.png'),
|
|
|
|
+ btnsStyle: {
|
|
|
|
+ top: '-2.2rem',
|
|
|
|
+ },
|
|
|
|
+ handStyle: {
|
|
|
|
+ top: '-0.42667rem',
|
|
|
|
+ },
|
|
|
|
+ imgStyle: {
|
|
|
|
+ top: '-2.4rem',
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ ele: '',
|
|
|
|
+ img: getImage('step2.png'),
|
|
|
|
+ btnsStyle: {
|
|
|
|
+ top: '-0.7rem',
|
|
|
|
+ left: '-2.5rem',
|
|
|
|
+ 'justify-content': 'space-evenly',
|
|
|
|
+ padding: 0,
|
|
|
|
+ },
|
|
|
|
+ handStyle: {
|
|
|
|
+ top: '-0.42667rem',
|
|
|
|
+ },
|
|
|
|
+ imgStyle: {
|
|
|
|
+ top: '-2.7rem',
|
|
|
|
+ left: '-2.3rem',
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
step: 0,
|
|
step: 0,
|
|
- rect: {} as any,
|
|
|
|
})
|
|
})
|
|
- // 开始引导
|
|
|
|
- const handleStart = () => {
|
|
|
|
- getEle()
|
|
|
|
|
|
+
|
|
|
|
+ const getStepELe = () => {
|
|
|
|
+ for (let i = 0; i < data.steps.length; i++) {
|
|
|
|
+ const ele: HTMLElement = document.querySelector(`[data-step='step${i}']`)!
|
|
|
|
+ if (ele) {
|
|
|
|
+ const eleNode: any = ele.cloneNode(true)
|
|
|
|
+ const eleRect = ele.getBoundingClientRect()
|
|
|
|
+ const parentElement = document.createElement('div')
|
|
|
|
+ parentElement.classList.add(styles.parent)
|
|
|
|
+ parentElement.style.left = eleRect?.left - 10 + 'px'
|
|
|
|
+ parentElement.style.top = eleRect?.top - 10 + 'px'
|
|
|
|
+ parentElement.style.width = eleRect?.width + 20 + 'px'
|
|
|
|
+ parentElement.style.height = eleRect?.height + 20 + 'px'
|
|
|
|
+ parentElement.appendChild(eleNode)
|
|
|
|
+ data.steps[i].ele = parentElement.outerHTML
|
|
|
|
+ data.steps[i].eleRect = eleRect
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // console.log(data.steps)
|
|
}
|
|
}
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
- handleStart()
|
|
|
|
|
|
+ getStepELe()
|
|
})
|
|
})
|
|
- // 移除之前的
|
|
|
|
- const hanldeRemove = () => {
|
|
|
|
- const nodes = document.querySelectorAll(`.${styles.parent}`)
|
|
|
|
- for (let n of nodes) {
|
|
|
|
- n.remove()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- /**
|
|
|
|
- * 获取需要引导的元素的位置大小
|
|
|
|
- */
|
|
|
|
- const getEle = () => {
|
|
|
|
- hanldeRemove()
|
|
|
|
- const ele = document.querySelector(`[data-step='step${data.step}']`)
|
|
|
|
- const eleRect = ele?.getBoundingClientRect()
|
|
|
|
- const eleNode: any = ele?.cloneNode(true)
|
|
|
|
- if (ele && eleRect) {
|
|
|
|
- const parentElement = document.createElement('div')
|
|
|
|
- parentElement.classList.add(styles.parent)
|
|
|
|
- parentElement.style.left = eleRect?.left - 10 + 'px'
|
|
|
|
- parentElement.style.top = eleRect?.top - 10 + 'px'
|
|
|
|
- parentElement.style.width = eleRect?.width + 20 + 'px'
|
|
|
|
- parentElement.style.height = eleRect?.height + 20 + 'px'
|
|
|
|
- parentElement.onclick = (e: Event) => e.stopPropagation()
|
|
|
|
- data.rect = eleRect || {}
|
|
|
|
- parentElement.appendChild(eleNode)
|
|
|
|
- contentRef.value?.append(parentElement)
|
|
|
|
- // console.log('🚀 ~ eleRect', contentRef.value, eleRect, `[data-step='step${data.step}']`)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
const handleNext = (step?: number) => {
|
|
const handleNext = (step?: number) => {
|
|
if (step !== undefined) {
|
|
if (step !== undefined) {
|
|
data.step = step
|
|
data.step = step
|
|
} else {
|
|
} else {
|
|
- if (data.step + 1 >= steps.length) {
|
|
|
|
|
|
+ if (data.step + 1 >= data.steps.length) {
|
|
handleStop()
|
|
handleStop()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
data.step += 1
|
|
data.step += 1
|
|
}
|
|
}
|
|
-
|
|
|
|
- getEle()
|
|
|
|
}
|
|
}
|
|
const handleStop = () => {
|
|
const handleStop = () => {
|
|
emit('hanldeStop')
|
|
emit('hanldeStop')
|
|
}
|
|
}
|
|
- return () => {
|
|
|
|
- const item = steps[data.step]
|
|
|
|
- return (
|
|
|
|
- <div class={styles.content} ref={contentRef} onClick={() => handleNext()}>
|
|
|
|
- <div class={styles.backBtn} onClick={() => handleStop()}>
|
|
|
|
- 跳过引导
|
|
|
|
- </div>
|
|
|
|
- <div
|
|
|
|
- onClick={(e: Event) => e.stopPropagation()}
|
|
|
|
- class={styles.item}
|
|
|
|
- style={{
|
|
|
|
- left: `${data.rect?.left}px`,
|
|
|
|
- top: `${data.rect?.top}px`,
|
|
|
|
- }}
|
|
|
|
- >
|
|
|
|
- <img class={styles.img} style={item.imgStyle} src={item.img} />
|
|
|
|
- <img class={styles.iconHead} style={item.handStyle} src={getImage('icon-header.png')} />
|
|
|
|
- <div class={styles.btns} style={item.btnsStyle}>
|
|
|
|
- {data.step + 1 == steps.length ? (
|
|
|
|
- <>
|
|
|
|
- <Button
|
|
|
|
- class={styles.btn}
|
|
|
|
- round
|
|
|
|
- color="transparent"
|
|
|
|
- style={{ 'border-color': '#fff' }}
|
|
|
|
- type="primary"
|
|
|
|
- onClick={() => handleNext(0)}
|
|
|
|
- >
|
|
|
|
- 再看一遍
|
|
|
|
- </Button>
|
|
|
|
- <Button class={styles.btn} round type="primary" onClick={() => handleStop()}>
|
|
|
|
- 完成
|
|
|
|
|
|
+ return () => (
|
|
|
|
+ <div class={styles.content} ref={contentRef} onClick={() => handleNext()}>
|
|
|
|
+ <div
|
|
|
|
+ class={styles.backBtn}
|
|
|
|
+ onClick={(e: Event) => {
|
|
|
|
+ e.stopPropagation()
|
|
|
|
+ handleStop()
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ 跳过引导
|
|
|
|
+ </div>
|
|
|
|
+ {data.steps.map((item: any, index) => (
|
|
|
|
+ <div style={{ display: index === data.step ? 'block' : 'none' }} onClick={(e: Event) => e.stopPropagation()}>
|
|
|
|
+ <div
|
|
|
|
+ class={styles.item}
|
|
|
|
+ style={{
|
|
|
|
+ left: `${item.eleRect?.left}px`,
|
|
|
|
+ top: `${item.eleRect?.top}px`,
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ <img class={styles.img} style={item.imgStyle} src={item.img} />
|
|
|
|
+ <img class={styles.iconHead} style={item.handStyle} src={getImage('icon-header.png')} />
|
|
|
|
+ <div class={styles.btns} style={item.btnsStyle}>
|
|
|
|
+ {data.step + 1 == data.steps.length ? (
|
|
|
|
+ <>
|
|
|
|
+ <Button
|
|
|
|
+ class={styles.btn}
|
|
|
|
+ round
|
|
|
|
+ color="transparent"
|
|
|
|
+ style={{ 'border-color': '#fff' }}
|
|
|
|
+ type="primary"
|
|
|
|
+ onClick={() => handleNext(0)}
|
|
|
|
+ >
|
|
|
|
+ 再看一遍
|
|
|
|
+ </Button>
|
|
|
|
+ <Button class={styles.btn} round type="primary" onClick={() => handleStop()}>
|
|
|
|
+ 完成
|
|
|
|
+ </Button>
|
|
|
|
+ </>
|
|
|
|
+ ) : (
|
|
|
|
+ <Button class={styles.btn} round type="primary" onClick={() => handleNext()}>
|
|
|
|
+ 下一步 ({data.step + 1}/{data.steps.length})
|
|
</Button>
|
|
</Button>
|
|
- </>
|
|
|
|
- ) : (
|
|
|
|
- <Button class={styles.btn} round type="primary" onClick={() => handleNext()}>
|
|
|
|
- 下一步 ({data.step + 1}/{steps.length})
|
|
|
|
- </Button>
|
|
|
|
- )}
|
|
|
|
|
|
+ )}
|
|
|
|
+ </div>
|
|
</div>
|
|
</div>
|
|
|
|
+ <div innerHTML={item.ele}></div>
|
|
</div>
|
|
</div>
|
|
- </div>
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
|
|
+ ))}
|
|
|
|
+ </div>
|
|
|
|
+ )
|
|
},
|
|
},
|
|
})
|
|
})
|