|
@@ -1,5 +1,9 @@
|
|
|
-import { Button, Form, Input, Modal, Popconfirm, Select } from "antd";
|
|
|
+import { RootState } from "@/store";
|
|
|
+import { getUserInfoByIdAPI, userSaveAPI } from "@/store/action/user";
|
|
|
+import { SaveUserType } from "@/types";
|
|
|
+import { Button, Form, Input, message, Modal, Popconfirm, Select } from "antd";
|
|
|
import React, { useCallback, useEffect, useRef } from "react";
|
|
|
+import { useSelector } from "react-redux";
|
|
|
import "./index.css";
|
|
|
|
|
|
type Props = {
|
|
@@ -14,7 +18,9 @@ function UserAdd({ id, closePage, upTableList, addTableList }: Props) {
|
|
|
const FormBoxRef = useRef<any>({});
|
|
|
|
|
|
const getInfoInAPIFu = useCallback(async (id: number) => {
|
|
|
- console.log("是编辑,在这里发请求拿数据");
|
|
|
+ const res =await getUserInfoByIdAPI(id)
|
|
|
+ FormBoxRef.current.setFieldsValue(res.data)
|
|
|
+ console.log("是编辑,在这里发请求拿数据",res);
|
|
|
}, []);
|
|
|
|
|
|
// 没有通过校验
|
|
@@ -29,17 +35,32 @@ function UserAdd({ id, closePage, upTableList, addTableList }: Props) {
|
|
|
}
|
|
|
}, [getInfoInAPIFu, id]);
|
|
|
|
|
|
+ // 从仓库获取角色下拉列表信息
|
|
|
+ const roleList = useSelector(
|
|
|
+ (state: RootState) => state.userReducer.roleList
|
|
|
+ );
|
|
|
+
|
|
|
// 通过校验点击确定
|
|
|
- const onFinish = useCallback(async (values: any) => {
|
|
|
- // if (res.code === 0) {
|
|
|
- // message.success(id ? "编辑成功!" : "新增成功!");
|
|
|
- // if (id) upTableList();
|
|
|
- // else addTableList();
|
|
|
-
|
|
|
- // closePage();
|
|
|
- // }
|
|
|
- console.log("通过校验,点击确定");
|
|
|
- }, []);
|
|
|
+ const onFinish = useCallback(
|
|
|
+ async (values: any) => {
|
|
|
+ const obj: SaveUserType = {
|
|
|
+ ...values,
|
|
|
+ id: id ? id : null,
|
|
|
+ };
|
|
|
+
|
|
|
+ const res: any = await userSaveAPI(obj);
|
|
|
+
|
|
|
+ if (res.code === 0) {
|
|
|
+ message.success(id ? "编辑成功!" : "新增成功!");
|
|
|
+ if (id) upTableList();
|
|
|
+ else addTableList();
|
|
|
+
|
|
|
+ closePage();
|
|
|
+ }
|
|
|
+ console.log("通过校验,点击确定");
|
|
|
+ },
|
|
|
+ [addTableList, closePage, id, upTableList]
|
|
|
+ );
|
|
|
|
|
|
return (
|
|
|
<Modal
|
|
@@ -66,7 +87,7 @@ function UserAdd({ id, closePage, upTableList, addTableList }: Props) {
|
|
|
rules={[{ required: true, message: "请输入账号名!" }]}
|
|
|
getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
>
|
|
|
- <Input maxLength={15} showCount placeholder="请输入内容" />
|
|
|
+ <Input disabled={id} maxLength={15} showCount placeholder="请输入内容" />
|
|
|
</Form.Item>
|
|
|
|
|
|
<Form.Item
|
|
@@ -83,13 +104,7 @@ function UserAdd({ id, closePage, upTableList, addTableList }: Props) {
|
|
|
name="roleId"
|
|
|
rules={[{ required: true, message: "请选择角色!" }]}
|
|
|
>
|
|
|
- <Select
|
|
|
- placeholder="请选择"
|
|
|
- options={[
|
|
|
- { label: 0, value: "1xx" },
|
|
|
- { label: 1, value: "2xx" },
|
|
|
- ]}
|
|
|
- />
|
|
|
+ <Select placeholder="请选择" options={roleList} />
|
|
|
</Form.Item>
|
|
|
|
|
|
<Form.Item
|
|
@@ -101,7 +116,7 @@ function UserAdd({ id, closePage, upTableList, addTableList }: Props) {
|
|
|
<Input maxLength={8} showCount placeholder="请输入内容" />
|
|
|
</Form.Item>
|
|
|
|
|
|
- <div className="passTit">* 默认密码 123456</div>
|
|
|
+ {id ? null : <div className="passTit">* 默认密码 123456</div>}
|
|
|
|
|
|
{/* 确定和取消按钮 */}
|
|
|
<br />
|