v1.0-230926 #27
@@ -21,9 +21,10 @@
|
|||||||
color: #666;
|
color: #666;
|
||||||
}
|
}
|
||||||
|
|
||||||
.scroll-to-down {
|
.scroll-down {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 20px;
|
bottom: 10px;
|
||||||
|
padding: 20px;
|
||||||
animation: 1.5s infinite;
|
animation: 1.5s infinite;
|
||||||
@include mixins.unique-keyframes {
|
@include mixins.unique-keyframes {
|
||||||
0%,
|
0%,
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
const FitFullScreen: React.FC<FitFullscreenProps> = (props: FitFullscreenProps) => {
|
interface FitFullscreenProps extends PropsWithChildren {
|
||||||
|
zIndex?: number
|
||||||
|
backgroundColor?: string
|
||||||
|
ref?: RefObject<HTMLDivElement>
|
||||||
|
}
|
||||||
|
|
||||||
|
const FitFullScreen: React.FC<FitFullscreenProps> = (props) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
import React, { PropsWithChildren } from 'react'
|
import React from 'react'
|
||||||
import '@/assets/css/hide-scrollbar.scss'
|
import '@/assets/css/hide-scrollbar.scss'
|
||||||
|
|
||||||
const HideScrollbar: React.FC<PropsWithChildren> = (prop: PropsWithChildren) => {
|
interface HideScrollbarProps extends PropsWithChildren {
|
||||||
|
getHideScrollbarRef: (hideScrollbarRef: RefObject<HTMLElement>) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const HideScrollbar: React.FC<HideScrollbarProps> = (props) => {
|
||||||
const hideScrollbarRef = useRef<HTMLDivElement>(null)
|
const hideScrollbarRef = useRef<HTMLDivElement>(null)
|
||||||
const [verticalScrollbarWidth, setVerticalScrollbarWidth] = useState(0)
|
const [verticalScrollbarWidth, setVerticalScrollbarWidth] = useState(0)
|
||||||
const [horizontalScrollbarWidth, setHorizontalScrollbarWidth] = useState(0)
|
const [horizontalScrollbarWidth, setHorizontalScrollbarWidth] = useState(0)
|
||||||
|
|
||||||
|
props.getHideScrollbarRef(hideScrollbarRef)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const hideScrollbarElement = hideScrollbarRef.current
|
const hideScrollbarElement = hideScrollbarRef.current
|
||||||
|
|
||||||
@@ -42,7 +48,7 @@ const HideScrollbar: React.FC<PropsWithChildren> = (prop: PropsWithChildren) =>
|
|||||||
height: `calc(100vh + ${horizontalScrollbarWidth}px`
|
height: `calc(100vh + ${horizontalScrollbarWidth}px`
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{prop.children}
|
{props.children}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,8 +3,14 @@ import '@/assets/css/home.scss'
|
|||||||
import FitFullScreen from '@/components/FitFullScreen.tsx'
|
import FitFullScreen from '@/components/FitFullScreen.tsx'
|
||||||
import FitCenter from '@/components/FitCenter.tsx'
|
import FitCenter from '@/components/FitCenter.tsx'
|
||||||
import Icon from '@ant-design/icons'
|
import Icon from '@ant-design/icons'
|
||||||
|
import { MainFrameworkContext } from '@/pages/MainFramework.tsx'
|
||||||
|
|
||||||
const Home: React.FC = () => {
|
const Home: React.FC = () => {
|
||||||
|
const {
|
||||||
|
controllers: { scrollY }
|
||||||
|
} = useContext(MainFrameworkContext)
|
||||||
|
const fitFullScreenRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
const [slogan, setSlogan] = useState('')
|
const [slogan, setSlogan] = useState('')
|
||||||
const [sloganType, setSloganType] = useState(true)
|
const [sloganType, setSloganType] = useState(true)
|
||||||
const typeText = '/* 因为热爱 所以折腾 */'
|
const typeText = '/* 因为热爱 所以折腾 */'
|
||||||
@@ -26,9 +32,13 @@ const Home: React.FC = () => {
|
|||||||
}, 50)
|
}, 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleScrollDown = () => {
|
||||||
|
scrollY(1000)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FitFullScreen zIndex={100} backgroundColor={'#FBFBFB'}>
|
<FitFullScreen zIndex={100} backgroundColor={'#FBFBFB'} ref={fitFullScreenRef}>
|
||||||
<FitCenter>
|
<FitCenter>
|
||||||
<div className={'center-box'}>
|
<div className={'center-box'}>
|
||||||
<div className={'big-logo'}>FatWeb</div>
|
<div className={'big-logo'}>FatWeb</div>
|
||||||
@@ -36,7 +46,7 @@ const Home: React.FC = () => {
|
|||||||
{slogan || <> </>}
|
{slogan || <> </>}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className={'scroll-to-down'}>
|
<div className={'scroll-down'} onClick={handleScrollDown}>
|
||||||
<Icon
|
<Icon
|
||||||
component={IconFatwebDown}
|
component={IconFatwebDown}
|
||||||
style={{ fontSize: '1.8em', color: '#666' }}
|
style={{ fontSize: '1.8em', color: '#666' }}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { createContext } from 'react'
|
import React from 'react'
|
||||||
import '@/assets/css/header.scss'
|
import '@/assets/css/header.scss'
|
||||||
import LoadingMask from '@/components/LoadingMask.tsx'
|
import LoadingMask from '@/components/LoadingMask.tsx'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
@@ -9,21 +9,129 @@ export const MainFrameworkContext = createContext<{
|
|||||||
navbarHidden: boolean
|
navbarHidden: boolean
|
||||||
setNavbarHidden: (newValue: boolean) => void
|
setNavbarHidden: (newValue: boolean) => void
|
||||||
}
|
}
|
||||||
|
controllers: {
|
||||||
|
scrollX(x: number): void
|
||||||
|
scrollY(y: number): void
|
||||||
|
scrollTo(x: number, y: number): void
|
||||||
|
getX(): number | undefined
|
||||||
|
getY(): number | undefined
|
||||||
|
scrollLeft(length: number): void
|
||||||
|
scrollRight(length: number): void
|
||||||
|
scrollUp(length: number): void
|
||||||
|
scrollDown(length: number): void
|
||||||
|
}
|
||||||
}>({
|
}>({
|
||||||
navbarHiddenState: {
|
navbarHiddenState: {
|
||||||
navbarHidden: false,
|
navbarHidden: false,
|
||||||
setNavbarHidden: () => undefined
|
setNavbarHidden: () => undefined
|
||||||
|
},
|
||||||
|
controllers: {
|
||||||
|
scrollX: function (): void {
|
||||||
|
throw new Error('Function not implemented.')
|
||||||
|
},
|
||||||
|
scrollY: function (): void {
|
||||||
|
throw new Error('Function not implemented.')
|
||||||
|
},
|
||||||
|
scrollTo: function (): void {
|
||||||
|
throw new Error('Function not implemented.')
|
||||||
|
},
|
||||||
|
getX: function (): number | undefined {
|
||||||
|
throw new Error('Function not implemented.')
|
||||||
|
},
|
||||||
|
getY: function (): number | undefined {
|
||||||
|
throw new Error('Function not implemented.')
|
||||||
|
},
|
||||||
|
scrollLeft: function (): void {
|
||||||
|
throw new Error('Function not implemented.')
|
||||||
|
},
|
||||||
|
scrollRight: function (): void {
|
||||||
|
throw new Error('Function not implemented.')
|
||||||
|
},
|
||||||
|
scrollUp: function (): void {
|
||||||
|
throw new Error('Function not implemented.')
|
||||||
|
},
|
||||||
|
scrollDown: function (): void {
|
||||||
|
throw new Error('Function not implemented.')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const MainFramework: React.FC = () => {
|
const MainFramework: React.FC = () => {
|
||||||
const [navbarHidden, setNavbarHidden] = useState(false)
|
const [navbarHidden, setNavbarHidden] = useState(false)
|
||||||
|
|
||||||
|
const [hideScrollbarRef, setHideScrollbarRef] = useState<RefObject<HTMLElement>>()
|
||||||
const routeId = useMatches()[1].id
|
const routeId = useMatches()[1].id
|
||||||
const routeChildren = router.routes[0].children?.find((value) => value.id === routeId)?.children
|
const routeChildren = router.routes[0].children?.find((value) => value.id === routeId)?.children
|
||||||
|
|
||||||
|
const getHideScrollbarRef = (ref: RefObject<HTMLElement>) => {
|
||||||
|
setHideScrollbarRef(ref)
|
||||||
|
}
|
||||||
|
|
||||||
|
const hideScrollbarRefController = {
|
||||||
|
scrollX(x: number): void {
|
||||||
|
hideScrollbarRef?.current?.scrollTo({
|
||||||
|
left: x,
|
||||||
|
top: hideScrollbarRef?.current?.scrollTop,
|
||||||
|
behavior: 'smooth'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
scrollY(y: number): void {
|
||||||
|
hideScrollbarRef?.current?.scrollTo({
|
||||||
|
left: hideScrollbarRef?.current?.scrollLeft,
|
||||||
|
top: y,
|
||||||
|
behavior: 'smooth'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
scrollLeft(length: number): void {
|
||||||
|
hideScrollbarRef?.current?.scrollTo({
|
||||||
|
left: (hideScrollbarRef?.current?.scrollLeft ?? 0) - length,
|
||||||
|
behavior: 'smooth'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
scrollRight(length: number): void {
|
||||||
|
hideScrollbarRef?.current?.scrollTo({
|
||||||
|
left: (hideScrollbarRef?.current?.scrollLeft ?? 0) + length,
|
||||||
|
behavior: 'smooth'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
scrollUp(length: number): void {
|
||||||
|
hideScrollbarRef?.current?.scrollTo({
|
||||||
|
top: (hideScrollbarRef?.current?.scrollTop ?? 0) - length,
|
||||||
|
behavior: 'smooth'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
scrollDown(length: number): void {
|
||||||
|
hideScrollbarRef?.current?.scrollTo({
|
||||||
|
top: (hideScrollbarRef?.current?.scrollTop ?? 0) + length,
|
||||||
|
behavior: 'smooth'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
scrollTo(x: number, y: number): void {
|
||||||
|
hideScrollbarRef?.current?.scrollTo({
|
||||||
|
left: x,
|
||||||
|
top: y,
|
||||||
|
behavior: 'smooth'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
getX(): number | undefined {
|
||||||
|
return hideScrollbarRef?.current?.scrollLeft
|
||||||
|
},
|
||||||
|
|
||||||
|
getY(): number | undefined {
|
||||||
|
return hideScrollbarRef?.current?.scrollTop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<HideScrollbar>
|
<HideScrollbar getHideScrollbarRef={getHideScrollbarRef}>
|
||||||
<div className={'body'}>
|
<div className={'body'}>
|
||||||
<header className={'nav ' + (navbarHidden ? 'hide' : '')}>
|
<header className={'nav ' + (navbarHidden ? 'hide' : '')}>
|
||||||
<a className={'logo'} href={'https://fatweb.top'}>
|
<a className={'logo'} href={'https://fatweb.top'}>
|
||||||
@@ -50,7 +158,10 @@ const MainFramework: React.FC = () => {
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<MainFrameworkContext.Provider
|
<MainFrameworkContext.Provider
|
||||||
value={{ navbarHiddenState: { navbarHidden, setNavbarHidden } }}
|
value={{
|
||||||
|
navbarHiddenState: { navbarHidden, setNavbarHidden },
|
||||||
|
controllers: hideScrollbarRefController
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Suspense
|
<Suspense
|
||||||
fallback={
|
fallback={
|
||||||
|
|||||||
5
src/vite-env.d.ts
vendored
5
src/vite-env.d.ts
vendored
@@ -6,11 +6,6 @@ type RouteHandle = {
|
|||||||
auth?: boolean
|
auth?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FitFullscreenProps extends PropsWithChildren {
|
|
||||||
zIndex?: number
|
|
||||||
backgroundColor?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
type _Response<T> = {
|
type _Response<T> = {
|
||||||
code: number
|
code: number
|
||||||
msg: string
|
msg: string
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export default defineConfig({
|
|||||||
'react-router',
|
'react-router',
|
||||||
'react-router-dom',
|
'react-router-dom',
|
||||||
{
|
{
|
||||||
react: ['Suspense'],
|
react: ['Suspense', 'createContext'],
|
||||||
'react-router': ['useMatches', 'RouterProvider'],
|
'react-router': ['useMatches', 'RouterProvider'],
|
||||||
'react-router-dom': ['createBrowserRouter'],
|
'react-router-dom': ['createBrowserRouter'],
|
||||||
antd: ['message']
|
antd: ['message']
|
||||||
@@ -38,7 +38,7 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
from: 'react',
|
from: 'react',
|
||||||
imports: ['PropsWithChildren'],
|
imports: ['PropsWithChildren', 'RefObject'],
|
||||||
type: true
|
type: true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user