forked from MuxiKeStack/muxiK-StackFrontend2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
552 additions
and
71 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
src/common/components/QuestionListComponent/QuestionListComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* eslint-disable import/first */ | ||
import { Image, View } from '@tarojs/components'; | ||
import Taro from '@tarojs/taro'; | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import './index.scss'; | ||
|
||
import answericon from '@/common/assets/img/publishQuestion/answer.png'; | ||
import askicon from '@/common/assets/img/publishQuestion/ask.png'; | ||
import PublishHeader from '@/common/components/PublishHeader/PublishHeader'; | ||
import { useCourseStore } from '@/pages/main/store/store'; | ||
|
||
interface IUser { | ||
avatar: string; | ||
id: number; | ||
nickname: string; | ||
} | ||
|
||
interface IQuestion { | ||
id: number; | ||
questioner_id: number; | ||
biz: string; | ||
biz_id: number; | ||
content: string; | ||
answer_cnt: number; | ||
preview_answers: Array<{ | ||
id: number; | ||
publisher_id: number; | ||
question_id: number; | ||
content: string; | ||
utime: number; | ||
ctime: number; | ||
user?: IUser; | ||
}>; | ||
utime: number; | ||
ctime: number; | ||
user?: IUser; | ||
} | ||
|
||
const formatTime = (timestamp: number) => { | ||
const date = new Date(timestamp); | ||
const year = date.getFullYear(); | ||
const month = (date.getMonth() + 1).toString().padStart(2, '0'); | ||
const day = date.getDate().toString().padStart(2, '0'); | ||
const hour = date.getHours().toString().padStart(2, '0'); | ||
const minute = date.getMinutes().toString().padStart(2, '0'); | ||
const second = date.getSeconds().toString().padStart(2, '0'); | ||
return `${year}-${month}-${day} ${hour}:${minute}:${second}`; | ||
}; | ||
|
||
const QuestionListComponent: React.FC<{ question: IQuestion }> = ({ question }) => { | ||
const dispatch = useCourseStore(({ getPublishers }) => ({ getPublishers })); | ||
|
||
const [questionDetail, setQuestion] = useState<IQuestion>(question); | ||
|
||
useEffect(() => { | ||
const fetchQuestionWithUserInfo = async () => { | ||
try { | ||
const user = await dispatch.getPublishers(question.questioner_id); | ||
const questionWithUserInfo = { ...question, user }; | ||
setQuestion(questionWithUserInfo); | ||
|
||
// 检查 preview_answers 是否存在并且是一个数组 | ||
const previewAnswersWithUserInfo = | ||
question.preview_answers && question.preview_answers.length > 0 | ||
? await Promise.all( | ||
question.preview_answers.map(async (answer) => { | ||
const newuser = await dispatch.getPublishers(answer.publisher_id); | ||
return { ...answer, newuser }; | ||
}) | ||
) | ||
: []; | ||
|
||
// 更新问题状态,包括填充了用户信息的 preview_answers | ||
setQuestion((prev) => ({ | ||
...prev, | ||
user: questionWithUserInfo.user, // 确保用户信息被设置 | ||
preview_answers: previewAnswersWithUserInfo, | ||
})); | ||
} catch (error) { | ||
console.error('Error fetching question with user info:', error); | ||
} | ||
}; | ||
|
||
void fetchQuestionWithUserInfo(); | ||
}, [question]); | ||
|
||
const handleQuestionDetailClick = () => { | ||
void Taro.navigateTo({ | ||
url: `/pages/questionInfo/index?id=${questionDetail.id}`, | ||
}); | ||
}; | ||
|
||
return ( | ||
<View className="questionDetail" onClick={handleQuestionDetailClick}> | ||
<View className="question-detail"> | ||
<PublishHeader | ||
avatarUrl={questionDetail?.user?.avatar ?? ''} | ||
nickName={questionDetail?.user?.nickname ?? ''} | ||
date={formatTime(questionDetail?.ctime)} | ||
/> | ||
<View className="question-item"> | ||
{ | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
<Image src={askicon} className="askicon" /> | ||
} | ||
<View className="question-value">{questionDetail.content}</View> | ||
</View> | ||
</View> | ||
<View className="answer-list"> | ||
{questionDetail.preview_answers && | ||
questionDetail.preview_answers.map((answer, index) => ( | ||
<View key={index} className="answer-item"> | ||
<PublishHeader | ||
avatarUrl={answer?.user?.avatar ?? ''} | ||
nickName={answer?.user?.nickname ?? ''} | ||
date={formatTime(answer.ctime)} | ||
/> | ||
<View className="question-item"> | ||
{ | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
<Image src={answericon} className="askicon" /> | ||
} | ||
<View className="answer-content">{answer.content}</View> | ||
</View> | ||
</View> | ||
))} | ||
</View> | ||
</View> | ||
); | ||
}; | ||
|
||
export default QuestionListComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
.questionDetail { | ||
background-color: #f9f9f2; | ||
width: 659.42rpx; | ||
position: relative; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
margin: 20rpx 0; | ||
} | ||
|
||
.question-detail { | ||
width: 603.26rpx; | ||
border-bottom: #e3e3e3 solid 2rpx; | ||
padding-top: 40rpx; | ||
padding-bottom: 35rpx; | ||
} | ||
|
||
.answer-item { | ||
@extend .question-detail; | ||
} | ||
|
||
.askicon { | ||
width: 44.44rpx; | ||
height: 47.05rpx; | ||
margin-left: 22rpx; | ||
margin-right: 60rpx; | ||
} | ||
|
||
.question-item { | ||
font-size: 21.74rpx; | ||
color: #565552; | ||
display: flex; | ||
margin-top: 20rpx; | ||
} | ||
|
||
.question-value { | ||
max-width: 471rpx; | ||
margin-top: 5rpx; | ||
} | ||
|
||
.answer-content { | ||
@extend .question-value; | ||
} | ||
|
||
.icon { | ||
width: 40rpx; | ||
height: 40rpx; | ||
box-shadow: 0rpx 5rpx 11rpx 2rpx rgba(0, 0, 0, 0.16); | ||
opacity: 1; | ||
border-radius: 50%; | ||
display: inline-block; | ||
text-align: center; | ||
line-height: 40rpx; | ||
// margin-left: 15rpx; | ||
Image { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
} | ||
.text1 { | ||
font-size: 22rpx; | ||
font-weight: bold; | ||
color: #565552; | ||
margin: 0 10rpx; | ||
} | ||
|
||
.answer-statistics { | ||
display: flex; | ||
align-items: center; | ||
margin-left: 450rpx; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default definePageConfig({ | ||
navigationBarTitleText: '问问同学', | ||
navigationBarBackgroundColor: '#F9F9F2', | ||
}); |
Empty file.
Oops, something went wrong.