Merge branch 'main' of http://113.45.157.195:3003/insiinc/re-mooc
This commit is contained in:
commit
cdceba2294
|
@ -6,24 +6,30 @@ const TermInfo = ({ terms = [] }: { terms?: TermDto[] }) => {
|
|||
<div>
|
||||
{terms && terms?.length > 0 ? (
|
||||
<div className="flex gap-2 mb-4">
|
||||
{terms?.map((term: any) => {
|
||||
return (
|
||||
<Tag
|
||||
key={term.id}
|
||||
color={
|
||||
term?.taxonomy?.slug ===
|
||||
{terms
|
||||
?.sort((a, b) =>
|
||||
String(a?.taxonomy?.id || "").localeCompare(
|
||||
String(b?.taxonomy?.id || "")
|
||||
)
|
||||
)
|
||||
?.map((term: any) => {
|
||||
return (
|
||||
<Tag
|
||||
key={term.id}
|
||||
color={
|
||||
term?.taxonomy?.slug ===
|
||||
TaxonomySlug.CATEGORY
|
||||
? "green"
|
||||
: term?.taxonomy?.slug ===
|
||||
TaxonomySlug.LEVEL
|
||||
? "blue"
|
||||
: "orange"
|
||||
}
|
||||
className="px-3 py-1 rounded-full border-0">
|
||||
{term.name}
|
||||
</Tag>
|
||||
);
|
||||
})}
|
||||
? "green"
|
||||
: term?.taxonomy?.slug ===
|
||||
TaxonomySlug.LEVEL
|
||||
? "blue"
|
||||
: "orange"
|
||||
}
|
||||
className="px-3 py-1 rounded-full border-0">
|
||||
{term.name}
|
||||
</Tag>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex gap-2 mb-4">
|
||||
|
|
|
@ -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(<LinkOutlined />)
|
||||
const hyperLinkDom = createRoot(item);
|
||||
hyperLinkDom.render(<LinkOutlined />);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
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>
|
||||
<TermSelect
|
||||
maxTagCount={1}
|
||||
multiple
|
||||
disabled={!canEdit}
|
||||
className=" w-48"
|
||||
className=" w-56"
|
||||
placeholder={`请选择${tax.name}`}
|
||||
taxonomyId={tax.id}
|
||||
/>
|
||||
|
@ -264,4 +283,4 @@ export default function MindEditor({ id }: { id?: string }) {
|
|||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 (
|
||||
<CourseEditorContext.Provider
|
||||
value={{
|
||||
|
@ -164,6 +174,8 @@ export function CourseFormProvider({
|
|||
form,
|
||||
}}>
|
||||
<Form
|
||||
// requiredMark="optional"
|
||||
variant="filled"
|
||||
form={form}
|
||||
onFinish={onSubmit}
|
||||
initialValues={{
|
||||
|
|
|
@ -65,6 +65,8 @@ export function CourseBasicForm() {
|
|||
name={tax.id}
|
||||
key={index}>
|
||||
<TermSelect
|
||||
maxTagCount={4}
|
||||
multiple
|
||||
placeholder={`请选择${tax.name}`}
|
||||
taxonomyId={tax.id}></TermSelect>
|
||||
</Form.Item>
|
||||
|
|
|
@ -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>
|
||||
)
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue