visitor.store.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { defineStore } from 'pinia';
  2. import type { PulseAnalysisModel, RegisterModel } from '@/request/model';
  3. type Patient = { [K in keyof RegisterModel]?: RegisterModel[K] | string };
  4. export const useVisitor = defineStore('visitor', () => {
  5. const patientId = ref<string>();
  6. const resultId = ref<string>();
  7. const reportId = ref<string>();
  8. const pulseReport = shallowRef<PulseAnalysisModel>();
  9. const patient = shallowRef<Patient>();
  10. const $reset = () => {
  11. patientId.value = '';
  12. resultId.value = '';
  13. reportId.value = '';
  14. pulseReport.value = void 0;
  15. patient.value = void 0;
  16. };
  17. function updatePulseReport(report: PulseAnalysisModel, patient?: string) {
  18. if (patientId.value?.toString() !== patient || !pulseReport.value?.results) {
  19. if (patient) patientId.value = patient;
  20. pulseReport.value = report;
  21. }
  22. }
  23. function updatePatient(data: Patient, id?: string) {
  24. if (!id || id === patientId.value) patient.value = data;
  25. else patient.value = void 0;
  26. }
  27. return { patientId, resultId, reportId, pulseReport, $reset, updatePulseReport, patient, updatePatient };
  28. });