This commit is contained in:
Kunagisa 2025-06-14 20:08:00 +08:00
parent a4376549ba
commit 367e24d2ea
5 changed files with 60 additions and 11 deletions

View File

@ -13,7 +13,11 @@ const axiosInstance = axios.create({
timeout: 10000
});
// 请求拦截器
/**
* 请求拦截器
* - 对需要认证的请求在请求头中添加Authorization
* - 对登录注册和获取列表的请求不添加Authorization
*/
axiosInstance.interceptors.request.use(
config => {
const token = localStorage.getItem('access_token');
@ -35,7 +39,10 @@ axiosInstance.interceptors.request.use(
}
);
// 响应拦截器
/**
* 响应拦截器
* - 如果收到401错误未授权并且不是来自登录请求则调用logoutUser函数清除用户凭证
*/
axiosInstance.interceptors.response.use(
response => response,
error => {

View File

@ -1,6 +1,9 @@
import axiosInstance from './axiosConfig';
/**
* 获取地图编辑者列表
* @returns {Promise<any>} 返回一个包含地图编辑者信息的Promise对象
*/
export const getMapEditors = async () => {
try {
const response = await axiosInstance.get('/map/editors');

View File

@ -50,7 +50,10 @@ import { loginSuccess } from '../utils/jwt';
// }
// )
// 获取验证码
/**
* 获取验证码
* @returns {Promise<any>} 返回一个包含验证码信息的Promise对象
*/
export const getCaptcha = async () => {
try {
const response = await axiosInstance.get('/captcha');
@ -60,7 +63,14 @@ export const getCaptcha = async () => {
}
};
// 用户登录
/**
* 用户登录
* @param {string} username - 用户名
* @param {string} password - 密码
* @param {string} token - 验证码token
* @param {string} captcha - 用户输入的验证码
* @returns {Promise<any>} 返回一个包含登录结果信息的Promise对象
*/
export const userLogin = async (username, password, token, captcha) => {
try {
const response = await axiosInstance.post('/user/login', {
@ -80,7 +90,14 @@ export const userLogin = async (username, password, token, captcha) => {
}
};
// 用户注册
/**
* 用户注册
* @param {string} qq_code - QQ号
* @param {string} password - 密码
* @param {string} token - 验证码token
* @param {string} captcha - 用户输入的验证码
* @returns {Promise<any>} 返回一个包含注册结果信息的Promise对象
*/
export const userRegister = async (qq_code, password, token, captcha) => {
try {
const response = await axiosInstance.post('/user/register', {

View File

@ -2,7 +2,16 @@ import axios from 'axios'
const API_BASE_URL = 'https://ra3.z31.xyz/v1'
// 获取地图列表
/**
* 获取地图列表
* @param {object} params - 查询参数
* @param {number} params.page - 页码
* @param {string} params.search - 搜索关键字
* @param {string} params.player_count - 玩家数量
* @param {string} params.tags - 标签
* @param {string} params.ordering - 排序方式
* @returns {Promise<any>}
*/
export const getMaps = async (params = {}) => {
try {
const response = await axios.get(`${API_BASE_URL}/maps/`, {
@ -21,7 +30,13 @@ export const getMaps = async (params = {}) => {
}
}
// 获取每周推荐地图
/**
* 获取每周推荐地图
* @param {object} params - 查询参数
* @param {number} params.page - 页码
* @param {string} params.ordering - 排序方式
* @returns {Promise<any>}
*/
export const getWeeklyTopMaps = async (params = {}) => {
try {
const response = await axios.get(`${API_BASE_URL}/maps/`, {
@ -38,7 +53,11 @@ export const getWeeklyTopMaps = async (params = {}) => {
}
}
// 获取地图详情
/**
* 获取地图详情
* @param {number} id - 地图ID
* @returns {Promise<any>}
*/
export const getMapDetail = async (id) => {
try {
const response = await axios.get(`${API_BASE_URL}/maps/${id}/`)
@ -49,7 +68,10 @@ export const getMapDetail = async (id) => {
}
}
// 获取所有标签
/**
* 获取所有标签
* @returns {Promise<string[]>}
*/
export const getAllTags = async () => {
try {
const response = await axios.get(`${API_BASE_URL}/maps/`)

View File

@ -304,7 +304,7 @@ const closeModal = () => {
//
const openAddModal = (demand) => {
reply.value = demand;
replyModal.value = true;
showAddModal.value = true;
resetReplyForm();
}