From e5f76fc0a96a7f0dba0c9228f5017b96dae42511 Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Thu, 20 Aug 2026 11:19:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(request):=20=E6=8E=A5=E5=8F=A3=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E5=AD=97=E6=AE=B5=E7=94=B1=20data=20=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E4=B8=BA=20result=20=E5=B9=B6=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E7=A0=81=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ApiResponse 业务数据字段由 data 改为 result,成功码由字符串 '00000' 改为数字 200, 登录与补充资料页面同步改为读取 res.result。 Co-Authored-By: Claude Sonnet 4.6 --- miniprogram/pages/login/login.ts | 34 ++++++++----------- .../supplementPersonal/supplementPersonal.ts | 8 ++--- miniprogram/utils/request/config.ts | 4 +-- miniprogram/utils/request/index.ts | 2 +- miniprogram/utils/request/types.ts | 4 +-- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/miniprogram/pages/login/login.ts b/miniprogram/pages/login/login.ts index 6a1fe09..c6980df 100644 --- a/miniprogram/pages/login/login.ts +++ b/miniprogram/pages/login/login.ts @@ -21,24 +21,20 @@ Page({ this.setData({ loading: true }) // 获取微信临时 code → 调用 OpenID 登录接口 - app.getWxLoginCode() - .then((code) => checkOpenIdLogin(code)) - .then((res) => { - const { token, user } = res.data - // 持久化登录凭证和用户信息 - wx.setStorageSync('token', token) - if (user) { - wx.setStorageSync('userInfo', user) - wx.reLaunch({ url: '/pages/home/home' }) - } else { - wx.reLaunch({ url: '/pages/supplementPersonal/supplementPersonal' }) - } - }) - .catch((err) => { - wx.showToast({ title: err.msg || '登录失败,请重试', icon: 'none' }) - }) - .finally(() => { - this.setData({ loading: false }) - }) + app.getWxLoginCode().then((code) => checkOpenIdLogin(code)).then((res) => { + const { token, user } = res.result + // 持久化登录凭证和用户信息 + wx.setStorageSync('token', token) + if (user) { + wx.setStorageSync('userInfo', user) + wx.reLaunch({ url: '/pages/home/home' }) + } else { + wx.reLaunch({ url: '/pages/supplementPersonal/supplementPersonal' }) + } + }).catch((err) => { + wx.showToast({ title: err.msg || '登录失败,请重试', icon: 'none' }) + }).finally(() => { + this.setData({ loading: false }) + }) }, }) diff --git a/miniprogram/pages/supplementPersonal/supplementPersonal.ts b/miniprogram/pages/supplementPersonal/supplementPersonal.ts index 26e02ec..0a850a8 100644 --- a/miniprogram/pages/supplementPersonal/supplementPersonal.ts +++ b/miniprogram/pages/supplementPersonal/supplementPersonal.ts @@ -43,9 +43,9 @@ Page({ idCard: this.data.idCard, realname: this.data.name, }).then((res) => { - if (res.data) { - const { gender, age } = parseIdCard(res.data.idCard) - this.setData({ serverResult: res.data, gender, age }) + if (res.result) { + const { gender, age } = parseIdCard(res.result.idCard) + this.setData({ serverResult: res.result, gender, age }) } }).catch(() => {}) }, @@ -91,7 +91,7 @@ Page({ sex: parsed.sex, birthday: parsed.birthday, }).then((res) => { - wx.setStorageSync('userInfo', res.data) + wx.setStorageSync('userInfo', res.result) wx.showToast({ title: '保存成功', icon: 'success' }) }).catch(() => { wx.showToast({ title: '保存失败,请重试', icon: 'none' }) diff --git a/miniprogram/utils/request/config.ts b/miniprogram/utils/request/config.ts index fd73f89..c0f65f1 100644 --- a/miniprogram/utils/request/config.ts +++ b/miniprogram/utils/request/config.ts @@ -1,8 +1,8 @@ // TODO: 替换为实际接口地址 -const IS_DEV = false +const IS_DEV = true export const BASE_URL = IS_DEV - ? '' + ? 'http://10.10.10.10:8889/' : '' export const TIMEOUT = 30000 diff --git a/miniprogram/utils/request/index.ts b/miniprogram/utils/request/index.ts index 299fc59..fb26d6e 100644 --- a/miniprogram/utils/request/index.ts +++ b/miniprogram/utils/request/index.ts @@ -39,7 +39,7 @@ const request = ( success: (res) => { if (loading) _hideLoading() const body = res.data as ApiResponse - if (body.code === '00000') { + if (body.code === 200) { resolve(body) } else { wx.showToast({ title: body.msg || '请求失败', icon: 'none' }) diff --git a/miniprogram/utils/request/types.ts b/miniprogram/utils/request/types.ts index b645020..62c7d3d 100644 --- a/miniprogram/utils/request/types.ts +++ b/miniprogram/utils/request/types.ts @@ -1,7 +1,7 @@ export interface ApiResponse { - code: string + code: number msg: string - data: T + result: T } export type HttpMethod = 'GET' | 'POST' | 'PUT'