说明:此文档列出当前代码库中发现的直接发起网络请求(uni.request)位置,建议将这些请求迁移到 src/api 下统一管理。每一项包含:文件路径、发现的后端路径/用途、建议目标 api 文件、当前状态与建议操作。
src/** 中查找 uni.request(...)。src/api 中的文件):
src/pages/patient/profile/index.vuesrc/pages/patient/profile/infos/base-info.vuesrc/pages/patient/health/details/physical.vuesrc/pages/patient/index/index.vuesrc/pages/patient-family/profile/infos/base-info.vuesrc/pages/patient-family/profile/index.vuesrc/pages/patient-family/index/index.vuesrc/pages/doctor/profile/infos/base-info.vuesrc/pages/public/profile/index.vuesrc/pages/public/profile/qr/index.vuesrc/pages/public/login/index.vue注意:
src/api目录内的文件(例如bloodGlucose.ts、bloodPressure.ts)本身已经在封装请求,这里不再重复列出。
src/pages/patient/profile/infos/base-info.vuePOST https://wx.baiyun.work/user_infoPOST https://wx.baiyun.work/update_user_infoPOST https://wx.baiyun.work/user/avatar/upload(uni.uploadFile)GET https://wx.baiyun.work/user/avatar/{userId}(头像下载)GET https://wx.baiyun.work/geo/nearest?latitude=...&longitude=...(地理编码/附近定位)api 文件:src/api/user.ts(新增或扩展函数)src/api/user.ts 中的 fetchUserInfo)建议操作:
src/api/user.ts 中添加 fetchUserInfo()、updateUserInfo(payload)、uploadAvatar(filePath)(或 uploadAvatarFormData)、downloadAvatar(userId)、geocodeNearest(lat, lon)。uni.request/uni.uploadFile/uni.downloadFile 调用替换为导入的 API 函数,并仅在页面内保留 UI 逻辑(loading、提示、表单校验等)。
src/api/user.ts 中的封装;页面保留 UI 逻辑)。src/pages/doctor/profile/infos/base-info.vuebase-info.vue 内容基本相同,使用的接口也与用户信息相关(user_info、头像上传、geo 等)。src/api/user.tssrc/api/user.ts 中的 fetchUserInfo)user.ts 中导出的函数。src/pages/patient-family/profile/infos/base-info.vueuser_info、头像上传、geo。建议目标 src/api/user.ts。
src/api/user.ts 中的封装;页面保留 UI 逻辑)。src/pages/public/profile/index.vue 和 src/pages/public/profile/qr/index.vuePOST /user_info 拉取用户信息;qr 页面也会拉取 user_info 用于生成二维码。src/api/user.ts(函数名例如 fetchUserInfo)src/api/user.ts 中的 fetchUserInfo)src/pages/public/login/index.vuePOST https://wx.baiyun.work/get_openid(后端返回 token/openid)src/api/user.ts(函数名例如 loginWithWx(code, role) 或 getOpenId(code, role))src/api/user.ts,新增函数 loginWithWx(code, role);src/pages/public/login/index.vue 已替换为调用该函数)src/pages/patient/index/index.vuePOST /user_info 并在缺少头像时下载 GET /user/avatar/{userId}。src/api/user.ts(fetchUserInfo, downloadAvatar)
src/api/user.ts 中的 fetchUserInfo,并在需要时使用 downloadAvatar 封装下载头像)src/pages/patient/health/details/physical.vuePOST https://wx.baiyun.work/physical/listPOST https://wx.baiyun.work/physical/addPOST https://wx.baiyun.work/physical/deletesrc/api/physical.ts,包含 listPhysical、addPhysical、deletePhysical 等函数。src/api/physical.ts 并替换页面中的 list/add/delete 请求)src/pages/patient-family/index/index.vue、src/pages/patient-family/profile/index.vue、其它首页和列表页uni.request 调用(多数为 user_info 或与列表/分页相关的后端接口)。user.ts、doctor.ts、bloodGlucose.ts、bloodPressure.ts、或新增模块(如 physical.ts、notification.ts 等)
user_info 的调用已改为使用 src/api/user.ts::fetchUserInfo;其它接口视情况待迁移)src/api 接口函数(示例)src/api/user.ts(扩展)
export async function fetchUserInfo()export async function updateUserInfo(payload)export async function uploadAvatar(filePath)export async function downloadAvatar(userId)export async function getOpenId(code, role)(保留或兼容现有的 getUserInfo(userId))src/api/physical.ts(新建)
export async function listPhysical(params)export async function addPhysical(payload)export async function deletePhysical(id)src/api/user.ts)// src/api/user.ts
export async function fetchUserInfo() {
const token = uni.getStorageSync('token')
const res: any = await uni.request({
url: 'https://wx.baiyun.work/user_info',
method: 'POST',
header: { 'content-type': 'application/json', Authorization: `Bearer ${token}` },
data: {}
})
return res
}
页面中的调用替换为:
import { fetchUserInfo } from '@/api/user'
const resp = await fetchUserInfo()
// 只在页面处理 UI(loading、跳转、toast)与数据映射
user_info、登录、头像等),因为多个页面复用了这些调用。src/api 中添加函数并导出,写好入参/返回类型注释(TypeScript)。uni.request 调用,保留页面的 UI/错误处理逻辑。uni.uploadFile/uni.downloadFile),建议把真正的网络操作封装在 api 中,但可以选择让页面传递 filePath 并由 API 返回解析后的结果。src/api/user.ts 中添加上面列出的函数骨架并替换某些页面的调用(逐文件进行,先做 base-info.vue 或 login.vue);注:本次扫描仅基于
uni.request的静态文本搜索,未检测动态构造的请求函数、第三方库封装(如axios、自定义requesthelper)或服务端渲染调用。若项目中存在其他请求模式,请告知我以扩展扫描策略。