This commit is contained in:
zyb
2025-05-06 19:57:50 +08:00
parent 56d8d7a345
commit 062550d126
22 changed files with 14472 additions and 0 deletions

65
src/api/maps.js Normal file
View 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
}
}