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