|
@@ -1,3 +1,14 @@
|
|
|
|
+import type {
|
|
|
|
+ AuthSuccess,
|
|
|
|
+ AuthFailed,
|
|
|
|
+ PostListSuccess,
|
|
|
|
+ PostGetSuccess,
|
|
|
|
+ DefaultFailedResponse,
|
|
|
|
+ TagList,
|
|
|
|
+ PostBody,
|
|
|
|
+ PushSuccess,
|
|
|
|
+ UpdateSuccess,
|
|
|
|
+} from '@/models'
|
|
import axios from 'axios'
|
|
import axios from 'axios'
|
|
|
|
|
|
let token = ''
|
|
let token = ''
|
|
@@ -9,82 +20,9 @@ const baseServer = axios.create({
|
|
},
|
|
},
|
|
})
|
|
})
|
|
|
|
|
|
-export interface AuthSuccess {
|
|
|
|
- code: 200
|
|
|
|
- token: string
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface AuthFailed {
|
|
|
|
- code: 401
|
|
|
|
- msg: string
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface PostListSuccess {
|
|
|
|
- code: number
|
|
|
|
- data: Datum[]
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface Datum {
|
|
|
|
- id: number
|
|
|
|
- title: string
|
|
|
|
- createdAt: string
|
|
|
|
- updatedAt: string
|
|
|
|
- tags: Tag[]
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface Tag {
|
|
|
|
- name: string
|
|
|
|
- id: number
|
|
|
|
- color: string
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface TagList {
|
|
|
|
- code: number
|
|
|
|
- data: Tag[]
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface PostGetSuccess {
|
|
|
|
- code: number
|
|
|
|
- data: PostDetail
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface PostDetail {
|
|
|
|
- id: number
|
|
|
|
- title: string
|
|
|
|
- content: string
|
|
|
|
- createdAt: string
|
|
|
|
- updatedAt: string
|
|
|
|
- tags: Tag[]
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface DefaultFailedResponse {
|
|
|
|
- code: 404
|
|
|
|
- msg: string
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface PostBody {
|
|
|
|
- title: string
|
|
|
|
- content: string
|
|
|
|
- tags: string[]
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface PushSuccess {
|
|
|
|
- code: number
|
|
|
|
- msg: string
|
|
|
|
- data: {
|
|
|
|
- id: number
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface UpdateSuccess {
|
|
|
|
- code: 200,
|
|
|
|
- msg: string
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
export const api = {
|
|
export const api = {
|
|
auth(password: string) {
|
|
auth(password: string) {
|
|
- return (baseServer.post('/auth/', { password }) as Promise<AuthSuccess | AuthFailed>).then(
|
|
|
|
|
|
+ return (baseServer.post('/auth/', { password }).then(res => res.data) as Promise<AuthSuccess | AuthFailed>).then(
|
|
(data) => {
|
|
(data) => {
|
|
if (data.code == 200) token = data.token
|
|
if (data.code == 200) token = data.token
|
|
return data
|
|
return data
|
|
@@ -92,18 +30,18 @@ export const api = {
|
|
)
|
|
)
|
|
},
|
|
},
|
|
postList(length: number = 10, start: number = 10) {
|
|
postList(length: number = 10, start: number = 10) {
|
|
- return baseServer.get(`/post/list?length=${length}&start=${start}`) as Promise<PostListSuccess>
|
|
|
|
|
|
+ return baseServer.get(`/post/list?length=${length}&start=${start}`).then(res => res.data) as Promise<PostListSuccess>
|
|
},
|
|
},
|
|
postGet(id: number = 2) {
|
|
postGet(id: number = 2) {
|
|
- return baseServer.get(`/post/get/${id}`) as Promise<PostGetSuccess | DefaultFailedResponse>
|
|
|
|
|
|
+ return baseServer.get(`/post/get/${id}`).then(res => res.data) as Promise<PostGetSuccess | DefaultFailedResponse>
|
|
},
|
|
},
|
|
tagList() {
|
|
tagList() {
|
|
- return baseServer.get('/tag/list') as Promise<TagList>
|
|
|
|
|
|
+ return baseServer.get('/tag/list').then(res => res.data) as Promise<TagList>
|
|
},
|
|
},
|
|
postPush(body: PostBody) {
|
|
postPush(body: PostBody) {
|
|
- return baseServer.post('/post/push', body) as Promise<PushSuccess | AuthFailed>
|
|
|
|
|
|
+ return baseServer.post('/post/push', body).then(res => res.data) as Promise<PushSuccess | AuthFailed>
|
|
},
|
|
},
|
|
postEdit(id: number, body: PostBody) {
|
|
postEdit(id: number, body: PostBody) {
|
|
- return baseServer.post(`/post/edit/${id}`, body) as Promise<UpdateSuccess | AuthFailed>
|
|
|
|
- }
|
|
|
|
|
|
+ return baseServer.post(`/post/edit/${id}`, body).then(res => res.data) as Promise<UpdateSuccess | AuthFailed>
|
|
|
|
+ },
|
|
}
|
|
}
|