#
luxiaotao1123
2024-02-20 7af31594ce22ef04c53f187d29aee949b1332b6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import React, { useState, useRef, useEffect, useMemo } from 'react';
import {
    ProForm,
    ProFormDigit,
    ProFormText,
    ProFormSelect,
    ProFormDateTimePicker,
    ProFormTreeSelect
} from '@ant-design/pro-components';
import { Form, Modal } from 'antd';
import moment from 'moment';
import Http from '@/utils/http';
 
const Edit = (props) => {
    const [menuType, setMenuType] = useState(0);
    const [form] = Form.useForm();
    const { } = props;
 
    useEffect(() => {
        form.resetFields();
        form.setFieldsValue({
            ...props.values
        })
    }, [form, props])
 
    const handleCancel = () => {
        props.onCancel();
    };
 
    const handleOk = () => {
        form.submit();
    }
 
    const handleFinish = async (values) => {
        props.onSubmit({ ...values });
    }
 
    return (
        <>
            <Modal
                title="Edit"
                width={640}
                forceRender
                destroyOnClose
                open={props.open}
                onCancel={handleCancel}
                onOk={handleOk}
            >
                <ProForm
                    form={form}
                    submitter={false}
                    onFinish={handleFinish}
                    layout="horizontal"
                    grid={true}
                >
                    <ProFormDigit
                        name="id"
                        disabled
                        hidden={true}
                    />
                    <ProForm.Group>
                        <ProFormTreeSelect
                            name="parentId"
                            label="上级菜单"
                            params={props.treeData}
                            request={async () => {
                                return props.treeData;
                            }}
                            colProps={{ md: 12, xl: 12 }}
                            placeholder="请选择"
                            rules={[{ required: true, message: "上级菜单不能为空" }]}
                            fieldProps={{
                                defaultValue: 0,
                                treeDefaultExpandedKeys: [0]
                            }}
                        />
                        <ProFormText
                            name="name"
                            label="名称"
                            colProps={{ md: 12, xl: 12 }}
                            placeholder="请输入"
                            rules={[{ required: true, message: "名称不能为空!" }]}
                        />
                    </ProForm.Group>
                    <ProForm.Group>
                        <ProFormText
                            name="route"
                            label="路由地址"
                            colProps={{ md: 12, xl: 12 }}
                            placeholder="请输入"
                        />
                        <ProFormText
                            name="component"
                            label="页面组件"
                            colProps={{ md: 12, xl: 12 }}
                            placeholder="请输入"
                        />
                    </ProForm.Group>
                    <ProForm.Group>
                        <ProFormSelect
                            name="type"
                            label="类型"
                            colProps={{ md: 12, xl: 12 }}
                            placeholder="请选择"
                            options={[
                                { label: '菜单', value: 0 },
                                { label: '按钮', value: 1 },
                            ]}
                            fieldProps={{
                                defaultValue: 0,
                                onChange: (e) => {
                                    setMenuType(e);
                                },
                            }}
                            rules={[{ required: true, message: "类型不能为空!" }]}
                        />
                        <ProFormText
                            name="authority"
                            label="权限标识"
                            hidden={menuType !== 1}
                            colProps={{ md: 12, xl: 12 }}
                            placeholder="请输入"
                        />
                        <ProFormText
                            name="icon"
                            label="菜单图标"
                            hidden={menuType !== 0}
                            colProps={{ md: 12, xl: 12 }}
                            placeholder="请输入"
                        />
                    </ProForm.Group>
                    <ProForm.Group>
                        <ProFormDigit
                            name="sort"
                            label="排序"
                            colProps={{ md: 12, xl: 12 }}
                            fieldProps={{ precision: 0 }}
                            placeholder="请输入"
                        />
                        <ProFormSelect
                            name="status"
                            label="状态"
                            colProps={{ md: 12, xl: 12 }}
                            placeholder="请选择"
                            options={[
                                { label: '正常', value: 1 },
                                { label: '禁用', value: 0 },
                            ]}
                        />
                    </ProForm.Group>
                </ProForm>
            </Modal>
        </>
    )
}
 
export default Edit;