zhaoyumao | f8f8184 | 2025-06-09 00:00:46 +0800 | [diff] [blame^] | 1 | import { request } from '@umijs/max'; |
| 2 | |
| 3 | export interface PlanetEntity { |
| 4 | planetId?: number; |
| 5 | name?: string; |
| 6 | filename?: string; |
| 7 | description?: string; |
| 8 | createTime?: string; |
| 9 | } |
| 10 | |
| 11 | export interface UserPlanetEntity { |
| 12 | userId?: number; |
| 13 | planetId?: number; |
| 14 | updateTime?: string; |
| 15 | } |
| 16 | |
| 17 | export async function getPlanetList(params: { |
| 18 | pageNum?: number; |
| 19 | pageSize?: number; |
| 20 | }) { |
| 21 | const res = await request<{ code: number; data: PlanetEntity[] }>('/api/planets/list', { |
| 22 | method: 'GET', |
| 23 | params, |
| 24 | }); |
| 25 | return res.data; |
| 26 | |
| 27 | } |
| 28 | |
| 29 | export async function getPlanetInfo(params: { planetId: number | undefined; }): Promise<PlanetEntity> { |
| 30 | const res = await request<{ code: number; data: PlanetEntity }>(`/api/planets/info/${params.planetId}`, { |
| 31 | method: 'GET', |
| 32 | }); |
| 33 | return res.data; |
| 34 | } |
| 35 | |
| 36 | export async function uploadPlanetFile(file: File) { |
| 37 | const formData = new FormData(); |
| 38 | formData.append('file', file); |
| 39 | return request('/api/planets/upload', { |
| 40 | method: 'POST', |
| 41 | data: formData, |
| 42 | requestType: 'form', |
| 43 | }); |
| 44 | } |
| 45 | |
| 46 | export async function getUserPlanet(params: { userId: number }) { |
| 47 | const res = await request<{ code: number; data: UserPlanetEntity }>('/api/planets/user', { |
| 48 | method: 'GET', |
| 49 | params, |
| 50 | }); |
| 51 | return res.data; |
| 52 | } |
| 53 | |
| 54 | export async function updatePlanet(entity: PlanetEntity) { |
| 55 | return request('/api/planets/update', { |
| 56 | method: 'POST', |
| 57 | data: entity, |
| 58 | }); |
| 59 | } |
| 60 | export async function updateUserPlanet(entity: UserPlanetEntity) { |
| 61 | return request('/api/planets/updateUserPlanet', { |
| 62 | method: 'POST', |
| 63 | data: entity, |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | export async function deletePlanet(ids: number[]) { |
| 68 | return request('/api/planets/delete', { |
| 69 | method: 'POST', |
| 70 | data: ids, |
| 71 | }); |
| 72 | } |
| 73 | |
| 74 | export async function getRandomUserPlanets() { |
| 75 | const res = await request<{ code: number; data: UserPlanetEntity[] }>('/api/planets/random', { |
| 76 | method: 'GET', |
| 77 | }) |
| 78 | return res.data; |
| 79 | } |