feat: 增加默认跳转
This commit is contained in:
20
src/App.tsx
20
src/App.tsx
@@ -1,6 +1,6 @@
|
||||
import React, { Component } from 'react';
|
||||
import React, { Component, useEffect } from 'react';
|
||||
import './App.less';
|
||||
import { Outlet } from "react-router-dom"
|
||||
import { useLocation, useNavigate, Outlet } from 'react-router-dom';
|
||||
import PubSub from 'pubsub-js';
|
||||
import { Input } from 'antd';
|
||||
import Logo from '@views/imgs/logo.jpg'
|
||||
@@ -70,13 +70,21 @@ class NavTop extends Component {
|
||||
);
|
||||
}
|
||||
}
|
||||
export default class App extends Component {
|
||||
render() {
|
||||
|
||||
const App = () => {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate()
|
||||
useEffect(() => {
|
||||
if (location.pathname === '/') {
|
||||
navigate('/question-bank')
|
||||
}
|
||||
}, [location])
|
||||
return (
|
||||
<div className="app-main">
|
||||
<NavTop />
|
||||
<Outlet />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
|
22
src/main.tsx
22
src/main.tsx
@@ -2,31 +2,11 @@ import './main.less'
|
||||
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App'
|
||||
import QuestionBank from '@views/question-bank';
|
||||
import UploadQuestions from '@views/upload-questions';
|
||||
import BrushQuestions from '@views/brush-questions'
|
||||
import router from '@/router'
|
||||
import {
|
||||
createBrowserRouter,
|
||||
RouterProvider,
|
||||
} from "react-router-dom";
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: "/",
|
||||
element: <App />,
|
||||
children: [
|
||||
{
|
||||
path: "question-bank",
|
||||
element: <QuestionBank />,
|
||||
},
|
||||
{
|
||||
path: "brush-question",
|
||||
element: <BrushQuestions />,
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
|
@@ -1,22 +0,0 @@
|
||||
|
||||
import QuestionBank from '@views/question-bank';
|
||||
import UploadQuestions from '@views/upload-questions';
|
||||
import BrushQuestions from '@views/brush-questions'
|
||||
|
||||
export default [
|
||||
// {
|
||||
// path: '/question-bank',
|
||||
// exact: true,
|
||||
// component: QuestionBank,
|
||||
// },
|
||||
// {
|
||||
// path: '/upload-questions',
|
||||
// exact: true,
|
||||
// component: UploadQuestions,
|
||||
// },
|
||||
// {
|
||||
// path: '/brush-questions',
|
||||
// exact: true,
|
||||
// component: BrushQuestions,
|
||||
// },
|
||||
];
|
31
src/router/index.tsx
Normal file
31
src/router/index.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
import App from '@/App'
|
||||
import QuestionBank from '@views/question-bank';
|
||||
import UploadQuestions from '@views/upload-questions';
|
||||
import BrushQuestions from '@views/brush-questions'
|
||||
import {
|
||||
createBrowserRouter,
|
||||
} from "react-router-dom";
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: "/",
|
||||
element: <App />,
|
||||
children: [
|
||||
{
|
||||
path: "question-bank",
|
||||
element: <QuestionBank />,
|
||||
},
|
||||
{
|
||||
path: "brush-question",
|
||||
element: <BrushQuestions />,
|
||||
},
|
||||
{
|
||||
path: "upload-question",
|
||||
element: <UploadQuestions />,
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
export default router
|
@@ -24,7 +24,7 @@ const QuestionBank = () => {
|
||||
|
||||
|
||||
/**
|
||||
* 获取一级分类数据
|
||||
* 获取大类分类
|
||||
*/
|
||||
const getPrimaryCategoryInfo = () => {
|
||||
setIsShowSpin(true)
|
||||
@@ -35,16 +35,34 @@ const QuestionBank = () => {
|
||||
})
|
||||
.then((res: Record<string, any>) => {
|
||||
if (res.data && res.data.length > 0) {
|
||||
setPromaryCategoryId(res.data[0].primaryCategoryId);
|
||||
setPromaryCategoryId(res.data[0].id);
|
||||
setFirstCategoryList(res.data)
|
||||
setIsShowSpin(false)
|
||||
} else {
|
||||
setIsShowSpin(false)
|
||||
}
|
||||
})
|
||||
.catch((err: string) => console.log(err));
|
||||
.catch((err: string) => {
|
||||
console.log(err)
|
||||
}).finally(() => {
|
||||
setIsShowSpin(false)
|
||||
})
|
||||
}
|
||||
|
||||
// 获取大类下分类
|
||||
const getCategoryByPrimary = () => {
|
||||
req({
|
||||
method: 'post',
|
||||
url: apiName.queryCategoryByPrimary,
|
||||
data: { categoryType: 1, parentId: 1 }
|
||||
}).then(res => {
|
||||
console.log(res)
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (primaryCategoryId) {
|
||||
getCategoryByPrimary()
|
||||
}
|
||||
}, [primaryCategoryId])
|
||||
|
||||
/**
|
||||
* 切换一级分类
|
||||
* @param {*} e
|
||||
|
@@ -50,6 +50,7 @@ export default class KindEditor extends Component {
|
||||
componentDidMount() {
|
||||
const elemMenu = this.refs.editorElemMenu;
|
||||
const elemBody = this.refs.editorElemBody;
|
||||
if (this.editor) return
|
||||
this.editor = new Editor(elemMenu, elemBody);
|
||||
// // 使用 onchange 函数监听内容的变化,并实时更新到 state 中
|
||||
this.editor.config.onchange = (html) => {
|
||||
|
@@ -36,24 +36,24 @@ export const ModuleType = {
|
||||
export const starList = [
|
||||
{
|
||||
categoryId: 1,
|
||||
categoryName: 'T4',
|
||||
categoryName: '初级',
|
||||
active: true,
|
||||
},
|
||||
{
|
||||
categoryId: 2,
|
||||
categoryName: 'T5',
|
||||
categoryName: '中级',
|
||||
},
|
||||
{
|
||||
categoryId: 3,
|
||||
categoryName: 'T6',
|
||||
categoryName: '高级',
|
||||
},
|
||||
{
|
||||
categoryId: 4,
|
||||
categoryName: 'T7',
|
||||
categoryName: '资深',
|
||||
},
|
||||
{
|
||||
categoryId: 5,
|
||||
categoryName: 'T8',
|
||||
categoryName: '专家',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -63,24 +63,24 @@ export const starList = [
|
||||
export const uploadLayout = [
|
||||
{
|
||||
id: 1,
|
||||
title: '问答题',
|
||||
title: '简答题',
|
||||
active: true,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: '单选题',
|
||||
active: false,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: '多选题',
|
||||
active: false,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
title: '判断题',
|
||||
active: false,
|
||||
},
|
||||
// {
|
||||
// id: 2,
|
||||
// title: '单选题',
|
||||
// active: false,
|
||||
// },
|
||||
// {
|
||||
// id: 3,
|
||||
// title: '多选题',
|
||||
// active: false,
|
||||
// },
|
||||
// {
|
||||
// id: 4,
|
||||
// title: '判断题',
|
||||
// active: false,
|
||||
// },
|
||||
];
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user