Parcourir la source

添加请求缓存失效

cc12458 il y a 1 an
Parent
commit
1bbac201b0

+ 8 - 2
src/pages/index/patient/room@aside.vue

@@ -1,9 +1,11 @@
 <script setup lang="ts">
 import { genderFormatter }         from '@/libs/vxe/formatter';
 import type { PatientReportModel } from '@/model';
+import request                     from '@/request/alova';
 import { patientsRoomMethod }      from '@/request/api/patient.api';
 import { UserOutlined }            from '@ant-design/icons-vue';
 import { useRouteQuery }           from '@vueuse/router';
+import { invalidateCache }         from 'alova';
 import { useRequest }              from 'alova/client';
 import { useRouter }               from 'vue-router';
 import { RecycleScroller }         from 'vue-virtual-scroller';
@@ -22,8 +24,12 @@ const { data, loading, send } = useRequest(
 
 const router = useRouter();
 
-function handle(model: PatientReportModel) {
-  router.replace({
+async function handle(model: PatientReportModel) {
+  const matchedMethods = request.snapshots.match({
+    name: /(report|scheme|indicator)$/
+  });
+  await invalidateCache(matchedMethods);
+  await router.replace({
     path: router.currentRoute.value.path,
     query: { patientId: model.id, reportId: model.report.id },
   });

+ 4 - 0
src/pages/login.vue

@@ -4,6 +4,7 @@ import { accountMethod, getMenusMethod, loginMethod } from '@/request/api/accoun
 import router                                         from '@/router';
 import { useAccountStore }                            from '@/stores';
 import { LockOutlined, UserOutlined }                 from '@ant-design/icons-vue';
+import { invalidateCache }                            from 'alova';
 import { useSerialRequest }                           from 'alova/client';
 import { Form }                                       from 'ant-design-vue';
 import { h }                                          from 'vue';
@@ -35,13 +36,16 @@ const { loading, error, send } = useSerialRequest([
 );
 
 async function handle() {
+  loading.value = true;
   try {
     await validate();
+    await invalidateCache()
     await send();
   } catch ( error: any ) {
     const field = error?.errorFields?.[ 0 ];
     if ( field ) formWrapper.value?.querySelector<HTMLInputElement>(`#${ field.name }`)?.focus();
   }
+  loading.value = false;
 }
 </script>
 <template>

+ 2 - 0
src/request/api/patient.api.ts

@@ -32,11 +32,13 @@ export function patientsRoomMethod(query?: PatientQuery) {
         createTime: item.createTime,
       }));
     },
+    cacheFor: 1000
   });
 }
 
 export function patientMethod(id: string) {
   return request.Get<PatientModel, any>(`/fdhb-pc/patientInfoManage/getPatientInfoDetailById`, {
+    name: 'patient-report',
     params: { patientId: id },
     transform(data, headers) {
       data.patientId ??= id;

+ 8 - 0
src/request/api/report.api.ts

@@ -18,6 +18,7 @@ import dayjs   from 'dayjs';
 
 export function reportsMethod(patientId: string) {
   return request.Get<ReportModel[], any[]>(`/fdhb-pc/analysisManage/getHarsTid`, {
+    name: 'list-report',
     params: { patientId },
     transform(data, headers) {
       return data?.map(item => {
@@ -34,6 +35,7 @@ export function reportsMethod(patientId: string) {
 export function reportMethod(id: string) {
   return request.Get<ReportModel, any>(`/fdhb-pc/analysisManage/getHealRepDetailById`, {
     hitSource: 'confirm-scheme',
+    name: 'get-report',
     params: { healthAnalysisReportId: id },
     transform(data, headers) {
       return {
@@ -52,6 +54,8 @@ export function reportMethod(id: string) {
 
 export function reportSchemeMethod(reportId: string) {
   return request.Get(`/fdhb-pc/analysisManage/getCondProgDetailById`, {
+    hitSource: /-scheme$/,
+    name: 'report-scheme',
     params: { healthAnalysisReportId: reportId },
     transform(data: any, headers) {
       data.healthAnalysisReportId ??= reportId;
@@ -91,6 +95,7 @@ export function editSchemeMethod(reportId: string, scheme: ReportSchemeItemModel
     items: filterData(scheme.content),
     attrs: filterData(scheme.descriptions),
   }, {
+    name: 'edit-scheme',
     transform(data: string, headers) {
       scheme.id ??= data;
       return scheme;
@@ -100,6 +105,7 @@ export function editSchemeMethod(reportId: string, scheme: ReportSchemeItemModel
 
 export function deleteSchemeMethod(reportId: string, scheme: ReportSchemeItemModel) {
   return request.Get(`/fdhb-pc/analysisManage/condProgramDelete`, {
+    name: 'delete-scheme',
     params: { id: scheme.id },
     transform(data: any, headers) {
       return scheme;
@@ -127,6 +133,7 @@ export function confirmSchemeMethod(reportId: string) {
 export function indicatorByReportIdMethod(reportId: string, filter = true) {
   return request.Get<ReportIndicatorModel[], any[]>(`fdhb-pc/analysisManage/getLast7Day`, {
     hitSource: 'update-indicator',
+    name: 'report-indicator',
     params: { healthAnalysisReportId: reportId },
     transform(data, headers) {
       const indicators = transformIndicators(data);
@@ -143,6 +150,7 @@ export function indicatorByReportIdMethod(reportId: string, filter = true) {
 export function indicatorByPatientIdMethod(patientId: string, filter = true) {
   return request.Get<ReportIndicatorModel[], any[]>(`/fdhb-pc/patientQuota/getCurQuovalByPatId`, {
     hitSource: 'update-indicator',
+    name: 'patient-indicator',
     params: { patientId },
     transform(data, headers) {
       const indicators = transformIndicators(data);

+ 4 - 4
vite.config.ts

@@ -79,15 +79,15 @@ export default defineConfig((configEnv) => {
       open: true,
       proxy: {
         '/prod-api': {
-          target: 'http://121.43.162.141:8001',
+          target: 'https://wx.hzliuzhi.com/admin',
           secure: false,
-          changeOrigin: false,
+          changeOrigin: true,
           logLevel: 'debug',
         },
         '/fdhb-pc': {
-          target: 'https://wx.hzliuzhi.com/manager',
+          target: 'https://wx.hzliuzhi.com/admin',
           secure: false,
-          changeOrigin: false,
+          changeOrigin: true,
           logLevel: 'debug',
         },
       },