From 4a6957f1814f4125800baf6b6bfed4f508b40da3 Mon Sep 17 00:00:00 2001 From: ditiqi Date: Wed, 26 Feb 2025 21:08:38 +0800 Subject: [PATCH] addd --- apps/server/src/models/post/post.service.ts | 60 +++++++++---------- apps/server/src/queue/models/post/utils.ts | 2 +- .../main/courses/components/CourseCard.tsx | 22 ++++--- .../src/app/main/layout/NavigationMenu.tsx | 27 +++++++-- .../src/app/main/layout/UserMenu/UserMenu.tsx | 4 +- apps/web/src/app/main/my-duty/page.tsx | 24 ++++++-- apps/web/src/app/main/my-learning/page.tsx | 20 ++++++- .../models/course/list/CourseList.tsx | 14 ++++- apps/web/src/routes/index.tsx | 21 ++++++- packages/common/prisma/schema.prisma | 13 ++-- packages/common/src/models/select.ts | 4 +- 11 files changed, 147 insertions(+), 64 deletions(-) diff --git a/apps/server/src/models/post/post.service.ts b/apps/server/src/models/post/post.service.ts index 6964696..8f90a85 100755 --- a/apps/server/src/models/post/post.service.ts +++ b/apps/server/src/models/post/post.service.ts @@ -306,37 +306,37 @@ export class PostService extends BaseTreeService { staff?.id && { authorId: staff.id, }, - staff?.id && { - watchableStaffs: { - some: { - id: staff.id, - }, - }, - }, - deptId && { - watchableDepts: { - some: { - id: { - in: parentDeptIds, - }, - }, - }, - }, + // staff?.id && { + // watchableStaffs: { + // some: { + // id: staff.id, + // }, + // }, + // }, + // deptId && { + // watchableDepts: { + // some: { + // id: { + // in: parentDeptIds, + // }, + // }, + // }, + // }, - { - AND: [ - { - watchableStaffs: { - none: {}, // 匹配 watchableStaffs 为空 - }, - }, - { - watchableDepts: { - none: {}, // 匹配 watchableDepts 为空 - }, - }, - ], - }, + // { + // AND: [ + // { + // watchableStaffs: { + // none: {}, // 匹配 watchableStaffs 为空 + // }, + // }, + // { + // watchableDepts: { + // none: {}, // 匹配 watchableDepts 为空 + // }, + // }, + // ], + // }, ].filter(Boolean); if (orCondition?.length > 0) return orCondition; diff --git a/apps/server/src/queue/models/post/utils.ts b/apps/server/src/queue/models/post/utils.ts index 51d2b04..51bffca 100644 --- a/apps/server/src/queue/models/post/utils.ts +++ b/apps/server/src/queue/models/post/utils.ts @@ -23,7 +23,7 @@ export async function updateTotalCourseViewCount(type: VisitType) { views: true, }, where: { - postId: { in: lectures.map((lecture) => lecture.id) }, + postId: { in: posts.map((post) => post.id) }, type: type, }, }); diff --git a/apps/web/src/app/main/courses/components/CourseCard.tsx b/apps/web/src/app/main/courses/components/CourseCard.tsx index 5de3a9d..3dd5032 100755 --- a/apps/web/src/app/main/courses/components/CourseCard.tsx +++ b/apps/web/src/app/main/courses/components/CourseCard.tsx @@ -9,13 +9,18 @@ import { useNavigate } from "react-router-dom"; interface CourseCardProps { course: CourseDto; + edit?: boolean; } const { Title, Text } = Typography; -export default function CourseCard({ course }: CourseCardProps) { +export default function CourseCard({ course, edit = false }: CourseCardProps) { const navigate = useNavigate(); const handleClick = (course: CourseDto) => { - navigate(`/course/${course.id}/detail`); - window.scrollTo({ top: 0, behavior: "smooth", }) + if (!edit) { + navigate(`/course/${course.id}/detail`); + } else { + navigate(`/course/${course.id}/editor`); + } + window.scrollTo({ top: 0, behavior: "smooth" }); }; return ( - {course?.meta?.views - ? `观看次数 ${course?.meta?.views}` - : null} + + {`观看次数 ${course?.meta?.views || 0}`}
@@ -91,7 +95,7 @@ export default function CourseCard({ course }: CourseCardProps) { size="large" className="w-full shadow-[0_8px_20px_-6px_rgba(59,130,246,0.5)] hover:shadow-[0_12px_24px_-6px_rgba(59,130,246,0.6)] transform hover:translate-y-[-2px] transition-all duration-500 ease-out"> - 立即学习 + {edit ? "进行编辑" : "立即学习"}
diff --git a/apps/web/src/app/main/layout/NavigationMenu.tsx b/apps/web/src/app/main/layout/NavigationMenu.tsx index 53efdb3..6f0f5de 100755 --- a/apps/web/src/app/main/layout/NavigationMenu.tsx +++ b/apps/web/src/app/main/layout/NavigationMenu.tsx @@ -1,15 +1,30 @@ +import { useAuth } from "@web/src/providers/auth-provider"; import { Menu } from "antd"; +import { useMemo } from "react"; import { useNavigate, useLocation } from "react-router-dom"; -const menuItems = [ - { key: "home", path: "/", label: "首页" }, - { key: "courses", path: "/courses", label: "全部课程" }, - { key: "paths", path: "/paths", label: "学习路径" }, -]; - export const NavigationMenu = () => { const navigate = useNavigate(); + const { isAuthenticated } = useAuth(); const { pathname } = useLocation(); + + const menuItems = useMemo(() => { + const baseItems = [ + { key: "home", path: "/", label: "首页" }, + { key: "courses", path: "/courses", label: "全部课程" }, + { key: "paths", path: "/paths", label: "学习路径" }, + ]; + if (!isAuthenticated) { + return baseItems; + } else { + return [ + ...baseItems, + { key: "my-duty", path: "/my-duty", label: "我创建的" }, + { key: "my-learning", path: "/my-learning", label: "我学习的" }, + ]; + } + }, [isAuthenticated]); + const selectedKey = menuItems.find((item) => item.path === pathname)?.key || ""; return ( diff --git a/apps/web/src/app/main/layout/UserMenu/UserMenu.tsx b/apps/web/src/app/main/layout/UserMenu/UserMenu.tsx index 41da474..e3ef21f 100755 --- a/apps/web/src/app/main/layout/UserMenu/UserMenu.tsx +++ b/apps/web/src/app/main/layout/UserMenu/UserMenu.tsx @@ -90,14 +90,14 @@ export function UserMenu() { icon: , label: "我创建的课程", action: () => { - setModalOpen(true); + navigate("/my/duty"); }, }, { icon: , label: "我学习的课程", action: () => { - setModalOpen(true); + navigate("/my/learning"); }, }, canManageAnyStaff && { diff --git a/apps/web/src/app/main/my-duty/page.tsx b/apps/web/src/app/main/my-duty/page.tsx index 7871969..fd33761 100644 --- a/apps/web/src/app/main/my-duty/page.tsx +++ b/apps/web/src/app/main/my-duty/page.tsx @@ -1,7 +1,21 @@ +import CourseList from "@web/src/components/models/course/list/CourseList"; +import { useAuth } from "@web/src/providers/auth-provider"; + export default function MyDutyPage() { - - - - return <> - + const { user } = useAuth(); + return ( + <> +
+ +
+ + ); } diff --git a/apps/web/src/app/main/my-learning/page.tsx b/apps/web/src/app/main/my-learning/page.tsx index 503600c..0216515 100644 --- a/apps/web/src/app/main/my-learning/page.tsx +++ b/apps/web/src/app/main/my-learning/page.tsx @@ -1,3 +1,21 @@ +import CourseList from "@web/src/components/models/course/list/CourseList"; +import { useAuth } from "@web/src/providers/auth-provider"; + export default function MyLearningPage() { - return <>; + const { user } = useAuth(); + return ( + <> +
+ +
+ + ); } diff --git a/apps/web/src/components/models/course/list/CourseList.tsx b/apps/web/src/components/models/course/list/CourseList.tsx index 3ba3eaf..2111a3a 100755 --- a/apps/web/src/components/models/course/list/CourseList.tsx +++ b/apps/web/src/components/models/course/list/CourseList.tsx @@ -13,6 +13,7 @@ interface CourseListProps { }; cols?: number; showPagination?: boolean; + edit?: boolean; } interface CoursesPagnationProps { data: { @@ -25,6 +26,7 @@ export default function CourseList({ params, cols = 3, showPagination = true, + edit = false, }: CourseListProps) { const [currentPage, setCurrentPage] = useState(params?.page || 1); const { data, isLoading }: CoursesPagnationProps = @@ -55,7 +57,11 @@ export default function CourseList({ window.scrollTo({ top: 0, behavior: "smooth" }); } if (isLoading) { - return ; + return ( +
+ +
+ ); } return (
@@ -66,7 +72,11 @@ export default function CourseList({ ) : ( courses.map((course) => ( - + )) )}
diff --git a/apps/web/src/routes/index.tsx b/apps/web/src/routes/index.tsx index e1ae965..1ba39aa 100755 --- a/apps/web/src/routes/index.tsx +++ b/apps/web/src/routes/index.tsx @@ -18,6 +18,8 @@ import CoursesPage from "../app/main/courses/page"; import PathsPage from "../app/main/paths/page"; import { adminRoute } from "./admin-route"; import { CoursePreview } from "../app/main/course/preview/page"; +import MyLearningPage from "../app/main/my-learning/page"; +import MyDutyPage from "../app/main/my-duty/page"; interface CustomIndexRouteObject extends IndexRouteObject { name?: string; breadcrumb?: string; @@ -63,15 +65,32 @@ export const routes: CustomRouteObject[] = [ path: "courses", element: , }, + { + path: "my-duty", + element: ( + + + + ), + }, + { + path: "my-learning", + element: ( + + + + ), + }, ], }, + { path: "course", children: [ { path: ":id?/editor", element: ( - + ), diff --git a/packages/common/prisma/schema.prisma b/packages/common/prisma/schema.prisma index 236c4ab..75e8be6 100755 --- a/packages/common/prisma/schema.prisma +++ b/packages/common/prisma/schema.prisma @@ -88,9 +88,12 @@ model Staff { deletedAt DateTime? @map("deleted_at") officerId String? @map("officer_id") - watchedPost Post[] @relation("post_watch_staff") + // watchedPost Post[] @relation("post_watch_staff") visits Visit[] posts Post[] + + + learningPost Post[] @relation("post_student") sentMsgs Message[] @relation("message_sender") receivedMsgs Message[] @relation("message_receiver") registerToken String? @@ -124,7 +127,7 @@ model Department { deptStaffs Staff[] @relation("DeptStaff") terms Term[] @relation("department_term") - watchedPost Post[] @relation("post_watch_dept") + // watchedPost Post[] @relation("post_watch_dept") hasChildren Boolean? @default(false) @map("has_children") @@index([parentId]) @@ -201,7 +204,7 @@ model Post { order Float? @default(0) @map("order") duration Int? rating Int? @default(0) - + students Staff[] @relation("post_student") depts Department[] @relation("post_dept") // 索引 // 日期时间类型字段 @@ -223,8 +226,8 @@ model Post { ancestors PostAncestry[] @relation("DescendantPosts") descendants PostAncestry[] @relation("AncestorPosts") resources Resource[] // 附件列表 - watchableStaffs Staff[] @relation("post_watch_staff") // 可观看的员工列表,关联 Staff 模型 - watchableDepts Department[] @relation("post_watch_dept") // 可观看的部门列表,关联 Department 模型 + // watchableStaffs Staff[] @relation("post_watch_staff") + // watchableDepts Department[] @relation("post_watch_dept") // 可观看的部门列表,关联 Department 模型 meta Json? // 封面url 视频url objectives具体的学习目标 rating评分Int // 索引 diff --git a/packages/common/src/models/select.ts b/packages/common/src/models/select.ts index 2e96315..38fd3bf 100755 --- a/packages/common/src/models/select.ts +++ b/packages/common/src/models/select.ts @@ -6,8 +6,8 @@ export const postDetailSelect: Prisma.PostSelect = { title: true, content: true, resources: true, - watchableDepts: true, - watchableStaffs: true, + // watchableDepts: true, + // watchableStaffs: true, updatedAt: true, author: { select: {