完善表单校验与公共数据逻辑

Co-Authored-By: Kimi-K3.1-Pro <noreply@moonshot.ai>
This commit is contained in:
lik
2026-10-24 18:49:02 +08:00
committed by trae-solo-agent
co-authored by Kimi-K3.1-Pro
parent d731fc1da3
commit a45a3d7a86
18 changed files with 496 additions and 336 deletions
+32 -45
View File
@@ -1,9 +1,12 @@
const API = require('../../utils/api.js')
const { formatDate } = require('../../utils/date.js')
const { maskIdNumber } = require('../../utils/privacy.js')
Page({
data: {
profiles: [],
loading: false
loading: false,
loadError: ''
},
// 用 onShow 而不是 onLoad:从新增/编辑页返回后需要刷新列表
@@ -17,41 +20,34 @@ Page({
})
},
// 拉取当前登录用户的就诊人列表
loadProfiles() {
this.setData({
loading: true
})
// 拉取当前登录用户的就诊人列表;空数组只在请求成功后展示为空态。
async loadProfiles() {
this.setData({ loading: true, loadError: '' })
return API.healthProfile.getMyProfiles({
page: 1,
pageSize: 50
})
.then((res) => {
if (res.code !== 0) {
wx.showToast({
title: res.msg || '加载失败',
icon: 'none'
})
return
}
const list = (res.data && res.data.list) || []
this.setData({
profiles: list.map((item) => this.formatProfile(item))
})
})
.catch((err) => {
console.log('获取就诊人失败', err)
wx.showToast({
title: '网络请求失败',
icon: 'none'
})
})
.finally(() => {
this.setData({
loading: false
})
try {
await getApp().waitForAuth()
const res = await API.healthProfile.getMyProfiles({ page: 1, pageSize: 50 })
if (res.code !== 0) throw new Error(res.msg || '就诊人加载失败')
const list = (res.data && res.data.list) || []
this.setData({
profiles: list.map((item) => this.formatProfile(item))
})
} catch (err) {
console.log('获取就诊人失败', err)
if (this.data.profiles.length === 0) {
this.setData({ loadError: err.message || '网络请求失败,请重试' })
} else {
// 已有成功数据时保留列表,刷新失败不打断查看和编辑。
wx.showToast({ title: '刷新失败,请重试', icon: 'none' })
}
} finally {
this.setData({ loading: false })
}
},
retryLoad() {
this.loadProfiles()
},
// 后端返回的是嵌套结构,这里拍平成卡片展示需要的字段
@@ -63,13 +59,13 @@ Page({
// 顺序:出生年月 → 联系电话 → 证件号(脱敏)
const metaList = []
if (profile.birth) {
metaList.push(profile.birth)
metaList.push(formatDate(profile.birth, profile.birth))
}
if (profile.mobile) {
metaList.push(profile.mobile)
}
if (profile.idnumber) {
metaList.push(this.maskIdNumber(profile.idnumber))
metaList.push(maskIdNumber(profile.idnumber))
}
return {
@@ -83,15 +79,6 @@ Page({
}
},
// 证件号脱敏:仅保留前 4 位与后 4 位(只在有值时调用)
maskIdNumber(idnumber) {
const value = String(idnumber || '')
if (value.length <= 8) {
return value
}
return `${value.slice(0, 4)}********${value.slice(-4)}`
},
onAdd() {
wx.navigateTo({
url: '/pages/health/profileedit'