This commit is contained in:
2026-08-25 20:50:01 +08:00
parent f6d4ed6c3c
commit 6572771227
12 changed files with 341 additions and 86 deletions
+10 -1
View File
@@ -1,11 +1,13 @@
import { API_ROOT } from '@/config/runtime.js'
function authRequest(path, data) {
function authRequest(path, data, options = {}) {
return new Promise((resolve, reject) => {
uni.request({
url: `${API_ROOT}${path}`,
method: 'POST',
data,
header: options.header,
timeout: options.timeout || 15000,
success(response) {
const body = response.data || {}
if (String(body.code ?? response.statusCode) !== '200') {
@@ -34,3 +36,10 @@ export function login(username, password) {
export function refresh(refreshToken) {
return authRequest('/auth/refresh', { refreshToken })
}
export function logout(refreshToken, accessToken) {
return authRequest('/auth/logout', { refreshToken }, {
header: accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined,
timeout: 5000
})
}