Skip to content

Commit

Permalink
feat(collect): 收藏跳转课程主页
Browse files Browse the repository at this point in the history
  • Loading branch information
eleliauk committed Dec 10, 2024
1 parent 0f84a69 commit 3f417ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/common/components/CollectionCourse/CollectionCourse.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { View } from '@tarojs/components';
import Taro from '@tarojs/taro';
import React from 'react';
import { AtRate } from 'taro-ui';

Expand All @@ -10,6 +11,7 @@ interface CollectionCourseProps {
courseRate?: number;
courseTeacher?: string;
isCollected?: boolean;
courseId?: number;
}

const CollectionCourse: React.FC<CollectionCourseProps> = ({
Expand All @@ -18,11 +20,21 @@ const CollectionCourse: React.FC<CollectionCourseProps> = ({
courseRate,
courseTeacher,
isCollected,
courseId,
}) => {
if (!isCollected) {
return null;
}
console.log(courseType);
const navigateToPage = async () => {
await Taro.navigateTo({
url: `/pages/classInfo/index?course_id=${courseId}`, // 传递 course_id 参数
});
};

const handleClickToClass = () => {
console.log('Clicked on course:');

Check warning on line 35 in src/common/components/CollectionCourse/CollectionCourse.tsx

View workflow job for this annotation

GitHub Actions / lint-and-format

Unexpected console statement
void navigateToPage().then((r) => console.log(r)); // 这里调用异步函数,但不返回 Promise

Check warning on line 36 in src/common/components/CollectionCourse/CollectionCourse.tsx

View workflow job for this annotation

GitHub Actions / lint-and-format

Unexpected console statement
};
let courseIcon: string = '';
// CoursePropertyGeneralCore = 通识核心课
// CoursePropertyGeneralElective = 通识选修课
Expand All @@ -47,7 +59,7 @@ const CollectionCourse: React.FC<CollectionCourseProps> = ({
break;
}
return (
<View className="collection_course">
<View className="collection_course" onClick={handleClickToClass}>
<View className="collection_course_type">{courseIcon}</View>
<View className="collection_course_detail">
<View className="collection_course_name">{courseName}</View>
Expand All @@ -56,7 +68,6 @@ const CollectionCourse: React.FC<CollectionCourseProps> = ({
<AtRate className="collection_course_rate" value={courseRate} size={15} />
</View>
</View>
{/*<View className="collection_course_collected">已收藏</View>*/}
</View>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/common/components/Comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const CommentHeader: React.FC<CommentProps> = memo((props) => {
};

const handleClickToClass = () => {
void navigateToPage().then((r) => console.log(r)); // 这里调用异步函数,但不返回 Promise
void navigateToPage().then((r) => console.log(r));

Check warning on line 48 in src/common/components/Comment/index.tsx

View workflow job for this annotation

GitHub Actions / lint-and-format

Unexpected console statement
};

return (
Expand Down
1 change: 1 addition & 0 deletions src/pages/myCollection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const MyCollection: React.FC = () => {
{collection.map((course) => (
<CollectionCourse
key={course.id}
courseId={course.course_id}
courseType={course.type}
courseName={course.name || ''}
courseRate={course.composite_score || 0}
Expand Down

0 comments on commit 3f417ba

Please sign in to comment.