Commit 7c18cb1e authored by hewenhao's avatar hewenhao

feat: 发起PK

parent 3dea30a8
......@@ -10,5 +10,47 @@
"w": 80,
"h": 80,
"ossName": "/pk-math/3rh5MFpZF96fZE91zu7G1dcjdnsX/80x80"
},
"pk-fail-left.png": {
"u": "https://cdn.jkwljy.com/pk-math/4HKPvzCid6i65r3KFKMsG6fUQoPW/390x372",
"w": 390,
"h": 372,
"ossName": "/pk-math/4HKPvzCid6i65r3KFKMsG6fUQoPW/390x372"
},
"pk-fail-right.png": {
"u": "https://cdn.jkwljy.com/pk-math/3o3ESnEoAoPvNauDuLxjPPGmoyRv/390x372",
"w": 390,
"h": 372,
"ossName": "/pk-math/3o3ESnEoAoPvNauDuLxjPPGmoyRv/390x372"
},
"pk-fail.png": {
"u": "https://cdn.jkwljy.com/pk-math/o67P39ZoFCqbsKQMLoF5MHfrN8m/520x460",
"w": 520,
"h": 460,
"ossName": "/pk-math/o67P39ZoFCqbsKQMLoF5MHfrN8m/520x460"
},
"pk-success-left.png": {
"u": "https://cdn.jkwljy.com/pk-math/kPpvGxHFYGFh5V8cU56WBDuHH3c/390x372",
"w": 390,
"h": 372,
"ossName": "/pk-math/kPpvGxHFYGFh5V8cU56WBDuHH3c/390x372"
},
"pk-success-right.png": {
"u": "https://cdn.jkwljy.com/pk-math/WXobLoPkgcg1iRqdaoDYhgzPvFF/390x372",
"w": 390,
"h": 372,
"ossName": "/pk-math/WXobLoPkgcg1iRqdaoDYhgzPvFF/390x372"
},
"pk-success.png": {
"u": "https://cdn.jkwljy.com/pk-math/4MEYpXTDweEFKUg4noHtZkoTeP2U/520x460",
"w": 520,
"h": 460,
"ossName": "/pk-math/4MEYpXTDweEFKUg4noHtZkoTeP2U/520x460"
},
"btn_bg.png": {
"u": "https://cdn.jkwljy.com/pk-math/3k3He53c4T1SHnmWtit4JSbPtYgu/348x116",
"w": 348,
"h": 116,
"ossName": "/pk-math/3k3He53c4T1SHnmWtit4JSbPtYgu/348x116"
}
}
......@@ -28,7 +28,7 @@ export const enum StageType {
Strong = '强化',
Enhance = '练习',
OneStop = '一战到底',
Special = '奖励关卡'
Special = '挑战'
}
export const enum StageGear {
......@@ -57,6 +57,11 @@ export interface Stage {
type?: StageType;
upGear: boolean;
part?: number;
/** pk负 */
pkLoseNum: number | null;
/** pk胜场 */
pkWinNum: number | null;
}
export type StageRank = {
......
......@@ -10,5 +10,40 @@ export default {
"u": "https://cdn.jkwljy.com/pk-math/3rh5MFpZF96fZE91zu7G1dcjdnsX/80x80",
"w": 80,
"h": 80
},
"pk-fail-left.png": {
"u": "https://cdn.jkwljy.com/pk-math/4HKPvzCid6i65r3KFKMsG6fUQoPW/390x372",
"w": 390,
"h": 372
},
"pk-fail-right.png": {
"u": "https://cdn.jkwljy.com/pk-math/3o3ESnEoAoPvNauDuLxjPPGmoyRv/390x372",
"w": 390,
"h": 372
},
"pk-fail.png": {
"u": "https://cdn.jkwljy.com/pk-math/o67P39ZoFCqbsKQMLoF5MHfrN8m/520x460",
"w": 520,
"h": 460
},
"pk-success-left.png": {
"u": "https://cdn.jkwljy.com/pk-math/kPpvGxHFYGFh5V8cU56WBDuHH3c/390x372",
"w": 390,
"h": 372
},
"pk-success-right.png": {
"u": "https://cdn.jkwljy.com/pk-math/WXobLoPkgcg1iRqdaoDYhgzPvFF/390x372",
"w": 390,
"h": 372
},
"pk-success.png": {
"u": "https://cdn.jkwljy.com/pk-math/4MEYpXTDweEFKUg4noHtZkoTeP2U/520x460",
"w": 520,
"h": 460
},
"btn_bg.png": {
"u": "https://cdn.jkwljy.com/pk-math/3k3He53c4T1SHnmWtit4JSbPtYgu/348x116",
"w": 348,
"h": 116
}
} as const
......@@ -16,7 +16,7 @@ const defaultParamsFn = <T extends object = {}>() => ({
path: undefined,
})
const useShare = <T extends object = {}>(paramsFn?: UseShareParams<T>) => {
const useShare = <T extends object = {}>(paramsFn?: UseShareParams<T>, getNextIdIfShare?: boolean) => {
const [shareIds, setShareIds] = useState<number[]>([])
const router = useRouter<{ scene?: string; shareId?: string }>()
......@@ -63,6 +63,10 @@ const useShare = <T extends object = {}>(paramsFn?: UseShareParams<T>) => {
}).catch((error) => {
console.log('save share occur error', error)
})
if (getNextIdIfShare) {
getSeeds()
}
// failback
const queryString = qs(safeParams)
sharePath = `${sharePath}?scene=${encodeURIComponent(`shareId=${defaultShareId}`)}${queryString ? `&${queryString}` : ''}`
......@@ -83,7 +87,7 @@ const useShare = <T extends object = {}>(paramsFn?: UseShareParams<T>) => {
}
})
return shareIds
return getSeeds
}
export { useShare }
......@@ -76,7 +76,7 @@ const BattlesModal = () => {
</View>
</View>
<ScrollView className={styles.gameResult} scrollY>
<ScrollView className={styles.gameResult} scrollY enableFlex>
<GameResult levelInfo={levelInfo} players={players} />
<GameResult levelInfo={levelInfo2} players={players} />
<GameResult levelInfo={levelInfo} players={players} />
......
.wrap {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: rgba(0,0,0,0.85);
}
.pk_result {
width: 520px;
height: 460px;
animation-name: roomIn;
animation-timing-function: ease-in-out;
animation-duration: .5s;
animation-fill-mode: backwards;
}
@keyframes roomIn {
0% {
transform: scale3d(2, 2, 1) translateY(230px);
}
100% {
transform: scale3d(1, 1, 1) translateY(0px);
}
}
.game_bonus {
display: flex;
align-items: center;
font-size: 48px;
font-weight: bold;
color: #FFFFFF;
line-height: 58px;
animation-name: fadeInUp;
animation-timing-function: ease-in-out;
animation-duration: .5s;
animation-fill-mode: backwards;
animation-delay: 0.5s;
}
@keyframes fadeInUp {
0% {
opacity: 0;
transform: scale3d(1, 1, 1) translateY(80px);
}
100% {
opacity: 1;
transform: scale3d(1, 1, 1) translateY(0px);
}
}
.diamond {
width: 100px;
height: 100px;
display: block;
margin-right: 20px;
}
.game_role {
width: 750px;
display: flex;
justify-content: space-between;
padding-top: 40px;
}
.game_role_left {
width: 390px;
height: 372px;
background-image: url(https://cdn.jkwljy.com/pk-math/kPpvGxHFYGFh5V8cU56WBDuHH3c/390x372);
background-size: 100% 100%;
animation-name: slideLeft;
animation-timing-function: ease-in-out;
animation-duration: .5s;
animation-fill-mode: backwards;
animation-delay: .5s;
&.is_fail {
background-image: url(https://cdn.jkwljy.com/pk-math/4HKPvzCid6i65r3KFKMsG6fUQoPW/390x372);
.info {
color: #FF5B5E;
background: rgba(255,255,255,0.7);
}
}
}
@keyframes slideLeft {
0% {
transform: translate3d(-100%, 0, 0);
}
100% {
transform: translate3d(0, 0, 0);
}
}
.user_name {
font-size: 32px;
font-weight: 600;
color: #FFFFFF;
line-height: 44px;
padding: 40px 0 0 32px;
}
.info {
height: 64px;
border-radius: 0px 32px 32px 0px;
display: flex;
padding-left: 32px;
align-items: center;
width: 312px;
box-sizing: border-box;
font-size: 28px;
font-weight: 500;
line-height: 40px;
color: #009AFB;
background: rgba(255,255,255,0.7);
margin-top: 28px;
&.is_info_2 {
width: 292px;
}
}
.user_level {
display: flex;
align-items: center;
padding-left: 32px;
font-size: 28px;
font-weight: 400;
color: #FFFFFF;
line-height: 40px;
}
.level_icon {
width: 60px;
height: 60px;
margin-right: 4px;
}
.game_role_right {
width: 390px;
height: 372px;
background-image: url(https://cdn.jkwljy.com/pk-math/WXobLoPkgcg1iRqdaoDYhgzPvFF/390x372);
background-size: 100% 100%;
margin-top: 60px;
animation-name: slideRight;
animation-timing-function: ease-in-out;
animation-duration: .5s;
animation-fill-mode: backwards;
animation-delay: 0.75s;
.user_name {
text-align: right;
padding: 40px 32px 0 0;
}
.user_level {
justify-content: flex-end;
padding-left: 0;
padding-right: 32px;
}
.info {
border-radius: 32px 0 0 32px;
margin-left: auto;
}
&.is_fail {
background-image: url(https://cdn.jkwljy.com/pk-math/3o3ESnEoAoPvNauDuLxjPPGmoyRv/390x372);
.info {
color: #FF5B5E;
background: rgba(255,255,255,0.7);
}
}
}
@keyframes slideRight {
0% {
transform: translate3d(100%, 0, 0);
}
100% {
transform: translate3d(0, 0, 0);
}
}
.footer {
display: flex;
align-items: center;
animation-name: fadeIn;
animation-timing-function: ease-in-out;
animation-duration: .5s;
animation-fill-mode: backwards;
animation-delay: 1s;
}
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.share {
width: 280px;
height: 108px;
border-radius: 54px;
border: 4px solid #FFFFFF;
margin-right: 28px;
display: flex;
align-items: center;
justify-content: center;
font-size: 36px;
font-weight: 500;
color: #FFFFFF;
line-height: 50px;
}
.back_main {
width: 348px;
height: 116px;
display: flex;
align-items: center;
justify-content: center;
font-size: 36px;
font-weight: 500;
color: #FFFFFF;
line-height: 50px;
box-sizing: border-box;
background-image: url(https://cdn.jkwljy.com/pk-math/3k3He53c4T1SHnmWtit4JSbPtYgu/348x116);
background-size: 100% 100%;
}
.gap_1 {
flex: 4;
}
.gap_2 {
flex: 2;
}
.gap_3 {
flex: 3;
}
import { View, Image } from '@tarojs/components'
import assetsGame from '@/assets/oss/assets-game'
import assetsPrepare from '@/assets/oss/assets-prepare'
import assetsPk from '@/assets/oss/assets-pk'
import classNames from 'classnames'
import styles from './battle-complete.module.scss'
type BattleCompleteProps = {
data?: {}
}
const BattleComplete = (props: BattleCompleteProps) => {
const { data } = props
if (!data) {
return null
}
return (
<View className={styles.wrap}>
<View className={styles.gap_1}></View>
<Image src={assetsGame['pk-fail.png'].u} className={styles.pk_result} mode="heightFix"></Image>
<View className={styles.game_bonus}>
<Image src={assetsPrepare['diamond.png'].u} className={styles.diamond}></Image>
水晶 +5
</View>
<View className={styles.game_role}>
<View className={styles.game_role_left}>
<View className={styles.user_name}>用户名称用户名</View>
<View className={styles.user_level}>
<Image src={assetsPk['bronze.png'].u} className={styles.level_icon}></Image>青铜Ⅰ
</View>
<View className={styles.info}>答题对错:全对</View>
<View className={classNames(styles.info, styles.is_info_2)}>答题用时:21.3s</View>
</View>
<View className={classNames(styles.game_role_right, styles.is_fail)}>
<View className={styles.user_name}>用户名称用户名</View>
<View className={styles.user_level}>
<Image src={assetsPk['bronze.png'].u} className={styles.level_icon}></Image>青铜Ⅰ
</View>
<View className={styles.info}>答题对错:全对</View>
<View className={classNames(styles.info, styles.is_info_2)}>答题用时:21.3s</View>
</View>
</View>
<View className={styles.gap_2}></View>
<View className={styles.footer}>
<View className={styles.share}>分享结果</View>
<View className={styles.back_main}>提升自己</View>
</View>
<View className={styles.gap_3}></View>
</View>
)
}
export default BattleComplete
......@@ -11,6 +11,7 @@ import PageHead from './components/page-head'
import PageFooter from './components/page-footer'
import Question from './components/question'
import CountUp from './components/count-up'
import BattleComplete from './components/battle-complete'
// import NumberKeyboard from './components/number-keyboard'
import styles from './index.module.scss'
......@@ -94,6 +95,7 @@ const GamePlay = () => {
)}
</EyeProtectionView>
<ModalContinue />
<BattleComplete />
</>
)
}
......
......@@ -146,20 +146,14 @@
.pk_flash_left, .pk_flash_right {
width: 360px;
height: 200px;
animation-name: flash;
animation-timing-function: ease-in;
animation-duration: 0.8s;
animation-fill-mode: backwards;
animation-delay: 0.5s;
}
.pk_flash_left {
animation-name: flash_shake_1;
}
.pk_flash_right {
animation-name: flash_shake_1;
}
@keyframes flash_shake_1 {
@keyframes flash {
0% {
opacity: 0;
}
......
......@@ -15,11 +15,12 @@ type CreatePkProps = {
const CreatePk = (props: CreatePkProps) => {
const { visible } = props
const userInfo = useStoreState(states => states.userModel.userInfo)
const currentPkStage = useStoreState(states => states.mainModel.currentPkStage)
const nav = useMemo(getMenuButtonBoundingClientRect, [])
const updateState = useStoreActions(actions => actions.mainModel.updateState)
const closeModal = () => {
updateState({ isCreatePkShow: false })
updateState({ isCreatePkShow: false, currentPkStage: null })
}
const closeStyle = useMemo(() => {
......@@ -52,7 +53,7 @@ const CreatePk = (props: CreatePkProps) => {
<View className={styles.me_info}>
<View>{userInfo.nickName}</View>
<View className={styles.info_detail}><Image src={assetsPk['bronze-small.png'].u} className={styles.pk_level} />青铜Ⅰ</View>
<View className={styles.info_detail}>本关战绩:胜 2 负 3</View>
<View className={styles.info_detail}>本关战绩:胜 {currentPkStage?.pkWinNum ?? 0} 负 {currentPkStage?.pkLoseNum ?? 0}</View>
<View className={styles.info_detail}>最佳表现:全对丨29.3s</View>
</View>
</View>
......
......@@ -43,15 +43,17 @@ const Scene = (props: SceneProps) => {
useEffect(() => {
if (props.stageList.length < 1) return
nextTick(() => {
if (!domRef.current) return
createSelectorQuery()
.select(`#${domRef.current.uid}`)
.boundingClientRect().exec(([rect]) => {
if (!rect) {
return
}
setContainerHeight(rect.height)
})
setTimeout(() => {
if (!domRef.current) return
createSelectorQuery()
.select(`#${domRef.current.uid}`)
.boundingClientRect().exec(([rect]) => {
if (!rect) {
return
}
setContainerHeight(rect.height)
})
})
})
}, [props.stageList])
......
......@@ -141,7 +141,9 @@ const StageComp = (props: StageProps) => {
}
const handleLongPress = () => {
updateMainModelState({ isCreatePkShow: true })
if (stage.status === StageStatus.PASSED) {
updateMainModelState({ isCreatePkShow: true, currentPkStage: stage })
}
}
const handleCompleteGuide = () => {
......@@ -190,8 +192,8 @@ const StageComp = (props: StageProps) => {
<Image src={getStarSrc(2, 2)} className={styles.star_2}></Image>
<Image src={getStarSrc(3, 2)} className={styles.star_3}></Image>
<View className={styles.pk}>
<View className={styles.pk_item}>2</View>
<View className={classNames(styles.pk_item, styles.is_right)}>2</View>
<View className={styles.pk_item}>{stage.pkWinNum ?? 0}</View>
<View className={classNames(styles.pk_item, styles.is_right)}>{stage.pkLoseNum ?? 0}</View>
</View>
</View>
)
......
......@@ -6,6 +6,7 @@ import { useShare } from '@/hooks'
import { setNavigationBarColor, useRouter } from '@tarojs/taro'
import { handleShare } from '@/utils/share'
import Loading from '@/components/Loading'
import { useStoreState } from '@/store/hooks'
import styles from './main.module.scss'
import MainComponent from './main-underground/main-component'
import Guide from './guide'
......@@ -15,19 +16,34 @@ const MainPage = () => {
const [isReady, setIsReady] = useState(false)
const router = useRouter()
const currentPkStage = useStoreState(states => states.mainModel.currentPkStage)
useEffect(() => {
handleShare(router.params)
}, [router.params])
const getShareParams = useCallback(() => {
const userInfo = getStorage(StorageKeys.userInfo)
if (currentPkStage && userInfo?.userId) {
return {
title: '听说你的能力不错,我们battle一下',
path: 'pages/accept-pk/index',
imageUrl: 'https://cdn.jkwljy.com/pk-math/4LHyu63hfeteRxAKNb2cj2uCrahf/420x336',
pageParams: {
initiator: userInfo.userId,
stageId: currentPkStage.id
}
}
}
return {
title: '邀请你来一起PKmath,快乐提升哦',
path: 'pages/main/main',
imageUrl: 'https://cdn.jkwljy.com/pk-math/4LHyu63hfeteRxAKNb2cj2uCrahf/420x336',
}
}, [])
}, [currentPkStage])
useShare(getShareParams)
useShare(getShareParams, true)
const handleDone = useCallback(() => {
setIsDone(true)
......
......@@ -25,11 +25,13 @@ export interface MainModel {
fetchStage: Thunk<MainModel, void, void, AppStoreModel, Promise<[Stage[], Stage[]]>>;
isCreatePkShow: boolean;
currentPkStage: Stage | null;
}
const mainModel: MainModel = {
isReady: false,
player: getPlayer(),
currentPkStage: null,
isCreatePkShow: false,
stageList: [],
updateState: action((state, payload) => {
......
......@@ -131,7 +131,7 @@ const Prepare = () => {
getQuestionList(+router.params.id || 1).then(() => {
isClickRef.current = false
navigateTo({
url: `/pages/game/play/index?id=${router.params.id}`
url: `/pages/game/play/index?id=${router.params.id}&isBattle=true`
})
})
}
......
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