add liaohui
This commit is contained in:
parent
f5825dc962
commit
ab6727e23b
|
@ -6,45 +6,45 @@ import { CoursesSectionTag } from "./CoursesSectionTag";
|
|||
import CourseList from "@web/src/components/models/course/list/CourseList";
|
||||
import LookForMore from "./LookForMore";
|
||||
interface GetTaxonomyProps {
|
||||
categories: string[];
|
||||
isLoading: boolean;
|
||||
categories: string[];
|
||||
isLoading: boolean;
|
||||
}
|
||||
function useGetTaxonomy({ type }): GetTaxonomyProps {
|
||||
const { data, isLoading }: { data: TermDto[]; isLoading: boolean } =
|
||||
api.term.findMany.useQuery({
|
||||
where: {
|
||||
taxonomy: {
|
||||
slug: type,
|
||||
},
|
||||
parentId : null
|
||||
},
|
||||
take: 11, // 只取前10个
|
||||
});
|
||||
const categories = useMemo(() => {
|
||||
const allCategories = isLoading
|
||||
? []
|
||||
: data?.map((course) => course.name);
|
||||
return [...Array.from(new Set(allCategories))];
|
||||
}, [data]);
|
||||
return { categories, isLoading };
|
||||
const { data, isLoading }: { data: TermDto[]; isLoading: boolean } =
|
||||
api.term.findMany.useQuery({
|
||||
where: {
|
||||
taxonomy: {
|
||||
slug: type,
|
||||
},
|
||||
parentId: null
|
||||
},
|
||||
take: 11, // 只取前10个
|
||||
});
|
||||
const categories = useMemo(() => {
|
||||
const allCategories = isLoading
|
||||
? []
|
||||
: data?.map((course) => course.name);
|
||||
return [...Array.from(new Set(allCategories))];
|
||||
}, [data]);
|
||||
return { categories, isLoading };
|
||||
}
|
||||
const { Title, Text } = Typography;
|
||||
interface CoursesSectionProps {
|
||||
title: string;
|
||||
description: string;
|
||||
initialVisibleCoursesCount?: number;
|
||||
title: string;
|
||||
description: string;
|
||||
initialVisibleCoursesCount?: number;
|
||||
}
|
||||
const CoursesSection: React.FC<CoursesSectionProps> = ({
|
||||
title,
|
||||
description,
|
||||
initialVisibleCoursesCount = 8,
|
||||
title,
|
||||
description,
|
||||
initialVisibleCoursesCount = 8,
|
||||
}) => {
|
||||
const [selectedCategory, setSelectedCategory] = useState<string>("全部");
|
||||
const gateGory: GetTaxonomyProps = useGetTaxonomy({
|
||||
type: TaxonomySlug.CATEGORY,
|
||||
});
|
||||
return (
|
||||
<section className="relative py-16 overflow-hidden ">
|
||||
<section className="relative py-16 overflow-hidden ">
|
||||
<div className="max-w-screen-2xl mx-auto px-4 relative">
|
||||
<div className="flex justify-between items-end mb-12 ">
|
||||
<div>
|
||||
|
@ -87,10 +87,10 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
|||
where: {
|
||||
terms: !(selectedCategory === "全部")
|
||||
? {
|
||||
some: {
|
||||
name: selectedCategory,
|
||||
},
|
||||
}
|
||||
some: {
|
||||
name: selectedCategory,
|
||||
},
|
||||
}
|
||||
: {},
|
||||
},
|
||||
}}
|
||||
|
|
|
@ -12,15 +12,7 @@ import toast from "react-hot-toast";
|
|||
export default function StaffForm() {
|
||||
const { user } = useAuth();
|
||||
const { create, update } = useStaff(); // Ensure you have these methods in your hooks
|
||||
const {
|
||||
formLoading,
|
||||
modalOpen,
|
||||
setModalOpen,
|
||||
domainId,
|
||||
setDomainId,
|
||||
form,
|
||||
setFormLoading,
|
||||
} = useContext(UserEditorContext);
|
||||
const {formLoading,modalOpen,setModalOpen,domainId,setDomainId,form,setFormLoading,} = useContext(UserEditorContext);
|
||||
const {
|
||||
data,
|
||||
isLoading,
|
||||
|
@ -76,6 +68,8 @@ export default function StaffForm() {
|
|||
}
|
||||
useEffect(() => {
|
||||
form.resetFields();
|
||||
console.log('cc',data);
|
||||
|
||||
if (data) {
|
||||
form.setFieldValue("username", data.username);
|
||||
form.setFieldValue("showname", data.showname);
|
||||
|
|
|
@ -35,12 +35,8 @@ interface CourseFormProviderProps {
|
|||
editId?: string; // 添加 editId 参数
|
||||
}
|
||||
|
||||
export const CourseDetailContext =
|
||||
createContext<CourseDetailContextType | null>(null);
|
||||
export function CourseDetailProvider({
|
||||
children,
|
||||
editId,
|
||||
}: CourseFormProviderProps) {
|
||||
export const CourseDetailContext =createContext<CourseDetailContextType | null>(null);
|
||||
export function CourseDetailProvider({children,editId}: CourseFormProviderProps) {
|
||||
const navigate = useNavigate();
|
||||
const { read } = useVisitor();
|
||||
const { user, hasSomePermissions } = useAuth();
|
||||
|
@ -61,6 +57,7 @@ export function CourseDetailProvider({
|
|||
{ enabled: Boolean(editId) }
|
||||
);
|
||||
const canEdit = useMemo(() => {
|
||||
//先判断登陆再判断是否是作者,三个条件满足一个就有编辑权限
|
||||
const isAuthor = user?.id === course?.authorId;
|
||||
const isDept = course?.depts
|
||||
?.map((dept) => dept.id)
|
||||
|
@ -68,6 +65,7 @@ export function CourseDetailProvider({
|
|||
const isRoot = hasSomePermissions(RolePerms?.MANAGE_ANY_POST);
|
||||
return isAuthor || isDept || isRoot;
|
||||
}, [user, course]);
|
||||
|
||||
const [selectedLectureId, setSelectedLectureId] = useState<
|
||||
string | undefined
|
||||
>(lectureId || undefined);
|
||||
|
|
|
@ -13,14 +13,13 @@ import dayjs from "dayjs";
|
|||
import { useNavigate, useParams } from "react-router-dom";
|
||||
|
||||
export const CourseDetailDescription: React.FC = () => {
|
||||
const { course, isLoading, selectedLectureId, setSelectedLectureId } =
|
||||
const { course,canEdit, isLoading, selectedLectureId, setSelectedLectureId } =
|
||||
useContext(CourseDetailContext);
|
||||
const { Paragraph, Title } = Typography;
|
||||
const firstLectureId = useMemo(() => {
|
||||
return course?.sections?.[0]?.lectures?.[0]?.id;
|
||||
}, [course]);
|
||||
const navigate = useNavigate();
|
||||
const { canEdit } = useContext(CourseDetailContext);
|
||||
const { id } = useParams();
|
||||
return (
|
||||
<div className="w-full bg-white shadow-md rounded-lg border border-gray-200 p-5 my-4">
|
||||
|
@ -72,7 +71,7 @@ export const CourseDetailDescription: React.FC = () => {
|
|||
}
|
||||
</div>
|
||||
<div className="text-gray-800 flex justify-start gap-5">
|
||||
|
||||
|
||||
|
||||
<div className="flex gap-1">
|
||||
<CalendarOutlined></CalendarOutlined>
|
||||
|
|
Loading…
Reference in New Issue