From aa1acf685d15b9d3810f26bb8f882960d0522b7d Mon Sep 17 00:00:00 2001 From: zrll_ Date: Tue, 14 Nov 2023 15:44:35 +0800 Subject: [PATCH] add: user info --- app/authenticate/page.tsx | 4 +-- app/dashboard/page.tsx | 52 ++++++++++++++++++++++----------------- interface/userAPI.ts | 5 ++++ 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/app/authenticate/page.tsx b/app/authenticate/page.tsx index 61c7b5f..cdf5385 100644 --- a/app/authenticate/page.tsx +++ b/app/authenticate/page.tsx @@ -34,9 +34,7 @@ export default function Page() { if (state) { let userModel: UserModel = JSON.parse(user); Message.message("欢迎回来, " + userModel.username); - // setTimeout(() => { - router.push("/dashboard"); - // }, 1000); + router.push("/dashboard"); } }) diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index 0dc5d90..d0f17c2 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -17,30 +17,38 @@ export default function Page() { let [used, setUsed] = useState(0); let [total, setTotal] = useState(1); - let [timeLeft, setTimeLift] = useState(0); - let [timeTotal, setTimeTotal] = useState(1); + let [timeLeft, setTimeLeft] = useState(100); + let [timeDescription, setTimeDescription] = useState("无限时间"); - UserAPI.getExtendedInformation().then((r) => { - if (r == undefined) { - router.push("/authenticate"); - } - let user = r!; - let price = getGroupPrice(r!.extend!.userGroup); - setUsed(Number((user.extend!.storageUsed / 1024 / 1024).toFixed(2))); - setTotal(Number(price.allSpace.substring(0, price.allSpace.length - 3)) * 1024); - if (user.extend!.groupStartDate != undefined || user.extend!.groupEndDate != undefined) { - let startDate = new Date(user.extend!.groupStartDate!); - let endDate = new Date(user.extend!.groupEndDate!); - console.log(startDate); - console.log(endDate); - } - }) - PictureAPI.getPicturesList().then(); + if (used == 0 && total == 1) { + UserAPI.getExtendedInformation().then((r) => { + if (r == undefined) { + router.push("/authenticate"); + } + let user = r!; + let price = getGroupPrice(r!.extend!.userGroup); - let router = useRouter(); + setUsed(Number((user.extend!.storageUsed / 1024 / 1024).toFixed(2))); + setTotal(Number(price.allSpace.substring(0, price.allSpace.length - 3)) * 1024); + if (user.extend!.groupStartDate != undefined || user.extend!.groupEndDate != undefined) { + if (user.extend!.groupStartDate != 0 && user.extend!.groupEndDate != 0) { + let startDate = user.extend!.groupStartDate!; + let endDate = user.extend!.groupEndDate!; + let now = new Date().getTime() / 1000; + let validDate = new Date(endDate * 1000); + + setTimeLeft(100 - (now - startDate) / (endDate - startDate) * 100); + setTimeDescription(validDate.toLocaleDateString() + " 过期"); + } + } + }) + PictureAPI.getPicturesList().then(); + } + let router = useRouter(); + return (
@@ -54,9 +62,8 @@ export default function Page() {
- {timeLeft} 天 / {timeTotal} 天 + {timeDescription}
@@ -70,7 +77,8 @@ export default function Page() { } onChange={(e) => { let files = e.target.files!; let file = files[0]; - PictureAPI.uploadFile(file).then(() => {}); + PictureAPI.uploadFile(file).then(() => { + }); }}>