-
+
FatWeb
@@ -115,11 +116,9 @@ const MainFramework: React.FC = () => {
key={subRoute.id}
>
{
})}
{
-
+
{routeChildren?.map((route) => {
return (
@@ -187,7 +184,7 @@ const MainFramework: React.FC = () => {
- {
>
-
+
>
)
}
-export default MainFramework
+export default HomeFramework
diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx
index 02ff4d2..92a8bac 100644
--- a/src/pages/Login.tsx
+++ b/src/pages/Login.tsx
@@ -12,6 +12,7 @@ import '@/assets/css/pages/login.scss'
const Login: React.FC = () => {
const [messageApi, contextHolder] = message.useMessage()
const navigate = useNavigate()
+ const [searchParams] = useSearchParams()
const [isLoggingIn, setIsLoggingIn] = useState(false)
const onFinish = (values: LoginForm) => {
@@ -25,7 +26,11 @@ const Login: React.FC = () => {
setToken(data?.token ?? '')
void messageApi.success('登录成功')
setTimeout(() => {
- navigate('/')
+ if (searchParams.has('redirect')) {
+ navigate(searchParams.get('redirect') ?? '/')
+ } else {
+ navigate('/')
+ }
}, 1500)
break
case SYSTEM_USERNAME_NOT_FOUND:
diff --git a/src/pages/ToolsFramework.tsx b/src/pages/ToolsFramework.tsx
new file mode 100644
index 0000000..fb3c76d
--- /dev/null
+++ b/src/pages/ToolsFramework.tsx
@@ -0,0 +1,197 @@
+import React from 'react'
+import FitFullScreen from '@/components/common/FitFullScreen'
+import '@/assets/css/pages/tools-framework.scss'
+import Icon from '@ant-design/icons'
+import { toolsJsonObjects } from '@/router/tools.tsx'
+import HideScrollbar, { HideScrollbarElement } from '@/components/common/HideScrollbar.tsx'
+import { getLocalStorage, setLocalStorage } from '@/utils/common.ts'
+
+const ToolsFramework: React.FC = () => {
+ const hideScrollbarRef = useRef
(null)
+ const [submenuTop, setSubmenuTop] = useState(0)
+ const [submenuLeft, setSubmenuLeft] = useState(0)
+ const [hideSidebar, setHideSidebar] = useState(getLocalStorage('hideSidebar') === 'false')
+
+ const switchSidebar = () => {
+ setHideSidebar(!hideSidebar)
+ setLocalStorage('hideSidebar', hideSidebar ? 'true' : 'false')
+ setTimeout(() => {
+ hideScrollbarRef.current?.refreshLayout()
+ }, 300)
+ }
+
+ const showSubmenu = (e: React.MouseEvent) => {
+ const parentElement = e.currentTarget.parentElement
+ if (parentElement && parentElement.childElementCount === 2) {
+ const parentClientRect = parentElement.getBoundingClientRect()
+ if (parentClientRect.top <= screen.height / 2) {
+ setSubmenuTop(parentClientRect.top)
+ } else {
+ setSubmenuTop(
+ parentClientRect.top -
+ (parentElement.lastElementChild?.clientHeight ?? 0) +
+ e.currentTarget.clientHeight
+ )
+ }
+ setSubmenuLeft(parentClientRect.right)
+ }
+ }
+
+ return (
+ <>
+
+
+
+
+
+
+ 氮工具
+
+
+
+
+ -
+
+
+ isPending ? 'pending' : isActive ? 'active' : ''
+ }
+ >
+
+ {toolsJsonObjects[0].icon ? (
+
+ ) : undefined}
+
+ {toolsJsonObjects[0].name}
+
+
+
+ -
+
+
+ isPending ? ' pending' : isActive ? ' active' : ''
+ }
+ >
+
+ {toolsJsonObjects[1].icon ? (
+
+ ) : undefined}
+
+ {toolsJsonObjects[1].name}
+
+
+
+ -
+
+
+
+
+
+
+ {toolsJsonObjects.map((tool) => {
+ return tool.menu &&
+ tool.id !== 'tools' &&
+ tool.id !== 'tools-all' ? (
+ -
+
+
+ isPending
+ ? 'pending'
+ : isActive
+ ? 'active'
+ : ''
+ }
+ >
+
+ {tool.icon ? (
+
+ ) : undefined}
+
+ {tool.name}
+
+
+ {tool.children ? (
+
+
+ {tool.children.map((subTool) => {
+ return subTool.menu ? (
+
-
+
+ isPending
+ ? 'pending'
+ : isActive
+ ? 'active'
+ : ''
+ }
+ >
+
+ {subTool.name}
+
+
+
+ ) : undefined
+ })}
+
+
+ ) : undefined}
+
+ ) : undefined
+ })}
+
+
+
+
+
+
+
+
+
+ 未登录
+
+
+
+
+ >
+ )
+}
+
+export default ToolsFramework
diff --git a/src/pages/Home.tsx b/src/pages/home/index.tsx
similarity index 97%
rename from src/pages/Home.tsx
rename to src/pages/home/index.tsx
index 3091de0..25ca34d 100644
--- a/src/pages/Home.tsx
+++ b/src/pages/home/index.tsx
@@ -1,7 +1,7 @@
import React from 'react'
import '@/assets/css/components/home/home.scss'
import FitFullScreen from '@/components/common/FitFullScreen'
-import { MainFrameworkContext } from '@/pages/MainFramework'
+import { HomeFrameworkContext } from '@/pages/HomeFramework'
import Slogan from '@/components/home/Slogan'
import OxygenToolbox from '@/components/home/OxygenToolbox'
import Indicator from '@/components/common/Indicator'
@@ -13,7 +13,7 @@ const Home: React.FC = () => {
navbarHiddenState: { navbarHidden, setNavbarHidden },
showDropdownMenuState: { setShowDropdownMenu },
preventScrollState: { setPreventScroll }
- } = useContext(MainFrameworkContext)
+ } = useContext(HomeFrameworkContext)
const fitFullScreenRef = useRef(null)
const scrollTimeout = useRef(0)
diff --git a/src/pages/tools/All.tsx b/src/pages/tools/All.tsx
new file mode 100644
index 0000000..85e812d
--- /dev/null
+++ b/src/pages/tools/All.tsx
@@ -0,0 +1,7 @@
+import React from 'react'
+
+const All: React.FC = () => {
+ return <>>
+}
+
+export default All
diff --git a/src/pages/Tools.tsx b/src/pages/tools/index.tsx
similarity index 100%
rename from src/pages/Tools.tsx
rename to src/pages/tools/index.tsx
diff --git a/src/router/index.tsx b/src/router/index.tsx
index 580eaf6..ea360d9 100644
--- a/src/router/index.tsx
+++ b/src/router/index.tsx
@@ -1,4 +1,5 @@
import React from 'react'
+import tools from '@/router/tools'
const routes: RouteObject[] = [
{
@@ -15,15 +16,26 @@ const routes: RouteObject[] = [
id: 'loading',
Component: React.lazy(() => import('@/components/common/LoadingMask'))
},
+ {
+ path: '/tools',
+ id: 'toolsFramework',
+ Component: React.lazy(() => import('@/pages/ToolsFramework')),
+ children: tools,
+ handle: {
+ name: '工具',
+ title: '工具',
+ auth: false
+ }
+ },
{
path: '',
- id: 'mainFramework',
- Component: React.lazy(() => import('@/pages/MainFramework')),
+ id: 'homeFramework',
+ Component: React.lazy(() => import('@/pages/HomeFramework')),
children: [
{
path: '',
id: 'home',
- Component: React.lazy(() => import('@/pages/Home')),
+ Component: React.lazy(() => import('@/pages/home')),
handle: {
name: '主页',
menu: true,
@@ -32,33 +44,28 @@ const routes: RouteObject[] = [
},
{
path: 'https://blog.fatweb.top',
- id: 'blog',
+ id: 'url-blog',
handle: {
name: '博客',
- menu: true,
- auth: false
+ menu: true
}
},
{
- path: 'tools',
- id: 'tools',
- Component: React.lazy(() => import('@/pages/Tools')),
+ path: '/tools',
+ id: 'url-tools',
children: [
{
path: 'translation',
- id: 'tools-translation',
- Component: React.lazy(() => import('@/pages/tools/Translation')),
+ id: 'url-tools-translation',
handle: {
name: '翻译',
- menu: true,
- auth: false
+ menu: true
}
}
],
handle: {
name: '工具',
- menu: true,
- auth: false
+ menu: true
}
}
]
diff --git a/src/router/tools.tsx b/src/router/tools.tsx
new file mode 100644
index 0000000..a98995c
--- /dev/null
+++ b/src/router/tools.tsx
@@ -0,0 +1,312 @@
+import React from 'react'
+
+const defaultTitle = '氮工具'
+
+export const toolsJsonObjects: ToolsJsonObject[] = [
+ {
+ path: '',
+ id: 'tools',
+ component: React.lazy(() => import('@/pages/tools')),
+ icon: React.lazy(() => import('~icons/fatweb/logo.jsx')),
+ name: '主页',
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'all',
+ id: 'tools-all',
+ component: React.lazy(() => import('@/pages/tools')),
+ name: '全部工具',
+ titlePostfix: ' - 全部工具',
+ icon: React.lazy(() => import('~icons/fatweb/logo.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation',
+ id: 'tools-translation',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false,
+ children: [
+ {
+ path: '1',
+ id: '1',
+ name: '翻译1',
+ icon: React.lazy(() => import('~icons/fatweb/logo.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: '2',
+ id: '2',
+ name: '翻译2',
+ menu: true,
+ auth: false
+ }
+ ]
+ },
+ {
+ path: 'translation-',
+ id: 'tools-translation-',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译-',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false,
+ children: [
+ {
+ path: '1-',
+ id: '1-',
+ name: '翻译1-',
+ menu: true,
+ auth: false
+ },
+ {
+ path: '2-',
+ id: '2-',
+ name: '翻译2-',
+ menu: true,
+ auth: false
+ }
+ ]
+ },
+ {
+ path: 'translation--',
+ id: 'tools-translation--',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--1',
+ id: 'tools-translation--1',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--1',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--2',
+ id: 'tools-translation--2',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--2',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--3',
+ id: 'tools-translation--3',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--3',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--4',
+ id: 'tools-translation--4',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--4',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--5',
+ id: 'tools-translation--5',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--5',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--6',
+ id: 'tools-translation--6',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--6',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--7',
+ id: 'tools-translation--7',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--7',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--8',
+ id: 'tools-translation--8',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--8',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--9',
+ id: 'tools-translation--9',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--9',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--10',
+ id: 'tools-translation--10',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--10',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--1-',
+ id: 'tools-translation--1-',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--1-',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--2-',
+ id: 'tools-translation--2-',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--2-',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--3-',
+ id: 'tools-translation--3-',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--3-',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--4-',
+ id: 'tools-translation--4-',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--4-',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--5-',
+ id: 'tools-translation--5-',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--5-',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--6-',
+ id: 'tools-translation--6-',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--6-',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--7-',
+ id: 'tools-translation--7-',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--7-',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--8-',
+ id: 'tools-translation--8-',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--8-',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--9-',
+ id: 'tools-translation--9-',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--9-',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false
+ },
+ {
+ path: 'translation--10-',
+ id: 'tools-translation--10-',
+ component: React.lazy(() => import('@/pages/tools/Translation')),
+ name: '翻译--10-',
+ icon: React.lazy(() => import('~icons/fatweb/jenkins.jsx')),
+ menu: true,
+ auth: false,
+ children: [
+ {
+ path: '1-1',
+ id: '1-1',
+ name: '翻译1-',
+ menu: true,
+ auth: false
+ },
+ {
+ path: '2-1',
+ id: '2-1',
+ name: '翻译2-',
+ menu: true,
+ auth: false
+ }
+ ]
+ }
+]
+
+const tools: RouteObject[] = toolsJsonObjects.map((value) => ({
+ path: value.path,
+ id: value.id,
+ Component: value.component,
+ handle: {
+ name: value.name,
+ titlePrefix: value.titlePrefix,
+ title: value.title ?? defaultTitle,
+ titlePostfix: value.titlePostfix,
+ icon: value.icon,
+ menu: value.menu,
+ auth: value.auth
+ },
+ children: value.children?.map((value) => ({
+ path: value.path,
+ id: value.id,
+ Component: value.component,
+ handle: {
+ name: value.name,
+ titlePrefix: value.titlePrefix,
+ title: value.title ?? defaultTitle,
+ titlePostfix: value.titlePostfix,
+ icon: value.icon,
+ menu: value.menu,
+ auth: value.auth
+ }
+ }))
+}))
+
+export default tools
diff --git a/src/utils/common.ts b/src/utils/common.ts
index 96f1784..7d0f9ce 100644
--- a/src/utils/common.ts
+++ b/src/utils/common.ts
@@ -18,14 +18,14 @@ export function setCookie(
daysToLive: number | null,
path: string | null
): void {
- let cookie = name + '=' + encodeURIComponent(value)
+ let cookie = `${name}=${encodeURIComponent(value)}`
if (typeof daysToLive === 'number') {
cookie = `${cookie}; max-age=${daysToLive * 24 * 60 * 60}`
}
if (typeof path === 'string') {
- cookie += '; path=' + path
+ cookie = `${cookie}; path=${path}`
}
document.cookie = cookie
@@ -61,7 +61,7 @@ export function getToken(): string | null {
}
export function removeCookie(name: string): void {
- document.cookie = name + '=; max-age=0'
+ document.cookie = `${name}=; max-age=0`
}
export function removeLocalStorage(name: string): void {