import { doFetch } from "@/utils/doFetch"; import { ProDescriptions } from "@ant-design/pro-components"; import CheckIcon from "@mui/icons-material/Check"; import CloseIcon from "@mui/icons-material/Close"; import EditIcon from "@mui/icons-material/Edit"; import EmailIcon from "@mui/icons-material/Email"; import PhoneIcon from "@mui/icons-material/Phone"; import PriorityHighIcon from "@mui/icons-material/PriorityHigh"; import { Box, Card, Container, Stack, Tooltip, Typography, } from "@mui/material"; import IconButton from "@mui/material/IconButton"; import { useModel } from "@umijs/max"; import * as Antd from "antd"; import { useState } from "react"; import Fade from "react-reveal/Fade"; import Head from "./head"; import "./index.less"; const { Col, Row, Input } = Antd; function isValidChinesePhoneNumber(phoneNumber) { const regEx = /^1[3-9]\d{9}$/; return regEx.test(phoneNumber); } function isChinaEmail(email) { const regExp = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; return regExp.test(email); } function Usercenter() { const { initialState: { fetchUserInfo, currentUser }, setInitialState, } = useModel("@@initialState"); const dofetchUserInfo = async () => { const userInfo = await fetchUserInfo(); if (userInfo) { await setInitialState((s) => { return { ...s, currentUser: userInfo }; }); } }; const [edit, setedit] = useState(false); const [telephone, settelephone] = useState(currentUser?.telephone); const [email, setemail] = useState(currentUser?.email); return ( 个人信息 支持的格式 *.jpeg, *.jpg, *.png, *.gif
文件不大于 2 MB
<> {currentUser?.telephone || "未填写手机号"} {currentUser?.email || "未填写邮箱"}
<> } value={telephone} onChange={(e) => { settelephone(e.target.value); }} > } value={email} onChange={(e) => { setemail(e.target.value); }} style={{ marginTop: 12 }} >
{ setedit(true); settelephone(currentUser?.telephone); setemail(currentUser?.email); }} >
{ setedit(false); }} sx={{ backgroundColor: "rgba(0,0,0,0.05)" }} > { let res = await doFetch({ url: "/user/updateTelephoneAndEmail", params: { telephone, email }, }); if (res?.code === "0000") { setedit(false); await dofetchUserInfo(); } }} > {isValidChinesePhoneNumber(telephone) && isChinaEmail(email) ? ( ) : ( )}
); } export default Usercenter;