chore: init bj_power monorepo (dashboard/mes/wms/wms_client/workstation), clear subproject git metadata and align naming to folder names
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import React, { ReactElement, Suspense, useEffect } from 'react'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import useGlobalStore from '@/stores'
|
||||
import SuspendFallbackLoading from '@/components/fallback-loading'
|
||||
|
||||
interface IProps {
|
||||
children: ReactElement
|
||||
permission?: string | undefined
|
||||
}
|
||||
|
||||
export default ({ children }: IProps) => {
|
||||
const { pathname } = useLocation()
|
||||
const { setCurrentKeys } = useGlobalStore(state => state)
|
||||
|
||||
let ignore = false
|
||||
useEffect(() => {
|
||||
if (!ignore) {
|
||||
setCurrentKeys([pathname])
|
||||
return () => {
|
||||
ignore = true
|
||||
}
|
||||
}
|
||||
}, [ignore, pathname])
|
||||
|
||||
/* if (!token) {
|
||||
// Toast.warning("token 过期,请重新登录!");
|
||||
return <Navigate to={'/login'} replace={true}/>
|
||||
}
|
||||
if (!hasPermission(userInfo, permission)) {
|
||||
// Toast.warning("权限不足!");
|
||||
return <Empty title="没有权限" description="请向管理员申请相关权限" type="403"/>
|
||||
// return <Navigate to={'/403'} replace={true}/>
|
||||
}*/
|
||||
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<SuspendFallbackLoading message="加载中" description={'请耐心等待'} />
|
||||
}>
|
||||
{children}
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import React, { FC } from 'react'
|
||||
import { RouteObject } from 'react-router'
|
||||
import { Outlet, useRoutes } from 'react-router-dom'
|
||||
import Login from '@/views/login'
|
||||
import Empty from '@/components//empty'
|
||||
import routers, { Router } from '@/router/routers'
|
||||
import AuthRoute from '@/router/auth-route'
|
||||
import LayoutPage from '@/layouts/index'
|
||||
import { Layout } from '@douyinfe/semi-ui'
|
||||
import NavHeader from '@/layouts/header'
|
||||
|
||||
const genRoutes = (items: Router[]): RouteObject[] => {
|
||||
const routes: RouteObject[] = []
|
||||
items.forEach(r => {
|
||||
if (!r.disabled) {
|
||||
const item: RouteObject = {
|
||||
path: r.path,
|
||||
index: r.index
|
||||
}
|
||||
if (r.element) {
|
||||
item.element = (
|
||||
<AuthRoute permission={r.permission}>{r.element}</AuthRoute>
|
||||
)
|
||||
}
|
||||
if (r.children) {
|
||||
item.children = genRoutes(r.children)
|
||||
}
|
||||
routes.push(item)
|
||||
}
|
||||
})
|
||||
return routes
|
||||
}
|
||||
|
||||
const RenderRouter: FC = () => {
|
||||
const routeMenuList = genRoutes(routers)
|
||||
const routeList: RouteObject[] = [
|
||||
{
|
||||
path: '',
|
||||
element: (
|
||||
<AuthRoute>
|
||||
<Layout
|
||||
style={{ height: '100%', minHeight: '100%', display: 'flex' }}>
|
||||
<Layout.Header
|
||||
style={{ height: 60, backgroundColor: 'var(--semi-color-bg-1)' }}>
|
||||
<NavHeader />
|
||||
</Layout.Header>
|
||||
<Outlet />
|
||||
</Layout>
|
||||
</AuthRoute>
|
||||
),
|
||||
children: [
|
||||
{
|
||||
path: '/',
|
||||
element: <LayoutPage />,
|
||||
children: routeMenuList
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
element: (
|
||||
<Empty title="找不到咯" description="这里什么也没有~" type="404" />
|
||||
)
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
element: <Login />
|
||||
}
|
||||
]
|
||||
return useRoutes(routeList)
|
||||
}
|
||||
|
||||
export default RenderRouter
|
||||
@@ -0,0 +1,52 @@
|
||||
import React, {lazy} from 'react'
|
||||
|
||||
import {IconHistogram, IconCard, IconUser} from '@douyinfe/semi-icons'
|
||||
|
||||
const Dashboard = lazy(() => import('@/views/dashboard'))
|
||||
const WorkOrder = lazy(() => import('@/views/work-order'))
|
||||
const Profile = lazy(() => import('@/views/profile'))
|
||||
|
||||
interface Router {
|
||||
name: string
|
||||
index?: boolean | undefined
|
||||
icon?: React.ReactNode
|
||||
path: string
|
||||
isMenu?: boolean
|
||||
disabled?: boolean
|
||||
auth?: boolean
|
||||
permission?: string
|
||||
element?: React.ReactElement
|
||||
children?: Array<Router>
|
||||
}
|
||||
|
||||
export default [
|
||||
{
|
||||
name: 'app.menu.dashboard',
|
||||
index: true,
|
||||
path: '/',
|
||||
icon: <IconHistogram/>,
|
||||
isMenu: true,
|
||||
element: <Dashboard/>
|
||||
},
|
||||
{
|
||||
name: 'app.menu.product.management',
|
||||
icon: <IconCard/>,
|
||||
isMenu: true,
|
||||
children: [
|
||||
{
|
||||
name: 'app.menu.workOrder.management',
|
||||
path: '/work-order',
|
||||
isMenu: true,
|
||||
element: <WorkOrder/>
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'app.user.profile',
|
||||
icon: <IconUser/>,
|
||||
path: '/profile',
|
||||
element: <Profile/>
|
||||
}
|
||||
] as Router[]
|
||||
|
||||
export type {Router}
|
||||
@@ -0,0 +1,14 @@
|
||||
const hasPermission = (
|
||||
userInfo: UserInfosState,
|
||||
permission: string | undefined
|
||||
) => {
|
||||
if (!permission) {
|
||||
return true
|
||||
}
|
||||
if (userInfo && userInfo.permissions) {
|
||||
return userInfo.permissions.includes(permission)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export { hasPermission }
|
||||
Reference in New Issue
Block a user