From a635d71a3c3ab0cfc8c2f80872494c498b543771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4=E6=B5=AE=E5=B0=98?= <18510549872@163.comm> Date: Sun, 5 Nov 2023 23:51:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.less | 4 + src/App.tsx | 56 ++----------- src/components/category-list/index.jsx | 2 +- src/components/question-list/constant.js | 4 +- src/components/top-menu/index.jsx | 13 ++- src/{views => }/imgs/clickImg.png | Bin src/{views => }/imgs/head.jpg | Bin src/{views => }/imgs/javaImg.png | Bin src/{views => }/imgs/logo.jpg | Bin src/router/index.tsx | 10 +++ src/utils/request.ts | 6 +- src/views/header/index.tsx | 97 +++++++++++++++++++++++ src/views/login/index.tsx | 8 ++ src/views/question-bank/constant.ts | 6 +- src/views/user-info/index.less | 4 + src/views/user-info/index.tsx | 60 ++++++++++++++ 16 files changed, 211 insertions(+), 59 deletions(-) rename src/{views => }/imgs/clickImg.png (100%) rename src/{views => }/imgs/head.jpg (100%) rename src/{views => }/imgs/javaImg.png (100%) rename src/{views => }/imgs/logo.jpg (100%) create mode 100644 src/views/header/index.tsx create mode 100644 src/views/login/index.tsx create mode 100644 src/views/user-info/index.less create mode 100644 src/views/user-info/index.tsx diff --git a/src/App.less b/src/App.less index 9cd1648..cb96a0e 100644 --- a/src/App.less +++ b/src/App.less @@ -20,6 +20,10 @@ -moz-user-select: none; /* Firefox */ -ms-user-select: none; /* Internet Explorer/Edge */ user-select: none; /* Non-prefixed version, currently not supported by any browser */ + .content-box{ + width: 1439px; + margin: 0 auto; + } } .header-navigator { diff --git a/src/App.tsx b/src/App.tsx index e65b63d..e5b329b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,55 +1,7 @@ import { useEffect, memo } from 'react'; import './App.less'; import { useLocation, useNavigate, Outlet } from 'react-router-dom'; -import PubSub from 'pubsub-js'; -import { Input } from 'antd'; -import Logo from '@views/imgs/logo.jpg' -import Head from '@views/imgs/head.jpg' -import TopMenu from '@components/top-menu' - -const { Search } = Input; - -const NavTop = () => { - const { pathname } = window.location; - - return ( -
-
-
-
- (window.location.href = '/question-bank') - }> - -
- -
-
-
- {'/question-bank' == pathname && ( -
- console.log(value)} - style={{ width: 300, borderRadius: '10px' }} - /> -
- )} -
- {/* */} -
-
- -
-
-
-
- ) -} +import Header from '@views/header' const App = () => { const location = useLocation(); @@ -61,8 +13,10 @@ const App = () => { }, [location]) return (
- - +
+
+ +
) } diff --git a/src/components/category-list/index.jsx b/src/components/category-list/index.jsx index 88e0013..bb3c8b3 100644 --- a/src/components/category-list/index.jsx +++ b/src/components/category-list/index.jsx @@ -80,7 +80,7 @@ const CategoryList = ({ primaryCategoryId, categoryList, ...props }) => { let list = res.data for (let i = 0; i < list.length; i++) { list[i].children = await getLabels(list[i].id) - if (i === 0) { + if (i === 0 && list[i].children.length) { list[i].children[0].active = true } } diff --git a/src/components/question-list/constant.js b/src/components/question-list/constant.js index 044345e..370f5d7 100644 --- a/src/components/question-list/constant.js +++ b/src/components/question-list/constant.js @@ -65,8 +65,8 @@ export const imgObject = { 'https://img11.360buyimg.com/imagetools/jfs/t1/206213/24/13307/2603/617f4fc4E676d448d/622d5287fbf5a919.png', dataImg: 'https://img12.360buyimg.com/imagetools/jfs/t1/207558/34/7606/3672/617f4fc4E1ca685fc/3953a92a6072fba4.png', - javaImg: - '../../views/imgs/javaImg.png', + // javaImg: + // '../../views/imgs/javaImg.png', npmImg: 'https://img11.360buyimg.com/imagetools/jfs/t1/200551/24/15367/3145/617f4fc4Ea153dc2e/b4bbf2de8807f42d.png', parallelComputingImg: 'https://img14.360buyimg.com/imagetools/jfs/t1/207198/23/7638/3037/617f4fc4E0e20ab9d/40197a6c79c5a33f.png', diff --git a/src/components/top-menu/index.jsx b/src/components/top-menu/index.jsx index 8ed5172..cb11af8 100644 --- a/src/components/top-menu/index.jsx +++ b/src/components/top-menu/index.jsx @@ -1,5 +1,5 @@ import { message } from 'antd'; -import React, { Component, useState, memo } from 'react' +import React, { useState, memo, useEffect } from 'react' import { useLocation, useNavigate } from 'react-router-dom'; import './index.less' // 顶部tab @@ -37,6 +37,16 @@ const TopMenu = () => { const location = useLocation() const navigate = useNavigate() + useEffect(() => { + const cur = MENULIST.filter(t => t.route === location.pathname) + if (cur.length) { + setCurrentKey(cur[0].key) + } else { + setCurrentKey('') + } + }, [location.pathname]); + + /** * 切换item * @param {*} item @@ -46,6 +56,7 @@ const TopMenu = () => { if (item.key === "questionBank") { if (location.pathname === '/question-bank') return navigate('/question-bank') + setCurrentKey(item.key) } else { return message.info("敬请期待") } diff --git a/src/views/imgs/clickImg.png b/src/imgs/clickImg.png similarity index 100% rename from src/views/imgs/clickImg.png rename to src/imgs/clickImg.png diff --git a/src/views/imgs/head.jpg b/src/imgs/head.jpg similarity index 100% rename from src/views/imgs/head.jpg rename to src/imgs/head.jpg diff --git a/src/views/imgs/javaImg.png b/src/imgs/javaImg.png similarity index 100% rename from src/views/imgs/javaImg.png rename to src/imgs/javaImg.png diff --git a/src/views/imgs/logo.jpg b/src/imgs/logo.jpg similarity index 100% rename from src/views/imgs/logo.jpg rename to src/imgs/logo.jpg diff --git a/src/router/index.tsx b/src/router/index.tsx index 0fa6f57..fa797a2 100644 --- a/src/router/index.tsx +++ b/src/router/index.tsx @@ -3,6 +3,8 @@ import App from '@/App' import QuestionBank from '@views/question-bank'; import UploadQuestions from '@views/upload-questions'; import BrushQuestions from '@views/brush-questions' +import Login from '@views/login' +import UserInfo from '@views/user-info' import { createBrowserRouter, } from "react-router-dom"; @@ -24,6 +26,14 @@ const router = createBrowserRouter([ path: "upload-question", element: , }, + { + path: 'login', + element: + }, + { + path: 'user-info', + element: + } ], }, ]); diff --git a/src/utils/request.ts b/src/utils/request.ts index b530e59..f689f5f 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,5 +1,6 @@ import axios from 'axios'; -import { message } from 'antd'; +import { message, Modal } from 'antd'; +import { useLocation, useNavigate } from 'react-router-dom'; export const baseHttp = () => { const http = axios.create({ @@ -15,6 +16,8 @@ export const baseHttp = () => { }; export default function request(config, url) { + // const navigate = useNavigate() + const baseURL = url || '/subject'; // 1.创建axios的实例 const instance = axios.create({ @@ -50,6 +53,7 @@ export default function request(config, url) { let { status } = err?.response ?? {}; if (status === 401 || !status) { message.info('页面异常') + window.location.replace('/login') } else if (status === 500 || status === 503) { message.error('服务器错误'); } diff --git a/src/views/header/index.tsx b/src/views/header/index.tsx new file mode 100644 index 0000000..a371083 --- /dev/null +++ b/src/views/header/index.tsx @@ -0,0 +1,97 @@ +import { Input, Dropdown, message } from 'antd'; +import Logo from '@/imgs/logo.jpg' +import Head from '@/imgs/head.jpg' +import TopMenu from '@components/top-menu' +import { UserOutlined, HeartOutlined, LikeOutlined, LoginOutlined } from '@ant-design/icons' + +const { Search } = Input; + +const menuItems = [ + { + label: '个人中心', + key: 1, + icon: + }, + { + label: '我的收藏', + key: 2, + icon: + }, { + label: '我的点赞', + key: 3, + icon: + }, + { + type: 'divider', + }, + { + label: '退出', + key: 4, + icon: + } +] + +const Header = () => { + const { pathname } = window.location; + + + const handleMenuClick = e => { + console.log(e) + if (e.key != 1) { + return message.info('敬请期待') + } + } + + return ( +
+
+
+
+ (window.location.href = '/question-bank') + }> + +
+ +
+
+
+ {'/question-bank' == pathname && ( +
+ console.log(value)} + style={{ width: 300, borderRadius: '10px' }} + /> +
+ )} +
+ {/* */} +
+
+ + + + +
+
+
+
+ ) +} +export default Header \ No newline at end of file diff --git a/src/views/login/index.tsx b/src/views/login/index.tsx new file mode 100644 index 0000000..97e6d0f --- /dev/null +++ b/src/views/login/index.tsx @@ -0,0 +1,8 @@ + +const Login = () => { + return (
+ login +
) +} + +export default Login \ No newline at end of file diff --git a/src/views/question-bank/constant.ts b/src/views/question-bank/constant.ts index 33f1d9d..8fb6c9e 100644 --- a/src/views/question-bank/constant.ts +++ b/src/views/question-bank/constant.ts @@ -1,4 +1,4 @@ -import JavaImg from '@views/imgs/javaImg.png' +// import JavaImg from '@views/imgs/javaImg.png' /** * 难度等级 */ @@ -73,7 +73,7 @@ export const apiName = { export const imgObject = { clickImg: - 'https://img13.360buyimg.com/imagetools/jfs/t1/222669/25/807/6590/617f4f06Eb2094586/64c39ce3769b8a16.png', + 'http://117.72.14.166:9000/jichi/icon/%E7%83%AD%E9%97%A8.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20231102%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20231102T153146Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=e6b8cdb3231b1c3d7114212cb9278ecc17cf6d4ec0f759ea0200e04156d4c8b7', ranking1Img: 'https://img12.360buyimg.com/imagetools/jfs/t1/110906/3/22471/3750/6214a3bfE392596cf/122c9e4b30948682.png', ranking2Img: @@ -88,7 +88,7 @@ export const imgObject = { 'https://img11.360buyimg.com/imagetools/jfs/t1/206213/24/13307/2603/617f4fc4E676d448d/622d5287fbf5a919.png', dataImg: 'https://img12.360buyimg.com/imagetools/jfs/t1/207558/34/7606/3672/617f4fc4E1ca685fc/3953a92a6072fba4.png', - javaImg: JavaImg, + // javaImg: JavaImg, npmImg: 'https://img11.360buyimg.com/imagetools/jfs/t1/200551/24/15367/3145/617f4fc4Ea153dc2e/b4bbf2de8807f42d.png', parallelComputingImg: 'https://img14.360buyimg.com/imagetools/jfs/t1/207198/23/7638/3037/617f4fc4E0e20ab9d/40197a6c79c5a33f.png', diff --git a/src/views/user-info/index.less b/src/views/user-info/index.less new file mode 100644 index 0000000..d292f76 --- /dev/null +++ b/src/views/user-info/index.less @@ -0,0 +1,4 @@ +.user-info-box{ + background-color: white; + height: 100%; +} \ No newline at end of file diff --git a/src/views/user-info/index.tsx b/src/views/user-info/index.tsx new file mode 100644 index 0000000..da9fb25 --- /dev/null +++ b/src/views/user-info/index.tsx @@ -0,0 +1,60 @@ +import { useState } from 'react' +import { Form, Row, Col, Input, Button, Card } from 'antd' + +import './index.less' + +const layout = { + labelCol: { span: 4 }, + wrapperCol: { span: 10, offset: 1 } +} + +const UserInfo = () => { + + const [editFields, setEditFields] = useState>({ + nickName: false, + gender: false, + introduce: false, + birth: false + }) + + const changeEditFields = (field: string) => { + setEditFields({ + ...editFields, + [field]: !editFields[field] + }) + } + + return
+ +
+ + + + {editFields.nickName ? : <> + 昵称 + } + + + + + + + + + + + + + + + + + + +
+
+ +
+} + +export default UserInfo \ No newline at end of file