初始化
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
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>
|
||||
)
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
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
|
||||
@@ -1,209 +0,0 @@
|
||||
import React, {lazy} from 'react'
|
||||
|
||||
import {IconHistogram, IconUser} from '@douyinfe/semi-icons'
|
||||
import {IconCard, IconConfig, IconMarkdown, IconPopover, IconScrollList} from '@douyinfe/semi-icons-lab'
|
||||
|
||||
const Dashboard = lazy(() => import('@/views/dashboard'))
|
||||
const Profile = lazy(() => import('@/views/profile'))
|
||||
const Role = lazy(() => import('@/views/settings/role'))
|
||||
const Organization = lazy(() => import('@/views/settings/organization'))
|
||||
const Equipment = lazy(() => import('@/views/equipment'))
|
||||
const WorkOrder = lazy(() => import('@/views/work-order'))
|
||||
const Process = lazy(() => import('@/views/process'))
|
||||
const Workpiece = lazy(() => import('@/views/workpiece'))
|
||||
const ProductionReport = lazy(() => import('@/views/reports/production-report'))
|
||||
const MachineUtilizationReport = lazy(
|
||||
() => import('@/views/reports/machine-utilization')
|
||||
)
|
||||
const SamplingData = lazy(() => import('@/views/reports/sampling-data'))
|
||||
const Rgv = lazy(() => import('@/views/rgv'))
|
||||
const EventLog = lazy(() => import('@/views/event-log'))
|
||||
const StationMonitor = lazy(() => import('@/views/station-monitor'))
|
||||
const Inspection = lazy(() => import('@/views/inspection'))
|
||||
const InspectionImages = lazy(() => import('@/views/inspection-images'))
|
||||
|
||||
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: '/dashboard',
|
||||
path: '/',
|
||||
icon: <IconHistogram/>,
|
||||
isMenu: true,
|
||||
element: <Dashboard/>
|
||||
},
|
||||
{
|
||||
name: 'app.menu.station.monitor',
|
||||
path: '/station-monitor',
|
||||
icon: <IconMarkdown/>,
|
||||
isMenu: true,
|
||||
element: <StationMonitor/>
|
||||
},
|
||||
{
|
||||
name: 'app.menu.product.management',
|
||||
icon: <IconCard/>,
|
||||
isMenu: true,
|
||||
children: [
|
||||
{
|
||||
name: 'app.menu.workOrder.management',
|
||||
path: '/work-order',
|
||||
isMenu: true,
|
||||
element: <WorkOrder/>
|
||||
},
|
||||
{
|
||||
name: 'app.menu.workpiece.management',
|
||||
path: '/workpiece',
|
||||
isMenu: true,
|
||||
element: <Workpiece/>
|
||||
},
|
||||
{
|
||||
name: 'app.menu.product.log',
|
||||
path: '/event-log',
|
||||
isMenu: true,
|
||||
element: <EventLog/>
|
||||
}
|
||||
]
|
||||
},
|
||||
/*{
|
||||
name: 'app.menu.technology.management',
|
||||
icon: <IconCascader />,
|
||||
isMenu: true,
|
||||
children: [
|
||||
{
|
||||
name: 'app.menu.process.management',
|
||||
path: '/process',
|
||||
isMenu: true,
|
||||
element: <Process />
|
||||
}
|
||||
/!*,
|
||||
{
|
||||
name: 'app.menu.parameters.management',
|
||||
path: '/params',
|
||||
isMenu: true,
|
||||
element: <Parameter />
|
||||
}*!/
|
||||
]
|
||||
},*/
|
||||
{
|
||||
name: 'app.menu.device.management',
|
||||
icon: <IconPopover/>,
|
||||
// path: '/technology',
|
||||
isMenu: true,
|
||||
children: [
|
||||
/*{
|
||||
name: 'app.menu.category.management',
|
||||
path: '/category',
|
||||
isMenu: true,
|
||||
element: <Category />
|
||||
},*/
|
||||
{
|
||||
name: 'app.menu.equipment.management',
|
||||
path: '/equipment',
|
||||
isMenu: true,
|
||||
element: <Equipment/>
|
||||
},
|
||||
{
|
||||
name: 'app.menu.inspection',
|
||||
path: '/inspection',
|
||||
isMenu: true,
|
||||
element: <Inspection/>
|
||||
}/*,
|
||||
{
|
||||
name: 'app.menu.rgv.management',
|
||||
path: '/rgv',
|
||||
isMenu: true,
|
||||
element: <Rgv />
|
||||
},
|
||||
{
|
||||
name: 'app.menu.cnc-machine.management',
|
||||
path: '/cnc-machine',
|
||||
isMenu: true,
|
||||
element: <CncMachine />
|
||||
},
|
||||
{
|
||||
name: 'app.menu.robot.management',
|
||||
path: '/robot',
|
||||
isMenu: true,
|
||||
element: <Robot />
|
||||
},
|
||||
{
|
||||
name: 'app.menu.plc.management',
|
||||
path: '/plc',
|
||||
isMenu: true,
|
||||
element: <Plc />
|
||||
}*/
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'app.menu.data.report',
|
||||
icon: <IconScrollList/>,
|
||||
isMenu: true,
|
||||
children: [
|
||||
{
|
||||
name: 'app.menu.inspection.image',
|
||||
path: '/inspection-images',
|
||||
isMenu: true,
|
||||
element: <InspectionImages/>
|
||||
},
|
||||
{
|
||||
name: 'app.menu.sampling.data',
|
||||
path: '/sampling-data',
|
||||
isMenu: true,
|
||||
element: <SamplingData/>
|
||||
},
|
||||
{
|
||||
name: 'app.menu.production.report',
|
||||
path: '/production/report',
|
||||
isMenu: true,
|
||||
element: <ProductionReport/>
|
||||
},
|
||||
{
|
||||
name: 'app.menu.machine.utilization.report',
|
||||
path: '/machine/utilization/report',
|
||||
isMenu: true,
|
||||
element: <MachineUtilizationReport/>
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'app.menu.settings',
|
||||
icon: <IconConfig/>,
|
||||
// path: '/technology',
|
||||
isMenu: true,
|
||||
children: [
|
||||
{
|
||||
name: 'app.menu.settings.organization',
|
||||
path: '/organization',
|
||||
isMenu: true,
|
||||
element: <Organization/>
|
||||
},
|
||||
{
|
||||
name: 'app.menu.settings.role',
|
||||
path: '/role',
|
||||
isMenu: true,
|
||||
element: <Role/>
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'app.user.profile',
|
||||
icon: <IconUser/>,
|
||||
path: '/profile',
|
||||
element: <Profile/>
|
||||
}
|
||||
] as Router[]
|
||||
|
||||
export type {Router}
|
||||
@@ -1,14 +0,0 @@
|
||||
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