feat(banban): add standalone entry and mini app base wiring

This commit is contained in:
ChengCan
2026-04-30 00:57:35 +08:00
parent 6f18b73f95
commit eefa450e83
6 changed files with 79 additions and 16 deletions

View File

@@ -62,9 +62,11 @@ export default function Login() {
}, 300)
} catch (error: any) {
console.error('[login] failed:', error)
Taro.showToast({
title: error?.message || '登录失败,请重试',
icon: 'none',
const message = String(error?.message || '登录失败,请重试')
Taro.showModal({
title: '登录失败',
content: message,
showCancel: false,
})
} finally {
Taro.hideLoading()

View File

@@ -13,6 +13,7 @@ class ApiError extends Error {
function getErrorDetail(data: any): string {
if (!data) return 'Request failed'
if (typeof data.errMsg === 'string') return data.errMsg
if (typeof data.detail === 'string') return data.detail
if (Array.isArray(data.detail)) {
return data.detail.map((item: any) => String(item?.msg || item)).join('; ')
@@ -30,6 +31,8 @@ async function request<T>(
} = {}
): Promise<T> {
const token = getToken()
const requestUrl = `${BASE_URL}${url}`
const requestMethod = options.method || 'GET'
const headers: Record<string, string> = {
'Content-Type': 'application/json',
...options.headers,
@@ -41,22 +44,19 @@ async function request<T>(
let response
try {
response = await Taro.request({
url: `${BASE_URL}${url}`,
method: options.method || 'GET',
url: requestUrl,
method: requestMethod,
data: options.data,
header: headers,
timeout: REQUEST_TIMEOUT_MS,
})
} catch (error: any) {
const message = String(error?.errMsg || error?.message || '')
const detail = message.includes('timeout')
? '请求超时,请检查后端服务是否可访问'
: '网络请求失败,请检查后端地址和网络连接'
throw new ApiError(0, detail)
const message = String(error?.errMsg || error?.message || 'request:fail')
throw new ApiError(0, message)
}
if (response.statusCode === 401) {
handleUnauthorized({ redirect: !url.startsWith('/auth/') })
handleUnauthorized({ redirect: !url.startsWith('/banban/auth/') })
}
if (response.statusCode >= 400) {

View File

@@ -30,7 +30,7 @@ export interface Parent {
}
export async function wechatLogin(data: WechatLoginPayload): Promise<LoginSession> {
const session = await request<LoginSession>('/auth/login', {
const session = await request<LoginSession>('/banban/auth/login', {
method: 'POST',
data,
})
@@ -39,14 +39,14 @@ export async function wechatLogin(data: WechatLoginPayload): Promise<LoginSessio
}
export async function getParent(userId: number): Promise<Parent> {
return request<Parent>(`/parents/${userId}`)
return request<Parent>(`/banban/parents/${userId}`)
}
export async function updateParent(
userId: number,
data: { nickname?: string; avatar_url?: string; phone?: string }
): Promise<Parent> {
return request<Parent>(`/parents/${userId}`, {
return request<Parent>(`/banban/parents/${userId}`, {
method: 'PATCH',
data,
})