feat: 增加接口验证
parent
a856a66bc2
commit
f92a1a3491
|
|
@ -1,3 +1,5 @@
|
|||
import { useUserStore } from "@/store/user";
|
||||
|
||||
/*
|
||||
* @Author: HideInMatrix
|
||||
* @Date: 2024-07-15
|
||||
|
|
@ -26,8 +28,11 @@ const apiClient = (method: HttpMethod) => {
|
|||
data?: unknown,
|
||||
options: FetchOptions = {}
|
||||
): Promise<ApiResponse> => {
|
||||
const userStore = useUserStore();
|
||||
const accessToken = userStore.getAccessToken
|
||||
const config: FetchOptions = {
|
||||
method,
|
||||
headers:{ Authorization: `Bearer ${accessToken}`},
|
||||
...options,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
<template>
|
||||
<div class="login-bg">
|
||||
<SvgComponent :content="titleSvg" class="h-[156px] mt-[141px]" />
|
||||
|
||||
<div class="flex items-center justify-end mt-[17px] mr-[24px]">
|
||||
<div class="text-[#45A2FF] text-[14px]">{{ year }}-{{ month }}-{{ day }} {{ weekday }}</div>
|
||||
<DigitalWatch class="ml-[10px]" />
|
||||
</div>
|
||||
<SvgComponent :content="titleSvg" class="h-[156px] mt-[95px]" />
|
||||
<div class="login-form-wrapper w-[622px] h-[419px] mx-auto mt-[87px]">
|
||||
<form class="w-full h-full flex flex-col items-center pt-[126px]" @submit="handleSubmit">
|
||||
<div class="form-item px-[71px] w-full">
|
||||
|
|
@ -36,10 +39,13 @@
|
|||
import { useRouter } from "vue-router";
|
||||
import { postRequest } from "@/api/customFetch";
|
||||
import { useUserStore } from "@/store/user";
|
||||
import DigitalWatch from "@/components/watch/DigitalWatch.vue";
|
||||
import { useDate } from "@/composables/useDate";
|
||||
|
||||
const { year, month, day, weekday, formateTime } = useDate();
|
||||
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore()
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
const titleSvg = ref("");
|
||||
const getTitleSvg = async () => {
|
||||
|
|
@ -78,12 +84,12 @@
|
|||
).then((resp) => {
|
||||
if (resp.code === 200) {
|
||||
// 登录成功,存储token
|
||||
const {accessToken,refreshToken} = resp.result as {refreshToken:string,accessToken:string}
|
||||
userStore.setAccessToken(accessToken)
|
||||
userStore.setRefreshToken(refreshToken)
|
||||
const { accessToken, refreshToken } = resp.result as { refreshToken: string; accessToken: string };
|
||||
userStore.setAccessToken(accessToken);
|
||||
userStore.setRefreshToken(refreshToken);
|
||||
|
||||
// 跳转到首页
|
||||
router.push('/')
|
||||
router.push("/");
|
||||
} else {
|
||||
// 登录失败提示
|
||||
alert(resp.message || "登录失败");
|
||||
|
|
@ -96,6 +102,7 @@
|
|||
};
|
||||
|
||||
onBeforeMount(() => {
|
||||
formateTime();
|
||||
getTitleSvg();
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue