mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-01 01:30:27 +08:00
feat: api 鉴权
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import axios from 'axios';
|
||||
import type { BangumiItem } from '#/bangumi';
|
||||
|
||||
export const apiBangumi = {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import axios from 'axios';
|
||||
|
||||
export const apiCheck = {
|
||||
/**
|
||||
* 检测下载器
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import axios from 'axios';
|
||||
import type { Config } from '#/config';
|
||||
|
||||
export const apiConfig = {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import axios from 'axios';
|
||||
import type { BangumiItem } from '#/bangumi';
|
||||
|
||||
interface Status {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import axios from 'axios';
|
||||
|
||||
export const apiLog = {
|
||||
async getLog() {
|
||||
const { data } = await axios.get('api/v1/log');
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import axios from 'axios';
|
||||
|
||||
interface Success {
|
||||
status: 'ok';
|
||||
}
|
||||
|
||||
1
src/auto-imports.d.ts
vendored
1
src/auto-imports.d.ts
vendored
@@ -15,6 +15,7 @@ declare global {
|
||||
const assert: typeof import('vitest')['assert']
|
||||
const asyncComputed: typeof import('@vueuse/core')['asyncComputed']
|
||||
const autoResetRef: typeof import('@vueuse/core')['autoResetRef']
|
||||
const axios: typeof import('./utils/axios')['axios']
|
||||
const beforeAll: typeof import('vitest')['beforeAll']
|
||||
const beforeEach: typeof import('vitest')['beforeEach']
|
||||
const chai: typeof import('vitest')['chai']
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import type { User } from '#/auth';
|
||||
|
||||
export const useAuth = createSharedComposable(() => {
|
||||
const token = useLocalStorage('token', '');
|
||||
const auth = useLocalStorage('auth', '');
|
||||
|
||||
const user = reactive<User>({
|
||||
username: '',
|
||||
password: '',
|
||||
});
|
||||
|
||||
const isLogin = computed(() => token.value !== '');
|
||||
const isLogin = computed(() => auth.value !== '');
|
||||
|
||||
const login = async () => {
|
||||
const res = await apiAuth.login(user.username, user.password);
|
||||
token.value = res.access_token;
|
||||
auth.value = `${res.token_type} ${res.access_token}`;
|
||||
};
|
||||
|
||||
const logout = async () => {
|
||||
@@ -29,7 +29,7 @@ export const useAuth = createSharedComposable(() => {
|
||||
};
|
||||
|
||||
return {
|
||||
token,
|
||||
auth,
|
||||
user,
|
||||
isLogin,
|
||||
|
||||
|
||||
@@ -12,7 +12,13 @@ definePage({
|
||||
<template>
|
||||
<div flex="~ wrap" gap-12px>
|
||||
<ab-container title="Log" w-660px grow>
|
||||
<div rounded-10px border="1px solid black" overflow-auto p-10px>
|
||||
<div
|
||||
rounded-10px
|
||||
border="1px solid black"
|
||||
overflow-auto
|
||||
p-10px
|
||||
max-h-60vh
|
||||
>
|
||||
<pre text-main>{{ log }}</pre>
|
||||
</div>
|
||||
</ab-container>
|
||||
|
||||
9
src/utils/axios.ts
Normal file
9
src/utils/axios.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import Axios from 'axios';
|
||||
|
||||
const { auth } = useAuth();
|
||||
|
||||
export const axios = Axios.create({
|
||||
headers: {
|
||||
Authorization: auth.value,
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user