Commit 83123b6f authored by 666's avatar 666

feat: 优化代码

parent 9ea07dd7
......@@ -94,5 +94,29 @@
"w": 750,
"h": 960,
"ossName": "/pk-math/39zMBKhthpUN8JGaLtJ5e1qmnewc/750x960"
},
"arror-bottom-left.png": {
"u": "https://cdn.jkwljy.com/pk-math/21nmtfooeLeoKtMNsHqa2AMinWSi/128x128",
"w": 128,
"h": 128,
"ossName": "/pk-math/21nmtfooeLeoKtMNsHqa2AMinWSi/128x128"
},
"arrow-top-left.png": {
"u": "https://cdn.jkwljy.com/pk-math/3VAxvzEMBNyVZMuwf8hRTWDvgtnC/128x128",
"w": 128,
"h": 128,
"ossName": "/pk-math/3VAxvzEMBNyVZMuwf8hRTWDvgtnC/128x128"
},
"cat-4.png": {
"u": "https://cdn.jkwljy.com/pk-math/3tYeViwvJo7vFGEUsNhaCSfx8G55/300x300",
"w": 300,
"h": 300,
"ossName": "/pk-math/3tYeViwvJo7vFGEUsNhaCSfx8G55/300x300"
},
"cat-5.png": {
"u": "https://cdn.jkwljy.com/pk-math/2kSynNrNPPyZCzys49Bs9yVkqCr/200x300",
"w": 200,
"h": 300,
"ossName": "/pk-math/2kSynNrNPPyZCzys49Bs9yVkqCr/200x300"
}
}
......@@ -80,5 +80,25 @@ export default {
"u": "https://cdn.jkwljy.com/pk-math/39zMBKhthpUN8JGaLtJ5e1qmnewc/750x960",
"w": 750,
"h": 960
},
"arror-bottom-left.png": {
"u": "https://cdn.jkwljy.com/pk-math/21nmtfooeLeoKtMNsHqa2AMinWSi/128x128",
"w": 128,
"h": 128
},
"arrow-top-left.png": {
"u": "https://cdn.jkwljy.com/pk-math/3VAxvzEMBNyVZMuwf8hRTWDvgtnC/128x128",
"w": 128,
"h": 128
},
"cat-4.png": {
"u": "https://cdn.jkwljy.com/pk-math/3tYeViwvJo7vFGEUsNhaCSfx8G55/300x300",
"w": 300,
"h": 300
},
"cat-5.png": {
"u": "https://cdn.jkwljy.com/pk-math/2kSynNrNPPyZCzys49Bs9yVkqCr/200x300",
"w": 200,
"h": 300
}
} as const
......@@ -16,35 +16,14 @@ export const Scene = ({ children }: { children: React.ReactNode }) => {
const stageDetail = useStoreState(state => state.gameModel.stageDetail)
const showMask = useMemo(() => {
return !guideComplete && guideActive
}, [guideComplete, guideActive])
return !guideComplete && guideActive && passStep === 1
}, [guideComplete, guideActive, passStep])
useEffect(() => {
if (!guideComplete) {
updateState({ guideActive: true })
}
}, [guideComplete])
const renderMessage = (step: number) => {
switch (step) {
case 1:
return (
<Text>
哇,你通关了,表现不错哦;你的熟练度,
<Text className={styles.strong}>打败了{stageDetail?.gear || 0}%的同学</Text>
,当然相信你还可以变得更好!
</Text>
)
case 2:
return (
<Text>
想通关,首先要
<Text className={styles.strong}>考验你的准确性</Text>
,粗心大意可是通不了关的哦。
</Text>
)
}
}
}, [guideComplete, updateState])
return (
<UserGuideView
......@@ -53,15 +32,15 @@ export const Scene = ({ children }: { children: React.ReactNode }) => {
isActive={showMask && passStep < 3}
guideContent={(
<View className={styles.guide}>
<Image className={styles.guideCat} src={require('../assets/cat-3.png')} />
<Image className={styles.guideCat} src={tutorialAssets['cat-4.png'].u} />
<View className={styles.guideMain}>
<View className={styles.inner}>
{renderMessage(passStep)}
<View
className={styles.continue}
onClick={() => updateState({ passStep: passStep + 1 })}
>
<Text>继续</Text>
<View className={styles.inner} onClick={() => updateState({ passStep: passStep + 1 })}>
<Text>
哇,你通关了,表现不错哦;你的熟练度,
<Text className={styles.strong}>打败了{stageDetail?.gear || 0}%的同学</Text>
,当然相信你还可以变得更好!
</Text>
<View className={styles.continue}>
<Image style={{ width: 14, height: 14 }} src={tutorialAssets['continue-arrow.png'].u} /></View>
</View>
</View>
......
.wrapperScene2 {
.wrapperScene {
border-radius: 20px;
}
.bordered {
border-radius: 32px;
// padding: 8PX;
border: 2PX dashed #FFFFFF;
}
.guide {
......@@ -44,9 +50,3 @@
}
}
}
\ No newline at end of file
.bordered {
border-radius: 32px;
padding: 8PX;
border: 2PX dashed #FFFFFF;
}
\ No newline at end of file
import { View, Image, Text } from '@tarojs/components'
import { useCallback, useEffect, useMemo } from 'react'
import { pageScrollTo } from '@tarojs/taro'
import tutorialAssets from '@/assets/oss/assets-tutorial'
import UserGuideView from '@/components/UserGuideView'
import classNames from 'classnames'
......@@ -8,139 +9,135 @@ import { useStoreState, useStoreActions } from '@/store/hooks'
import styles from './scene-2.module.scss'
import wrapStyles from '../../components/main-header.module.scss'
export const Scene = ({ children, index }: { index: number, children: React.ReactNode }) => {
const passStep = useStoreState(state => state.prepareModel.passStep)
const guideActive = useStoreState(state => state.prepareModel.guideActive)
const guideComplete = useStoreState(state => state.prepareModel.passGuideComplete)
const updateState = useStoreActions(actions => actions.prepareModel.updateState)
const stageDetail = useStoreState(state => state.gameModel.stageDetail)
const gear = useMemo(() => {
const detail = stageDetail?.nextSteps?.find(step => ['10', '20', '30'].includes(step.nextStep.toString()))
const index1 = stageDetail?.nextSteps?.findIndex(step => ['10', '20', '30'].includes(step.nextStep.toString()))
return {
detail,
index: index1
}
}, [stageDetail?.nextSteps])
const level = useMemo(() => {
const detail = stageDetail?.nextSteps?.find(step => ['S', 'A', 'B'].includes(step.nextStep.toString()))
const index1 = stageDetail?.nextSteps?.findIndex(step => ['S', 'A', 'B'].includes(step.nextStep.toString()))
return {
detail,
index: index1
}
}, [stageDetail?.nextSteps])
const upGear = useMemo(() => {
const detail = stageDetail?.nextSteps?.find(step => step.nextStep === 'upGear')
const index1 = stageDetail?.nextSteps?.findIndex(step => step.nextStep === 'upGear')
const useStepDetails = (stageDetail, targetSteps) => {
return useMemo(() => {
const details = targetSteps
.map(targetStep => {
const detail = stageDetail?.nextSteps?.find(
step => step.nextStep === targetStep
)
const index = stageDetail?.nextSteps?.findIndex(
step => step.nextStep === targetStep
)
return {
detail,
index: index1
}
}, [stageDetail?.nextSteps])
const showMask = useMemo(() => {
// return !guideComplete && guideActive
return true
}, [guideComplete, guideActive])
useEffect(() => {
if (guideComplete !== undefined && guideComplete === false) {
updateState({ guideActive: true })
index,
}
}, [guideComplete])
})
.filter(item => item.detail !== undefined && item.index !== -1)
return details
}, [stageDetail?.nextSteps, targetSteps])
}
const MessageRenderer = ({ step, level, gear, upGear }) => {
const renderMessage = useCallback(() => {
if (level && level.index! + 2 === passStep) {
return (
<Text>
只要你
<Text className={styles.strong}>再提高{level.detail?.nextStepTime}秒</Text>,
就可以达到<Text className={styles.strong}>【{level.detail?.nextStep}级水准】</Text>,了哦,并
<Text className={styles.strong}>获得{level.detail?.nextStepReward}水晶奖励</Text>
。
</Text>
)
}
if (gear && gear.index! + 2 === passStep) {
return (
<Text>
如果你更加熟练,<Text className={styles.strong}>再快{gear.detail?.nextStepTime}秒</Text>
,就说明你到这个技能的顶尖水平了,并
<Text className={styles.strong}>获得象征荣耀的【TOP】(前30%、20%、10%)勋章和水晶奖励</Text>,
。
</Text>
const detailIndexMap = { level, gear, upGear }
const targetStep = Object.keys(detailIndexMap).find(
key => detailIndexMap[key].index + 2 === step
)
if (!targetStep) {
return null
}
if (upGear && upGear.index! + 2 === passStep) {
return (
<Text>
你只要<Text className={styles.strong}>再快{upGear.detail?.nextStepTime}秒</Text>
const { detail } = detailIndexMap[targetStep]
const textTemplate = {
upGear: (
<>
你只要
<Text className={styles.strong}>再快{detail.nextStepTime}秒</Text>
,就可以领先更多同学,提升你的档位,
<Text className={styles.strong}>获得【升档】勋章和{upGear.detail?.nextStepReward}水晶奖励</Text>
<Text className={styles.strong}>
获得【升档】勋章和{detail.nextStepReward}水晶奖励
</Text>
,粗心大意可是通不了关的哦。
</>
),
gear: (
<>
如果你更加熟练,
<Text className={styles.strong}>再快{detail.nextStepTime}秒</Text>
,就说明你到这个技能的顶尖水平了,并
<Text className={styles.strong}>
获得象征荣耀的【TOP】(前30%、20%、10%)勋章和水晶奖励
</Text>
)
。
</>
),
level: (
<>
只要你
<Text className={styles.strong}>再提高{detail.nextStepTime}秒</Text>,
就可以达到
<Text className={styles.strong}>【{detail.nextStep}级水准】</Text>,了哦,并
<Text className={styles.strong}>获得{detail.nextStepReward}水晶奖励</Text>
。
</>
),
}
return null
}, [upGear, gear, passStep])
return <Text>{textTemplate[targetStep]}</Text>
}, [upGear, gear, level, step])
const onClick = () => {
if (level.detail && gear.detail && upGear.detail) {
if (passStep === 4) {
updateState({ passStep: 10 })
return
}
} else if (level.detail && gear.detail) {
if (passStep === 3) {
updateState({ passStep: 10 })
return
}
} else if (level.detail && upGear.detail) {
if (passStep === 3) {
updateState({ passStep: 10 })
return
}
} else if (gear.detail && upGear.detail) {
if (passStep === 3) {
updateState({ passStep: 10 })
return
}
} else if (level.detail) {
if (passStep === 2) {
updateState({ passStep: 10 })
return
}
} else if (gear.detail) {
if (passStep === 2) {
updateState({ passStep: 10 })
return
}
} else if (upGear.detail) {
if (passStep === 2) {
updateState({ passStep: 10 })
return
return renderMessage()
}
export const Scene = ({ children, index }: { index: number, children: React.ReactNode }) => {
const step = useStoreState(state => state.prepareModel.passStep)
const guideActive = useStoreState(state => state.prepareModel.guideActive)
const guideComplete = useStoreState(state => state.prepareModel.passGuideComplete)
const updateState = useStoreActions(actions => actions.prepareModel.updateState)
const stageDetail = useStoreState(state => state.gameModel.stageDetail)
const [level, gear, upGear] = useStepDetails(stageDetail, ['S', 'A', 'B', '10', '20', '30', 'upGear'])
const scrollToBottom = useCallback((scrollTop?: number) => {
pageScrollTo({
duration: 600,
selector: '#guideScrollView',
scrollTop: scrollTop ?? 60,
})
}, [])
const showMask = useMemo(() => {
return !guideComplete && guideActive && step === index
}, [guideComplete, guideActive, step, index])
useEffect(() => {
if (!guideComplete) {
updateState({ guideActive: true })
}
}, [guideComplete, updateState])
const onClick = () => {
const stepDetails = [level, gear, upGear]
const activeSteps = stepDetails.filter(item => item.detail)
const activeStepIndex = activeSteps.length
if (step === activeStepIndex + 1) {
scrollToBottom(0)
setTimeout(() => {
updateState({ passStep: -1 })
}, 666)
} else {
scrollToBottom()
updateState({ passStep: step + 1 })
}
updateState({ passStep: passStep + 1 })
}
return (
<View id="guideScrollView">
<UserGuideView
wrapClass={styles.wrapperScene2}
className={classNames(wrapStyles.againDetail, showMask && passStep === index ? styles.bordered : null)}
isActive={showMask && passStep === index}
horizonPadding={0}
verticalPadding={0}
wrapClass={styles.wrapperScene}
className={classNames(wrapStyles.againDetail, showMask ? styles.bordered : null)}
isActive={showMask}
guideContent={(
<View className={styles.guide}>
<Image className={styles.guideCat} src={require('../assets/cat-4.png')} />
<Image className={styles.guideCat} src={tutorialAssets['cat.png'].u} />
<View className={styles.guideMain}>
<View className={styles.inner} onClick={onClick}>
{renderMessage()}
<MessageRenderer step={step} level={level} gear={gear} upGear={upGear} />
<View className={styles.continue}>
<Text>继续</Text>
<Image style={{ width: 14, height: 14 }} src={tutorialAssets['continue-arrow.png'].u} /></View>
......@@ -151,6 +148,7 @@ export const Scene = ({ children, index }: { index: number, children: React.Reac
>
{children}
</UserGuideView>
</View>
)
}
......
......@@ -20,16 +20,31 @@
top: -100px;
left: 20px;
@keyframes arrowAnimation {
0% {
transform: translate(0, 0) rotate(0);
}
50% {
transform: translate(16px, 16px) rotate(0);
}
100% {
transform: translate(0, 0) rotate(0);
}
}
.tutorialArrow {
width: 128px;
height: 128px;
margin-right: 30px;
position: relative;
left: 130px;
animation: arrowAnimation 1.6s linear infinite;
}
.text {
width: 400px;
line-height: 1.6;
margin: 40px 0 0 40px;
}
}
}
......
......@@ -3,19 +3,20 @@ import { useMemo } from 'react'
import UserGuideView from '@/components/UserGuideView'
import classNames from 'classnames'
import { useStoreState, useStoreActions } from '@/store/hooks'
import tutorialAssets from '@/assets/oss/assets-tutorial'
import styles from './scene-3.module.scss'
import wrapStyles from '../../components/top-bar.module.scss'
export const Scene = ({ children, onClickConent }: { onClickConent: () => void, children: React.ReactNode }) => {
const passStep = useStoreState(state => state.prepareModel.passStep)
const step = useStoreState(state => state.prepareModel.passStep)
const guideActive = useStoreState(state => state.prepareModel.guideActive)
const guideComplete = useStoreState(state => state.prepareModel.passGuideComplete)
const completePassGuide = useStoreActions(actions => actions.prepareModel.completePassGuide)
const showMask = useMemo(() => {
return !guideComplete && guideActive && passStep === 10
}, [guideComplete, guideActive])
return !guideComplete && guideActive && step === -1
}, [guideComplete, guideActive, step])
const handleCompleteGuide = async () => {
await completePassGuide()
......@@ -30,10 +31,10 @@ export const Scene = ({ children, onClickConent }: { onClickConent: () => void,
onClickConent={handleCompleteGuide}
guideContent={(
<View className={styles.guide}>
<Image className={styles.guideCat} src={require('../assets/cat-5.png')} />
<Image className={styles.guideCat} src={tutorialAssets['cat-3.png'].u} />
<View className={styles.guideMain}>
<View className={styles.tutorialFailInner}>
<Image src={require('../assets/arrow-top-left.png')} className={styles.tutorialArrow} />
<Image src={tutorialAssets['arrow-top-left.png'].u} className={styles.tutorialArrow} />
<View className={styles.text}>对了,水晶有什么用呢?我来介绍一下。</View>
</View>
</View>
......
......@@ -36,32 +36,33 @@ export const Scene = ({ children }: { children: React.ReactNode }) => {
const updateState = useStoreActions(actions => actions.prepareModel.updateState)
const showMask = useMemo(() => {
return !guideComplete && guideActive
}, [guideComplete, guideActive])
return !guideComplete && guideActive && step < 3
}, [guideComplete, guideActive, step])
useEffect(() => {
if (guideComplete !== undefined && guideComplete === false) {
if (!guideComplete) {
updateState({ guideActive: true })
}
}, [guideComplete])
}, [guideComplete, updateState])
return (
<UserGuideView
wrapClass={styles.wrapper}
className={classNames(wrapStyles.againDetails, showMask ? styles.bordered : null)}
isActive={showMask && step < 3}
isActive={showMask}
guideContent={(
<View className={styles.top}>
<Image style={{ width: 100, height: 110 }} src={require('../assets/cat-1.png')} />
<Image style={{ width: 100, height: 110 }} src={tutorialAssets['cat-2.png'].u} />
<View className={styles.content}>
<View className={styles.inner}>
{renderMessage(step)}
<View
className={styles.continue}
className={styles.inner}
onClick={() => updateState({
step: step + 1
})}
})
}
>
{renderMessage(step)}
<View className={styles.continue}>
<Text>继续</Text>
<Image style={{ width: 14, height: 14 }} src={tutorialAssets['continue-arrow.png'].u} /></View>
</View>
......
......@@ -321,11 +321,24 @@
display: flex;
flex-direction: column;
@keyframes arrowAnimation {
0% {
transform: translate(0, 0) rotate(0);
}
50% {
transform: translate(-16px, 16px) rotate(0);
}
100% {
transform: translate(0, 0) rotate(0);
}
}
&_arrow {
margin-top: 18px;
margin-left: 50px;
width: 128px;
height: 128px;
animation: arrowAnimation 1.6s linear infinite;
}
}
......
......@@ -15,6 +15,7 @@ import assetsGroup from '@/assets/oss/assets-group'
import { palyAudio } from '@/utils/play-audio'
import audio from '@/assets/oss/assets-audio'
import { EyeProtectionView } from '@/components'
import tutorialAssets from '@/assets/oss/assets-tutorial'
import Tabs, { type TabItem } from './components/tabs'
import TopBar from './components/top-bar'
......@@ -36,6 +37,7 @@ const Prepare = () => {
const cardNum = useStoreState(state => state.userModel.cardNum)
const point = useStoreState(state => state.userModel.point)
const userInfo = useStoreState(state => state.userModel.userInfo)
// const isSubmit = true
const isSubmit = useStoreState(state => state.gameModel.isSubmit)
const tribeInfo = useStoreState(state => state.groupModel.tribeInfo)
const stageList = useStoreState(state => state.mainModel.stageList)
......@@ -109,7 +111,7 @@ const Prepare = () => {
!guideComplete && await completeGuide()
/** 首次闯关失败引导完成 */
!failGuideComplete && await completeFailGuide()
isSubmit && !failGuideComplete && await completeFailGuide()
if (cardNum < 1 && !stageDetail?.firstTime) {
setTrue()
......@@ -131,6 +133,7 @@ const Prepare = () => {
const guideActive = useStoreState(state => state.prepareModel.guideActive)
const updateGuideState = useStoreActions(actions => actions.prepareModel.updateState)
/** 显示首次闯关引导开始闯关按钮 */
const showMask = useMemo(() => {
return step === 3 && guideActive && !guideComplete
}, [step, guideActive, guideComplete])
......@@ -140,7 +143,7 @@ const Prepare = () => {
{showMask && <View className={styles.mask}></View>}
{showMask && <View className={styles.tutorial}>
<Text>让我们开始试试吧!</Text>
<Image src={require('./guide/assets/arrow.png')} className={styles.tutorial_arrow}></Image>
<Image src={tutorialAssets['arror-bottom-left.png'].u} className={styles.tutorial_arrow}></Image>
</View>}
<View className={classNames(styles.challenge, showMask ? styles.maskWrap : null)}>
<Button size="large" onClick={handleClick} image={styles.image} hoverImage={styles.hover_image}>
......@@ -183,20 +186,20 @@ const Prepare = () => {
guideActive: true
})
}
}, [guideActive, isSubmit, failGuideComplete, stageDetail?.level, stageDetail?.firstTime])
}, [isSubmit, failGuideComplete, stageDetail?.level, stageDetail?.firstTime, updateGuideState])
const showFailMask = useMemo(() => {
return guideActive && !failGuideComplete && isSubmit && !hasNextBtn
}, [guideActive, failGuideComplete, hasNextBtn])
}, [guideActive, failGuideComplete, hasNextBtn, isSubmit])
const renderAgainActions = () => (
<View>
{showFailMask && <View className={styles.mask}></View>}
{showFailMask && <View className={classNames(styles.tutorial, styles.tutorialFail)}>
<Image className={styles.failGuideCat} src={require('./guide/assets/cat-2.png')} />
<Image className={styles.failGuideCat} src={tutorialAssets['cat-5.png'].u} />
<View className={styles.tutorialFailInner}>
<Text>嗯,说明这个技能还需要提高哦。我们再来一次吧!</Text>
<Image src={require('./guide/assets/arrow.png')} className={styles.tutorial_arrow}></Image>
<Image src={tutorialAssets['arror-bottom-left.png'].u} className={styles.tutorial_arrow}></Image>
</View>
</View>}
......
......@@ -30,7 +30,7 @@ const prepareModel: PrepareModel = {
guideActive: false,
guideComplete: getStorage(StorageKeys.prepareGuideComplete),
failGuideComplete: getStorage(StorageKeys.prepareFailGuideComplete),
passGuideComplete: getStorage(StorageKeys.prepareFailGuideComplete),
passGuideComplete: getStorage(StorageKeys.preparePassGuideComplete),
updateState: action((state, payload) => {
for (const k in payload) {
......
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