https://backend.qicai321.comhttp://192.168.66.187:8083所有请求会自动添加以下请求头:
{
'Authorization': 'Bearer {token}',
'X-CSRF-Token': '{csrfToken}',
'Content-Type': 'application/json'
}
项目使用封装的 http 对象提供以下方法:
import http from '@/utils/request.js';
// GET 请求
http.get(url, data, options)
// POST 请求
http.post(url, data, options)
// PUT 请求
http.put(url, data, options)
// DELETE 请求
http.delete(url, data, options)
// 文件上传
http.upload(url, filePath, name, formData, options)
自动添加的功能:
自动处理的功能:
import { wxLogin } from '@/api/user.js';
// 请求参数
const params = {
code: '微信登录code',
userInfo: {
nickname: '用户昵称',
avatarUrl: '头像URL',
gender: 0, // 性别
province: '省份',
city: '城市',
country: '国家',
tenant_id: 1
},
signature: '签名',
rawData: '原始数据',
encryptedData: '加密数据',
iv: '初始向量',
_csrf: 'CSRF token'
};
// 调用
const result = await wxLogin(params);
接口地址: POST /wechat/wechatLogin
返回数据:
{
status: 2000,
code: 0,
data: {
token: 'jwt_token',
userInfo: {
openid: 'openid',
nickname: '昵称',
avatarUrl: '头像',
tenant_id: 1
}
}
}
import { getUserInfo } from '@/api/user.js';
// 获取当前用户信息
const userInfo = await getUserInfo();
// 获取指定用户信息
const otherUserInfo = await getUserInfo(userId, openid);
接口地址: GET /wechat/getUserDetail 或 GET /api/wechat/get_user_info
import { getUserPhoneNumber } from '@/api/user.js';
const params = {
code: '微信授权code',
encryptedData: '加密数据',
iv: '初始向量'
};
const phoneInfo = await getUserPhoneNumber(params);
接口地址: POST /wechat/getUserPhoneNumber
import { updateUserInfo } from '@/api/user.js';
const userData = {
nickname: '新昵称',
phone: '手机号',
// ...其他用户信息
};
await updateUserInfo(userData);
接口地址: PUT /api/user/update
import { uploadAvatar } from '@/api/user.js';
const filePath = '/path/to/image.jpg';
const result = await uploadAvatar(filePath);
接口地址: POST /api/upload/avatar
import { logout } from '@/api/user.js';
await logout();
接口地址: POST /wechat/wechatLogout
import { fillUserInfo } from '@/api/user.js';
const userInfo = {
name: '姓名',
phone: '手机号',
email: '邮箱',
// ...其他信息
};
await fillUserInfo(userInfo);
接口地址: POST /api/wechat/save_user_info
import { getJobList } from '@/api/user.js';
const params = {
page: 1,
limit: 50,
searchTerms: '关键词',
status: '状态',
tenant_id: 1
};
const jobList = await getJobList(params);
接口地址: GET /api/system/job/list
请求参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| page | Number | 否 | 页码,默认1 |
| limit | Number | 否 | 每页数量,默认50 |
| searchTerms | String | 否 | 搜索关键词 |
| status | String | 否 | 职位状态 |
| tenant_id | Number | 否 | 租户ID |
import { applyJob } from '@/api/user.js';
const params = {
job_id: 123,
user_id: 456,
resume_id: 789
};
await applyJob(params);
接口地址: POST /api/job/apply
import { getApplicationDetail } from '@/api/user.js';
const params = {
id: 123,
application_id: 456
};
const detail = await getApplicationDetail(params);
接口地址: GET /api/job/application_detail
请求参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | Number | 是 | 用户ID |
| tenant_id | Number | 是 | 租户ID |
| application_id | Number | 是 | 申请ID |
import { getInterviewList } from '@/api/user.js';
const params = {
user_id: 123,
job_id: 456
};
const interviewList = await getInterviewList(params);
接口地址: GET /job/questions
import { getInterviewDetail } from '@/api/user.js';
const params = {
interview_id: 123
};
const detail = await getInterviewDetail(params);
接口地址: GET /interview_question/detail
import { submitAnswer } from '@/api/user.js';
const params = {
question_id: 123,
answer: '答案内容',
video_url: '视频URL',
audio_url: '音频URL'
};
await submitAnswer(params);
接口地址: POST /api/job/submit_answer
import { getQuestions } from '@/api/user.js';
const params = {
job_id: 123,
tenant_id: 1
};
const questions = await getQuestions(params);
接口地址: GET /api/wechat/choice_questions/
请求参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| job_id | Number | 是 | 职位ID |
| tenant_id | Number | 是 | 租户ID |
// 直接调用 uni.request
const res = await uni.request({
url: `${apiBaseUrl}/api/voice_interview_interaction/`,
method: 'POST',
data: {
tenant_id: 1,
question_id: 123,
position_config_id: 456,
application_id: 789
}
});
接口地址: POST /api/voice_interview_interaction/
import { uploadPhoto } from '@/api/user.js';
const params = {
file: '文件路径',
type: 'photo',
user_id: 123
};
const result = await uploadPhoto(params);
接口地址: POST /api/upload/
上传文件示例:
import http from '@/utils/request.js';
const result = await http.upload(
'/api/upload/',
filePath,
'file', // 文件字段名
{
type: 'photo',
tenant_id: 1
}
);
| HTTP 状态码 | 业务码 | 说明 | 处理方式 |
|---|---|---|---|
| 200 | 2000 | 请求成功 | 正常处理 |
| 400 | - | 请求参数错误 | 检查请求参数 |
| 401 | - | 未登录或token过期 | 跳转登录页面 |
| 403 | - | 无权限 | 提示用户 |
| 500 | - | 服务器错误 | 提示用户稍后重试 |
| 400 | 999 | 业务错误(如职位已截止) | 显示错误信息 |
import http from '@/utils/request.js';
try {
const result = await http.post('/api/example', data);
// 处理成功结果
} catch (error) {
// 错误已在拦截器中处理并提示用户
// 这里可以做额外的处理
if (error.status === 401) {
// 跳转到登录页面
uni.reLaunch({ url: '/pages/login/login' });
}
}
当返回 status: 999 或 code: 999 时,表示业务逻辑错误(如职位申请已截止),不会自动提示,需要手动处理:
try {
await applyJob(params);
} catch (error) {
if (error.status === 999) {
uni.showToast({
title: error.message || '申请已截止',
icon: 'none'
});
}
}
// 在页面中导入
import { wxLogin, getUserInfo } from '@/api/user.js';
// 使用
export default {
methods: {
async handleLogin() {
try {
const result = await wxLogin(params);
// 处理登录结果
} catch (error) {
// 错误处理
}
}
}
}
import apiService from '@/services/ApiService.js';
// 获取用户API
const userApi = apiService.get('user');
const result = await userApi.getUserInfo();
// 或使用简写
const userApi = apiService.user;
const result = await userApi.getUserInfo();
import { useUserApi } from '@/composables/useUserApi.js';
export default {
setup() {
const { login, loading, error } = useUserApi();
const handleLogin = async () => {
try {
const result = await login(code, userInfo);
return result;
} catch (err) {
console.error('Login failed:', error.value);
}
};
return {
handleLogin,
loading,
error
};
}
}
import { apiBaseUrl } from '@/common/config.js';
const res = await uni.request({
url: `${apiBaseUrl}/api/wechat/user/get_full_info`,
method: 'GET',
data: {
tenant_id: 1,
openid: 'openid'
}
});
uni.getStorageSync('token')uni.getStorageSync('csrfToken')X-CSRF-Tokenoptions.timeout 参数自定义超时时间Promise.all()修改 common/config.js 中的 apiBaseUrl:
// 生产环境
export const apiBaseUrl = 'https://backend.qicai321.com';
// 测试环境
export const apiBaseUrl = 'http://192.168.66.187:8083';
POST /wechat/wechatLoginGET /wechat/getUserDetailPOST /wechat/getUserPhoneNumberPUT /api/user/updatePOST /api/upload/avatarPOST /wechat/wechatLogoutPOST /api/wechat/save_user_infoGET /api/system/job/listPOST /api/job/applyGET /api/job/application_detailGET /job/questionsGET /interview_question/detailPOST /api/job/submit_answerGET /api/wechat/choice_questions/POST /api/voice_interview_interaction/POST /api/upload/GET /api/public/agreements/terms_of_service/