mirror of
https://github.com/PlayEdu/backend
synced 2025-12-23 07:09:27 +08:00
部门新建、编辑弹窗组件化
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user