diff --git a/src/api/medical.js b/src/api/medical.js index e6f4b16..2f58b3d 100644 --- a/src/api/medical.js +++ b/src/api/medical.js @@ -4,32 +4,62 @@ const BASE_URL = '/api/medical-records'; export const medicalApi = { // 创建病历 - createRecord(record) { - return axiosInstance.post(BASE_URL, record) + async createRecord(record) { + try { + const response = await axiosInstance.post(BASE_URL, record); + return response.data; // 返回响应数据 + } catch (error) { + console.error('创建病历失败:', error); + throw new Error(error.response?.data?.message || '创建病历失败'); // 抛出错误 + } }, // 获取所有病历 - getAllRecords(patientName = '') { - - return axiosInstance.get(BASE_URL, { - params: { - patientName - } - }) + async getAllRecords(patientName = '') { + try { + const response = await axiosInstance.get(BASE_URL, { + params: { + patientName + } + }); + console.log('111获取所有病历的响应:', response); // 打印响应 + console.log('222获取所有病历的响应:', response.data); // 打印响应 + return response ; // 返回响应数据 + } catch (error) { + console.error('获取病历失败:', error); + throw new Error(error.response?.data?.message || '获取病历失败'); // 抛出错误 + } }, // 获取单个病历 - getRecord(id) { - return axiosInstance.get(`${BASE_URL}/${id}`) + async getRecord(id) { + try { + const response = await axiosInstance.get(`${BASE_URL}/${id}`); + return response.data; // 返回响应数据 + } catch (error) { + console.error('获取病历失败:', error); + throw new Error(error.response?.data?.message || '获取病历失败'); // 抛出错误 + } }, // 更新病历 - updateRecord(id, record) { - return axiosInstance.put(`${BASE_URL}/${id}`, record) + async updateRecord(id, record) { + try { + const response = await axiosInstance.put(`${BASE_URL}/${id}`, record); + return response.data; // 返回响应数据 + } catch (error) { + console.error('更新病历失败:', error); + throw new Error(error.response?.data?.message || '更新病历失败'); // 抛出错误 + } }, // 删除病历 - deleteRecord(id) { - return axiosInstance.delete(`${BASE_URL}/${id}`) + async deleteRecord(id) { + try { + await axiosInstance.delete(`${BASE_URL}/${id}`); + } catch (error) { + console.error('删除病历失败:', error); + throw new Error(error.response?.data?.message || '删除病历失败'); // 抛出错误 + } } } diff --git a/src/views/login/Index.vue b/src/views/login/Index.vue index e932f20..6eba87e 100644 --- a/src/views/login/Index.vue +++ b/src/views/login/Index.vue @@ -1,18 +1,21 @@