Merge branch 'main' of http://113.45.157.195:3003/insiinc/re-mooc
This commit is contained in:
commit
f352a55c02
|
@ -21,6 +21,7 @@ import { useNavigate } from "react-router-dom";
|
||||||
import { useAuth } from "@web/src/providers/auth-provider";
|
import { useAuth } from "@web/src/providers/auth-provider";
|
||||||
import { MIND_OPTIONS } from "./constant";
|
import { MIND_OPTIONS } from "./constant";
|
||||||
export default function MindEditor({ id }: { id?: string }) {
|
export default function MindEditor({ id }: { id?: string }) {
|
||||||
|
//containerRef 容器ref instance 实例
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const [instance, setInstance] = useState<MindElixirInstance | null>(null);
|
const [instance, setInstance] = useState<MindElixirInstance | null>(null);
|
||||||
const { isAuthenticated, user, hasSomePermissions } = useAuth();
|
const { isAuthenticated, user, hasSomePermissions } = useAuth();
|
||||||
|
@ -31,7 +32,7 @@ export default function MindEditor({ id }: { id?: string }) {
|
||||||
id,
|
id,
|
||||||
},
|
},
|
||||||
select: postDetailSelect,
|
select: postDetailSelect,
|
||||||
});
|
}, { enabled: Boolean(id) });
|
||||||
const canEdit: boolean = useMemo(() => {
|
const canEdit: boolean = useMemo(() => {
|
||||||
//登录了且是作者、超管、无id新建模式
|
//登录了且是作者、超管、无id新建模式
|
||||||
const isAuth = isAuthenticated && user?.id === post?.author?.id;
|
const isAuth = isAuthenticated && user?.id === post?.author?.id;
|
||||||
|
@ -45,7 +46,7 @@ export default function MindEditor({ id }: { id?: string }) {
|
||||||
const { handleFileUpload } = useTusUpload();
|
const { handleFileUpload } = useTusUpload();
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (post?.id) {
|
if (post?.id && id) {
|
||||||
read.mutateAsync({
|
read.mutateAsync({
|
||||||
data: {
|
data: {
|
||||||
visitorId: user?.id || null,
|
visitorId: user?.id || null,
|
||||||
|
@ -64,8 +65,8 @@ export default function MindEditor({ id }: { id?: string }) {
|
||||||
deptIds: deptIds,
|
deptIds: deptIds,
|
||||||
};
|
};
|
||||||
post.terms?.forEach((term) => {
|
post.terms?.forEach((term) => {
|
||||||
formData[term.taxonomyId] = term.id; // 假设 taxonomyName 是您在 Form.Item 中使用的 name
|
formData[term.taxonomyId] = term.id // 假设 taxonomyName是您在 Form.Item 中使用的name
|
||||||
});
|
})
|
||||||
form.setFieldsValue(formData);
|
form.setFieldsValue(formData);
|
||||||
}
|
}
|
||||||
}, [post, form, instance, id]);
|
}, [post, form, instance, id]);
|
||||||
|
@ -87,6 +88,7 @@ export default function MindEditor({ id }: { id?: string }) {
|
||||||
});
|
});
|
||||||
mind.init(MindElixir.new("新思维导图"));
|
mind.init(MindElixir.new("新思维导图"));
|
||||||
containerRef.current.hidden = true;
|
containerRef.current.hidden = true;
|
||||||
|
//挂载实例
|
||||||
setInstance(mind);
|
setInstance(mind);
|
||||||
}, [canEdit]);
|
}, [canEdit]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -98,6 +100,7 @@ export default function MindEditor({ id }: { id?: string }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [id, post, instance]);
|
}, [id, post, instance]);
|
||||||
|
//保存 按钮 函数
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
if (!instance) return;
|
if (!instance) return;
|
||||||
const values = form.getFieldsValue();
|
const values = form.getFieldsValue();
|
||||||
|
|
|
@ -82,7 +82,7 @@ export function CourseFormProvider({
|
||||||
}, [course, form]);
|
}, [course, form]);
|
||||||
|
|
||||||
const onSubmit = async (values: any) => {
|
const onSubmit = async (values: any) => {
|
||||||
console.log(values);
|
|
||||||
const sections = values?.sections || [];
|
const sections = values?.sections || [];
|
||||||
const deptIds = values?.deptIds || [];
|
const deptIds = values?.deptIds || [];
|
||||||
const termIds = taxonomies
|
const termIds = taxonomies
|
||||||
|
@ -149,6 +149,7 @@ export function CourseFormProvider({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CourseEditorContext.Provider
|
<CourseEditorContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
|
|
@ -9,7 +9,7 @@ import DepartmentSelect from "../../../department/department-select";
|
||||||
const { TextArea } = Input;
|
const { TextArea } = Input;
|
||||||
|
|
||||||
export function CourseBasicForm() {
|
export function CourseBasicForm() {
|
||||||
// 将 CourseLevelLabel 转换为 Ant Design Select 需要的选项格式
|
// 将 CourseLevelLabel 使用 Object.entries 将 CourseLevelLabel 对象转换为键值对数组。
|
||||||
const levelOptions = Object.entries(CourseLevelLabel).map(
|
const levelOptions = Object.entries(CourseLevelLabel).map(
|
||||||
([key, value]) => ({
|
([key, value]) => ({
|
||||||
label: value,
|
label: value,
|
||||||
|
|
Loading…
Reference in New Issue