chore: 前端首次基线提交
运行必须源码:src/、public/、index.html、package.json 及构建配置。 已忽略运行非必须:node_modules/、dist/、.env*。
This commit is contained in:
94
src/api/auth.js
Normal file
94
src/api/auth.js
Normal file
@@ -0,0 +1,94 @@
|
||||
import request from './request'
|
||||
|
||||
// ==================== 认证相关 API ====================
|
||||
|
||||
/**
|
||||
* 获取图形验证码
|
||||
* @returns {Promise} 验证码图片数据
|
||||
*/
|
||||
export function getCaptcha() {
|
||||
return request.post('/auth/captcha')
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信验证码(激活流程)
|
||||
* 前端传入身份证号,后端自动查找绑定手机号发送短信
|
||||
* @param {string} phone - 身份证号
|
||||
* @param {string} captcha - 图形验证码
|
||||
* @returns {Promise} { smsCode, phone, name, group }
|
||||
*/
|
||||
export function sendSms(phone, captcha) {
|
||||
return request.post('/auth/sms', { phone, captcha })
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活账号(设置密码)
|
||||
* @param {object} data - { id_number, phone, password, smsCode }
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function activate(data) {
|
||||
return request.post('/auth/activate', data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 参赛者登录(身份证号 + 密码)
|
||||
* @param {string} idNumber - 身份证号
|
||||
* @param {string} password - 密码
|
||||
* @returns {Promise} { token, user }
|
||||
*/
|
||||
export function login(phone, password) {
|
||||
return request.post('/auth/login', { phone, password })
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员登录(用户名 + 密码)
|
||||
* @param {string} username - 管理员用户名
|
||||
* @param {string} password - 密码
|
||||
* @returns {Promise} { token, user }
|
||||
*/
|
||||
export function adminLogin(username, password) {
|
||||
return request.post('/auth/admin-login', { username, password })
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户信息
|
||||
* @returns {Promise} 用户信息对象
|
||||
*/
|
||||
export function getCurrentUser() {
|
||||
return request.get('/auth/current-user')
|
||||
}
|
||||
|
||||
/**
|
||||
* 忘记密码 - 发送短信验证码
|
||||
* @param {string} idNumber - 身份证号
|
||||
* @param {string} captcha - 图形验证码
|
||||
* @returns {Promise} { smsCode, phone }
|
||||
*/
|
||||
export function forgotPassword(idNumber, captcha) {
|
||||
return request.post('/auth/forgot-password', { id_number: idNumber, captcha })
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
* @param {object} data - { id_number, password, smsCode }
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function resetPassword(data) {
|
||||
return request.post('/auth/reset-password', data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function logout() {
|
||||
return request.post('/auth/logout')
|
||||
}
|
||||
|
||||
/**
|
||||
* 静默刷新令牌(用户无感知续期,避免被强制踢出登录)
|
||||
* @returns {Promise<{token: string, user: object}>}
|
||||
*/
|
||||
export function refreshToken() {
|
||||
return request.post('/auth/refresh', null, { silent: true })
|
||||
}
|
||||
Reference in New Issue
Block a user