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