Commit e88426fd authored by hewenhao's avatar hewenhao

feat: add guide component

parent 0ff79b1d
......@@ -2,7 +2,7 @@
"miniprogramRoot": "dist/",
"projectname": "GeekLearnMathWeapp",
"description": "",
"appid": "wx8f25def587982a19",
"appid": "wx693fe3460124d84b",
"setting": {
"urlCheck": false,
"es6": false,
......
.contentWrap {
border-radius: 16px;
position: absolute;
z-index: 9999998;
opacity: 1;
box-shadow: rgb(33 33 33 / 50%) 0px 0px 0px 5000PX;
}
.content {
width: 100%;
height: 100%;
}
.mask {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: 9999997;
}
import { View, type ViewProps, RootPortal } from '@tarojs/components'
import { type PropsWithChildren, useState, useMemo, useRef, useEffect, type ReactNode } from 'react'
import { createSelectorQuery, usePageScroll } from '@tarojs/taro'
import styles from './index.module.scss'
type UserGuideProps = {
onFinish?: () => void;
isActive?: boolean;
onClickConent?: () => void;
verticalPadding?: number;
horizonPadding?: number;
guideContent?: ReactNode;
}
const UserGuideView = (props: PropsWithChildren<UserGuideProps & ViewProps>) => {
const { isActive, children, guideContent, verticalPadding = 0, horizonPadding = 0, onClickConent, ...rest } = props
const [rect, setRect] = useState({ width: 80, height: 80, top: 0, left: 0 })
const [_isActive, setIsActive] = useState(false)
const scrollRef = useRef(0)
usePageScroll(({ scrollTop }) => {
scrollRef.current = scrollTop
})
useEffect(() => {
if (isActive) {
console.log(domRef.current)
setTimeout(() => {
createSelectorQuery()
.select(`#${domRef.current.uid}`)
.boundingClientRect().exec(([_rect]) => {
console.log(_rect)
setRect({ ..._rect, top: _rect.top + scrollRef.current })
setIsActive(true)
})
}, 1000)
} else {
setIsActive(false)
}
}, [isActive])
const domRef = useRef<any>()
const style = useMemo(() => {
return {
width: `${rect.width + horizonPadding * 2}px`,
height: `${rect.height + verticalPadding * 2}px`,
top: `${rect.top - verticalPadding}px`,
left: `${rect.left - horizonPadding}px`,
}
}, [rect, horizonPadding, verticalPadding])
return (
<>
<View {...rest} ref={domRef}>
{children}
</View>
{_isActive && (
<RootPortal>
<View className={styles.contentWrap} catchMove style={style}>
<View className={styles.content} onClick={onClickConent}>
</View>
{guideContent}
</View>
<View className={styles.mask} catchMove></View>
</RootPortal>
)}
</>
)
}
export default UserGuideView
export { default as EyeProtectionView } from './EyeProtectionView/index'
export { default as EyeProtectionView } from './EyeProtectionView'
export { default as UserGuideView } from './UserGuideView'
import LazeImage from '../lazy-image'
import { type SmallPart, } from './constants'
import RoundComp from './stage'
import StageComp from './stage'
import styles from './small-part.module.scss'
......@@ -26,7 +26,7 @@ const SceneSmallPart = (props: SceneSmallPartProps) => {
<LazeImage source={part.bg}>
{part.stages.map((item, index) => {
return (
<RoundComp stage={item} key={item.id} className={getClassName(index, part.type)} />
<StageComp stage={item} key={item.id} className={getClassName(index, part.type)} />
)
})}
</LazeImage>
......
......@@ -5,7 +5,7 @@ import { cs } from '@/styles'
import { navigateTo } from '@tarojs/taro'
import type { ImageSource } from '@/types'
import { useStoreActions, useStoreState } from '@/store/hooks'
import { UserGuideView } from '@/components'
import { type Stage, StageType, StageStatus, StageLevel, CurrentRoundId } from './constants'
import StageTag from './stage-tag'
......@@ -155,15 +155,21 @@ const StageComp = (props: StageProps) => {
}
return (
<View
<UserGuideView
className={classNames(props.className, cs.bounce_btn)}
hoverClass={cs.bounce_btn_hover}
id={stage.status === StageStatus.CURRENT ? CurrentRoundId : undefined}
onClick={handleClick}
isActive={stage.status === StageStatus.CURRENT}
verticalPadding={15}
horizonPadding={15}
guideContent={(
<View style={{ color: '#ffffff' }}>123123123234234234sdfsdf sdfsdfsdf sdf sdf sdf sdf sdfsd fsd </View>
)}
>
{renderRound(isReady)}
<View className={styles.roundName}>{stage.name}</View>
</View>
</UserGuideView>
)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment