tiefen_space_h5/app/my/editUserProfile/selectUserProfileItem/page.js

163 lines
4.8 KiB
JavaScript
Raw Normal View History

2024-07-02 23:08:38 +08:00
"use client";
2024-07-10 00:48:37 +08:00
import React, { useEffect, useState } from "react";
2024-07-10 16:50:53 +08:00
import { Avatar, Divider, Toast } from "antd-mobile";
2024-07-02 23:08:38 +08:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleLeft, faAngleRight } from "@fortawesome/free-solid-svg-icons";
import { useRouter } from "next/navigation";
2024-07-10 00:48:37 +08:00
import { get, save } from "@/utils/storeInfo";
import { uploadImage } from "@/utils/upload";
import { getUserInfo } from "@/api/public";
2024-07-22 16:07:41 +08:00
import requireAPI from "@/utils/requireAPI";
2024-07-02 23:08:38 +08:00
export default function SelectUserProfileItem() {
const router = useRouter();
2024-07-10 00:48:37 +08:00
const [userInfo, setUserInfo] = useState({});
useEffect(() => {
const userInfo = get("account");
if (setUserInfo) {
setUserInfo(userInfo);
}
}, []);
2024-07-10 16:50:53 +08:00
const uploadHead = async (e) => {
const avatarId = await uploadImage(e.target.files[0]);
2024-07-10 00:48:37 +08:00
try {
2024-07-22 16:07:41 +08:00
const data = await requireAPI("POST", "/api/account/update", {
2024-07-10 00:48:37 +08:00
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);
}
};
2024-07-02 23:08:38 +08:00
return (
<div>
<div className="p-4 fixed top-0 z-10 w-full">
<div className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full absolute">
<FontAwesomeIcon
icon={faAngleLeft}
size="xl"
onClick={() => {
router.back();
}}
/>
</div>
<p className="text-base text-center leading-9">修改资料</p>
</div>
{/* 内容 */}
<div className="pt-16 px-4">
<div className="flex justify-between items-center mt-2">
<span className="text-base font-medium">头像</span>
2024-07-10 00:48:37 +08:00
{/* <CustomUploadButton img={userInfo?.avatar?.images[0]?.urls[0]} /> */}
<label htmlFor="uploadAvatarBtn">
<div
className="flex items-center"
// onClick={() => setMediaPickerModalVisible(!mediaPickerModalVisible)}
>
<Avatar
src={userInfo?.avatar?.images[0]?.urls[0]}
style={{ "--border-radius": "50px", "--size": "2rem" }}
/>
<FontAwesomeIcon
icon={faAngleRight}
size="xl"
className=" ml-2"
/>
</div>
</label>
<input
type="file"
id="uploadAvatarBtn"
style={{ display: "none" }}
accept="image/png, image/jpeg"
2024-07-31 20:05:17 +08:00
// capture="camera"
2024-07-10 16:50:53 +08:00
onChange={uploadHead}
2024-07-10 00:48:37 +08:00
/>
2024-07-02 23:08:38 +08:00
</div>
<Divider className="my-2" />
<div
className="flex justify-between items-center mt-2"
onClick={() => {
router.push("/my/editUserProfile/editUserName");
}}
>
<span className="text-base font-medium">昵称</span>
<div>
2024-07-10 00:48:37 +08:00
<span className="text-base font-medium">{userInfo?.name}</span>
2024-07-02 23:08:38 +08:00
<FontAwesomeIcon
icon={faAngleRight}
size="xl"
className=" ml-2"
onClick={() => {
router.push("my/editUserProfile/editUserName");
}}
/>
</div>
</div>
<Divider className="my-2" />
<div className="flex justify-between items-center mt-2">
<span className="text-base font-medium">ID</span>
<span className="text-base text-[#FFFFFF80] font-medium">
2024-07-10 00:48:37 +08:00
{userInfo?.user_id}
2024-07-02 23:08:38 +08:00
</span>
</div>
<Divider className="my-2" />
</div>
</div>
);
}
2024-07-10 00:48:37 +08:00
// const CustomUploadButton = ({ img }) => {
// const [fileList, setFileList] = useState([
// {
// url: img,
// },
// ]);
// const uploadImg = async (file) => {
// console.log(file);
// return {
// url: URL.createObjectURL(file),
// };
// };
// return (
// <ImageUploader
// value={fileList}
// onChange={setFileList}
// upload={uploadImg}
// maxCount={1}
// preview={false}
// deletable={false}
// style={{ "--cell-size": "50px" }}
// >
// <div
// style={{
// width: 50,
// height: 50,
// borderRadius: 40,
// backgroundColor: "#f5f5f5",
// display: "flex",
// justifyContent: "center",
// alignItems: "center",
// color: "#999999",
// }}
// >
// <Avatar
// src={img}
// style={{ "--border-radius": "50px", "--size": "2rem" }}
// />
// </div>
// </ImageUploader>
// );
// };