优化
This commit is contained in:
parent
a4376549ba
commit
367e24d2ea
@ -13,7 +13,11 @@ const axiosInstance = axios.create({
|
|||||||
timeout: 10000
|
timeout: 10000
|
||||||
});
|
});
|
||||||
|
|
||||||
// 请求拦截器
|
/**
|
||||||
|
* 请求拦截器
|
||||||
|
* - 对需要认证的请求,在请求头中添加Authorization
|
||||||
|
* - 对登录、注册和获取列表的请求,不添加Authorization
|
||||||
|
*/
|
||||||
axiosInstance.interceptors.request.use(
|
axiosInstance.interceptors.request.use(
|
||||||
config => {
|
config => {
|
||||||
const token = localStorage.getItem('access_token');
|
const token = localStorage.getItem('access_token');
|
||||||
@ -35,7 +39,10 @@ axiosInstance.interceptors.request.use(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// 响应拦截器
|
/**
|
||||||
|
* 响应拦截器
|
||||||
|
* - 如果收到401错误(未授权),并且不是来自登录请求,则调用logoutUser函数清除用户凭证
|
||||||
|
*/
|
||||||
axiosInstance.interceptors.response.use(
|
axiosInstance.interceptors.response.use(
|
||||||
response => response,
|
response => response,
|
||||||
error => {
|
error => {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import axiosInstance from './axiosConfig';
|
import axiosInstance from './axiosConfig';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取地图编辑者列表
|
||||||
|
* @returns {Promise<any>} 返回一个包含地图编辑者信息的Promise对象
|
||||||
|
*/
|
||||||
export const getMapEditors = async () => {
|
export const getMapEditors = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axiosInstance.get('/map/editors');
|
const response = await axiosInstance.get('/map/editors');
|
||||||
|
@ -50,7 +50,10 @@ import { loginSuccess } from '../utils/jwt';
|
|||||||
// }
|
// }
|
||||||
// )
|
// )
|
||||||
|
|
||||||
// 获取验证码
|
/**
|
||||||
|
* 获取验证码
|
||||||
|
* @returns {Promise<any>} 返回一个包含验证码信息的Promise对象
|
||||||
|
*/
|
||||||
export const getCaptcha = async () => {
|
export const getCaptcha = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axiosInstance.get('/captcha');
|
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) => {
|
export const userLogin = async (username, password, token, captcha) => {
|
||||||
try {
|
try {
|
||||||
const response = await axiosInstance.post('/user/login', {
|
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) => {
|
export const userRegister = async (qq_code, password, token, captcha) => {
|
||||||
try {
|
try {
|
||||||
const response = await axiosInstance.post('/user/register', {
|
const response = await axiosInstance.post('/user/register', {
|
||||||
|
@ -2,7 +2,16 @@ import axios from 'axios'
|
|||||||
|
|
||||||
const API_BASE_URL = 'https://ra3.z31.xyz/v1'
|
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 = {}) => {
|
export const getMaps = async (params = {}) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_BASE_URL}/maps/`, {
|
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 = {}) => {
|
export const getWeeklyTopMaps = async (params = {}) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_BASE_URL}/maps/`, {
|
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) => {
|
export const getMapDetail = async (id) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_BASE_URL}/maps/${id}/`)
|
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 () => {
|
export const getAllTags = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_BASE_URL}/maps/`)
|
const response = await axios.get(`${API_BASE_URL}/maps/`)
|
||||||
|
@ -304,7 +304,7 @@ const closeModal = () => {
|
|||||||
// 打开弹窗
|
// 打开弹窗
|
||||||
const openAddModal = (demand) => {
|
const openAddModal = (demand) => {
|
||||||
reply.value = demand;
|
reply.value = demand;
|
||||||
replyModal.value = true;
|
showAddModal.value = true;
|
||||||
resetReplyForm();
|
resetReplyForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user