Skip to content

Commit

Permalink
add: user info
Browse files Browse the repository at this point in the history
  • Loading branch information
zrll12 committed Nov 14, 2023
1 parent 5306bf3 commit aa1acf6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
4 changes: 1 addition & 3 deletions app/authenticate/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
})

Expand Down
52 changes: 30 additions & 22 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="space-y-5">
<Card className="max-w-4xl">
Expand All @@ -54,9 +62,8 @@ export default function Page() {

<div>
<Progress style={{width: 400}} label={"方案剩余时间"} value={timeLeft} className="max-w-md"
maxValue={timeTotal}
formatOptions={{style: "percent"}} isStriped color="secondary"/>
{timeLeft} 天 / {timeTotal}
{timeDescription}
</div>
</CardBody>
<Divider/>
Expand All @@ -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(() => {
});
}}></Uploader>

<Button className="bg-gradient-to-tr from-pink-500 to-yellow-500 text-white" onClick={() => {
Expand Down
5 changes: 5 additions & 0 deletions interface/userAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import cookie from "react-cookies";
import {SERVER_URL} from "@/interface/api";
import {UserModel} from "@/interface/model/user";
import {Message} from "@/components/message";
import {SetLoggedInState} from "@/interface/hooks";

export class UserAPI {
static async checkEmail(email: string): Promise<boolean> {
Expand Down Expand Up @@ -82,6 +83,7 @@ export class UserAPI {
} catch (e) {
Message.error("登录错误:" + e + ", " + text);
cookie.remove("token");
SetLoggedInState(false);
return undefined;
}
}
Expand Down Expand Up @@ -111,6 +113,9 @@ export class UserAPI {

return [response.ok, await response!.text()];
} catch (e) {
Message.error("登录错误:" + e);
cookie.remove("token");
SetLoggedInState(false);
return [false, "登录错误:" + e];
}
}
Expand Down

0 comments on commit aa1acf6

Please sign in to comment.