部门新建、编辑弹窗组件化

This commit is contained in:
禺狨
2023-03-14 14:27:54 +08:00
parent 99db5c6c87
commit 3707e31eb8
12 changed files with 378 additions and 382 deletions

View File

@@ -2,7 +2,6 @@ import React, { useState, useRef, useEffect } from "react";
import { Modal, Form, Input, Cascader, message } from "antd";
import styles from "./create.module.less";
import { resourceCategory } from "../../../../api/index";
import type { FormInstance } from "antd/es/form";
interface PropInterface {
open: boolean;

View File

@@ -1,8 +1,7 @@
import React, { useState, useRef, useEffect } from "react";
import { Modal, Form, Input, Cascader, message } from "antd";
import styles from "./create.module.less";
import styles from "./update.module.less";
import { resourceCategory } from "../../../../api/index";
import type { FormInstance } from "antd/es/form";
interface PropInterface {
id: number;
@@ -37,13 +36,6 @@ export const ResourceCategoryUpdate: React.FC<PropInterface> = ({
getDetail();
}, [id]);
useEffect(() => {
form.setFieldsValue({
name: "",
parent_id: [0],
});
}, [form, open]);
const getParams = () => {
resourceCategory.createResourceCategory().then((res: any) => {
const categories = res.data.categories;
@@ -68,7 +60,6 @@ export const ResourceCategoryUpdate: React.FC<PropInterface> = ({
});
form.setFieldsValue({
name: data.name,
sort: data.sort,
parent_id: new_arr,
});
setParentId(data.parent_id);
@@ -97,7 +88,7 @@ export const ResourceCategoryUpdate: React.FC<PropInterface> = ({
const onFinish = (values: any) => {
resourceCategory
.updateResourceCategory(id, values.name, parent_id || 0, values.sort)
.updateResourceCategory(id, values.name, parent_id || 0, 0)
.then((res: any) => {
message.success("保存成功!");
onCancel();
@@ -122,13 +113,21 @@ export const ResourceCategoryUpdate: React.FC<PropInterface> = ({
};
const displayRender = (label: any, selectedOptions: any) => {
if (selectedOptions && selectedOptions[0]) {
let current = selectedOptions[selectedOptions.length - 1].value;
if (current === id) {
message.error("不能选择自己作为父类");
return "无";
}
}
return label[label.length - 1];
};
return (
<>
<Modal
title="新建分类"
title="编辑分类"
centered
forceRender
open={open}

View File

@@ -1,10 +1,9 @@
import React, { useState, useEffect } from "react";
import { Button, Space, Tree, Modal, message } from "antd";
import type { ColumnsType } from "antd/es/table";
import styles from "./index.module.less";
import { PlusOutlined, ExclamationCircleFilled } from "@ant-design/icons";
import { resourceCategory } from "../../../api/index";
import { Link, useNavigate } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import { PerButton } from "../../../compenents";
import type { DataNode, TreeProps } from "antd/es/tree";
import { ResourceCategoryCreate } from "./compenents/create";