From e93fbbcb53a1c40115f29f3a30af4da759311c17 Mon Sep 17 00:00:00 2001 From: ditiqi Date: Fri, 21 Feb 2025 16:57:22 +0800 Subject: [PATCH] add --- apps/web/src/app/main/paths/page.tsx | 5 +- .../components/common/editor/MindEditor.tsx | 40 +++---- .../components/common/form/FormArrayField.tsx | 15 --- .../src/components/common/input/InputList.tsx | 102 ++++++++++++++++++ .../course/editor/form/CourseBasicForm.tsx | 6 +- .../CourseContentForm/SortableSection.tsx | 6 +- .../course/editor/form/CourseGoalForm.tsx | 23 ++-- 7 files changed, 139 insertions(+), 58 deletions(-) create mode 100644 apps/web/src/components/common/input/InputList.tsx diff --git a/apps/web/src/app/main/paths/page.tsx b/apps/web/src/app/main/paths/page.tsx index 192652d..e1283a0 100644 --- a/apps/web/src/app/main/paths/page.tsx +++ b/apps/web/src/app/main/paths/page.tsx @@ -1,6 +1,5 @@ import MindEditor from "@web/src/components/common/editor/MindEditor"; -// import MindElixir, { MindElixirInstance } from "mind-elixir"; -import { useEffect, useRef } from "react"; + export default function PathsPage() { - return + return ; } diff --git a/apps/web/src/components/common/editor/MindEditor.tsx b/apps/web/src/components/common/editor/MindEditor.tsx index 9618322..732cfae 100644 --- a/apps/web/src/components/common/editor/MindEditor.tsx +++ b/apps/web/src/components/common/editor/MindEditor.tsx @@ -3,24 +3,24 @@ import { useRef, useEffect } from "react"; import MindElixir from "mind-elixir"; export default function MindEditor() { - const me = useRef(); - useEffect(() => { - const instance = new MindElixir({ - el: "#map", - direction: MindElixir.SIDE, - draggable: true, // default true - contextMenu: true, // default true - toolBar: true, // default true - nodeMenu: true, // default true - keypress: true // default true - - }); - // instance.install(NodeMenu); - instance.init(MindElixir.new("新主题")); - me.current = instance; - }, []); - return
- -
-
+ const me = useRef(); + useEffect(() => { + const instance = new MindElixir({ + el: "#map", + direction: MindElixir.SIDE, + draggable: true, // default true + contextMenu: true, // default true + toolBar: true, // default true + nodeMenu: true, // default true + keypress: true, // default true + }); + // instance.install(NodeMenu); + instance.init(MindElixir.new("新主题")); + me.current = instance; + }, []); + return ( +
+
+
+ ); } diff --git a/apps/web/src/components/common/form/FormArrayField.tsx b/apps/web/src/components/common/form/FormArrayField.tsx index 76835e5..2fc0d60 100644 --- a/apps/web/src/components/common/form/FormArrayField.tsx +++ b/apps/web/src/components/common/form/FormArrayField.tsx @@ -70,21 +70,6 @@ export function FormArrayField({ {...inputProps} placeholder={placeholder} style={{ width: "100%" }} - // suffix={ - // inputProps.maxLength && ( - // - // {inputProps.maxLength - - // ( - // Form.useWatch( - // [ - // name, - // field.name, - // ] - // ) || "" - // ).length} - // - // ) - // } onChange={(e) => { // 更新 items 状态 const newItems = [...items]; diff --git a/apps/web/src/components/common/input/InputList.tsx b/apps/web/src/components/common/input/InputList.tsx new file mode 100644 index 0000000..f6247d5 --- /dev/null +++ b/apps/web/src/components/common/input/InputList.tsx @@ -0,0 +1,102 @@ +import React, { useState } from "react"; +import { Input, Button } from "antd"; +import { DeleteOutlined } from "@ant-design/icons"; + +interface InputListProps { + initialValue?: string[]; + onChange?: (value: string[]) => void; + placeholder?: string; +} + +const InputList: React.FC = ({ + initialValue, + onChange, + placeholder = "请输入内容", +}) => { + // Internal state management with fallback to initial value or empty array + const [inputValues, setInputValues] = useState( + initialValue && initialValue.length > 0 ? initialValue : [""] + ); + + // Handle individual input value change + const handleInputChange = (index: number, newValue: string) => { + const newValues = [...inputValues]; + newValues[index] = newValue; + + // Update internal state + setInputValues(newValues); + + // Call external onChange if provided + onChange?.(newValues); + }; + + // Handle delete operation + const handleDelete = (index: number) => { + const newValues = inputValues.filter((_, i) => i !== index); + + // Ensure at least one input remains + const finalValues = newValues.length === 0 ? [""] : newValues; + + // Update internal state + setInputValues(finalValues); + + // Call external onChange if provided + onChange?.(finalValues); + }; + + // Add new input field + const handleAdd = () => { + const newValues = [...inputValues, ""]; + + // Update internal state + setInputValues(newValues); + + // Call external onChange if provided + onChange?.(newValues); + }; + + return ( +
+ {inputValues.map((item, index) => ( +
+ + handleInputChange(index, e.target.value) + } + placeholder={placeholder} + className="flex-grow" + /> + {inputValues.length > 1 && ( +
+ ))} +
+ + {inputValues.length > 1 && ( +
+
+ ); +}; + +export default InputList; 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 f038144..333e94d 100644 --- a/apps/web/src/components/models/course/editor/form/CourseBasicForm.tsx +++ b/apps/web/src/components/models/course/editor/form/CourseBasicForm.tsx @@ -3,6 +3,7 @@ import { CourseLevel, CourseLevelLabel } from "@nice/common"; import { convertToOptions } from "@nice/client"; import TermSelect from "../../../term/term-select"; import { useCourseEditor } from "../context/CourseEditorContext"; +import AvatarUploader from "@web/src/components/common/uploader/AvatarUploader"; const { TextArea } = Input; @@ -27,14 +28,12 @@ export function CourseBasicForm() { ]}> - -