From 0fa63b963ce217ef0ab1b861d49c82157709ff4b Mon Sep 17 00:00:00 2001 From: luoxin <1440155977@qq.com> Date: Mon, 6 Dec 2021 15:08:03 +0800 Subject: [PATCH] init --- config/defaultSettings.js | 2 +- config/dynamicRoutes.js | 42 ++++ config/routes.js | 5 + mock/route.js | 22 +- mock/user.js | 210 ----------------- package.json | 2 +- src/access.js | 2 +- src/app.jsx | 51 ++-- src/components/HeaderSearch/index.jsx | 83 ------- src/components/HeaderSearch/index.less | 25 -- src/components/NoticeIcon/NoticeIcon.jsx | 114 --------- src/components/NoticeIcon/NoticeList.jsx | 97 -------- src/components/NoticeIcon/NoticeList.less | 103 -------- src/components/NoticeIcon/index.jsx | 148 ------------ src/components/NoticeIcon/index.less | 35 --- src/components/RightContent/index.jsx | 26 --- src/components/index.md | 272 ---------------------- src/pages/Root.jsx | 9 +- src/pages/demolition/page1/index.jsx | 2 + src/pages/demolition/page2/index.jsx | 1 + src/pages/eawcs/page1/index.jsx | 2 +- src/pages/eawcs/page2/index.jsx | 1 + src/util/func.js | 0 23 files changed, 89 insertions(+), 1165 deletions(-) create mode 100644 config/dynamicRoutes.js delete mode 100644 mock/user.js delete mode 100644 src/components/HeaderSearch/index.jsx delete mode 100644 src/components/HeaderSearch/index.less delete mode 100644 src/components/NoticeIcon/NoticeIcon.jsx delete mode 100644 src/components/NoticeIcon/NoticeList.jsx delete mode 100644 src/components/NoticeIcon/NoticeList.less delete mode 100644 src/components/NoticeIcon/index.jsx delete mode 100644 src/components/NoticeIcon/index.less delete mode 100644 src/components/index.md create mode 100644 src/util/func.js diff --git a/config/defaultSettings.js b/config/defaultSettings.js index 80f08e3..0f005eb 100644 --- a/config/defaultSettings.js +++ b/config/defaultSettings.js @@ -4,7 +4,7 @@ const Settings = { primaryColor: '#1890ff', layout: 'mix', contentWidth: 'Fluid', - fixedHeader: false, + fixedHeader: true, fixSiderbar: true, colorWeak: false, title: 'Ant Design Pro', diff --git a/config/dynamicRoutes.js b/config/dynamicRoutes.js new file mode 100644 index 0000000..1ad6ded --- /dev/null +++ b/config/dynamicRoutes.js @@ -0,0 +1,42 @@ +export default [ + { + path: '/eawcs', + layout: true, + exact: true, + routes: [ + { path: '/eawcs', redirect: '/eawcs/des1' }, + { + path: '/eawcs/des1', + name: '环水保菜单1', + component:'./eawcs/page1' + }, + { + path: '/eawcs/des2', + name: '环水保菜单2', + component:'./eawcs/page2' + }, + ] + }, + { + path: '/demolition', + layout: true, + exact: true, + routes: [ + { path: '/demolition', redirect: '/demolition/dem1' }, + { + path: '/demolition/dem1', + name: '先签后建菜单1', + component:'./demolition/page1' + }, + { + path: '/demolition/dem2', + name: '先签后建菜单2', + exact: true, + component:'./demolition/page2' + }, + ] + }, + { + component: './404', + }, +]; diff --git a/config/routes.js b/config/routes.js index ea9dd32..68dcba0 100644 --- a/config/routes.js +++ b/config/routes.js @@ -1,3 +1,5 @@ +import dynamicRoutes from './dynamicRoutes' + export default [ { path: '/user/login', @@ -8,6 +10,9 @@ export default [ path: '/', component: './Root', layout: false, + routes:[ + ...dynamicRoutes + ], }, { component: './404', diff --git a/mock/route.js b/mock/route.js index e7eade2..a9a4d1a 100644 --- a/mock/route.js +++ b/mock/route.js @@ -4,14 +4,12 @@ export default { res.send({ data: [ { - path: '/des1', - name: '菜单1', - component:'@/eawcs/page1' + path: '/eawcs/des1', + name: '环水保菜单1', }, { - path: '/des2', - name: '菜单2', - component:'@/eawcs/page2' + path: '/eawcs/des2', + name: '环水保菜单2', } ], success: true, @@ -20,14 +18,14 @@ export default { res.send({ data: [ { - path: '/dem1', - name: '菜单1', - component:'@/demolition/page1' + path: '/demolition/dem1', + name: '先签后建菜单1', + exact: true, }, { - path: '/dem2', - name: '菜单2', - component:'@/demolition/page2' + path: '/demolition/dem2', + name: '先签后建菜单2', + exact: true, } ], success: true, diff --git a/mock/user.js b/mock/user.js deleted file mode 100644 index fa8c1b4..0000000 --- a/mock/user.js +++ /dev/null @@ -1,210 +0,0 @@ -const waitTime = (time = 100) => { - return new Promise((resolve) => { - setTimeout(() => { - resolve(true); - }, time); - }); -}; - -async function getFakeCaptcha(req, res) { - await waitTime(2000); - return res.json('captcha-xxx'); -} - -const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env; -/** - * 当前用户的权限,如果为空代表没登录 - * current user access, if is '', user need login - * 如果是 pro 的预览,默认是有权限的 - */ - -let access = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site' ? 'admin' : ''; - -const getAccess = () => { - return access; -}; // 代码中会兼容本地 service mock 以及部署站点的静态数据 - -export default { - // 支持值为 Object 和 Array - 'GET /api/currentUser': (req, res) => { - if (!getAccess()) { - res.status(401).send({ - data: { - isLogin: false, - }, - errorCode: '401', - errorMessage: '请先登录!', - success: true, - }); - return; - } - - res.send({ - success: true, - data: { - name: 'Serati Ma', - avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png', - userid: '00000001', - email: 'antdesign@alipay.com', - signature: '海纳百川,有容乃大', - title: '交互专家', - group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED', - tags: [ - { - key: '0', - label: '很有想法的', - }, - { - key: '1', - label: '专注设计', - }, - { - key: '2', - label: '辣~', - }, - { - key: '3', - label: '大长腿', - }, - { - key: '4', - label: '川妹子', - }, - { - key: '5', - label: '海纳百川', - }, - ], - notifyCount: 12, - unreadCount: 11, - country: 'China', - access: getAccess(), - geographic: { - province: { - label: '浙江省', - key: '330000', - }, - city: { - label: '杭州市', - key: '330100', - }, - }, - address: '西湖区工专路 77 号', - phone: '0752-268888888', - }, - }); - }, - // GET POST 可省略 - 'GET /api/users': [ - { - key: '1', - name: 'John Brown', - age: 32, - address: 'New York No. 1 Lake Park', - }, - { - key: '2', - name: 'Jim Green', - age: 42, - address: 'London No. 1 Lake Park', - }, - { - key: '3', - name: 'Joe Black', - age: 32, - address: 'Sidney No. 1 Lake Park', - }, - ], - 'POST /api/login/account': async (req, res) => { - const { password, username, type } = req.body; - await waitTime(2000); - - if (password === 'ant.design' && username === 'admin') { - res.send({ - status: 'ok', - type, - currentAuthority: 'admin', - }); - access = 'admin'; - return; - } - - if (password === 'ant.design' && username === 'user') { - res.send({ - status: 'ok', - type, - currentAuthority: 'user', - }); - access = 'user'; - return; - } - - if (type === 'mobile') { - res.send({ - status: 'ok', - type, - currentAuthority: 'admin', - }); - access = 'admin'; - return; - } - - res.send({ - status: 'error', - type, - currentAuthority: 'guest', - }); - access = 'guest'; - }, - 'POST /api/login/outLogin': (req, res) => { - access = ''; - res.send({ - data: {}, - success: true, - }); - }, - 'POST /api/register': (req, res) => { - res.send({ - status: 'ok', - currentAuthority: 'user', - success: true, - }); - }, - 'GET /api/500': (req, res) => { - res.status(500).send({ - timestamp: 1513932555104, - status: 500, - error: 'error', - message: 'error', - path: '/base/category/list', - }); - }, - 'GET /api/404': (req, res) => { - res.status(404).send({ - timestamp: 1513932643431, - status: 404, - error: 'Not Found', - message: 'No message available', - path: '/base/category/list/2121212', - }); - }, - 'GET /api/403': (req, res) => { - res.status(403).send({ - timestamp: 1513932555104, - status: 403, - error: 'Forbidden', - message: 'Forbidden', - path: '/base/category/list', - }); - }, - 'GET /api/401': (req, res) => { - res.status(401).send({ - timestamp: 1513932555104, - status: 401, - error: 'Unauthorized', - message: 'Unauthorized', - path: '/base/category/list', - }); - }, - 'GET /api/login/captcha': getFakeCaptcha, -}; diff --git a/package.json b/package.json index ad2b2d1..10497d4 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "react-dev-inspector": "^1.1.1", "react-dom": "^17.0.0", "react-helmet-async": "^1.0.4", - "umi": "^3.5.0", + "umi": "^3.5.20", "umi-serve": "^1.9.10" }, "devDependencies": { diff --git a/src/access.js b/src/access.js index 8fa4337..372c618 100644 --- a/src/access.js +++ b/src/access.js @@ -4,6 +4,6 @@ export default function access(initialState) { const { currentUser } = initialState || {}; return { - canAdmin: currentUser && currentUser.access === 'admin', + canAdmin: {} }; } diff --git a/src/app.jsx b/src/app.jsx index 806efaa..364c600 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -1,10 +1,11 @@ +import React from 'react'; import { PageLoading } from '@ant-design/pro-layout'; -import { history, Link } from 'umi'; +import { history } from 'umi'; import RightContent from '@/components/RightContent'; import Footer from '@/components/Footer'; -import { BookOutlined, LinkOutlined } from '@ant-design/icons'; -const isDev = process.env.NODE_ENV === 'development'; import { getMenus } from '@/services/client'; + +const isDev = process.env.NODE_ENV === 'development'; const loginPath = '/user/login'; /** 获取用户信息比较慢的时候会展示一个 loading */ @@ -41,30 +42,27 @@ export const initialStateConfig = { // }; // } // ProLayout 支持的api https://procomponents.ant.design/components/layout -let extraRoutes; - -// extraRoutesexport function patchRoutes({ routes }) { -// -// } -// -export function render(oldRender) { - const { location } = history - if(location.pathname !== '/'){ - if(location.query.sys){ - getMenus(location.query.sys).then(res=>{ - console.log(res); - }) - } - - } - oldRender(); +export function patchRoutes({ routes }) { + console.log(routes); } + export const layout = ({ initialState }) => { return { rightContentRender: () => , disableContentMargin: false, footerRender: () =>