fix(request): 接口响应字段由 data 统一为 result 并调整成功码判断
ApiResponse 业务数据字段由 data 改为 result,成功码由字符串 '00000' 改为数字 200, 登录与补充资料页面同步改为读取 res.result。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
cdef8e6513
commit
e5f76fc0a9
@@ -21,10 +21,8 @@ Page({
|
|||||||
this.setData({ loading: true })
|
this.setData({ loading: true })
|
||||||
|
|
||||||
// 获取微信临时 code → 调用 OpenID 登录接口
|
// 获取微信临时 code → 调用 OpenID 登录接口
|
||||||
app.getWxLoginCode()
|
app.getWxLoginCode().then((code) => checkOpenIdLogin(code)).then((res) => {
|
||||||
.then((code) => checkOpenIdLogin(code))
|
const { token, user } = res.result
|
||||||
.then((res) => {
|
|
||||||
const { token, user } = res.data
|
|
||||||
// 持久化登录凭证和用户信息
|
// 持久化登录凭证和用户信息
|
||||||
wx.setStorageSync('token', token)
|
wx.setStorageSync('token', token)
|
||||||
if (user) {
|
if (user) {
|
||||||
@@ -33,11 +31,9 @@ Page({
|
|||||||
} else {
|
} else {
|
||||||
wx.reLaunch({ url: '/pages/supplementPersonal/supplementPersonal' })
|
wx.reLaunch({ url: '/pages/supplementPersonal/supplementPersonal' })
|
||||||
}
|
}
|
||||||
})
|
}).catch((err) => {
|
||||||
.catch((err) => {
|
|
||||||
wx.showToast({ title: err.msg || '登录失败,请重试', icon: 'none' })
|
wx.showToast({ title: err.msg || '登录失败,请重试', icon: 'none' })
|
||||||
})
|
}).finally(() => {
|
||||||
.finally(() => {
|
|
||||||
this.setData({ loading: false })
|
this.setData({ loading: false })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ Page({
|
|||||||
idCard: this.data.idCard,
|
idCard: this.data.idCard,
|
||||||
realname: this.data.name,
|
realname: this.data.name,
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res.data) {
|
if (res.result) {
|
||||||
const { gender, age } = parseIdCard(res.data.idCard)
|
const { gender, age } = parseIdCard(res.result.idCard)
|
||||||
this.setData({ serverResult: res.data, gender, age })
|
this.setData({ serverResult: res.result, gender, age })
|
||||||
}
|
}
|
||||||
}).catch(() => {})
|
}).catch(() => {})
|
||||||
},
|
},
|
||||||
@@ -91,7 +91,7 @@ Page({
|
|||||||
sex: parsed.sex,
|
sex: parsed.sex,
|
||||||
birthday: parsed.birthday,
|
birthday: parsed.birthday,
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
wx.setStorageSync('userInfo', res.data)
|
wx.setStorageSync('userInfo', res.result)
|
||||||
wx.showToast({ title: '保存成功', icon: 'success' })
|
wx.showToast({ title: '保存成功', icon: 'success' })
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
wx.showToast({ title: '保存失败,请重试', icon: 'none' })
|
wx.showToast({ title: '保存失败,请重试', icon: 'none' })
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// TODO: 替换为实际接口地址
|
// TODO: 替换为实际接口地址
|
||||||
const IS_DEV = false
|
const IS_DEV = true
|
||||||
|
|
||||||
export const BASE_URL = IS_DEV
|
export const BASE_URL = IS_DEV
|
||||||
? ''
|
? 'http://10.10.10.10:8889/'
|
||||||
: ''
|
: ''
|
||||||
|
|
||||||
export const TIMEOUT = 30000
|
export const TIMEOUT = 30000
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ const request = <T = any>(
|
|||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (loading) _hideLoading()
|
if (loading) _hideLoading()
|
||||||
const body = res.data as ApiResponse<T>
|
const body = res.data as ApiResponse<T>
|
||||||
if (body.code === '00000') {
|
if (body.code === 200) {
|
||||||
resolve(body)
|
resolve(body)
|
||||||
} else {
|
} else {
|
||||||
wx.showToast({ title: body.msg || '请求失败', icon: 'none' })
|
wx.showToast({ title: body.msg || '请求失败', icon: 'none' })
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export interface ApiResponse<T = any> {
|
export interface ApiResponse<T = any> {
|
||||||
code: string
|
code: number
|
||||||
msg: string
|
msg: string
|
||||||
data: T
|
result: T
|
||||||
}
|
}
|
||||||
|
|
||||||
export type HttpMethod = 'GET' | 'POST' | 'PUT'
|
export type HttpMethod = 'GET' | 'POST' | 'PUT'
|
||||||
|
|||||||
Reference in New Issue
Block a user