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} - - -
- ) - })} -
-
纠错详情
-