diff --git a/config/config.ts b/config/config.ts index 371ee20..6e067ab 100644 --- a/config/config.ts +++ b/config/config.ts @@ -1,127 +1,17 @@ // import { defineConfig } from "umi"; import proxy from './proxy'; +import router from './router' //不使用defineConfig则能在其他地方获取这些配置 export default { plugins: [ '@umijs/plugins/dist/dva' ], - // proxy, + proxy, dva: {}, title: 'UMI4 Admin', favicons: [ '/favicon.svg' ], - routes: [ - { - path: '/', - component: '@/layouts/index', - }, - { - id: 2, - key: '2', - name: '关于', - path: '/about', - redirect: '', - routes: [ - { - id: 21, - key: '2-1', - name: '关于你', - path: '/about/u', - redirect: '', - pid: 2, - routes: [ - { - id: 211, - key: '2-1-1', - name: '关于你1', - path: '/about/u/index', - component: "@/pages/about/u/index", - redirect: '', - pid: 21 - }, - { - id: 212, - key: '2-1-2', - name: '关于你2', - path: '/about/u/2', - component: "@/pages/about/u/$id", - redirect: '', - pid: 21 - } - ] - }, - { - id: 22, - key: '2-2', - path: '/about/m', - redirect: '', - name: '(页面元素权限)关于我', - component: "@/pages/about/m", - pid: 2 - }, - { - id: 23, - key: '2-3', - path: '/about/um', - redirect: '', - name: '关于你和我', - component: "@/pages/about/um", - pid: 2 - } - ] - }, - { - id: 3, - key: '3', - name: '教师', - path: '/teacher', - redirect: '', - routes: [ - { - id: 31, - key: '3-1', - path: '/teacher/u', - redirect: '', - name: '(403)关于你教师', - component: "@/pages/teacher/u", - pid: 3 - }, - { - id: 32, - key: '3-2', - path: '/teacher/m', - redirect: '', - name: '关于我教师', - component: "@/pages/teacher/m", - pid: 3 - }, - { - id: 33, - key: '3-3', - path: '/teacher/um', - redirect: '', - name: '关于你和我教师', - component: "@/pages/teacher/um", - pid: 3 - } - ] - }, - { - id: 4, - key: '4', - name: '(404)学生', - path: '/student', - redirect: '', - }, - { - id: 5, - key: '5', - path: '/user/login', - redirect: '', - name: '登录', - component: "@/pages/user/login", - }, - ] + routes: router }; diff --git a/config/proxy.ts b/config/proxy.ts index f75f782..585353b 100644 --- a/config/proxy.ts +++ b/config/proxy.ts @@ -1,8 +1,15 @@ const proxy = { - '/api': { - target: 'http://10.104.1.38:3000', + '/auth': { + target: 'http://home.robot-z.cn:7001', changeOrigin: true, - pathRewrite: { '^/api': '' }, + secure: false, + pathRewrite: { '^/auth': '' }, + onProxyRes: function(proxyRes) { + proxyRes.headers['Access-Control-Allow-Origin'] = '*'; + proxyRes.headers['Access-Control-Allow-Methods'] = 'GET,PUT,POST,DELETE,OPTIONS'; + proxyRes.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization'; + proxyRes.headers['Access-Control-Allow-Credentials'] = 'true'; + } } } diff --git a/config/router.ts b/config/router.ts new file mode 100644 index 0000000..65dae3e --- /dev/null +++ b/config/router.ts @@ -0,0 +1,50 @@ +// 路由配置文件 +export default [ + { + path: '/user', + routes: [ + { + path: '/user/login', + redirect: '', + name: '登录', + component: "@/pages/user/login", + } + ] + }, + { + path: '/', + routes: [ + { + path: '/standard/index', + redirect: '', + name: '生成标准页面', + component: "@/pages/standard/index", + }, + { + path: '/examine', + redirect: '', + name: '走动式管理', + routes: [ + { + path: '/examine/index', + name: '考评分类管理', + component: "@/pages/examine/index", + }, + { + path: '/examine/question', + name: '考核问题管理', + component: "@/pages/examine/question", + }, + { + path: '/examine/modal', + name: '考核模版管理', + component: "@/pages/examine/modal", + } + ] + + }, + ] + } + +] + diff --git a/src/components/PageAccess.tsx b/src/components/PageAccess.tsx index 7a7dfc6..041af68 100644 --- a/src/components/PageAccess.tsx +++ b/src/components/PageAccess.tsx @@ -1,3 +1,11 @@ +/* + * @Author: cclu 1106109051@qq.com + * @Date: 2025-02-25 11:39:58 + * @LastEditors: cclu 1106109051@qq.com + * @LastEditTime: 2025-03-10 15:30:28 + * @FilePath: \umi4-admin-main\src\components\PageAccess.tsx + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ import type { FC, ReactElement } from 'react'; import { connect, history, useLocation } from 'umi'; import { Button, Result } from 'antd'; @@ -17,6 +25,9 @@ const PageAccess: FC = (props): ReactElement | null => { //当遇到输入的是菜单组件中可展开的节点的path的时候就没有权限了, 此时可能会报错, //加可选操作符可避免这个报错导致的页面渲染问题 const accessible = authority[pathname]?.some((item: string) => userAuthority.includes(item)); + console.log('authority', authority); + console.log('userAuthority', userAuthority); + console.log('children', children); let res = children; diff --git a/src/layouts/index.less b/src/layouts/index.less index f2eb771..4cfbca9 100644 --- a/src/layouts/index.less +++ b/src/layouts/index.less @@ -41,7 +41,48 @@ - + .pageLayout { + :global { + .ant-pro-menu-item { + &.ant-menu-item-selected { + background-color: #1890ff !important; + + .ant-pro-menu-item-title { + color: #fff !important; + } + + &:hover { + background-color: #1890ff !important; + } + } + } + + .ant-menu-item-selected { + background-color: #1890ff !important; + color: #fff !important; + + &:hover { + background-color: #1890ff !important; + color: #fff !important; + } + + a { + color: #fff !important; + } + } + + .ant-menu-submenu-selected > .ant-menu-submenu-title { + color: #1890ff; + } + + .ant-menu-item { + &:hover { + background-color: rgba(24, 144, 255, 0.1); + } + } + } + } + .ant-pro-layout-container{ background-color: #f0f2f5; main{ diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index 8ad5a95..dd96b41 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -1,3 +1,11 @@ +/* + * @Author: cclu 1106109051@qq.com + * @Date: 2025-02-27 15:55:46 + * @LastEditors: cclu 1106109051@qq.com + * @LastEditTime: 2025-03-10 17:46:55 + * @FilePath: \umi4-admin-main\src\layouts\index.tsx + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ import type { FC } from 'react'; import { useState, useEffect } from 'react'; import { Dropdown, Layout, Menu, Tabs, Tooltip } from 'antd'; @@ -9,7 +17,6 @@ import LayoutWrapper from '@/components/LayoutWrapper'; import Nav from '@/components/Nav'; import Page404 from '@/pages/404'; import handleRecursiveNestedData from '@/utils/handleRecursiveNestedData'; -import handleGetCurrentLocation from '@/utils/handleGetCurrentLocation'; import { MenuDataItem, ProLayout } from '@ant-design/pro-components'; import './index.less' import logo from '../assets/logo.svg'; @@ -41,10 +48,6 @@ const handleGetOpenKeys = (currentLocation: API.MenuItem[] | []): string[] => { for (let i = 0; i < currentLocation.length - 1; i++) { res.push(`${currentLocation[i].key}`); } - - console.log('res', res); - - return res; }; @@ -66,8 +69,8 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc console.log('props', props); console.log('pathname', pathname); + console.log('indexValidMenuItemByPath', indexValidMenuItemByPath); const validMenuItem = indexValidMenuItemByPath[pathname]; - console.log('validMenuItem', validMenuItem); // const selectedKeys = validMenuItem?.key; const [activeKey, setActiveKey] = useState(validMenuItem?.path || '/') @@ -81,7 +84,6 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc //点击有子菜单的父菜单的回调 // const onOpenChange: MenuProps['onOpenChange'] = (keys) => { // setOpenKeys(keys) - // console.log('keys', keys); // dispatch({ // namespace: "global/setProfileData", // payload: { @@ -101,7 +103,8 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc ? ( {item.name} ) : item.name, @@ -167,68 +170,35 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc SYSTEMMODULE_DESC: "", guid: "1", hideInMenu: false, - name: "首页", - path: "/", + name: "生成标准页面", + path: "/standard/index", }, { SYSTEMMODULE_DESC: "", guid: "2", hideInMenu: false, - name: "关于你1", - path: "/about/u/index", + name: "考评分类管理", + path: "/examine/index", }, { SYSTEMMODULE_DESC: "", guid: "3", hideInMenu: false, - name: "关于你2", - path: "/about/u/2", + name: "考核问题管理", + path: "/examine/question", }, { SYSTEMMODULE_DESC: "", guid: "4", hideInMenu: false, - name: "(页面元素权限)关于我", - path: "/about/m", - }, - { - SYSTEMMODULE_DESC: "", - guid: "5", - hideInMenu: false, - name: "关于你和我", - path: "/about/um", - }, - { - SYSTEMMODULE_DESC: "", - guid: "5", - hideInMenu: false, - name: "(403)关于你教师", - path: "/teacher/u", - }, - { - SYSTEMMODULE_DESC: "", - guid: "6", - hideInMenu: false, - name: "关于我教师", - path: "/teacher/m", - }, - { - SYSTEMMODULE_DESC: "", - guid: "7", - hideInMenu: false, - name: "关于你和我教师", - path: "/teacher/um", - }, - { - SYSTEMMODULE_DESC: "", - guid: "8", - hideInMenu: false, - name: "(404)学生", - path: "/student", + name: "考核模版管理", + path: "/examine/modal", } ] console.log('tabsRoutes', tabsRoutes); + console.log('location', location); + console.log('consumableMenu', consumableMenu); return ( @@ -247,10 +217,17 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc location={location} style={{ minHeight: '100vh' }} siderWidth={208} - menuDataRender={() => - consumableMenu - // menu - } + selectedKeys={[pathname]} + defaultSelectedKeys={[pathname]} + menuDataRender={() => consumableMenu} + menuItemRender={(menuItemProps, defaultDom) => { + if (menuItemProps.isUrl || !menuItemProps.path) { + return defaultDom; + } + return ( + {defaultDom} + ); + }} subMenuItemRender={(menuItemProps) => { if (menuItemProps.icon && typeof menuItemProps.icon === 'string') { const ele = React.createElement(Icon[menuItemProps.icon]) @@ -288,12 +265,11 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc }} actionsRender={() =>