Files
yunzerwebsiteallinone/uniapp/api/auth.js
T
2026-09-19 21:44:04 +08:00

194 lines
4.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 移动端认证接口 — 对接 Go /app/*
*/
import { request, requestRaw } from '@/api/request.js'
/** 账号密码登录(旧:租户端直登) */
export function login(data) {
return request({
url: '/app/login',
method: 'POST',
data
})
}
/* ==================== 统一认证中心(UAC) ====================
* APP 不走浏览器跳转,直接用密码直连模式:
* POST /auth/login 拿 access + refresh,多企业时再调 switch-tenant。
* 开关:VITE_AUTH_MODE=sso 时启用(见 utils/auth.js 的 isSSOEnabled)
* ============================================================ */
/** 统一认证:账号密码登录 */
export function loginUAC(data) {
return request({
url: '/auth/login',
method: 'POST',
data: Object.assign({ client_id: 'yz-uniapp' }, data)
})
}
/** 统一认证:选择/切换企业(一人多企业) */
export function switchTenant(data) {
return request({
url: '/auth/switch-tenant',
method: 'POST',
data: Object.assign({ client_id: 'yz-uniapp' }, data)
})
}
/** 统一认证:刷新访问令牌 */
export function refreshTokenUAC(data) {
return request({
url: '/auth/token',
method: 'POST',
header: { 'Content-Type': 'application/x-www-form-urlencoded' },
data: Object.assign({ grant_type: 'refresh_token', client_id: 'yz-uniapp' }, data),
silent: true
})
}
/** 统一认证:吊销令牌(登出) */
export function revokeUAC(data = {}) {
return request({
url: '/auth/revoke',
method: 'POST',
data,
silent: true,
timeout: 5000
})
}
/** 发送登录验证码(账号二次校验用,需后台开启验证) */
export function sendLoginCode(data) {
return request({
url: '/app/sendLoginCode',
method: 'POST',
data
})
}
/** 手机号验证码登录 */
export function loginBySms(data) {
return request({
url: '/app/loginBySms',
method: 'POST',
data
})
}
/** 退出登录(后端无状态,失败可忽略;短超时避免卡住) */
export function logoutApi(data = {}) {
return request({
url: '/app/logout',
method: 'POST',
data,
silent: true,
timeout: 5000
})
}
/** 当前用户信息 */
export function getCurrentUser() {
return request({
url: '/app/currentUser',
method: 'GET'
})
}
/** 是否开启登录人机/验证码校验 */
export function getOpenVerify() {
return request({
url: '/app/login/getOpenVerify',
method: 'GET',
silent: true,
timeout: 8000
})
}
/** 极验 3 配置 */
export function getGeetest3Infos() {
return request({
url: '/app/login/getGeetest3Infos',
method: 'GET',
silent: true
})
}
/** 极验 4 配置 */
export function getGeetest4Infos() {
return request({
url: '/app/login/getGeetest4Infos',
method: 'GET',
silent: true,
timeout: 8000
})
}
/** 注册 */
export function register(data) {
return request({
url: '/app/register',
method: 'POST',
data
})
}
/** 发送注册验证码 */
export function sendRegisterCode(data) {
return request({
url: '/app/sendRegisterCode',
method: 'POST',
data
})
}
/** 重置密码 */
export function resetPassword(data) {
return request({
url: '/app/resetPassword',
method: 'POST',
data
})
}
/** 验证租户和账号(找回密码第一步) */
export function verifyAccount(data) {
return request({
url: '/app/verifyAccount',
method: 'POST',
data
})
}
/** 发送找回密码验证码(找回密码第二步) */
export function sendResetCode(data) {
return request({
url: '/app/sendResetCode',
method: 'POST',
data
})
}
/**
* 解析 getOpenVerify 返回的 label/value 列表
* @returns {Promise<{ openVerify: boolean, verifyType: string }>}
*/
export async function fetchVerifyConfig() {
try {
const data = await getOpenVerify()
const list = Array.isArray(data) ? data : []
const map = {}
list.forEach((item) => {
if (item && item.label) map[item.label] = item.value
})
return {
openVerify: map.openVerify === '1' || map.openVerify === 1,
verifyType: map.verifyType || ''
}
} catch {
return { openVerify: false, verifyType: '' }
}
}
export { requestRaw }