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 (