feat: 首页大类查看更多,题目列表标签
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
|||||||
CaretUpOutlined,
|
CaretUpOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import req from '@utils/request';
|
import req from '@utils/request';
|
||||||
import { Divider, Spin } from 'antd';
|
import { Divider, Spin, Modal } from 'antd';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
import { apiName, imgObject } from './constant';
|
import { apiName, imgObject } from './constant';
|
||||||
@@ -32,12 +32,25 @@ const categoryShowCount = 4;
|
|||||||
|
|
||||||
const cacheMap = {}
|
const cacheMap = {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上万后展示 W+
|
||||||
|
* @param {*} total
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const formatTotal = (total) => {
|
||||||
|
if (total >= 10000) {
|
||||||
|
return Math.floor(total / 10000) + 'W+';
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
const CategoryList = ({ primaryCategoryId, categoryList, ...props }) => {
|
const CategoryList = ({ primaryCategoryId, categoryList, ...props }) => {
|
||||||
const [secondCategoryList, setSecondCategoryList] = useState([])
|
const [secondCategoryList, setSecondCategoryList] = useState([])
|
||||||
const [currentActive, setCurrentActive] = useState(categoryList[0])
|
const [currentActive, setCurrentActive] = useState(categoryList[0])
|
||||||
const [isPutAway, setIsPutAway] = useState(true)
|
const [isPutAway, setIsPutAway] = useState(true)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [currentLabelIndex, setCurrentLabelIndex] = useState([])
|
const [currentLabelIndex, setCurrentLabelIndex] = useState([])
|
||||||
|
const [openMoreFlag, setOpenMoreFlag] = useState(false)
|
||||||
|
|
||||||
|
|
||||||
const getLabels = (id) => {
|
const getLabels = (id) => {
|
||||||
@@ -126,7 +139,7 @@ const CategoryList = ({ primaryCategoryId, categoryList, ...props }) => {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
{categoryList.length > 7 && (
|
{categoryList.length > 7 && (
|
||||||
<div className="first-category-more">
|
<div className="first-category-more" onClick={() => setOpenMoreFlag(true)}>
|
||||||
更多
|
更多
|
||||||
<RightOutlined />
|
<RightOutlined />
|
||||||
</div>
|
</div>
|
||||||
@@ -136,6 +149,57 @@ const CategoryList = ({ primaryCategoryId, categoryList, ...props }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击更多的分类项
|
||||||
|
* @param {*} id
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const onChangeCategoryMore = (cur) => () => {
|
||||||
|
setOpenMoreFlag(false)
|
||||||
|
setCurrentActive(cur)
|
||||||
|
let list = [...categoryList].reduce((pre, item) => {
|
||||||
|
if (item.id !== cur.id) {
|
||||||
|
pre.push(item);
|
||||||
|
} else {
|
||||||
|
pre.unshift(item);
|
||||||
|
}
|
||||||
|
return pre;
|
||||||
|
}, []);
|
||||||
|
props.onChangeCategoryMore && props.onChangeCategoryMore(cur.id, list);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更多分类
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const renderMoreBox = () => {
|
||||||
|
return (
|
||||||
|
<div className="first-category-more-list">
|
||||||
|
{categoryList.slice(7).map((categoryModuleItem, categoryModuleIndex) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="first-category-item"
|
||||||
|
key={`first_more_category_${categoryModuleItem.id}`}
|
||||||
|
style={{
|
||||||
|
backgroundImage: `url(${categoryBackImg[categoryModuleIndex]})`,
|
||||||
|
}}
|
||||||
|
onClick={onChangeCategoryMore(
|
||||||
|
categoryModuleItem
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className="first-category-item-title">
|
||||||
|
{categoryModuleItem.categoryName}
|
||||||
|
</div>
|
||||||
|
<div className="first-category-item-count">
|
||||||
|
{formatTotal(categoryModuleItem.subjectCount)}道题
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 选择标签-支持单选(多选)
|
* 选择标签-支持单选(多选)
|
||||||
* @param {*} categoryId 一级分类id
|
* @param {*} categoryId 一级分类id
|
||||||
@@ -291,6 +355,14 @@ const CategoryList = ({ primaryCategoryId, categoryList, ...props }) => {
|
|||||||
{secondCategoryList?.length > 0 && this.renderSecondContainer()}
|
{secondCategoryList?.length > 0 && this.renderSecondContainer()}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)} */}
|
)} */}
|
||||||
|
<Modal
|
||||||
|
open={openMoreFlag}
|
||||||
|
footer={null}
|
||||||
|
closable={true}
|
||||||
|
centered
|
||||||
|
onCancel={() => setOpenMoreFlag(false)}>
|
||||||
|
{renderMoreBox()}
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
.category-box {
|
.category-box {
|
||||||
.first-category-list {
|
.first-category-list {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
.first-category-item {
|
.first-category-item {
|
||||||
flex-shrink: 1;
|
flex-shrink: 1;
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
@@ -16,30 +17,30 @@
|
|||||||
background-color: rgba(0, 0, 0, 0.04);
|
background-color: rgba(0, 0, 0, 0.04);
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
transition: all 0.5s;
|
transition: all 0.5s;
|
||||||
.first-category-item-title {
|
&-title {
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
-webkit-line-clamp: 1;
|
-webkit-line-clamp: 1;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
/* autoprefixer: off */
|
|
||||||
-webkit-box-orient: vertical;
|
-webkit-box-orient: vertical;
|
||||||
display: -webkit-box;
|
display: -webkit-box;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
.first-category-item-count {
|
&-count {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: rgba(255, 255, 255, 0.65);
|
color: rgba(255, 255, 255, 0.65);
|
||||||
line-height: 16px;
|
line-height: 16px;
|
||||||
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
&:hover {
|
&:hover {
|
||||||
transition: all 0.5s;
|
transition: all 0.5s;
|
||||||
transform: translateY(-8px);
|
transform: translateY(-8px);
|
||||||
}
|
}
|
||||||
}
|
&-active {
|
||||||
.first-category-item-active {
|
transform: translateY(-8px);
|
||||||
transform: translateY(-8px);
|
}
|
||||||
}
|
}
|
||||||
.first-category-more {
|
.first-category-more {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -140,3 +141,60 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ant-modal-content {
|
||||||
|
width: 606px;
|
||||||
|
background-color: #fff;
|
||||||
|
.ant-modal-body {
|
||||||
|
padding: 24px;
|
||||||
|
.first-category-more-list {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
width: 100%;
|
||||||
|
.first-category-item {
|
||||||
|
flex-shrink: 1;
|
||||||
|
display: inline-flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin: 10px 8px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
width: 120px;
|
||||||
|
height: 76px;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 4px;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
background-color: rgba(0, 0, 0, 0.04);
|
||||||
|
font-weight: 400;
|
||||||
|
transition: all 0.5s;
|
||||||
|
&-title {
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 14px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
-webkit-line-clamp: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
/* autoprefixer: off */
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
display: -webkit-box;
|
||||||
|
word-wrap: break-word;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
&-count {
|
||||||
|
font-size: 12px;
|
||||||
|
color: rgba(255, 255, 255, 0.65);
|
||||||
|
line-height: 16px;
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
transition: all 0.5s;
|
||||||
|
transform: translateY(-8px);
|
||||||
|
}
|
||||||
|
&-active {
|
||||||
|
transform: translateY(-8px);
|
||||||
|
}
|
||||||
|
&:nth-child(4n) {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -45,11 +45,11 @@ const QuestionList = (props) => {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div className="question-info-tags">
|
<div className="question-info-tags">
|
||||||
{item?.tags?.length > 0 &&
|
{item?.labelName?.length > 0 &&
|
||||||
item.tags.map((tagsItem, index) => {
|
item.labelName.map((tagsItem) => {
|
||||||
return (
|
return (
|
||||||
<div className="question-info-tag" key={index} style={{ backgroundColor: colors[RandomNumBoth(0, 7)] }}>
|
<div className="question-info-tag" key={tagsItem} style={{ backgroundColor: colors[RandomNumBoth(0, 7)] }}>
|
||||||
{tagsItem.name}
|
{tagsItem}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin: 0 0 20px 16px;
|
margin: 0 0 20px 16px;
|
||||||
padding: 0px 16px 0px;
|
padding: 0px 16px 0px;
|
||||||
width: 310px;
|
// width: 310px;
|
||||||
max-height: 416px;
|
max-height: 416px;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
// import { Component } from 'react';
|
// import { Component } from 'react';
|
||||||
import { useState, useEffect, memo } from 'react'
|
import { useState, useEffect, memo } from 'react'
|
||||||
import { useSearchParams } from 'react-router-dom'
|
// import { useSearchParams } from 'react-router-dom'
|
||||||
import QuestionList from '@components/question-list';
|
import QuestionList from '@components/question-list';
|
||||||
import CategoryList from '@components/category-list';
|
import CategoryList from '@components/category-list';
|
||||||
import ContributionList from './components/contribution-list';
|
import ContributionList from './components/contribution-list';
|
||||||
@@ -12,7 +12,7 @@ import './index.less';
|
|||||||
|
|
||||||
const QuestionBank = () => {
|
const QuestionBank = () => {
|
||||||
|
|
||||||
const [firstCategoryList, setFirstCategoryList] = useState([])
|
const [firstCategoryList, setFirstCategoryList] = useState<Record<string, any>[]>([])
|
||||||
const [questionList, setQuestionList] = useState([])
|
const [questionList, setQuestionList] = useState([])
|
||||||
const [isShowSpin, setIsShowSpin] = useState(false)
|
const [isShowSpin, setIsShowSpin] = useState(false)
|
||||||
const [labelList, setLabelList] = useState<string | number>(); // 选中的标签列表
|
const [labelList, setLabelList] = useState<string | number>(); // 选中的标签列表
|
||||||
@@ -22,12 +22,12 @@ const QuestionBank = () => {
|
|||||||
const [primaryCategoryId, setPromaryCategoryId] = useState(''); //第一个大类id
|
const [primaryCategoryId, setPromaryCategoryId] = useState(''); //第一个大类id
|
||||||
const [secondCategoryId, setSecondCategoryId] = useState('')
|
const [secondCategoryId, setSecondCategoryId] = useState('')
|
||||||
|
|
||||||
let [searchParams, setSearchParams] = useSearchParams();
|
// let [searchParams, setSearchParams] = useSearchParams();
|
||||||
const changeUrlParam = () => {
|
// const changeUrlParam = () => {
|
||||||
// console.log(searchParams.size)
|
// // console.log(searchParams.size)
|
||||||
setSearchParams({ id: 1 })
|
// setSearchParams({ id: 1 })
|
||||||
// window.history.pushState({}, '0', window.location.href + '?url=' + '参数');
|
// // window.history.pushState({}, '0', window.location.href + '?url=' + '参数');
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取大类分类
|
* 获取大类分类
|
||||||
@@ -102,11 +102,23 @@ const QuestionBank = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (labelList && secondCategoryId) {
|
if (labelList && secondCategoryId) {
|
||||||
setSearchParams({ second: secondCategoryId, label: labelList })
|
// setSearchParams({ second: secondCategoryId, label: labelList })
|
||||||
queryQuestionList()
|
queryQuestionList()
|
||||||
}
|
}
|
||||||
}, [labelList, pageIndex, secondCategoryId])
|
}, [labelList, pageIndex, secondCategoryId])
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更多分类切换
|
||||||
|
* @param {*} e
|
||||||
|
*/
|
||||||
|
const onChangeCategoryMore = (id: string, categoryList: Record<string, any>[]) => {
|
||||||
|
setFirstCategoryList(categoryList)
|
||||||
|
setPromaryCategoryId(id)
|
||||||
|
setLabelList('')
|
||||||
|
setQuestionList([])
|
||||||
|
setPageIndex(1)
|
||||||
|
setTotal(0)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="question-bank-box">
|
<div className="question-bank-box">
|
||||||
@@ -120,6 +132,7 @@ const QuestionBank = () => {
|
|||||||
onChangeLabel={onChangeLabel}
|
onChangeLabel={onChangeLabel}
|
||||||
primaryCategoryId={primaryCategoryId}
|
primaryCategoryId={primaryCategoryId}
|
||||||
isMultipleChoice={false}
|
isMultipleChoice={false}
|
||||||
|
onChangeCategoryMore={onChangeCategoryMore}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user