提交
This commit is contained in:
65
src/api/maps.js
Normal file
65
src/api/maps.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const API_BASE_URL = 'https://ra3.z31.xyz/v1'
|
||||
|
||||
// 获取地图列表
|
||||
export const getMaps = async (params = {}) => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/maps/`, {
|
||||
params: {
|
||||
p: params.page || 1,
|
||||
search: params.search || '',
|
||||
player_count: params.player_count || '',
|
||||
tags: params.tags || '',
|
||||
ordering: params.ordering || '-download_count'
|
||||
}
|
||||
})
|
||||
return response.data
|
||||
} catch (error) {
|
||||
console.error('获取地图列表失败:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 获取每周推荐地图
|
||||
export const getWeeklyTopMaps = async () => {
|
||||
try {
|
||||
const response = await axios.get('https://ra3.z31.xyz/v1/maps/', {
|
||||
params: {
|
||||
ordering: '-download_count',
|
||||
format: 'json',
|
||||
p: 1
|
||||
}
|
||||
})
|
||||
return response.data.results.slice(0, 10)
|
||||
} catch (error) {
|
||||
console.error('获取每周推荐地图失败:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 获取地图详情
|
||||
export const getMapDetail = async (id) => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/maps/${id}/`)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
console.error('获取地图详情失败:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 获取所有标签
|
||||
export const getAllTags = async () => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/maps/`)
|
||||
const tags = new Set()
|
||||
response.data.results.forEach(map => {
|
||||
map.tags.forEach(tag => tags.add(tag))
|
||||
})
|
||||
return Array.from(tags)
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user