import { useState, useEffect } from "react"; import styles from "./user.module.scss"; import EditIcon from "../icons/edit.svg"; import { List, ListItem, Modal, Popover, showModal, showToast } from "./ui-lib"; import { IconButton } from "./button"; import { useAccessStore, useAppConfig, } from "../store"; import Locale from "../locales"; import { Path } from "../constant"; import { ErrorBoundary } from "./error"; import { useNavigate } from "react-router-dom"; import { Avatar, AvatarPicker } from "./emoji"; import { useUserStore } from "../store/user"; import { encrypt } from "../rsaEncrypt"; function UserPwdModal(props: { onClose?: () => void }) { const useStor = useUserStore() const [oldPwd, setOldPwd] = useState(''); const [newPwd, setNewPwd] = useState(''); const [newPwd1, setNewPwd1] = useState(''); async function updatePass():Promise{ if(newPwd!=newPwd1){ showToast("两次输入的新密码不一致!") return false } if(oldPwd==newPwd1||oldPwd==newPwd){ showToast("新密码与旧密码一致!") return false } await useStor.updatePass(String(encrypt(oldPwd)),String(encrypt(newPwd))) } return (
props.onClose?.()} actions={[ } onClick={()=>{ updatePass().then(()=>{ props.onClose?.() }) }} bordered text={Locale.User.Save} />, ]} >
{setOldPwd(e.currentTarget.value)}} > {setNewPwd(e.currentTarget.value)}} > {setNewPwd1(e.currentTarget.value)}} >
); } export function User() { const navigate = useNavigate(); const [showEmojiPicker, setShowEmojiPicker] = useState(false); const [shouldShowPwdModal, setShowPwdModal] = useState(false); const config = useAppConfig(); const updateConfig = config.update; const accessStore = useAccessStore(); const useStor = useUserStore() const [userName, setUserName] = useState(""); const [kami, setKami] = useState(""); const onUserName = (text: string) => { setUserName(text) useStor.updateName(userName) }; function getVip(){ const curDate = new Date(); const paramDate = new Date(useStor.vip_time.replace(/-/g, "/")); console.log(paramDate); if (curDate >= paramDate) { return true; } return false; } function getVipTime(){ let time = String(new Date()); if(useStor.vip_time!=null || useStor.vip_time!=''){ console.log(useStor.vip_time) time=useStor.vip_time } const date = new Date(time) const Y = date.getFullYear() const M = date.getMonth() + 1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1 const D = date.getDate() return `${Y} - ${M} - ${D}` } useEffect(()=>{ if(accessStore.auth){ useStor.getUserInfo() } setUserName(useStor.name) },[useStor,accessStore]) useEffect(() => { const keydownEvent = (e: KeyboardEvent) => { if (e.key === "Escape") { navigate(Path.Home); } }; document.addEventListener("keydown", keydownEvent); return () => { document.removeEventListener("keydown", keydownEvent); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return (
{Locale.User.Title}
{Locale.User.SubTitle}
setShowEmojiPicker(false)} content={ { updateConfig((config) => (config.avatar = avatar)); setShowEmojiPicker(false); }} /> } open={showEmojiPicker} >
setShowEmojiPicker(true)} >
{onUserName(e.currentTarget.value)}} onChange={(e)=>{setUserName(e.currentTarget.value)}} > {useStor.mail}
剩余积分:{useStor.wallet}
{getVip()?"非会员":"会员"}
{getVipTime()}
{setKami(e.currentTarget.value)}}> { useStor.useKami(kami) setKami("") }} />
{ window.location.href="https://qtka.scgzfw.cn/links/879AEC7D" }} /> { useStor.userSig() }} /> { setShowPwdModal(true) }} />
{ window.location.href="https://pd.qq.com/s/e1veynn5h" }} /> { useStor.logOut().then(()=>{ accessStore.updateAuth("") setUserName("") }) showToast("登出成功!") }} /> {shouldShowPwdModal && ( setShowPwdModal(false)} /> )}
); }