"use client"; import React, { useState, useEffect } from "react"; import { Input, Button, Toast } from "antd-mobile"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleLeft } from "@fortawesome/free-solid-svg-icons"; import { useRouter } from "next/navigation"; import { getUserInfo } from "@/api/public"; import { get, save } from "@/utils/storeInfo"; import requireAPI from "@/utils/requireAPI"; import { utf8Length } from "@/utils/tools"; export default function EditUserName() { const router = useRouter(); const [name, setName] = useState(); const account = get("account"); useEffect(() => { const getName = async () => { setName(account.name); }; getName(); }, []); const handleSubmit = async () => { if (!name) { Toast.show({ icon: "fail", content: "昵称不得为空", position: "top", }); return; } else if (utf8Length(name) > 10) { Toast.show({ icon: "fail", content: "昵称过长", position: "top", }); return; } else if (name === account.name) { router.back(); return; } try { const data = await requireAPI( "POST", "/api/account/update", { body: { name: name, }, }, true ); if (data.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } //向服务器请求新的账号信息并保存到本地 const account = await getUserInfo(); save("account", JSON.stringify(account)); } catch (error) { // console.error(error); } router.back(); }; return (
{ router.back(); }} />

修改资料

{/* 内容 */}
setName(value)} value={name} style={{ "--placeholder-color": "#FFFFFF80", "--font-size": "16px", }} />
); }