feat: 课程创建
This commit is contained in:
parent
3f9ad4b2df
commit
12be9a9180
12
apps/admin/src/view/Course/Create/Chatpter/index.less
Normal file
12
apps/admin/src/view/Course/Create/Chatpter/index.less
Normal file
|
@ -0,0 +1,12 @@
|
|||
.chapter-list {
|
||||
li {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
&.l1 {
|
||||
margin-top: 20px;
|
||||
&:first-of-type {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,69 +1,80 @@
|
|||
import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
|
||||
import { Button, Col, Form, Input, Row, Space, Typography } from "antd";
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
Col,
|
||||
Form,
|
||||
Input,
|
||||
Radio,
|
||||
Row,
|
||||
Space,
|
||||
Typography,
|
||||
} from "antd";
|
||||
const { Text } = Typography;
|
||||
import {} from "antd";
|
||||
import { useEffect, useState } from "react";
|
||||
import "./index.less";
|
||||
|
||||
interface IProps {
|
||||
onChange?: Function;
|
||||
styles?: React.CSSProperties;
|
||||
}
|
||||
|
||||
interface IChapter {
|
||||
level: string;
|
||||
title: string;
|
||||
fileId?: string;
|
||||
}
|
||||
|
||||
const Chatpter = (props: IProps) => {
|
||||
const [form] = Form.useForm();
|
||||
const [chapterList, setChapterList] = useState<IChapter[]>([]);
|
||||
|
||||
const onBlur = () => {
|
||||
console.log(form.getFieldsValue().chapter);
|
||||
const onTocChange = () => {
|
||||
const { toc } = form.getFieldsValue();
|
||||
const process = toc.split("\n").map((row: string) => {
|
||||
const [level, title, fileId] = row.split("|");
|
||||
return !fileId ? { level, title } : { level, title, fileId };
|
||||
});
|
||||
setChapterList(process);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
console.log(chapterList);
|
||||
}, [chapterList]);
|
||||
|
||||
return (
|
||||
<div style={{ ...props.styles }}>
|
||||
<Form form={form} style={{ maxWidth: 600 }}>
|
||||
<Form.List name="chapter">
|
||||
{(fields, { add, remove }, { errors }) => (
|
||||
<>
|
||||
{fields.map((field, index) => (
|
||||
<Form.Item required={false} key={field.key}>
|
||||
<Form.Item
|
||||
{...field}
|
||||
validateTrigger={["onChange", "onBlur"]}
|
||||
rules={[{ required: true, message: "请输入章节名称" }]}
|
||||
noStyle
|
||||
>
|
||||
<Input
|
||||
placeholder="请输入章节名称"
|
||||
onBlur={onBlur}
|
||||
style={{ width: "60%" }}
|
||||
/>
|
||||
<Text>{JSON.stringify(field)}</Text>
|
||||
</Form.Item>
|
||||
{fields.length > 1 ? (
|
||||
<MinusCircleOutlined onClick={() => remove(field.name)} />
|
||||
) : null}
|
||||
</Form.Item>
|
||||
))}
|
||||
<Form.Item>
|
||||
<Space>
|
||||
<Button
|
||||
type="dashed"
|
||||
onClick={() => add("The head item", 0)}
|
||||
block
|
||||
icon={<PlusOutlined />}
|
||||
>
|
||||
1级章节
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => add("The head item", 0)}
|
||||
block
|
||||
icon={<PlusOutlined />}
|
||||
>
|
||||
2级章节
|
||||
</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</>
|
||||
)}
|
||||
</Form.List>
|
||||
</Form>
|
||||
<Row gutter={24}>
|
||||
<Col span={12}>
|
||||
<Form form={form} onChange={onTocChange}>
|
||||
<Form.Item name="toc">
|
||||
<Input.TextArea
|
||||
placeholder="级别|标题|FileId"
|
||||
style={{ minHeight: 600, lineHeight: 2, fontSize: 16 }}
|
||||
></Input.TextArea>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<ul className="chapter-list">
|
||||
{chapterList.map((chapter, index) => (
|
||||
<li
|
||||
key={index}
|
||||
className={+chapter.level === 1 ? "l1" : ""}
|
||||
style={{ paddingLeft: +chapter.level === 1 ? 0 : 20 }}
|
||||
>
|
||||
<Text style={{ fontSize: +chapter.level === 1 ? 18 : 16 }}>
|
||||
{chapter.title}
|
||||
</Text>
|
||||
{chapter.fileId && (
|
||||
<Text type="secondary">{chapter.fileId}</Text>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user