Pārlūkot izejas kodu

fix(patient): 修正患者用药记录查询参数类型问题

- 将 getMedicationListByPatientId 的 patientUserId 参数从 number 改为 string 类型
- 更新调用该函数的位置,确保传入的是字符串类型的用户ID
- 避免因 JavaScript Number 精度问题导致的数据不一致
- 统一接口参数处理方式,提升代码健壮性
mcbaiyun 1 mēnesi atpakaļ
vecāks
revīzija
7f7963767d

+ 2 - 2
src/api/patientMedication.ts

@@ -189,14 +189,14 @@ export async function getMedicationById(id: string | number) {
  * 根据患者ID获取用药记录列表
  * @param patientUserId 患者用户ID
  */
-export async function getMedicationListByPatientId(patientUserId: number) {
+export async function getMedicationListByPatientId(patientUserId: string) {
   // 检查参数
   if (!patientUserId) {
     return Promise.reject(new Error('Patient user ID is required'))
   }
   
   const res: any = await request({
-    url: `https://wx.baiyun.work/patient-medication/patient/${encodeURIComponent(String(patientUserId))}`,
+    url: `https://wx.baiyun.work/patient-medication/patient/${encodeURIComponent(patientUserId)}`,
     method: 'GET'
   })
   

+ 6 - 5
src/pages/patient/health/medication.vue

@@ -231,8 +231,8 @@ const loadUser = () => {
   }
 }
 
-// 获取当前用户ID
-const currentUserId = computed(() => user.value.id ? Number(user.value.id) : undefined)
+// 获取当前用户ID (保持为字符串以避免JavaScript Number精度问题)
+const currentUserId = computed(() => user.value.id || undefined)
 
 const medications = ref<Medication[]>([])
 
@@ -474,9 +474,9 @@ const confirmAdd = async () => {
       }
       result = await updateMedication(editingId.value, payload)
     } else {
-      // 添加用药
+      // 添加用药 (使用字符串类型的用户ID)
       const payload = {
-        patientUserId: currentUserId.value!,
+        patientUserId: currentUserId.value,
         medicineName: selectedMedicine.value.name,
         dosage: addDosage.value.trim(),
         frequency: frequency,
@@ -602,7 +602,8 @@ const loadMedications = async () => {
   }
   
   try {
-    const result: any = await getMedicationListByPatientId(currentUserId.value!)
+    // 传递字符串类型的用户ID而不是Number类型
+    const result: any = await getMedicationListByPatientId(currentUserId.value)
     
     if (result?.data?.code === 200) {
       medications.value = result.data.data.map((item: any) => ({