|
@@ -1,6 +1,8 @@
|
|
-import React from 'react';
|
|
|
|
-import { Col, Form, Input, message, Modal, Row } from 'antd';
|
|
|
|
|
|
+import React, { useEffect, useState } from 'react';
|
|
|
|
+import { Col, Form, Input, InputNumber, message, Modal, Row, Table } from 'antd';
|
|
|
|
+import type { ColumnsType } from 'antd/es/table';
|
|
import { createRole, editRole } from '@/services/role';
|
|
import { createRole, editRole } from '@/services/role';
|
|
|
|
+import { queryMenu } from '@/services/menu';
|
|
|
|
|
|
const { TextArea } = Input;
|
|
const { TextArea } = Input;
|
|
|
|
|
|
@@ -10,6 +12,13 @@ interface editPros {
|
|
params: any;
|
|
params: any;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+interface DataType {
|
|
|
|
+ key: React.Key;
|
|
|
|
+ name: string;
|
|
|
|
+ router: string;
|
|
|
|
+ record_id: string;
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 角色管理 - 编辑
|
|
* 角色管理 - 编辑
|
|
* @param props
|
|
* @param props
|
|
@@ -17,39 +26,77 @@ interface editPros {
|
|
*/
|
|
*/
|
|
const Edit: React.FC<editPros> = (props) => {
|
|
const Edit: React.FC<editPros> = (props) => {
|
|
const { params, visible, editCallback } = props;
|
|
const { params, visible, editCallback } = props;
|
|
|
|
+ const [menuList, setMenuList] = useState([]);
|
|
|
|
+ const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
|
const [form] = Form.useForm();
|
|
const [form] = Form.useForm();
|
|
|
|
|
|
|
|
+ // 菜单列表数据
|
|
|
|
+ const getMenuList = () => {
|
|
|
|
+ const data: any = {
|
|
|
|
+ q: 'tree',
|
|
|
|
+ query_all: 1,
|
|
|
|
+ };
|
|
|
|
+ queryMenu(data).then((res) => {
|
|
|
|
+ if (res && res.code === 0) {
|
|
|
|
+ setMenuList(res.data.list);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // 初始化
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ getMenuList();
|
|
|
|
+ // 获取被选中菜单的id
|
|
|
|
+ if (params) {
|
|
|
|
+ const arr: any = [];
|
|
|
|
+ params?.menus?.forEach((item: { menu_id: any }) => {
|
|
|
|
+ arr.push(item.menu_id);
|
|
|
|
+ });
|
|
|
|
+ setSelectedRowKeys(arr);
|
|
|
|
+ }
|
|
|
|
+ }, []);
|
|
|
|
+
|
|
|
|
+ // 提交
|
|
const onOk = () => {
|
|
const onOk = () => {
|
|
form.validateFields().then((values) => {
|
|
form.validateFields().then((values) => {
|
|
if (values) {
|
|
if (values) {
|
|
- const data = { ...values };
|
|
|
|
- if (params) {
|
|
|
|
- data.record_id = params.record_id;
|
|
|
|
- editRole(data)
|
|
|
|
- .then((res) => {
|
|
|
|
- if (res && res.code === 0) {
|
|
|
|
- message.success('编辑成功');
|
|
|
|
- editCallback();
|
|
|
|
- } else {
|
|
|
|
- message.error('编辑失败');
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- .catch((e) => {
|
|
|
|
- message.error(e?.message);
|
|
|
|
- });
|
|
|
|
|
|
+ if (selectedRowKeys && selectedRowKeys.length) {
|
|
|
|
+ const data = { ...values };
|
|
|
|
+ const arr: { menu_id: any }[] = [];
|
|
|
|
+ selectedRowKeys.forEach((res: any) => {
|
|
|
|
+ arr.push({ menu_id: res });
|
|
|
|
+ });
|
|
|
|
+ data.menus = arr;
|
|
|
|
+ if (params) {
|
|
|
|
+ data.record_id = params.record_id;
|
|
|
|
+ editRole(data)
|
|
|
|
+ .then((res) => {
|
|
|
|
+ if (res && res.code === 0) {
|
|
|
|
+ message.success('编辑成功');
|
|
|
|
+ editCallback();
|
|
|
|
+ } else {
|
|
|
|
+ message.error('编辑失败');
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch((e) => {
|
|
|
|
+ message.error(e?.message);
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ createRole(data)
|
|
|
|
+ .then((res) => {
|
|
|
|
+ if (res && res.code === 0) {
|
|
|
|
+ message.success('新增成功');
|
|
|
|
+ editCallback();
|
|
|
|
+ } else {
|
|
|
|
+ message.error('新增失败');
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch((e) => {
|
|
|
|
+ message.error(e?.message);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- createRole(data)
|
|
|
|
- .then((res) => {
|
|
|
|
- if (res && res.code === 0) {
|
|
|
|
- message.success('新增成功');
|
|
|
|
- editCallback();
|
|
|
|
- } else {
|
|
|
|
- message.error('新增失败');
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- .catch((e) => {
|
|
|
|
- message.error(e?.message);
|
|
|
|
- });
|
|
|
|
|
|
+ message.error('请选择菜单权限');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -60,6 +107,10 @@ const Edit: React.FC<editPros> = (props) => {
|
|
editCallback();
|
|
editCallback();
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ const handleTableSelectRow = (keys: any) => {
|
|
|
|
+ setSelectedRowKeys(keys);
|
|
|
|
+ };
|
|
|
|
+
|
|
const formItemLayout = {
|
|
const formItemLayout = {
|
|
labelCol: {
|
|
labelCol: {
|
|
span: 6,
|
|
span: 6,
|
|
@@ -73,6 +124,23 @@ const Edit: React.FC<editPros> = (props) => {
|
|
wrapperCol: { span: 21 },
|
|
wrapperCol: { span: 21 },
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ const columns: ColumnsType<DataType> = [
|
|
|
|
+ {
|
|
|
|
+ title: '序号',
|
|
|
|
+ align: 'center',
|
|
|
|
+ key: 'index',
|
|
|
|
+ render: (_: any, row: any, index: number) => index + 1,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '菜单名称',
|
|
|
|
+ dataIndex: 'name',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '访问路由',
|
|
|
|
+ dataIndex: 'router',
|
|
|
|
+ },
|
|
|
|
+ ];
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<Modal
|
|
<Modal
|
|
title={`${params ? '编辑' : '新增'}`}
|
|
title={`${params ? '编辑' : '新增'}`}
|
|
@@ -102,7 +170,7 @@ const Edit: React.FC<editPros> = (props) => {
|
|
rules={[{ required: true, message: '请输入排序值' }]}
|
|
rules={[{ required: true, message: '请输入排序值' }]}
|
|
initialValue={params?.sequence}
|
|
initialValue={params?.sequence}
|
|
>
|
|
>
|
|
- <Input placeholder="请输入排序值" />
|
|
|
|
|
|
+ <InputNumber placeholder="请输入排序值" style={{ width: '100%' }} />
|
|
</Form.Item>
|
|
</Form.Item>
|
|
</Col>
|
|
</Col>
|
|
<Col span={24}>
|
|
<Col span={24}>
|
|
@@ -117,6 +185,15 @@ const Edit: React.FC<editPros> = (props) => {
|
|
</Form.Item>
|
|
</Form.Item>
|
|
</Col>
|
|
</Col>
|
|
</Row>
|
|
</Row>
|
|
|
|
+ <Table
|
|
|
|
+ rowSelection={{
|
|
|
|
+ selectedRowKeys: selectedRowKeys,
|
|
|
|
+ onChange: handleTableSelectRow,
|
|
|
|
+ }}
|
|
|
|
+ columns={columns}
|
|
|
|
+ rowKey={(record) => record.record_id}
|
|
|
|
+ dataSource={menuList}
|
|
|
|
+ />
|
|
</Form>
|
|
</Form>
|
|
</Modal>
|
|
</Modal>
|
|
);
|
|
);
|