Commit 24d90c96 authored by hewenhao's avatar hewenhao

feat: pk math 首页

parent 359921d6
......@@ -2,6 +2,7 @@ module.exports = {
extends: ['standard', 'taro/preact', 'plugin:react/jsx-runtime'],
rules: {
'comma-dangle': 0,
'jsx-quotes': ['error', 'prefer-double']
},
overrides: [
{
......
......@@ -4,5 +4,101 @@
"w": 164,
"h": 140,
"ossName": "/pk-math/2irQDt3fGBdeUKTjbKWMbjn5eeKY/164x140"
},
"part-bg-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/3mpAEaHXT48jzwscgmPUqriAuxys/750x220",
"w": 750,
"h": 220,
"ossName": "/pk-math/3mpAEaHXT48jzwscgmPUqriAuxys/750x220"
},
"part-bg-2.png": {
"u": "https://cdn.jkwljy.com/pk-math/9Y7D4BTfqQhmt4pE346geHxGRGj/750x220",
"w": 750,
"h": 220,
"ossName": "/pk-math/9Y7D4BTfqQhmt4pE346geHxGRGj/750x220"
},
"part-bg-3.png": {
"u": "https://cdn.jkwljy.com/pk-math/35HK4qvcBuzDWpyTJEY54hpievz6/750x220",
"w": 750,
"h": 220,
"ossName": "/pk-math/35HK4qvcBuzDWpyTJEY54hpievz6/750x220"
},
"part-start-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/2RVqjVm8g6Cdn7d42a8EEtFBNMxZ/750x336",
"w": 750,
"h": 336,
"ossName": "/pk-math/2RVqjVm8g6Cdn7d42a8EEtFBNMxZ/750x336"
},
"part-start-2.png": {
"u": "https://cdn.jkwljy.com/pk-math/2KJcZriVZBBjaSUmemaAVktitde/750x336",
"w": 750,
"h": 336,
"ossName": "/pk-math/2KJcZriVZBBjaSUmemaAVktitde/750x336"
},
"part-start.png": {
"u": "https://cdn.jkwljy.com/pk-math/3MGDvwuhkhWAjLSRVgczHQhZs9rs/750x336",
"w": 750,
"h": 336,
"ossName": "/pk-math/3MGDvwuhkhWAjLSRVgczHQhZs9rs/750x336"
},
"round-center-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/3krqkCRJxWv2CNA5Ndmy9N1fS6Ji/750x256",
"w": 750,
"h": 256,
"ossName": "/pk-math/3krqkCRJxWv2CNA5Ndmy9N1fS6Ji/750x256"
},
"round-center-2.png": {
"u": "https://cdn.jkwljy.com/pk-math/usdnLF5tfbU8MyUyAjCfCc4Vbkb/750x256",
"w": 750,
"h": 256,
"ossName": "/pk-math/usdnLF5tfbU8MyUyAjCfCc4Vbkb/750x256"
},
"round-center-3.png": {
"u": "https://cdn.jkwljy.com/pk-math/3cLQ3B1tAA6ArBH7jCVKPxadryE4/750x256",
"w": 750,
"h": 256,
"ossName": "/pk-math/3cLQ3B1tAA6ArBH7jCVKPxadryE4/750x256"
},
"round-center-4.png": {
"u": "https://cdn.jkwljy.com/pk-math/2FcKPLj9jrU1tiLhPiMjdnojaTh5/750x256",
"w": 750,
"h": 256,
"ossName": "/pk-math/2FcKPLj9jrU1tiLhPiMjdnojaTh5/750x256"
},
"round-center-5.png": {
"u": "https://cdn.jkwljy.com/pk-math/2ibypWkZMqQTnYPmJs8E49vYj1ax/750x256",
"w": 750,
"h": 256,
"ossName": "/pk-math/2ibypWkZMqQTnYPmJs8E49vYj1ax/750x256"
},
"round-center-6.png": {
"u": "https://cdn.jkwljy.com/pk-math/3nuG2iMhVxBC3eEsfQ7pq22VgCcM/750x256",
"w": 750,
"h": 256,
"ossName": "/pk-math/3nuG2iMhVxBC3eEsfQ7pq22VgCcM/750x256"
},
"scene-footer.png": {
"u": "https://cdn.jkwljy.com/pk-math/UGtFQyu8CUYCTgr2SRJnyUw6UxM/750x292",
"w": 750,
"h": 292,
"ossName": "/pk-math/UGtFQyu8CUYCTgr2SRJnyUw6UxM/750x292"
},
"scene-head.png": {
"u": "https://cdn.jkwljy.com/pk-math/3J56uJAwwkpRthJJum2zsW3PAGWk/750x220",
"w": 750,
"h": 220,
"ossName": "/pk-math/3J56uJAwwkpRthJJum2zsW3PAGWk/750x220"
},
"short-cut-arrow.png": {
"u": "https://cdn.jkwljy.com/pk-math/42pbPGXs3hzTWK77EFWJ4jUU2XWj/60x60",
"w": 60,
"h": 60,
"ossName": "/pk-math/42pbPGXs3hzTWK77EFWJ4jUU2XWj/60x60"
},
"short-cut-bg.png": {
"u": "https://cdn.jkwljy.com/pk-math/3h61NcsK8f2Urp9GAB8PkwsnuGQY/108x108",
"w": 108,
"h": 108,
"ossName": "/pk-math/3h61NcsK8f2Urp9GAB8PkwsnuGQY/108x108"
}
}
{
"enhance-clear-base.png": {
"u": "https://cdn.jkwljy.com/pk-math/3RCWB68pGBrhBBhKXDJ4ACt5rTSS/168x168",
"w": 168,
"h": 168,
"ossName": "/pk-math/3RCWB68pGBrhBBhKXDJ4ACt5rTSS/168x168"
},
"enhance-current-base.png": {
"u": "https://cdn.jkwljy.com/pk-math/2KmXgfy2n2Mo5DVXfnUwZskoKoNJ/168x168",
"w": 168,
"h": 168,
"ossName": "/pk-math/2KmXgfy2n2Mo5DVXfnUwZskoKoNJ/168x168"
},
"enhance-unlock.png": {
"u": "https://cdn.jkwljy.com/pk-math/2GAzD9SiUMxxtgeyETBGcAHieSqh/168x168",
"w": 168,
"h": 168,
"ossName": "/pk-math/2GAzD9SiUMxxtgeyETBGcAHieSqh/168x168"
},
"one-stop-clear-base.png": {
"u": "https://cdn.jkwljy.com/pk-math/2WGz8gnQGn4ZrN6X2snSAbwjYZXi/176x168",
"w": 176,
"h": 168,
"ossName": "/pk-math/2WGz8gnQGn4ZrN6X2snSAbwjYZXi/176x168"
},
"one-stop-current.png": {
"u": "https://cdn.jkwljy.com/pk-math/2wr6d74xfdgXbWKcb4vQDBNcbRda/176x168",
"w": 176,
"h": 168,
"ossName": "/pk-math/2wr6d74xfdgXbWKcb4vQDBNcbRda/176x168"
},
"one-stop-unlock.png": {
"u": "https://cdn.jkwljy.com/pk-math/38fuqaJPcbKg9tjY8gpicDuHyo81/176x168",
"w": 176,
"h": 168,
"ossName": "/pk-math/38fuqaJPcbKg9tjY8gpicDuHyo81/176x168"
},
"score-a.png": {
"u": "https://cdn.jkwljy.com/pk-math/2gRKpWgt4r8qQCuhnYZ9vuBoaZLB/96x96",
"w": 96,
"h": 96,
"ossName": "/pk-math/2gRKpWgt4r8qQCuhnYZ9vuBoaZLB/96x96"
},
"score-b.png": {
"u": "https://cdn.jkwljy.com/pk-math/bRxeBDJMbaHiFz6v2jPkHGnaFUn/96x96",
"w": 96,
"h": 96,
"ossName": "/pk-math/bRxeBDJMbaHiFz6v2jPkHGnaFUn/96x96"
},
"score-s.png": {
"u": "https://cdn.jkwljy.com/pk-math/3imSh85BYTPjn24Qf394mp2Vo1C7/96x96",
"w": 96,
"h": 96,
"ossName": "/pk-math/3imSh85BYTPjn24Qf394mp2Vo1C7/96x96"
},
"strong-clear-base.png": {
"u": "https://cdn.jkwljy.com/pk-math/4KRY7t5hSbUysGFFKFcDVVabtMFc/168x168",
"w": 168,
"h": 168,
"ossName": "/pk-math/4KRY7t5hSbUysGFFKFcDVVabtMFc/168x168"
},
"strong-current-base.png": {
"u": "https://cdn.jkwljy.com/pk-math/3sfHg69tXyQvJwr2PwHwCm1RigGz/168x168",
"w": 168,
"h": 168,
"ossName": "/pk-math/3sfHg69tXyQvJwr2PwHwCm1RigGz/168x168"
},
"strong-unlock.png": {
"u": "https://cdn.jkwljy.com/pk-math/3LEQbPoqUxDqTwgGcGpTrUgXAcvV/168x168",
"w": 168,
"h": 168,
"ossName": "/pk-math/3LEQbPoqUxDqTwgGcGpTrUgXAcvV/168x168"
},
"top-10.png": {
"u": "https://cdn.jkwljy.com/pk-math/38dch85Nkj1rjvbBQWgKhgPNsRMJ/192x80",
"w": 192,
"h": 80,
"ossName": "/pk-math/38dch85Nkj1rjvbBQWgKhgPNsRMJ/192x80"
},
"top-20.png": {
"u": "https://cdn.jkwljy.com/pk-math/465aWg9Kyt1gw41FRDoGgLUiiFaT/192x80",
"w": 192,
"h": 80,
"ossName": "/pk-math/465aWg9Kyt1gw41FRDoGgLUiiFaT/192x80"
},
"top-30.png": {
"u": "https://cdn.jkwljy.com/pk-math/AaLpxXj3uEq7QxTpXSVkwmyJQG6/192x80",
"w": 192,
"h": 80,
"ossName": "/pk-math/AaLpxXj3uEq7QxTpXSVkwmyJQG6/192x80"
},
"top-n.png": {
"u": "https://cdn.jkwljy.com/pk-math/4EfUGL88udGyL8osFRS6K8unorkb/192x80",
"w": 192,
"h": 80,
"ossName": "/pk-math/4EfUGL88udGyL8osFRS6K8unorkb/192x80"
}
}
const path = require('path')
const styleMap = new Map()
let seeds = 100
const alphabet = 'LDUlv_EQgqiWPKdxztharpfbJcYwBsGZCkuFnOjSHeTmIRVyoXNMA' // 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').sort(() => Math.random() - 0.5).join('');
let seeds = 1
const alphabet = 'mQCF9KU4Za0fJ_o7OBglDip8cMqNbePz2vEyrwtHRIdkGsLxj6Tu3X1h5SWAYnV' // 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.split('').sort(() => Math.random() - 0.5).join('');
const len = alphabet.length
function getShortName (index, order = 0) {
......@@ -12,7 +12,7 @@ function getShortName (index, order = 0) {
if (order !== 0) {
// keys += order;
}
return `${keys}`
return `_${keys}`
}
const outputRoot = process.env.TARO_OUTPUT_ROOT || 'dist'
......@@ -65,6 +65,10 @@ const config = {
},
copy: {
patterns: [
{
from: path.resolve(__dirname, '../src/assets/tabbar/'),
to: path.resolve(__dirname, `../${outputRoot}/assets/tabbar/`)
},
],
options: {
}
......
......@@ -4,12 +4,13 @@
"description": "",
"appid": "wx8f25def587982a19",
"setting": {
"urlCheck": true,
"urlCheck": false,
"es6": false,
"enhance": false,
"compileHotReLoad": false,
"postcss": false,
"minified": false
},
"libVersion": "2.30.2",
"compileType": "miniprogram"
}
\ No newline at end of file
......@@ -7,10 +7,32 @@
export default {
pages: [
'pages/main/main',
'pages/group/index'
],
subPackages: {{packages}},
resizable: true,
preloadRule: {{preloadRule}},
tabBar: {
custom: true,
borderStyle: "black",
color: "#8c8c8c",
selectedColor: "#027AFF",
backgroundColor: "#ffffff",
list: [
{
pagePath: "pages/main/main",
text: "我的",
iconPath: "/assets/tabbar/personal-on.png",
selectedIconPath: "/assets/tabbar/personal-on.png"
},
{
pagePath: "pages/group/index",
text: "组团",
iconPath: "/assets/tabbar/group-on.png",
selectedIconPath: "/assets/tabbar/group-on.png"
}
]
},
window: {
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: '进击吧数学',
......@@ -24,4 +46,4 @@ export default {
desc: '你的位置信息将用于小程序位置接口的效果展示',
},
},
};
}
......@@ -119,7 +119,7 @@ async function uploadFolder ({ fileList, outputFileName, cachedOutputFileName })
fs.writeFileSync(outputFileName, `/* eslint-disable quotes */
/* eslint-disable quote-props */
export default ${JSON.stringify(output, null, 2)}
export default ${JSON.stringify(output, null, 2)} as const
`)
return mapper
})
......
......@@ -5,5 +5,85 @@ export default {
"u": "https://cdn.jkwljy.com/pk-math/2irQDt3fGBdeUKTjbKWMbjn5eeKY/164x140",
"w": 164,
"h": 140
},
"part-bg-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/3mpAEaHXT48jzwscgmPUqriAuxys/750x220",
"w": 750,
"h": 220
},
"part-bg-2.png": {
"u": "https://cdn.jkwljy.com/pk-math/9Y7D4BTfqQhmt4pE346geHxGRGj/750x220",
"w": 750,
"h": 220
},
"part-bg-3.png": {
"u": "https://cdn.jkwljy.com/pk-math/35HK4qvcBuzDWpyTJEY54hpievz6/750x220",
"w": 750,
"h": 220
},
"part-start-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/2RVqjVm8g6Cdn7d42a8EEtFBNMxZ/750x336",
"w": 750,
"h": 336
},
"part-start-2.png": {
"u": "https://cdn.jkwljy.com/pk-math/2KJcZriVZBBjaSUmemaAVktitde/750x336",
"w": 750,
"h": 336
},
"part-start.png": {
"u": "https://cdn.jkwljy.com/pk-math/3MGDvwuhkhWAjLSRVgczHQhZs9rs/750x336",
"w": 750,
"h": 336
},
"round-center-1.png": {
"u": "https://cdn.jkwljy.com/pk-math/3krqkCRJxWv2CNA5Ndmy9N1fS6Ji/750x256",
"w": 750,
"h": 256
},
"round-center-2.png": {
"u": "https://cdn.jkwljy.com/pk-math/usdnLF5tfbU8MyUyAjCfCc4Vbkb/750x256",
"w": 750,
"h": 256
},
"round-center-3.png": {
"u": "https://cdn.jkwljy.com/pk-math/3cLQ3B1tAA6ArBH7jCVKPxadryE4/750x256",
"w": 750,
"h": 256
},
"round-center-4.png": {
"u": "https://cdn.jkwljy.com/pk-math/2FcKPLj9jrU1tiLhPiMjdnojaTh5/750x256",
"w": 750,
"h": 256
},
"round-center-5.png": {
"u": "https://cdn.jkwljy.com/pk-math/2ibypWkZMqQTnYPmJs8E49vYj1ax/750x256",
"w": 750,
"h": 256
},
"round-center-6.png": {
"u": "https://cdn.jkwljy.com/pk-math/3nuG2iMhVxBC3eEsfQ7pq22VgCcM/750x256",
"w": 750,
"h": 256
},
"scene-footer.png": {
"u": "https://cdn.jkwljy.com/pk-math/UGtFQyu8CUYCTgr2SRJnyUw6UxM/750x292",
"w": 750,
"h": 292
},
"scene-head.png": {
"u": "https://cdn.jkwljy.com/pk-math/3J56uJAwwkpRthJJum2zsW3PAGWk/750x220",
"w": 750,
"h": 220
},
"short-cut-arrow.png": {
"u": "https://cdn.jkwljy.com/pk-math/42pbPGXs3hzTWK77EFWJ4jUU2XWj/60x60",
"w": 60,
"h": 60
},
"short-cut-bg.png": {
"u": "https://cdn.jkwljy.com/pk-math/3h61NcsK8f2Urp9GAB8PkwsnuGQY/108x108",
"w": 108,
"h": 108
}
}
} as const
/* eslint-disable quotes */
/* eslint-disable quote-props */
export default {
"enhance-clear-base.png": {
"u": "https://cdn.jkwljy.com/pk-math/3RCWB68pGBrhBBhKXDJ4ACt5rTSS/168x168",
"w": 168,
"h": 168
},
"enhance-current-base.png": {
"u": "https://cdn.jkwljy.com/pk-math/2KmXgfy2n2Mo5DVXfnUwZskoKoNJ/168x168",
"w": 168,
"h": 168
},
"enhance-unlock.png": {
"u": "https://cdn.jkwljy.com/pk-math/2GAzD9SiUMxxtgeyETBGcAHieSqh/168x168",
"w": 168,
"h": 168
},
"one-stop-clear-base.png": {
"u": "https://cdn.jkwljy.com/pk-math/2WGz8gnQGn4ZrN6X2snSAbwjYZXi/176x168",
"w": 176,
"h": 168
},
"one-stop-current.png": {
"u": "https://cdn.jkwljy.com/pk-math/2wr6d74xfdgXbWKcb4vQDBNcbRda/176x168",
"w": 176,
"h": 168
},
"one-stop-unlock.png": {
"u": "https://cdn.jkwljy.com/pk-math/38fuqaJPcbKg9tjY8gpicDuHyo81/176x168",
"w": 176,
"h": 168
},
"score-a.png": {
"u": "https://cdn.jkwljy.com/pk-math/2gRKpWgt4r8qQCuhnYZ9vuBoaZLB/96x96",
"w": 96,
"h": 96
},
"score-b.png": {
"u": "https://cdn.jkwljy.com/pk-math/bRxeBDJMbaHiFz6v2jPkHGnaFUn/96x96",
"w": 96,
"h": 96
},
"score-s.png": {
"u": "https://cdn.jkwljy.com/pk-math/3imSh85BYTPjn24Qf394mp2Vo1C7/96x96",
"w": 96,
"h": 96
},
"strong-clear-base.png": {
"u": "https://cdn.jkwljy.com/pk-math/4KRY7t5hSbUysGFFKFcDVVabtMFc/168x168",
"w": 168,
"h": 168
},
"strong-current-base.png": {
"u": "https://cdn.jkwljy.com/pk-math/3sfHg69tXyQvJwr2PwHwCm1RigGz/168x168",
"w": 168,
"h": 168
},
"strong-unlock.png": {
"u": "https://cdn.jkwljy.com/pk-math/3LEQbPoqUxDqTwgGcGpTrUgXAcvV/168x168",
"w": 168,
"h": 168
},
"top-10.png": {
"u": "https://cdn.jkwljy.com/pk-math/38dch85Nkj1rjvbBQWgKhgPNsRMJ/192x80",
"w": 192,
"h": 80
},
"top-20.png": {
"u": "https://cdn.jkwljy.com/pk-math/465aWg9Kyt1gw41FRDoGgLUiiFaT/192x80",
"w": 192,
"h": 80
},
"top-30.png": {
"u": "https://cdn.jkwljy.com/pk-math/AaLpxXj3uEq7QxTpXSVkwmyJQG6/192x80",
"w": 192,
"h": 80
},
"top-n.png": {
"u": "https://cdn.jkwljy.com/pk-math/4EfUGL88udGyL8osFRS6K8unorkb/192x80",
"w": 192,
"h": 80
}
} as const
export default {
component: true
}
.wrap {
background: #2B3347;
padding-bottom: env(safe-area-inset-bottom);
position: fixed;
z-index: 2000;
left: 0;
right: 0;
bottom: 0;
}
.inner {
display: flex;
height: 56PX;
}
.left, .right {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
position: relative;
z-index: 1;
}
.bg {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
z-index: 1;
}
.icon {
width: 50PX;
height: 50PX;
position: relative;
z-index: 2;
}
import { useState, useImperativeHandle, forwardRef, useCallback } from 'react'
import { View, Image } from '@tarojs/components'
import { switchTab } from '@tarojs/taro'
import styles from './index.module.scss'
type REfType = {
switchTab: (index: number, url: string) => void;
setSelected: (index: number) => void
}
const Tabbar = forwardRef<unknown, REfType>((_, ref) => {
const [selected, setSelected] = useState(0)
const _switchTab = useCallback((index: number, url: string) => {
setSelected(index)
switchTab({ url })
}, [])
useImperativeHandle(ref, () => {
return {
switchTab: _switchTab,
setSelected,
}
})
return (
<View className={styles.wrap}>
<View className={styles.inner}>
<View className={styles.left} onClick={() => _switchTab(0, '/pages/main/main')}>
{selected === 0 && (
<Image src="/assets/tabbar/personal-bg.png" className={styles.bg}></Image>
)}
<Image src="/assets/tabbar/personal-on.png" className={styles.icon} />
</View>
<View className={styles.right} onClick={() => _switchTab(1, '/pages/group/index')}>
{selected === 1 && (
<Image src="/assets/tabbar/group-bg.png" className={styles.bg}></Image>
)}
<Image src="/assets/tabbar/group-on.png" className={styles.icon} />
</View>
</View>
</View>
)
})
export default Tabbar
import { View } from '@tarojs/components'
import { useDidShow, getCurrentInstance, getTabBar } from '@tarojs/taro'
import { useMemo } from 'react'
const Group = () => {
const page = useMemo(() => getCurrentInstance().page, [])
useDidShow(() => {
const tabbar = getTabBar(page) as any
tabbar?.setSelected(1)
})
return (
<View>group</View>
)
}
export default Group
.chapter {
padding: 28px 32px 30px 32px;
border-top: 2px solid #03459C;
background-color: #1786f7;
background-image: url(../assets/chapter-bg.png);
background-size: 100% 100%;
color: #FFFFFF;
display: flex;
align-items: center;
width: 750px;
box-sizing: border-box;
}
.chapterContent {
flex: 1;
min-width: 0;
}
.chapterName {
font-size: 44px;
font-weight: 600;
color: #FFFFFF;
line-height: 60px;
}
.chapterTips {
font-size: 36px;
font-weight: 400;
color: #FFFFFF;
line-height: 50px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-top: 8px;
}
.help {
width: 96px;
height: 96px;
background-image: url(../assets/help-bg.png);
background-size: 100% 100%;
display: flex;
align-items: center;
justify-content: center;
transition: transform .3s ease-in-out;
will-change: transform;
margin-left: 60px;
&.is-hover-btn {
transform: scale(.95);
}
.icon {
width: 60px;
height: 60px;
}
}
import { View, Text, Image } from '@tarojs/components'
import styles from './chapter.module.scss'
const MainHeader = () => {
return (
<View className={styles.chapter}>
<View className={styles.chapterContent}>
<View className={styles.chapterName}>
<Text>第 1 单元</Text>
</View>
<View className={styles.chapterTips}><Text>单元内容名称单元内容名称单元内容名称单元内容名称</Text></View>
</View>
<View className={styles.help} hoverClass={styles['is-hover-btn']}>
<Image src={require('../assets/help.png')} className={styles.icon}></Image>
</View>
</View>
)
}
export default MainHeader
.header {
background-color: #1786f7;
position: fixed;
left: 0;
top: 0;
right: 0;
z-index: 2000;
}
.headerContent {
position: relative;
z-index: 2;
}
.bg {
position: absolute;
left: 0;
bottom: 0;
right: 0;
width: 100%;
}
.inner {
display: flex;
align-items: center;
font-size: 16PX;
font-weight: 500;
color: #FFFFFF;
line-height: 19PX;
}
.avatar {
flex: 1;
.icon {
margin-left: 16PX;
width: 32PX;
height: 32PX;
margin-right: 4PX;
border-radius: 16PX;
background-color: #999;
}
}
.score {
display: flex;
align-items: center;
flex: 1;
.icon {
width: 32PX;
height: 32PX;
margin-right: 4PX;
}
}
.ph {
display: flex;
align-items: center;
flex: 1;
.icon {
width: 32PX;
height: 32PX;
margin-right: 4PX;
}
}
import { View, Text, Image } from '@tarojs/components'
import { getMenuButtonBoundingClientRect, getSystemInfoSync } from '@tarojs/taro'
import { useMemo, useState } from 'react'
import styles from './header.module.scss'
const MainHeader = () => {
const [nav] = useState(getMenuButtonBoundingClientRect())
const [sys] = useState(getSystemInfoSync())
const innerStyle = useMemo(() => {
return {
height: `${nav.height + 10}px`,
paddingRight: `${nav.width + (sys.windowWidth - nav.right) * 2}px`
}
}, [sys, nav])
return (
<View className={styles.header}>
<Image src={require('../assets/head-bg.png')} className={styles.bg} mode="widthFix"></Image>
<View
className={styles.headerContent}
style={{
height: `${nav.height + 10}px`,
paddingTop: `${nav.top - 5}px`
}}
>
<View className={styles.inner} style={innerStyle}>
<View className={styles.avatar}>
<Image src="https://cdn.jkwljy.com/pbb/6gkGHSsPmxc_coeGYahBkelo_2w_/96x96" className={styles.icon}></Image>
</View>
<View className={styles.score}>
<Image src={require('../assets/score.png')} className={styles.icon} />
<Text>271</Text>
</View>
<View className={styles.ph}>
<Image src={require('../assets/ph.png')} className={styles.icon} />
<Text>10</Text>
</View>
</View>
</View>
</View>
)
}
export default MainHeader
.wrap {
display: block;
position: relative;
margin: -1px 0;
}
.img {
display: block;
width: 100%;
position: relative;
z-index: 1;
}
.content {
position: absolute;
z-index: 2;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
import { useState, useRef, useEffect, useMemo, PropsWithChildren } from 'react'
import { getSystemInfoSync, createIntersectionObserver } from '@tarojs/taro'
import { View, Image } from '@tarojs/components'
import classNames from 'classnames'
import styles from './lazy-image.module.scss'
let rect = getSystemInfoSync()
function getViewportWidth () {
if (rect && rect.windowWidth > 0) {
return rect.windowWidth
}
rect = getSystemInfoSync()
return rect.windowWidth
}
function computeHeight ({ h, w }, paddingHorizontal) {
const width = getViewportWidth() - 2 * paddingHorizontal
return h * (width / w)
}
type LazyImageProps = {
lazyLoad?: boolean | undefined;
paddingHorizontal?: number;
contentClass?: string;
source: {
w: number;
h: number;
u: string;
}
}
const LazeImage = (props: PropsWithChildren<LazyImageProps>) => {
const { source, lazyLoad = false, paddingHorizontal = 0 } = props
const [isRender, setIsRender] = useState(!lazyLoad)
const observerRef = useRef<IntersectionObserver | null>(null)
useEffect(() => {
if (!isRender) {
observerRef.current = (createIntersectionObserver as any)().relativeToViewport({ bottom: 0 })
.observe(`.${styles.wrap}`, ({ intersectionRatio }) => {
if (intersectionRatio > 0) {
setIsRender(true)
observerRef.current?.disconnect()
observerRef.current = null
}
})
}
return () => {
if (observerRef.current) {
observerRef.current.disconnect()
observerRef.current = null
}
}
}, [isRender])
const computedHeight = useMemo(() => {
if (!source) return 0
return computeHeight(source, paddingHorizontal)
}, [source, paddingHorizontal])
const renderContent = () => {
if (source) {
if (isRender) {
return (
<Image style={{ height: `${computedHeight}px` }} src={source.u} className={styles.img} mode="widthFix" lazyLoad={lazyLoad} />
)
}
return (
<View style={{ height: `${computedHeight}px` }}></View>
)
}
return null
}
return (
<View className={styles.wrap}>
{renderContent()}
<View className={classNames(styles.content, props.contentClass)}>
{props.children}
</View>
</View>
)
}
export default LazeImage
import assets from '@/assets/oss/assets-main'
export type ImageSource = {
w: number;
h: number;
u: string;
}
const PartBgPool = [
assets['part-bg-1.png'],
assets['part-bg-2.png'],
assets['part-bg-3.png']
]
const SpeicalPartBgPool = [
assets['part-start-1.png'],
assets['part-start-2.png']
]
const NomalPartBgPool = [
assets['round-center-1.png'],
assets['round-center-2.png'],
assets['round-center-3.png'],
assets['round-center-4.png'],
assets['round-center-5.png'],
assets['round-center-6.png'],
]
export const CurrentRoundId = '__current_round__'
export const getSmallPartBg = (index: number, type: 'even' | 'odd' | 'special'): ImageSource => {
switch (type) {
case 'even': {
return assets['part-start.png']
}
case 'odd': {
return NomalPartBgPool[index % 6]
}
case 'special': {
return SpeicalPartBgPool[index % 2]
}
}
}
let evenIndex = 0
let oddIndex = 0
let specialIndex = 0
export function groupRoundToSmallPart (list: Round[]): SmallPart[] {
const ret: SmallPart[] = []
let flag: 'even' | 'odd' = 'even'
const len = list.length
let start = 0
while (start < len) {
if (flag === 'even') {
const rounds = list.slice(start, start + 2)
let partType: SmallPart['type'] = 'even'
let bg: ImageSource
if (rounds.length < 2) {
specialIndex += 1
partType = 'special'
bg = getSmallPartBg(specialIndex, partType)
} else {
evenIndex += 1
bg = getSmallPartBg(evenIndex, partType)
}
ret.push({
rounds,
bg,
offset: start,
type: partType
})
start += 2
flag = 'odd'
} else if (flag === 'odd') {
oddIndex += 1
ret.push({
rounds: list.slice(start, start + 1),
bg: getSmallPartBg(oddIndex, 'odd'),
offset: start,
type: 'odd'
})
start += 1
flag = 'even'
}
}
return ret
}
export const enum RoundState {
/** 未解锁 */
Locked = 1,
/** 已完成 */
Clear = 2,
/** 已解锁 */
UnLocked = 3
}
export const enum RoundType {
Strong = 'Strong',
Enhance = 'Enhance',
OneStop = 'OneStop',
}
export const enum RoundScore {
S = 'S',
A = 'A',
B = 'B'
}
export type Round = {
state?: RoundState;
score?: RoundScore;
type?: RoundType;
id: number;
name?: string;
tag?: string;
}
export type SmallPart = {
rounds: Round[];
bg: ImageSource;
offset: number;
type: 'odd' | 'even' | 'special';
}
export type Part = {
rounds: Round[];
number: number;
}
export const getPartBg = (index) => {
if (index === 0) {
return assets['scene-head.png']
}
return PartBgPool[index % 3]
}
import { View } from '@tarojs/components'
import assets from '@/assets/oss/assets-main'
import LazeImage from '../lazy-image'
import { Part, RoundScore, RoundState, RoundType } from './constants'
import ScenePart from './part'
import styles from './scene.module.scss'
const dataList: Part[] = [
{
rounds: [
{
state: RoundState.Clear,
type: RoundType.Strong,
score: RoundScore.S,
name: '计算达标1',
tag: 'top10',
id: 1,
},
{
state: RoundState.Clear,
type: RoundType.Enhance,
score: RoundScore.S,
tag: 'top20',
name: '应用过关1',
id: 2,
},
{
state: RoundState.Clear,
type: RoundType.Enhance,
score: RoundScore.S,
tag: 'top30',
name: '应用过关2',
id: 3,
},
{
state: RoundState.Clear,
type: RoundType.Strong,
score: RoundScore.A,
tag: 'topn',
name: '计算达标3',
id: 4,
},
{
state: RoundState.Clear,
type: RoundType.OneStop,
score: RoundScore.B,
name: '一站到底1',
id: 5,
}
],
number: 0
},
{
rounds: [
{
id: 6,
state: RoundState.UnLocked,
name: '计算达标1',
},
{ id: 7 },
{ id: 8 },
{ id: 9 }
],
number: 1
},
{
rounds: [{ id: 10 }, { id: 11 }, { id: 12 }, { id: 13 }, { id: 14 }, { id: 15 }],
number: 2
},
{
rounds: [{ id: 16 }, { id: 17 }, { id: 18 }],
number: 3
},
{
rounds: [{ id: 19 }, { id: 20 }, { id: 21 }, { id: 22 }, { id: 23 }, { id: 24 }, { id: 25 }],
number: 4
},
]
const Scene = () => {
return (
<View>
{dataList.map(item => {
return (
<ScenePart part={item} key={item.number} />
)
})}
<LazeImage source={assets['scene-footer.png']} />
</View>
)
}
export default Scene
.partName {
height: 60px;
background: rgba(0,0,0,0.5);
border-radius: 60px;
font-size: 32px;
font-weight: 600;
color: #FFFFFF;
line-height: 44px;
padding: 0 32px;
display: flex;
align-items: center;
justify-content: center;
}
.content {
display: flex;
align-items: center;
justify-content: center;
}
import { View } from '@tarojs/components'
import { useMemo } from 'react'
import LazeImage from '../lazy-image'
import { type Part, type SmallPart, groupRoundToSmallPart, getPartBg } from './constants'
import SceneSmallPart from './small-part'
import styles from './part.module.scss'
type ScenePartProps = {
part: Part
}
const ScenePart = (props: ScenePartProps) => {
const { part } = props
const bg = useMemo(() => {
return getPartBg(part.number)
}, [part.number])
const smallParts = useMemo(() => {
return groupRoundToSmallPart(part.rounds)
}, [part])
return (
<View>
<LazeImage source={bg} contentClass={styles.content}>
<View className={styles.partName}>Part {part.number + 1}</View>
</LazeImage>
{smallParts.map(item => {
return (
<SceneSmallPart part={item} key={item.offset} />
)
})}
</View>
)
}
export default ScenePart
.icon {
width: 168px;
height: 168px;
&.isOneStop {
width: 176px;
}
}
.clear {
position: relative;
z-index: 1;
}
.clearIcon {
position: relative;
z-index: 2;
display: block;
}
.roundName {
// position: absolute;
// bottom: -48px;
margin: 8px -20px 0 -20px;
text-align: center;
font-size: 28px;
font-weight: 500;
color: #FFFFFF;
line-height: 40px;
}
.score {
position: absolute;
width: 96px;
height: 96px;
z-index: 3;
left: 50%;
top: 50%;
margin-top: -48px;
margin-left: -48px;
}
.tag {
position: absolute;
z-index: 3;
left: 50%;
top: -26px;
margin-left: -96px;
width: 192px;
height: 80px;
}
import { View, Image } from '@tarojs/components'
import assets from '@/assets/oss/assets-round'
import classNames from 'classnames'
import { RoundState, type Round, RoundType, type ImageSource, RoundScore, CurrentRoundId } from './constants'
import styles from './round.module.scss'
type RoundProps = {
round: Round;
className?: string;
}
const getLockedIcon = (type?: RoundType): ImageSource => {
switch (type) {
case RoundType.Strong: {
return assets['strong-unlock.png']
}
case RoundType.Enhance: {
return assets['enhance-unlock.png']
}
case RoundType.OneStop: {
return assets['one-stop-unlock.png']
}
}
return assets['strong-unlock.png']
}
const getTagIcon = (tag?: string): ImageSource | null => {
switch (tag) {
case 'top10': {
return assets['top-10.png']
}
case 'top20': {
return assets['top-20.png']
}
case 'top30': {
return assets['top-30.png']
}
case 'topn': {
return assets['top-n.png']
}
}
return null
}
const getUnlockedIcon = (type?: RoundType): ImageSource => {
switch (type) {
case RoundType.Strong: {
return assets['strong-current-base.png']
}
case RoundType.Enhance: {
return assets['enhance-current-base.png']
}
case RoundType.OneStop: {
return assets['one-stop-current.png']
}
}
return assets['strong-current-base.png']
}
const getClearIcon = (type?: RoundType): ImageSource => {
switch (type) {
case RoundType.Strong: {
return assets['strong-clear-base.png']
}
case RoundType.Enhance: {
return assets['enhance-clear-base.png']
}
case RoundType.OneStop: {
return assets['one-stop-clear-base.png']
}
}
return assets['strong-clear-base.png']
}
const getScoreIcon = (score?: RoundScore): ImageSource => {
switch (score) {
case RoundScore.S: {
return assets['score-s.png']
}
case RoundScore.A: {
return assets['score-a.png']
}
case RoundScore.B: {
return assets['score-b.png']
}
}
return assets['score-b.png']
}
const getIconClassNames = (type?: RoundType, extra: string[] = []) => {
return classNames(styles.icon, type === RoundType.OneStop && styles.isOneStop, ...extra)
}
const RoundComp = (props: RoundProps) => {
const { round } = props
const renderRound = () => {
switch (round.state) {
case RoundState.Locked: {
return (
<Image src={getLockedIcon(round.type).u} className={getIconClassNames(round.type)} />
)
}
case RoundState.UnLocked: {
return (
<Image src={getUnlockedIcon(round.type).u} className={getIconClassNames(round.type)} />
)
}
case RoundState.Clear: {
const tag = getTagIcon(round.tag)
return (
<View className={styles.clear}>
{!!tag && (
<Image src={tag.u} className={styles.tag}></Image>
)}
<Image src={getScoreIcon(round.score).u} className={styles.score} />
<Image src={getClearIcon(round.type).u} className={getIconClassNames(round.type, [styles.clearIcon])} />
</View>
)
}
}
return (
<Image src={getLockedIcon(round.type).u} className={getIconClassNames(round.type)} />
)
}
return (
<View className={props.className} id={round.state === RoundState.UnLocked ? CurrentRoundId : undefined}>
{renderRound()}
<View className={styles.roundName}>{round.name}</View>
</View>
)
}
export default RoundComp
.even_1 {
position: absolute;
top: 20px;
right: 108px;
}
.even_2 {
position: absolute;
top: 100px;
left: 108px;
}
.odd {
position: absolute;
top: 20px;
left: 291px;
}
.special {
position: absolute;
top: 34px;
right: 104px;
}
import LazeImage from '../lazy-image'
import { type SmallPart, } from './constants'
import RoundComp from './round'
import styles from './small-part.module.scss'
type SceneSmallPartProps = {
part: SmallPart
}
const getClassName = (index, type: SmallPart['type']) => {
if (type === 'even') {
return styles[`even_${index + 1}`]
}
if (type === 'odd') {
return styles.odd
}
if (type === 'special') {
return styles.special
}
}
const SceneSmallPart = (props: SceneSmallPartProps) => {
const { part } = props
return (
<LazeImage source={part.bg}>
{part.rounds.map((item, index) => {
return (
<RoundComp round={item} key={item.id} className={getClassName(index, part.type)} />
)
})}
</LazeImage>
)
}
export default SceneSmallPart
.shortcut {
bottom: 216px;
position: fixed;
right: 14px;
z-index: 2000;
}
@supports (bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom)) {
.shortcut {
margin-bottom: constant(safe-area-inset-bottom);
margin-bottom: env(safe-area-inset-bottom);
}
}
.shortcutInner {
position: relative;
opacity: 1;
transition: all ease-out .3s;
transform: translateY(0px);
&.isShow {
opacity: 0;
transform: translateY(-30px);
}
}
.bg {
position: relative;
z-index: 1;
width: 108px;
display: block;
height: 108px;
}
.arrow {
position: absolute;
left: 50%;
top: 50%;
width: 60px;
height: 60px;
margin-top: -30px;
margin-left: -30px;
z-index: 2;
&.isDown {
transform: rotate(180deg);
}
}
import { View, Image } from '@tarojs/components'
import assets from '@/assets/oss/assets-main'
import { useEffect, useState, useRef } from 'react'
import { usePageScroll, createIntersectionObserver } from '@tarojs/taro'
import classNames from 'classnames'
import { CurrentRoundId } from './scene/constants'
import styles from './short-cut.module.scss'
type ShortCutProps = {
onClick: () => void
}
const ShortCut = (props: ShortCutProps) => {
const [isShow, setIsShow] = useState(false)
const [isDown, setIsDown] = useState(false)
const scrollRef = useRef(0)
const lastEffectedScroll = useRef(0)
usePageScroll((payload) => {
scrollRef.current = payload.scrollTop
})
useEffect(() => {
let observer = (createIntersectionObserver as any)().relativeToViewport({ bottom: 0 })
.observe(`#${CurrentRoundId}`, ({ intersectionRatio }) => {
const show = intersectionRatio > 0
setIsShow(show)
if (show) {
setIsDown(lastEffectedScroll.current < scrollRef.current)
}
lastEffectedScroll.current = scrollRef.current
})
return () => {
if (observer) {
observer.disconnect()
observer = null
}
}
}, [])
return (
<View className={styles.shortcut}>
<View className={classNames(styles.shortcutInner, isShow && styles.isShow)} onClick={props.onClick}>
<Image src={assets['short-cut-bg.png'].u} className={styles.bg}></Image>
<Image src={assets['short-cut-arrow.png'].u} className={classNames(styles.arrow, isDown && styles.isDown)}></Image>
</View>
</View>
)
}
export default ShortCut
export default definePageConfig({
navigationBarTitleText: '首页'
navigationBarTitleText: 'pk-math',
navigationStyle: 'custom'
})
.index {
flex-direction: column;
width: 100%;
.viewport {
min-height: 100vh;
}
.body {
position: relative;
z-index: 1;
padding-bottom: 56PX;
}
.gap {
height: env(safe-area-inset-bottom);
}
import { View, Button, Text } from '@tarojs/components'
import { useStoreActions, useStoreState } from '@/store/hooks'
import { View } from '@tarojs/components'
import { getMenuButtonBoundingClientRect, useDidShow, getCurrentInstance, getTabBar, pageScrollTo, getSystemInfoSync } from '@tarojs/taro'
import { useState, useMemo, useEffect, useCallback } from 'react'
import { CurrentRoundId } from './components/scene/constants'
import MainHeader from './components/header'
import MainChapter from './components/chapter'
import MainScene from './components/scene'
import MainShortCut from './components/short-cut'
import styles from './main.module.scss'
const MainPage = () => {
const num = useStoreState(state => state.counterModel.count)
const add = useStoreActions(actions => actions.counterModel.add)
const dec = useStoreActions(actions => actions.counterModel.dec)
const asyncAdd = useStoreActions(actions => actions.counterModel.asyncAdd)
const page = useMemo(() => getCurrentInstance().page, [])
useDidShow(() => {
const tabbar = getTabBar(page) as any
tabbar?.setSelected(0)
})
const [nav] = useState(getMenuButtonBoundingClientRect())
const scrollToCurrent = useCallback(() => {
const height = getSystemInfoSync().windowHeight
pageScrollTo({
selector: `#${CurrentRoundId}`,
offsetTop: -height / 2
})
}, [])
useEffect(() => {
setTimeout(() => {
scrollToCurrent()
}, 1000)
}, [])
return (
<View className={styles.index}>
<Button className='add_btn' onClick={() => add()}>+</Button>
<Button className='dec_btn' onClick={() => dec()}>-</Button>
<Button className='dec_btn' onClick={() => asyncAdd()}>async</Button>
<View><Text>{num}</Text></View>
<View><Text>Hello, World</Text></View>
<View className={styles.viewport}>
<MainHeader />
<View className={styles.body} style={{ paddingTop: `${nav.height + nav.top + 5}px` }}>
<MainChapter />
<MainScene />
<View className={styles.gap}></View>
</View>
<MainShortCut onClick={scrollToCurrent} />
</View>
)
}
......
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