Skip to content

Commit

Permalink
feat(evaluate) : 新增匿名功能
Browse files Browse the repository at this point in the history
  • Loading branch information
eleliauk committed Dec 17, 2024
1 parent 3a1cc7e commit 7ffdd60
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
10 changes: 6 additions & 4 deletions src/common/components/AnswerToStudent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ interface Question {
const AnswerToStudent: React.FC<Question> = (props) => {
const { content, preview_answers } = props;
return (
<View className="flex h-[4vh] w-[90vw] items-center justify-center gap-2">
<Image src={Ask as string} className="h-6 w-6" />
<View className="text-base font-medium text-gray-800">{content}</View>
<View className="ml-auto text-sm text-gray-500">
<View className="flex min-h-[2vh] w-[80vw] items-center justify-start rounded-lg bg-white p-3 hover:bg-gray-50">
<Image src={Ask as string} className="h-5 w-5 flex-shrink-0" />
<View className="mx-3 line-clamp-2 flex-1 text-base font-medium text-gray-800">
{content}
</View>
<View className="flex-shrink-0 text-sm font-medium text-gray-500">
{preview_answers.length} 个回答
</View>
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/classInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default function Index() {
const fetchAnswer = () => {
try {
void get(
`/questions/list?biz=Course&biz_id=${courseId}&cur_question_id=${0}&limit=${100}`
`/questions/list?biz=Course&biz_id=${courseId}&cur_question_id=${0}&limit=${3}`
).then((res) => {
console.log(res);

Expand Down
66 changes: 34 additions & 32 deletions src/pages/evaluate/evaluate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { postBool } from '@/common/utils/fetch';
export default function evaluate() {
// 初始化状态,存储所有选中的 Radio 项的值
const [selectedValues, setSelectedValues] = useState<string[]>([]);

// 处理 Radio 变化的函数
const handleRadioChange = (value: string) => {
const currentIndex = selectedValues.indexOf(value);
Expand All @@ -31,8 +30,6 @@ export default function evaluate() {
setSelectedValues([...selectedValues, value]);
}
};

// 测试方式的数据
const testways = [
{ value: 'OpenBookExamination', text: '开卷考试' },
{ value: 'ClosedBookExamination', text: '闭卷考试' },
Expand All @@ -54,11 +51,10 @@ export default function evaluate() {
];

const [selectedFeatureValues, setSelectedFeatureValues] = useState<string[]>([]);

const [isAnonymous, setIsAnonymous] = useState(false);
const handleFeaturesChecked = (value: string) => {
const currentIndex = selectedFeatureValues.indexOf(value);
if (currentIndex > -1) {
// 如果 id 已选中,移除它
const newSelectedFeatureValues = selectedFeatureValues.filter(
(v, i) => i !== currentIndex
);
Expand Down Expand Up @@ -86,25 +82,29 @@ export default function evaluate() {
const [courseName, setName] = useState<string | null>('只能评价自己学过的课程哦');
const [test, setTest] = useState<boolean>(false);
useEffect(() => {
const getParams = () => {
void postBool('/checkStatus', { name: 'kestack' }).then((res) => {
const getParams = async () => {
try {
const res = await postBool('/checkStatus', { name: 'kestack' });
setTest(res.data.status);
console.log('res.data.status', test);
});
const instance = Taro.getCurrentInstance();
// 使用可选链操作符安全访问 router 和 params
const params = instance?.router?.params || {};

// 确保 id 是 number 类型
setId(params.id ? Number(params.id) : null);
// 解码 name 参数
setName(params.name ? decodeURIComponent(params.name) : '只能评价自己学过的课程哦');

console.log(params.id);
// 如果需要打印最新状态,可以在 useEffect 中单独监听 test 的变化

const instance = Taro.getCurrentInstance();
const params = instance?.router?.params || {};

setId(params.id ? Number(params.id) : null);
setName(
params.name ? decodeURIComponent(params.name) : '只能评价自己学过的课程哦'
);
} catch (error) {
console.error('Error fetching status:', error);
}
};

getParams();
}, [test]); // 这个 effect 仅在组件挂载时运行一次
void getParams();
}, []);
useEffect(() => {
console.log('test status updated:', test);
}, [test]);

const postEvaluation = () => {
if (selectedStarIndex === -1) {
Expand All @@ -122,6 +122,7 @@ export default function evaluate() {
features: selectedFeatureValues,
id: 0,
status: 'Public',
is_anonymous: isAnonymous,
};
console.log(evaluationobj);
post(`/evaluations/save`, evaluationobj)
Expand All @@ -130,25 +131,16 @@ export default function evaluate() {
void Taro.switchTab({
url: '/pages/main/index', // 页面路径
});
} else {
// 处理其他响应代码,可能需要给用户一些反馈
// 例如:Taro.showToast({ title: '发布课评失败', icon: 'none' });
}
})
.catch((error) => {
// 处理可能出现的错误情况
// 例如:Taro.showToast({ title: '发布失败,请稍后重试', icon: 'none' });
console.error('发布课评请求失败:', error);
});
};

//星级部分的代码
const [selectedStarIndex, setSelectedStarIndex] = useState(-1);

const onStarClick = (index) => {
console.log('选中的星级索引:', index);
setSelectedStarIndex(index + 1);
// 执行其他需要的逻辑
};

const onLableClick = () => {
Expand All @@ -158,8 +150,7 @@ export default function evaluate() {
});
}
};
// eslint-disable-next-line no-constant-condition
return { test } ? (
return !test ? (
<View>因为政策原因暂不能发布课评</View>
) : (
<Form className="view">
Expand Down Expand Up @@ -204,6 +195,17 @@ export default function evaluate() {
})}
</View>
</View>
<View className="p">
<Text>是否匿名:</Text>
<Radio
className="myradio"
checked={isAnonymous}
onClick={() => setIsAnonymous(!isAnonymous)}
color="#3399ff"
>
匿名发布
</Radio>
</View>
<Textarea
maxlength={450}
onInput={countContent}
Expand Down

0 comments on commit 7ffdd60

Please sign in to comment.