"use client"; import React, { useEffect, useState } from "react"; import { Avatar, Divider, Input } from "antd-mobile"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleLeft, faAngleRight } from "@fortawesome/free-solid-svg-icons"; import { useRouter } from "next/navigation"; import { get, save } from "@/utils/storeInfo"; import { uploadImage } from "@/utils/upload"; import { getUserInfo } from "@/api/public"; import require from "@/utils/require"; export default function SelectUserProfileItem() { const router = useRouter(); const [userInfo, setUserInfo] = useState({}); useEffect(() => { const userInfo = get("account"); if (setUserInfo) { setUserInfo(userInfo); } }, []); const uploadImg = async (e) => { console.log(e.target.files[0]); const file = e.target.files[0]; var reader = new FileReader(); reader.readAsDataURL(file); if (file) { reader.onload = (e) => { uploadHead(); }; } // return { // url: URL.createObjectURL(file), // }; }; const uploadHead = async () => { const avatarId = await uploadImage(userInfo?.avatar?.images[0]?.urls[0]); try { const data = await require("POST", "/api/account/update", { body: { avatar: { image_ids: [avatarId] } }, }, true); if (data.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } //向服务器请求新的账号信息并保存到本地 const account = await getUserInfo(); save("account", JSON.stringify(account)); setUserInfo(account); } catch (error) { console.error(error); } }; return (
修改资料