import { getUserInfoByIdAPI, userSaveAPI } from '@/store/action/Z1user' import { SaveUserType } from '@/types' import { MessageFu } from '@/utils/message' import { Button, Form, FormInstance, Input, Modal, Select } from 'antd' import React, { useCallback, useEffect, useRef } from 'react' import styles from './index.module.scss' import MyPopconfirm from '@/components/MyPopconfirm' type Props = { id: any closePage: () => void upTableList: () => void addTableList: () => void } function UserAdd({ id, closePage, upTableList, addTableList }: Props) { // 设置表单初始数据(区分编辑和新增) const FormBoxRef = useRef(null) const getInfoInAPIFu = useCallback(async (id: number) => { const res = await getUserInfoByIdAPI(id) FormBoxRef.current?.setFieldsValue(res.data) // console.log("是编辑,在这里发请求拿数据", res); }, []) // 没有通过校验 const onFinishFailed = useCallback(() => { // return MessageFu.warning("有表单不符号规则!"); }, []) useEffect(() => { if (id) getInfoInAPIFu(id) else { FormBoxRef.current?.setFieldsValue({}) } }, [getInfoInAPIFu, id]) // 通过校验点击确定 const onFinish = useCallback( async (values: any) => { const obj: SaveUserType = { ...values, id: id ? id : null } const res: any = await userSaveAPI(obj) if (res.code === 0) { MessageFu.success(id ? '编辑成功!' : '新增成功!') if (id) upTableList() else addTableList() closePage() } // console.log("通过校验,点击确定"); }, [addTableList, closePage, id, upTableList] ) return (
e.target.value.replace(/\s+/g, '')} > e.target.value.replace(/\s+/g, '')} >