This commit is contained in:
Your Name
2026-04-07 18:13:03 +08:00
parent a780356908
commit fdf714f833
397 changed files with 15086 additions and 1043 deletions
+176 -74
View File
@@ -40,6 +40,7 @@
v-model="formData.id_card"
placeholder="请输入身份证号"
maxlength="18"
@focus="handleIdCardFocus"
@blur="handleIdCardBlur"
/>
</el-form-item>
@@ -53,6 +54,7 @@
v-model="formData.phone"
placeholder="请输入手机号"
maxlength="11"
@focus="handlePhoneFocus"
@blur="handlePhoneBlur"
/>
</el-form-item>
@@ -163,12 +165,10 @@
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="空腹血糖(mmol/L)" prop="fasting_blood_sugar">
<el-input-number
<el-input
v-model="formData.fasting_blood_sugar"
:min="0"
:max="50"
:step="0.1"
placeholder="请输入空腹血糖"
placeholder="请输入空腹血糖,如:8.5 或 8-9"
maxlength="20"
class="w-full"
/>
</el-form-item>
@@ -239,14 +239,14 @@
</el-col>
<el-col :span="12">
<el-form-item label="发现糖尿病患病史" prop="diabetes_discovery_year">
<el-input-number
<el-input
v-model="formData.diabetes_discovery_year"
:min="0"
:max="100"
placeholder="请输入年数"
clearable
maxlength="50"
show-word-limit
placeholder="可填数字或文字,如:5、1年、半年"
class="w-full"
/>
<template #append></template>
</el-form-item>
</el-col>
</el-row>
@@ -511,7 +511,7 @@
<el-empty v-else description="请先保存诊单后再添加血糖血压记录" />
</el-tab-pane>
<!-- 病历记录标签页开方后自动显示 -->
<el-tab-pane label="处方" name="bingli" :disabled="!formData.id">
<el-tab-pane label="处方" name="bingli" :disabled="!formData.id" v-if="hasPermission(['tcm.diagnosis/chufang'])">
<div v-if="formData.id" class="bingli-tab-content">
<!-- 诊断信息舌苔照片检查报告 -->
<div class="bingli-diagnosis-section">
@@ -720,7 +720,7 @@ const formData = ref({
diagnosis_type: '',
syndrome_type: '',
diabetes_type: '',
diabetes_discovery_year: undefined as number | undefined,
diabetes_discovery_year: '',
local_hospital_diagnosis: [],
local_hospital_name: '',
marital_status: undefined as number | undefined,
@@ -729,7 +729,7 @@ const formData = ref({
region: '',
systolic_pressure: undefined as number | undefined,
diastolic_pressure: undefined as number | undefined,
fasting_blood_sugar: undefined as number | undefined,
fasting_blood_sugar: '',
appetite: [] as string[],
water_intake: '',
diet_condition: [],
@@ -750,6 +750,7 @@ const formData = ref({
allergy_history: 0,
family_history: 0,
pregnancy_history: 0,
assistant_id: undefined as number | undefined,
tongue_images: [] as string[],
report_files: [],
symptoms: '',
@@ -764,13 +765,124 @@ const formData = ref({
external_userid: ''
})
// 保存原始完整数据
const originalPhone = ref('')
const originalIdCard = ref('')
const isPhoneFocused = ref(false)
const isIdCardFocused = ref(false)
// 脱敏函数
const maskPhone = (phone: string) => {
if (!phone || phone.length < 11) return phone
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
}
const maskIdCard = (idCard: string) => {
if (!idCard) return idCard
if (idCard.length === 15) {
return idCard.replace(/(\d{6})\d{5}(\d{4})/, '$1*****$2')
} else if (idCard.length === 18) {
return idCard.replace(/(\d{6})\d{8}(\d{4})/, '$1********$2')
}
return idCard
}
// 手机号聚焦 - 显示完整数据
const handlePhoneFocus = () => {
isPhoneFocused.value = true
if (originalPhone.value) {
formData.value.phone = originalPhone.value
}
}
// 手机号失焦 - 恢复脱敏并验证
const handlePhoneBlur = async () => {
isPhoneFocused.value = false
// 保存原始数据并脱敏显示
if (formData.value.phone && formData.value.phone.length === 11) {
originalPhone.value = formData.value.phone
// 验证手机号唯一性
if (/^1[3-9]\d{9}$/.test(formData.value.phone)) {
try {
const result = await checkPhone({
phone: formData.value.phone,
id: formData.value.id || ''
})
if (result.exists) {
ElMessage.warning(result.message)
}
} catch (error) {
console.error('检查手机号失败:', error)
}
}
// 脱敏显示
formData.value.phone = maskPhone(formData.value.phone)
}
}
// 身份证聚焦 - 显示完整数据
const handleIdCardFocus = () => {
isIdCardFocused.value = true
if (originalIdCard.value) {
formData.value.id_card = originalIdCard.value
}
}
// 身份证失焦 - 恢复脱敏并验证
const handleIdCardBlur = async () => {
isIdCardFocused.value = false
// 保存原始数据并脱敏显示
if (formData.value.id_card && (formData.value.id_card.length === 15 || formData.value.id_card.length === 18)) {
originalIdCard.value = formData.value.id_card
// 验证身份证格式并计算年龄
if (/^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/.test(formData.value.id_card)) {
// 从身份证提取出生日期计算年龄
const id = formData.value.id_card
const birthYear = parseInt(id.substring(6, 10))
const birthMonth = parseInt(id.substring(10, 12))
const birthDay = parseInt(id.substring(12, 14))
const today = new Date()
let age = today.getFullYear() - birthYear
if (today.getMonth() + 1 < birthMonth || (today.getMonth() + 1 === birthMonth && today.getDate() < birthDay)) {
age--
}
formData.value.age = age
// 验证身份证唯一性
try {
const result = await checkIdCard({
id_card: formData.value.id_card,
id: formData.value.id || ''
})
if (result.exists) {
ElMessage.warning(result.message)
}
} catch (error) {
console.error('检查身份证号失败:', error)
}
}
// 脱敏显示
formData.value.id_card = maskIdCard(formData.value.id_card)
}
}
// 自定义验证规则
const validatePhone = (rule: any, value: any, callback: any) => {
if (!value) {
// 使用原始数据进行验证
const phoneToValidate = originalPhone.value || value
if (!phoneToValidate) {
callback(new Error('请输入手机号'))
return
}
if (!/^1[3-9]\d{9}$/.test(value)) {
if (!/^1[3-9]\d{9}$/.test(phoneToValidate)) {
callback(new Error('手机号格式不正确'))
return
}
@@ -778,7 +890,9 @@ const validatePhone = (rule: any, value: any, callback: any) => {
}
const validateIdCard = (rule: any, value: any, callback: any) => {
if (value && !/^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/.test(value)) {
// 使用原始数据进行验证
const idCardToValidate = originalIdCard.value || value
if (idCardToValidate && !/^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/.test(idCardToValidate)) {
callback(new Error('身份证号格式不正确'))
return
}
@@ -793,6 +907,7 @@ const formRules = {
age: [{ required: true, message: '请输入年龄', trigger: 'blur' }],
fasting_blood_sugar: [{ required: true, message: '请输入空腹血糖', trigger: 'blur' }],
diagnosis_type: [{ required: true, message: '请选择诊断类型', trigger: 'change' }],
diabetes_discovery_year: [{ max: 50, message: '最多50个字符', trigger: 'blur' }],
}
// 获取字典选项
@@ -881,58 +996,6 @@ const getDictOptions = async () => {
}
}
// 手机号失焦检查
const handlePhoneBlur = async () => {
if (!formData.value.phone || !/^1[3-9]\d{9}$/.test(formData.value.phone)) {
return
}
try {
const result = await checkPhone({
phone: formData.value.phone,
id: formData.value.id || ''
})
if (result.exists) {
ElMessage.warning(result.message)
}
} catch (error) {
console.error('检查手机号失败:', error)
}
}
// 身份证号失焦检查
const handleIdCardBlur = async () => {
if (!formData.value.id_card || !/^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/.test(formData.value.id_card)) {
return
}
// 从身份证提取出生日期计算年龄
const id = formData.value.id_card
const birthYear = parseInt(id.substring(6, 10))
const birthMonth = parseInt(id.substring(10, 12))
const birthDay = parseInt(id.substring(12, 14))
const today = new Date()
let age = today.getFullYear() - birthYear
if (today.getMonth() + 1 < birthMonth || (today.getMonth() + 1 === birthMonth && today.getDate() < birthDay)) {
age--
}
formData.value.age = age
try {
const result = await checkIdCard({
id_card: formData.value.id_card,
id: formData.value.id || ''
})
if (result.exists) {
ElMessage.warning(result.message)
}
} catch (error) {
console.error('检查身份证号失败:', error)
}
}
const open = async (type: string, id?: number) => {
mode.value = type
visible.value = true
@@ -943,7 +1006,19 @@ const open = async (type: string, id?: number) => {
if (type === 'edit' && id) {
const data = await tcmDiagnosisDetail({ id })
// 保存原始完整数据
originalPhone.value = data.phone || ''
originalIdCard.value = data.id_card || ''
// 显示脱敏数据
data.phone = maskPhone(data.phone || '')
data.id_card = maskIdCard(data.id_card || '')
formData.value = data
const y = data.diabetes_discovery_year
formData.value.diabetes_discovery_year =
y == null || y === '' ? '' : String(y)
} else if (type === 'add') {
const userStore = useUserStore()
formData.value.assistant_id = userStore.userInfo?.id || ''
@@ -955,8 +1030,15 @@ const handleSubmit = async () => {
submitting.value = true
try {
// 准备提交数据,使用原始完整数据
const submitData = {
...formData.value,
phone: originalPhone.value || formData.value.phone,
id_card: originalIdCard.value || formData.value.id_card
}
if (mode.value === 'add') {
const result = await tcmDiagnosisAdd(formData.value)
const result = await tcmDiagnosisAdd(submitData)
// 如果是新增,保存成功后切换到编辑模式,这样可以添加血糖血压记录
if (result && result.id) {
@@ -967,12 +1049,20 @@ const handleSubmit = async () => {
try {
const detail = await tcmDiagnosisDetail({ id: result.id })
formData.value.patient_id = detail.patient_id
// 更新原始数据
originalPhone.value = detail.phone || ''
originalIdCard.value = detail.id_card || ''
// 显示脱敏数据
formData.value.phone = maskPhone(detail.phone || '')
formData.value.id_card = maskIdCard(detail.id_card || '')
} catch (error) {
console.error('获取详情失败:', error)
}
}
} else {
await tcmDiagnosisEdit(formData.value)
await tcmDiagnosisEdit(submitData)
}
emit('success')
@@ -1011,17 +1101,21 @@ const handleClose = () => {
id_card: '',
phone: '',
gender: 1,
age: undefined as number | undefined,
diagnosis_date: '',
diagnosis_type: '',
syndrome_type: '',
diabetes_type: '',
diabetes_discovery_year: '',
local_hospital_diagnosis: [],
local_hospital_name: '',
marital_status: undefined as number | undefined,
height: undefined as number | undefined,
weight: undefined as number | undefined,
region: '',
systolic_pressure: undefined as number | undefined,
diastolic_pressure: undefined as number | undefined,
fasting_blood_sugar: undefined as number | undefined,
diabetes_discovery_year: undefined as number | undefined,
local_hospital_diagnosis: [],
local_hospital_name: '',
fasting_blood_sugar: '',
appetite: [] as string[],
water_intake: '',
diet_condition: [],
@@ -1042,6 +1136,7 @@ const handleClose = () => {
allergy_history: 0,
family_history: 0,
pregnancy_history: 0,
assistant_id: undefined as number | undefined,
tongue_images: [] as string[],
report_files: [],
symptoms: '',
@@ -1055,6 +1150,13 @@ const handleClose = () => {
status: 1,
external_userid: ''
}
// 重置原始数据
originalPhone.value = ''
originalIdCard.value = ''
isPhoneFocused.value = false
isIdCardFocused.value = false
visible.value = false
}