feat(banban): add standalone entry and mini app base wiring
This commit is contained in:
@@ -5,7 +5,7 @@ module.exports = {
|
||||
defineConstants: {
|
||||
__APP_ENV__: '"development"',
|
||||
// Update this to your LAN backend when testing on a real device.
|
||||
__API_BASE_URL__: '"http://192.168.101.86:8001"',
|
||||
__API_BASE_URL__: '"http://192.168.10.36:8001"',
|
||||
},
|
||||
mini: {},
|
||||
h5: {}
|
||||
|
||||
@@ -5,7 +5,7 @@ module.exports = {
|
||||
defineConstants: {
|
||||
__APP_ENV__: '"production"',
|
||||
// Replace with the production backend before release builds.
|
||||
__API_BASE_URL__: '"http://192.168.101.86:8001"',
|
||||
__API_BASE_URL__: '"http://192.168.10.36:8001"',
|
||||
},
|
||||
mini: {},
|
||||
h5: {}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user