diff --git a/.env.development b/.env.development index 78c929e..f333e5e 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,2 @@ -VITE_API_HOST=http://117.72.14.166:5000 +VITE_API_HOST=http://117.72.14.166:3010 VITE_IMG_HOST=http://117.72.14.166:9000 diff --git a/src/App.tsx b/src/App.tsx index 2a8fbc5..c9ed272 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import Header from '@views/header' -import { memo, useEffect } from 'react' +import { Suspense, memo, useEffect } from 'react' import { Outlet, useLocation, useNavigate } from 'react-router-dom' import './App.less' @@ -25,7 +25,9 @@ const App = () => { className='content-box' style={{ width: location.pathname === '/login' ? '100%' : '1439px' }} > - + }> + + ) diff --git a/src/components/category-list/constant.js b/src/components/category-list/constant.js index b58f5a5..3e1fbb4 100644 --- a/src/components/category-list/constant.js +++ b/src/components/category-list/constant.js @@ -1,15 +1,17 @@ - export const apiName = { - /** - * 获取二级和三级标签 - */ - getCategoryLabelInfo: '/admin/question/category/getCategoryLabelInfo', + /** + * 获取二级和三级标签 + */ + getCategoryLabelInfo: '/admin/question/category/getCategoryLabelInfo', - /** - * 查询大类下分类 - */ - queryCategoryByPrimary: '/category/queryCategoryByPrimary', + /** + * 查询大类下分类 + */ + queryCategoryByPrimary: '/category/queryCategoryByPrimary', - // 根据分类查标签 - queryLabelByCategoryId: '/label/queryLabelByCategoryId' -}; + // 根据分类查标签 + queryLabelByCategoryId: '/label/queryLabelByCategoryId', + + // 查询分类及标签 + queryCategoryAndLabel: '/category/queryCategoryAndLabel' +} diff --git a/src/components/category-list/index-new.jsx b/src/components/category-list/index-new.jsx new file mode 100644 index 0000000..e69de29 diff --git a/src/router/index.tsx b/src/router/index.tsx index fa797a2..91c884a 100644 --- a/src/router/index.tsx +++ b/src/router/index.tsx @@ -1,41 +1,38 @@ - 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"; +import { lazy } from 'react' +import { createBrowserRouter } from 'react-router-dom' const router = createBrowserRouter([ - { - path: "/", - element: , - children: [ - { - path: "question-bank", - element: , - }, - { - path: "brush-question/:id", - element: , - }, - { - path: "upload-question", - element: , - }, - { - path: 'login', - element: - }, - { - path: 'user-info', - element: - } - ], - }, -]); + { + path: '/', + element: , + children: [ + { + path: 'question-bank', + Component: lazy(() => import('@views/question-bank')) + }, + { + path: 'brush-question/:id', + // element: + Component: lazy(() => import('@views/brush-questions')) + }, + { + path: 'upload-question', + // element: + Component: lazy(() => import('@views/upload-questions')) + }, + { + path: 'login', + // element: + Component: lazy(() => import('@views/login')) + }, + { + path: 'user-info', + // element: + Component: lazy(() => import('@views/user-info')) + } + ] + } +]) -export default router \ No newline at end of file +export default router diff --git a/src/utils/request.ts b/src/utils/request.ts index b62f886..a2372eb 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,24 +1,12 @@ import { message } from 'antd' import axios from 'axios' -export const baseHttp = () => { - const http = axios.create({ - baseURL: '/subject', - timeout: 5 * 60 * 1000, // request timeout - withCredentials: true, // send cookies when cross-domain requests - headers: { - 'Content-Type': 'application/json; charset=utf-8' - } - }) - - return http -} - export default function request(config, url) { // const navigate = useNavigate() const userInfoStorage = localStorage.getItem('userInfo') const userInfo = userInfoStorage ? JSON.parse(userInfoStorage) : {} const baseURL = url || '/subject/subject' + // const baseURL = url || '/subject' // 1.创建axios的实例 const instance = axios.create({ baseURL, diff --git a/src/views/header/index.tsx b/src/views/header/index.tsx index 1970d95..d30591f 100644 --- a/src/views/header/index.tsx +++ b/src/views/header/index.tsx @@ -2,7 +2,8 @@ import Head from '@/imgs/head.jpg' import Logo from '@/imgs/logo.jpg' import { HeartOutlined, LikeOutlined, LoginOutlined, UserOutlined } from '@ant-design/icons' import TopMenu from '@components/top-menu' -import { Dropdown, Input, message } from 'antd' +import req from '@utils/request' +import { Dropdown, Input, Modal, message } from 'antd' import { useNavigate } from 'react-router-dom' const { Search } = Input @@ -42,10 +43,44 @@ const Header = () => { if (!userInfoStorage) { return message.info('请登录') } - if (e.key != 1) { - return message.info('敬请期待') + const { loginId } = JSON.parse(userInfoStorage) + switch (e.key) { + case '1': + navigate('/user-info') + break + case '4': + // 退出 + Modal.confirm({ + title: '退出提示', + content: '确定退出当前用户登录吗?', + okText: '确定', + cancelText: '取消', + onOk: () => { + req( + { + method: 'get', + url: '/user/logOut', + params: { + userName: loginId + } + }, + '/auth' + ).then(res => { + if (res.success) { + localStorage.removeItem('userInfo') + message.info('退出成功') + setTimeout(() => { + navigate('/login') + }, 500) + } + }) + } + }) + break + default: + message.info('敬请期待') + break } - navigate('/user-info') } return ( @@ -62,15 +97,15 @@ const Header = () => {
- {/* {'/question-bank' == pathname && ( -
- console.log(value)} - style={{ width: 300, borderRadius: '10px' }} - /> -
- )} */} + {'/question-bank' == pathname && ( +
+ console.log(value)} + style={{ width: 300, borderRadius: '10px' }} + /> +
+ )} {/*
*/} {/* */} {/*
*/} diff --git a/src/views/login/index.tsx b/src/views/login/index.tsx index 98cba84..414268b 100644 --- a/src/views/login/index.tsx +++ b/src/views/login/index.tsx @@ -33,6 +33,8 @@ const Login = () => { setTimeout(() => { navigate('/question-bank') }, 1000) + } else { + message.error('登录失败,请重试') } }) } diff --git a/src/views/question-bank/index.tsx b/src/views/question-bank/index.tsx index 3325dac..9ad37c4 100644 --- a/src/views/question-bank/index.tsx +++ b/src/views/question-bank/index.tsx @@ -181,7 +181,7 @@ const QuestionBank = () => {
{questionList.length == 0 - ? '暂无数据' + ? '' : loading && !finished ? '努力加载中...' : '我是有底线的(:'} diff --git a/src/views/user-info/index.tsx b/src/views/user-info/index.tsx index 93473ce..2c3e17a 100644 --- a/src/views/user-info/index.tsx +++ b/src/views/user-info/index.tsx @@ -1,30 +1,82 @@ import Head from '@/imgs/head.jpg' import { LoadingOutlined, PlusOutlined } from '@ant-design/icons' import req from '@utils/request' -import { Button, Card, Col, Form, Input, Radio, Row, message } from 'antd' -import { memo, useState } from 'react' -import { useNavigate } from 'react-router-dom' +import { Button, Card, Col, Form, Input, Radio, Row, Upload, message } from 'antd' +import { memo, useEffect, useState } from 'react' import './index.less' const { TextArea } = Input -const apiName = '/user/update' +const apiName = { + update: '/user/update', + queryInfo: '/user/getUserInfo' +} const layout = { labelCol: { span: 4 }, wrapperCol: { span: 10, offset: 1 } } +const beforeUpload = (file: RcFile) => { + const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png' + if (!isJpgOrPng) { + message.error('You can only upload JPG/PNG file!') + } + const isLt2M = file.size / 1024 / 1024 < 2 + if (!isLt2M) { + message.error('Image must smaller than 2MB!') + } + return isJpgOrPng && isLt2M +} + +interface UserInfo { + nickName?: string + phone?: string + email?: string + sex?: string | number + introduce?: string +} + +const Sex: Record = { + 1: '男', + 2: '女' +} + const UserInfo = () => { + const userInfoStorage = localStorage.getItem('userInfo') + const { loginId = '' } = userInfoStorage ? JSON.parse(userInfoStorage) : {} + const [form] = Form.useForm() const [editFlag, setEditFlag] = useState(false) const [loading, setLoading] = useState(false) - const navigate = useNavigate() + const [userInfo, setUserInfo] = useState({}) + + const getUserInfo = async () => { + req( + { + method: 'post', + url: apiName.queryInfo, + data: { + userName: loginId + } + }, + '/auth' + ).then(res => { + if (res?.success && res?.data) { + setUserInfo(res.data) + form.setFieldsValue(res.data) + } + }) + } + + useEffect(() => { + if (loginId) { + getUserInfo() + } + }, [loginId]) const onFinish = () => { setLoading(true) - const userInfoStorage = localStorage.getItem('userInfo') - const { loginId = '' } = userInfoStorage ? JSON.parse(userInfoStorage) : {} const values = form.getFieldsValue() if (!Object.values(values).filter(Boolean).length) { setLoading(false) @@ -37,7 +89,7 @@ const UserInfo = () => { req( { method: 'post', - url: apiName, + url: apiName.update, data: { ...params } }, '/auth' @@ -46,11 +98,13 @@ const UserInfo = () => { if (res.success) { message.success('更新成功') setTimeout(() => { - navigate('/question-bank') - }, 1000) + getUserInfo() + setLoading(false) + setEditFlag(false) + }, 500) + } else { + setLoading(false) } - setLoading(false) - setEditFlag(false) }) .catch(() => { message.error('更新失败') @@ -58,6 +112,10 @@ const UserInfo = () => { }) } + const handleChange = info => { + console.log(info) + } + const uploadButton = (
{loading ? : } @@ -71,9 +129,33 @@ const UserInfo = () => {
- + {editFlag ? ( + + + {uploadButton} + + + ) : ( + + + + )} + {/* - + */} {editFlag ? ( @@ -82,7 +164,7 @@ const UserInfo = () => { ) : ( - <>暂无 + <>{userInfo.nickName || ''} )} @@ -96,7 +178,7 @@ const UserInfo = () => { ) : ( - <>未知 + <>{userInfo.sex ? Sex[userInfo.sex] : '未知'} )} @@ -107,7 +189,7 @@ const UserInfo = () => { ) : ( - <>暂无 + <>{userInfo.phone || ''} )} @@ -121,7 +203,7 @@ const UserInfo = () => { ) : ( - <>暂无 + <>{userInfo.email || ''} )} @@ -132,7 +214,7 @@ const UserInfo = () => { ) : ( - <>这个人很懒,什么也没有留下。。。。 + <>{userInfo.introduce || '这个人很懒,什么也没有留下。。。。'} )} diff --git a/vite.config.ts b/vite.config.ts index 1501217..039106d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,11 +1,22 @@ import react from '@vitejs/plugin-react' import { defineConfig, loadEnv } from 'vite' + const path = require('path') // https://vitejs.dev/config/ export default ({ mode }) => { const env = loadEnv(mode, process.cwd()) return defineConfig({ + build: { + rollupOptions: { + output: { + manualChunks: { + vendor: ['react', 'react-dom', 'react-router-dom'], + common: ['axios', 'lodash', 'pubsub-js', 'wangeditor'] + } + } + } + }, resolve: { alias: { '@': path.resolve(__dirname, 'src'),