diff --git a/src/pages/department/create.module.less b/src/pages/department/create.module.less new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/department/create.tsx b/src/pages/department/create.tsx new file mode 100644 index 0000000..cfe1365 --- /dev/null +++ b/src/pages/department/create.tsx @@ -0,0 +1,142 @@ +import React, { useState, useEffect } from "react"; +import { Row, Col, Form, Input, Cascader, Button, message } from "antd"; +import styles from "./create.module.less"; +import { department } from "../../api/index"; +import { useNavigate } from "react-router-dom"; +import { BackBartment } from "../../compenents"; + +interface Option { + value: string | number; + label: string; + children?: Option[]; +} + +export const DepartmentCreatePage: React.FC = () => { + const navigate = useNavigate(); + const [form] = Form.useForm(); + const [loading, setLoading] = useState(true); + const [categories, setCategories] = useState([]); + const [parent_id, setParentId] = useState(0); + + useEffect(() => { + getParams(); + }, []); + + const getParams = () => { + department.createDepartment().then((res: any) => { + const departments = res.data.departments; + const new_arr: Option[] = checkArr(departments, 0); + setCategories(new_arr); + }); + }; + + const checkArr = (departments: any[], id: number) => { + const arr = []; + for (let i = 0; i < departments[id].length; i++) { + if (!departments[departments[id][i].id]) { + arr.push({ + label: departments[id][i].name, + value: departments[id][i].id, + }); + } else { + const new_arr: Option[] = checkArr(departments, departments[id][i].id); + arr.push({ + label: departments[id][i].name, + value: departments[id][i].id, + children: new_arr, + }); + } + } + return arr; + }; + + const onFinish = (values: any) => { + department + .storeDepartment(values.name, parent_id, values.sort) + .then((res: any) => { + message.success("保存成功!"); + navigate(-1); + }); + }; + + const onFinishFailed = (errorInfo: any) => { + console.log("Failed:", errorInfo); + }; + + const handleChange = (value: any) => { + let it = value[value.length - 1]; + setParentId(it); + }; + + const displayRender = (label: any, selectedOptions: any) => { + return label[label.length - 1]; + }; + + return ( + <> + + +
+ +
+
+
+ + + + + + + + + + + + + +
+
+ +
+ + ); +}; diff --git a/src/pages/department/index.tsx b/src/pages/department/index.tsx index e2970d6..fef729f 100644 --- a/src/pages/department/index.tsx +++ b/src/pages/department/index.tsx @@ -12,12 +12,14 @@ interface Option { name: string; created_at: string; children?: Option[]; + sort: number; } interface DataType { id: React.Key; name: string; created_at: string; + sort: number; } export const DepartmentPage: React.FC = () => { @@ -37,6 +39,11 @@ export const DepartmentPage: React.FC = () => { key: "id", dataIndex: "id", }, + { + title: "Sort", + key: "sort", + dataIndex: "sort", + }, { title: "时间", dataIndex: "created_at", @@ -96,6 +103,7 @@ export const DepartmentPage: React.FC = () => { arr.push({ name: departments[id][i].name, id: departments[id][i].id, + sort: departments[id][i].sort, created_at: departments[id][i].created_at, }); } else { @@ -104,6 +112,7 @@ export const DepartmentPage: React.FC = () => { name: departments[id][i].name, id: departments[id][i].id, created_at: departments[id][i].created_at, + sort: departments[id][i].sort, children: new_arr, }); } @@ -130,10 +139,7 @@ export const DepartmentPage: React.FC = () => {
- + diff --git a/src/pages/index.ts b/src/pages/index.ts index 1cb6d0a..ecda755 100644 --- a/src/pages/index.ts +++ b/src/pages/index.ts @@ -14,3 +14,4 @@ export * from "./system/adminroles/index"; export * from "./system/adminroles/create"; export * from "./system/adminroles/update"; export * from "./department"; +export * from "./department/create"; diff --git a/src/pages/member/create.tsx b/src/pages/member/create.tsx index c2655c8..102c535 100644 --- a/src/pages/member/create.tsx +++ b/src/pages/member/create.tsx @@ -78,7 +78,7 @@ export const MemberCreatePage: React.FC = () => {
- +
{
- +
{
- +
{ autoComplete="off" > diff --git a/src/pages/system/adminroles/update.tsx b/src/pages/system/adminroles/update.tsx index f3ae371..613fb01 100644 --- a/src/pages/system/adminroles/update.tsx +++ b/src/pages/system/adminroles/update.tsx @@ -79,7 +79,7 @@ export const AdminrolesUpdatePage: React.FC = () => { autoComplete="off" > diff --git a/src/router/routes.tsx b/src/router/routes.tsx index 66abe43..e320dd7 100644 --- a/src/router/routes.tsx +++ b/src/router/routes.tsx @@ -16,6 +16,7 @@ import { AdminrolesCreatePage, AdminrolesUpdatePage, DepartmentPage, + DepartmentCreatePage, } from "../pages"; const routes: RouteObject[] = [ @@ -71,6 +72,10 @@ const routes: RouteObject[] = [ path: "/department", element: , }, + { + path: "/department/create", + element: , + }, ], }, {