This commit is contained in:
Rao 2025-03-07 16:28:33 +08:00
commit cdceba2294
6 changed files with 73 additions and 53 deletions

View File

@ -6,24 +6,30 @@ const TermInfo = ({ terms = [] }: { terms?: TermDto[] }) => {
<div> <div>
{terms && terms?.length > 0 ? ( {terms && terms?.length > 0 ? (
<div className="flex gap-2 mb-4"> <div className="flex gap-2 mb-4">
{terms?.map((term: any) => { {terms
return ( ?.sort((a, b) =>
<Tag String(a?.taxonomy?.id || "").localeCompare(
key={term.id} String(b?.taxonomy?.id || "")
color={ )
term?.taxonomy?.slug === )
?.map((term: any) => {
return (
<Tag
key={term.id}
color={
term?.taxonomy?.slug ===
TaxonomySlug.CATEGORY TaxonomySlug.CATEGORY
? "green" ? "green"
: term?.taxonomy?.slug === : term?.taxonomy?.slug ===
TaxonomySlug.LEVEL TaxonomySlug.LEVEL
? "blue" ? "blue"
: "orange" : "orange"
} }
className="px-3 py-1 rounded-full border-0"> className="px-3 py-1 rounded-full border-0">
{term.name} {term.name}
</Tag> </Tag>
); );
})} })}
</div> </div>
) : ( ) : (
<div className="flex gap-2 mb-4"> <div className="flex gap-2 mb-4">

View File

@ -49,7 +49,10 @@ export default function MindEditor({ id }: { id?: string }) {
const canEdit: boolean = useMemo(() => { const canEdit: boolean = useMemo(() => {
const isAuth = isAuthenticated && user?.id === post?.author?.id; 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]); }, [user]);
const navigate = useNavigate(); const navigate = useNavigate();
@ -60,14 +63,14 @@ export default function MindEditor({ id }: { id?: string }) {
const { handleFileUpload } = useTusUpload(); const { handleFileUpload } = useTusUpload();
const [form] = Form.useForm(); const [form] = Form.useForm();
const CustomLinkIconPlugin = (mind) => { const CustomLinkIconPlugin = (mind) => {
mind.bus.addListener('operation', async () => { mind.bus.addListener("operation", async () => {
const hyperLinkElement = await document.querySelectorAll('.hyper-link'); const hyperLinkElement =
console.log('hyperLinkElement', hyperLinkElement); await document.querySelectorAll(".hyper-link");
console.log("hyperLinkElement", hyperLinkElement);
hyperLinkElement.forEach((item) => { hyperLinkElement.forEach((item) => {
const hyperLinkDom = createRoot(item) const hyperLinkDom = createRoot(item);
hyperLinkDom.render(<LinkOutlined />) hyperLinkDom.render(<LinkOutlined />);
}); });
}); });
}; };
useEffect(() => { useEffect(() => {
@ -89,8 +92,22 @@ export default function MindEditor({ id }: { id?: string }) {
title: post.title, title: post.title,
deptIds: deptIds, deptIds: deptIds,
}; };
// post.terms?.forEach((term) => {
// formData[term.taxonomyId] = term.id; // 假设 taxonomyName是您在 Form.Item 中使用的name
// });
// 按 taxonomyId 分组所有 terms
const termsByTaxonomy = {};
post.terms?.forEach((term) => { 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); form.setFieldsValue(formData);
} }
@ -136,8 +153,8 @@ export default function MindEditor({ id }: { id?: string }) {
imgBlob, imgBlob,
async (result) => { async (result) => {
const termIds = taxonomies const termIds = taxonomies
.map((tax) => values[tax.id]) .flatMap((tax) => values[tax.id] || []) // 获取每个 taxonomy 对应的选中值并展平
.filter((id) => id); .filter((id) => id); // 过滤掉空值
const deptIds = (values?.deptIds || []) as string[]; const deptIds = (values?.deptIds || []) as string[];
const { theme, ...data } = instance.getData(); const { theme, ...data } = instance.getData();
try { try {
@ -187,7 +204,7 @@ export default function MindEditor({ id }: { id?: string }) {
} }
console.log(result); console.log(result);
}, },
(error) => { }, (error) => {},
`mind-thumb-${new Date().toString()}` `mind-thumb-${new Date().toString()}`
); );
}; };
@ -207,8 +224,10 @@ export default function MindEditor({ id }: { id?: string }) {
// rules={[{ required: true }]} // rules={[{ required: true }]}
noStyle> noStyle>
<TermSelect <TermSelect
maxTagCount={1}
multiple
disabled={!canEdit} disabled={!canEdit}
className=" w-48" className=" w-56"
placeholder={`请选择${tax.name}`} placeholder={`请选择${tax.name}`}
taxonomyId={tax.id} taxonomyId={tax.id}
/> />

View File

@ -74,19 +74,30 @@ export function CourseFormProvider({
thumbnail: course?.meta?.thumbnail, thumbnail: course?.meta?.thumbnail,
}, },
}; };
// 按 taxonomyId 分组所有 terms
const termsByTaxonomy = {};
course.terms?.forEach((term) => { 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); form.setFieldsValue(formData);
} }
}, [course, form]); }, [course, form]);
const onSubmit = async (values: any) => { const onSubmit = async (values: any) => {
const sections = values?.sections || []; const sections = values?.sections || [];
const deptIds = values?.deptIds || []; const deptIds = values?.deptIds || [];
const termIds = taxonomies const termIds = taxonomies
.map((tax) => values[tax.id]) // 获取每个 taxonomy 对应的选中值 .flatMap((tax) => values[tax.id] || []) // 获取每个 taxonomy 对应的选中值并展平
.filter((id) => id); // 过滤掉空值 .filter((id) => id); // 过滤掉空值
const formattedValues = { const formattedValues = {
@ -153,7 +164,6 @@ export function CourseFormProvider({
} }
}; };
return ( return (
<CourseEditorContext.Provider <CourseEditorContext.Provider
value={{ value={{
@ -164,6 +174,8 @@ export function CourseFormProvider({
form, form,
}}> }}>
<Form <Form
// requiredMark="optional"
variant="filled"
form={form} form={form}
onFinish={onSubmit} onFinish={onSubmit}
initialValues={{ initialValues={{

View File

@ -65,6 +65,8 @@ export function CourseBasicForm() {
name={tax.id} name={tax.id}
key={index}> key={index}>
<TermSelect <TermSelect
maxTagCount={4}
multiple
placeholder={`请选择${tax.name}`} placeholder={`请选择${tax.name}`}
taxonomyId={tax.id}></TermSelect> taxonomyId={tax.id}></TermSelect>
</Form.Item> </Form.Item>

View File

@ -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(
<div className="staff-card">
<div className="staff-card__username">${username}</div>
</div>
)
}

View File

@ -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);
}