From a1d92de493b0b67a98617bc26c1ff1c1b2e7a8f4 Mon Sep 17 00:00:00 2001 From: ditiqi Date: Thu, 6 Mar 2025 22:26:59 +0800 Subject: [PATCH 1/4] add --- .../components/common/editor/MindEditor.tsx | 45 +++++++++++++------ .../editor/context/CourseEditorContext.tsx | 20 +++++++-- .../course/editor/form/CourseBasicForm.tsx | 1 + 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/apps/web/src/components/common/editor/MindEditor.tsx b/apps/web/src/components/common/editor/MindEditor.tsx index 9518d4f..065917e 100755 --- a/apps/web/src/components/common/editor/MindEditor.tsx +++ b/apps/web/src/components/common/editor/MindEditor.tsx @@ -49,7 +49,10 @@ export default function MindEditor({ id }: { id?: string }) { const canEdit: boolean = useMemo(() => { const isAuth = isAuthenticated && user?.id === post?.author?.id; - return !id || isAuth || hasSomePermissions(RolePerms.MANAGE_ANY_POST); + return ( + isAuthenticated && + (!id || isAuth || hasSomePermissions(RolePerms.MANAGE_ANY_POST)) + ); }, [user]); const navigate = useNavigate(); @@ -60,14 +63,14 @@ export default function MindEditor({ id }: { id?: string }) { const { handleFileUpload } = useTusUpload(); const [form] = Form.useForm(); const CustomLinkIconPlugin = (mind) => { - mind.bus.addListener('operation', async () => { - const hyperLinkElement = await document.querySelectorAll('.hyper-link'); - console.log('hyperLinkElement', hyperLinkElement); + mind.bus.addListener("operation", async () => { + const hyperLinkElement = + await document.querySelectorAll(".hyper-link"); + console.log("hyperLinkElement", hyperLinkElement); hyperLinkElement.forEach((item) => { - const hyperLinkDom = createRoot(item) - hyperLinkDom.render() + const hyperLinkDom = createRoot(item); + hyperLinkDom.render(); }); - }); }; useEffect(() => { @@ -89,8 +92,22 @@ export default function MindEditor({ id }: { id?: string }) { title: post.title, deptIds: deptIds, }; + // post.terms?.forEach((term) => { + // formData[term.taxonomyId] = term.id; // 假设 taxonomyName是您在 Form.Item 中使用的name + // }); + + // 按 taxonomyId 分组所有 terms + const termsByTaxonomy = {}; post.terms?.forEach((term) => { - formData[term.taxonomyId] = term.id; // 假设 taxonomyName是您在 Form.Item 中使用的name + if (!termsByTaxonomy[term.taxonomyId]) { + termsByTaxonomy[term.taxonomyId] = []; + } + termsByTaxonomy[term.taxonomyId].push(term.id); + }); + + // 将分组后的 terms 设置到 formData + Object.entries(termsByTaxonomy).forEach(([taxonomyId, termIds]) => { + formData[taxonomyId] = termIds; }); form.setFieldsValue(formData); } @@ -136,8 +153,8 @@ export default function MindEditor({ id }: { id?: string }) { imgBlob, async (result) => { const termIds = taxonomies - .map((tax) => values[tax.id]) - .filter((id) => id); + .flatMap((tax) => values[tax.id] || []) // 获取每个 taxonomy 对应的选中值并展平 + .filter((id) => id); // 过滤掉空值 const deptIds = (values?.deptIds || []) as string[]; const { theme, ...data } = instance.getData(); try { @@ -187,7 +204,7 @@ export default function MindEditor({ id }: { id?: string }) { } console.log(result); }, - (error) => { }, + (error) => {}, `mind-thumb-${new Date().toString()}` ); }; @@ -207,8 +224,10 @@ export default function MindEditor({ id }: { id?: string }) { // rules={[{ required: true }]} noStyle> @@ -264,4 +283,4 @@ export default function MindEditor({ id }: { id?: string }) { )} ); -} \ No newline at end of file +} diff --git a/apps/web/src/components/models/course/editor/context/CourseEditorContext.tsx b/apps/web/src/components/models/course/editor/context/CourseEditorContext.tsx index 6cbfd00..f623660 100755 --- a/apps/web/src/components/models/course/editor/context/CourseEditorContext.tsx +++ b/apps/web/src/components/models/course/editor/context/CourseEditorContext.tsx @@ -74,19 +74,30 @@ export function CourseFormProvider({ thumbnail: course?.meta?.thumbnail, }, }; + + // 按 taxonomyId 分组所有 terms + const termsByTaxonomy = {}; course.terms?.forEach((term) => { - formData[term.taxonomyId] = term.id; // 假设 taxonomyName 是您在 Form.Item 中使用的 name + if (!termsByTaxonomy[term.taxonomyId]) { + termsByTaxonomy[term.taxonomyId] = []; + } + termsByTaxonomy[term.taxonomyId].push(term.id); }); + + // 将分组后的 terms 设置到 formData + Object.entries(termsByTaxonomy).forEach(([taxonomyId, termIds]) => { + formData[taxonomyId] = termIds; + }); + form.setFieldsValue(formData); } }, [course, form]); const onSubmit = async (values: any) => { - const sections = values?.sections || []; const deptIds = values?.deptIds || []; const termIds = taxonomies - .map((tax) => values[tax.id]) // 获取每个 taxonomy 对应的选中值 + .flatMap((tax) => values[tax.id] || []) // 获取每个 taxonomy 对应的选中值并展平 .filter((id) => id); // 过滤掉空值 const formattedValues = { @@ -153,7 +164,6 @@ export function CourseFormProvider({ } }; - return (
From e60c5000f4ac181e3d42b3622b70d320da73b072 Mon Sep 17 00:00:00 2001 From: ditiqi Date: Thu, 6 Mar 2025 22:27:04 +0800 Subject: [PATCH 2/4] add --- apps/web/src/components/test/StaffCard.tsx | 13 ------------- apps/web/src/components/test/StaffList.tsx | 6 ------ 2 files changed, 19 deletions(-) delete mode 100644 apps/web/src/components/test/StaffCard.tsx delete mode 100644 apps/web/src/components/test/StaffList.tsx diff --git a/apps/web/src/components/test/StaffCard.tsx b/apps/web/src/components/test/StaffCard.tsx deleted file mode 100644 index 3c67ea6..0000000 --- a/apps/web/src/components/test/StaffCard.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { Staff } from "packages/common/dist"; -import { api } from "packages/client/dist"; -export const StaffCard = (staff: Staff) => { - const { data } = api.staff.findManyWithPagination.useQuery({ - page - }); - return( -
-
${username}
-
- ) - -} \ No newline at end of file diff --git a/apps/web/src/components/test/StaffList.tsx b/apps/web/src/components/test/StaffList.tsx deleted file mode 100644 index b418bdc..0000000 --- a/apps/web/src/components/test/StaffList.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import { api } from "packages/client/dist"; -import { ReactNode } from "react"; -export default function StaffList({ renderItem }: { renderItem: ReactNode }) { - const { data } = api.staff.findManyWithPagination.useQuery({}); - data.items.map((staff) => renderItem); -} From 48706e79ebde723cd8646fc80ecd64450f42bd28 Mon Sep 17 00:00:00 2001 From: ditiqi Date: Thu, 6 Mar 2025 22:34:18 +0800 Subject: [PATCH 3/4] add --- .../src/app/main/path/components/TermInfo.tsx | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/apps/web/src/app/main/path/components/TermInfo.tsx b/apps/web/src/app/main/path/components/TermInfo.tsx index b26f721..21fed6d 100755 --- a/apps/web/src/app/main/path/components/TermInfo.tsx +++ b/apps/web/src/app/main/path/components/TermInfo.tsx @@ -6,24 +6,30 @@ const TermInfo = ({ terms = [] }: { terms?: TermDto[] }) => {
{terms && terms?.length > 0 ? (
- {terms?.map((term: any) => { - return ( - + String(a?.taxonomy?.id || "").localeCompare( + String(b?.taxonomy?.id || "") + ) + ) + ?.map((term: any) => { + return ( + - {term.name} - - ); - })} + ? "green" + : term?.taxonomy?.slug === + TaxonomySlug.LEVEL + ? "blue" + : "orange" + } + className="px-3 py-1 rounded-full border-0"> + {term.name} + + ); + })}
) : (
From e23c201842da34348a9fad8f42d1322d81677d54 Mon Sep 17 00:00:00 2001 From: ditiqi Date: Thu, 6 Mar 2025 22:34:21 +0800 Subject: [PATCH 4/4] add --- .../src/components/models/course/editor/form/CourseBasicForm.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/web/src/components/models/course/editor/form/CourseBasicForm.tsx b/apps/web/src/components/models/course/editor/form/CourseBasicForm.tsx index 93b7c27..8ac7dbd 100755 --- a/apps/web/src/components/models/course/editor/form/CourseBasicForm.tsx +++ b/apps/web/src/components/models/course/editor/form/CourseBasicForm.tsx @@ -65,6 +65,7 @@ export function CourseBasicForm() { name={tax.id} key={index}>