From cca31e8de2013ee7c82f75574aab4c7235a98f08 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, 3 Mar 2024 00:02:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 4 +- src/components/category-list/label-list.jsx | 7 +- .../good-collection-error/index.jsx | 247 +--- src/utils/request.ts | 3 +- src/views/brush-questions/index.tsx | 123 +- src/views/header/index.tsx | 14 +- src/views/login/index.tsx | 2 +- .../components/good-bag/index.jsx | 55 +- .../components/question-list/index.jsx | 4 +- src/views/personal-center/index.jsx | 168 ++- .../components/practice-list/index.jsx | 147 ++- .../components/ranking-box/index.jsx | 38 +- src/views/question-bank/constant.ts | 57 +- src/views/question-bank/index.tsx | 2 +- src/views/question-bank/mock.ts | 1104 ++++++++--------- src/views/search-details/index.jsx | 113 +- 16 files changed, 943 insertions(+), 1145 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8530e0a..cd2a59a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -38,7 +38,9 @@ const App = () => { } useEffect(() => { - getUserInfo() + if (location.pathname !== '/login' && loginId) { + getUserInfo() + } }, []) useEffect(() => { diff --git a/src/components/category-list/label-list.jsx b/src/components/category-list/label-list.jsx index 09f436f..d6bea76 100644 --- a/src/components/category-list/label-list.jsx +++ b/src/components/category-list/label-list.jsx @@ -23,8 +23,9 @@ const LabelList = props => { }) .then(res => { if (res.data && res.data.length > 0) { - const ids = `${res.data[0].id}_${res.data[0].labelDTOList[0].id}` - setCategoryAndLabelList(res.data) + const filterData = [...res.data].filter(item => item?.labelDTOList?.length > 0) + const ids = `${filterData[0].id}_${filterData[0].labelDTOList[0].id}` + setCategoryAndLabelList(filterData) setCheckedLabelId(ids) changeLabel(ids) } else { @@ -32,10 +33,8 @@ const LabelList = props => { setCheckedLabelId('') changeLabel('') } - // setSpinning(false) }) .catch(err => { - // setSpinning(false) console.log(err) }) } diff --git a/src/components/good-collection-error/index.jsx b/src/components/good-collection-error/index.jsx index 56f346c..f001b18 100644 --- a/src/components/good-collection-error/index.jsx +++ b/src/components/good-collection-error/index.jsx @@ -1,177 +1,58 @@ -import { HeartTwoTone, InfoCircleTwoTone, LikeTwoTone } from '@ant-design/icons' +import { LikeTwoTone } from '@ant-design/icons' import req from '@utils/request' -import { Input, Modal, Radio, message } from 'antd' import React, { Component } from 'react' import './index.less' -const { TextArea } = Input export default class GoodCollectionError extends Component { constructor(props) { super(props) this.state = { isGood: false, //是否点赞 - isCollection: false, //是否收藏 goodAmount: 0, //点赞数量 - collectionAmount: 0, //收藏数量 - // index: 1, question: [], //题目列表 - isModal: false, //是否显示纠错弹框 - value: 1, //纠错类型对应值 - inputValue: '', //纠错详情内容 questionId: '' //题目id } } - /**纠错类型 */ - errorType = [ - { - value: 1, - content: '答案错误' - }, - { - value: 2, - content: '题目与答案不符' - } - ] componentDidMount() { - // this.getDetail() + const { + detail: { id, liked, likedCount } + } = this.props + this.setState({ + isGood: liked, + goodAmount: likedCount, + questionId: id + }) } - getDetail() { - let params = { - subjectId: this.props.questionId - } - req({ - method: 'post', - data: params, - url: 'admin/question/collect/getDetail' - }) - .then(res => { - if (res.data) { - this.setState({ - isGood: res.data.isThump, - goodAmount: res.data.thumpCount, - isCollection: res.data.isCollect, - collectionAmount: res.data.collectCount - }) - } - }) - .catch(err => console.log(err)) - } - - /** - * 点击纠错按钮 - */ - handleModal = () => { - return message.info('敬请期待') - this.setState({ - isModal: true - }) - } - /** - * 点击弹框确认按钮 - */ - handleOk = () => { - const { value, inputValue } = this.state - const { questionId } = this.props - - let params = { - subjectId: questionId, - errorType: value, - errorMsg: inputValue - } - if (inputValue.length === 0) { - message.warning('请填写纠错详情!') - } else { - this.setState({ - isModal: false, - inputValue: '' - }) - message.success('感谢纠错,立即更改!') - req({ - method: 'post', - data: params, - url: '/admin/question/subjectError/add' - }) - } - } - /** - * 点击弹框取消按钮 - */ - handleCancel = () => { - this.setState({ - isModal: false, - inputValue: '' - }) - } - /** - * - * @param {选择纠错类型} e - */ - handleChangeRadio = e => { - this.setState({ - value: e.target.value - }) - } - /** - * - * @param {纠错详情中填写内容} e - */ - handleChangeInput = e => { - this.setState({ - inputValue: e.target.value - }) - } /** * * @returns 点击点赞按钮 */ handleChangeGood = () => { - return message.info('敬请期待') - const { isGood, goodAmount } = this.state - const { questionId } = this.props + const { isGood, goodAmount, questionId } = this.state let params = { - subjectId: questionId + subjectId: questionId, + status: isGood ? 0 : 1 } this.setState( { - isGood: isGood === true ? false : true, - goodAmount: isGood === true ? goodAmount - 1 : goodAmount + 1 + isGood: !isGood, + goodAmount: isGood ? goodAmount - 1 : goodAmount + 1 }, () => { - req({ - method: 'post', - data: params, - url: 'admin/question/thump/addOrCancel' - }).catch(err => console.log(err)) - } - ) - } - /** - * 点击收藏按钮 - */ - handleChangeCollection = () => { - return message.info('敬请期待') - const { isCollection, collectionAmount } = this.state - const { questionId } = this.props - let params = { - subjectId: questionId - } - this.setState( - { - isCollection: isCollection === true ? false : true, - collectionAmount: isCollection === true ? collectionAmount - 1 : collectionAmount + 1 - }, - () => { - req({ - method: 'post', - data: params, - url: 'admin/question/collect/addOrCancel' - }).catch(err => console.log(err)) + req( + { + method: 'post', + data: params, + url: '/subjectLiked/add' + }, + '/subject' + ).catch(err => console.log(err)) } ) } render() { - const { isCollection, isGood, isModal, value, collectionAmount, goodAmount } = this.state + const { isGood, goodAmount } = this.state return (
- - ({goodAmount}) + ( + {goodAmount})
-
{ - this.handleChangeCollection() - }} - > - - ({collectionAmount}) -
- {/*
- - 评论 -
*/} -
{ - this.handleModal() - }} - > - - 纠错 -
- { - this.handleOk() - }} - onCancel={() => { - this.handleCancel() - }} - okText='确认' - cancelText='取消' - style={{ fontWeight: 500 }} - > -
-
纠错类型
-
- {this.errorType.map((item, index) => { - return ( -
- { - this.handleChangeRadio(e) - }} - defaultValue={1} - buttonStyle='solid' - value={value} - > - - {item.content} - - -
- ) - })} -
-
纠错详情
-