A8000
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.1 KiB

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
  1. import { BloodTypeItem } from '@/services/Index/testTube'
  2. import { ProjectInfo } from '@/websocket/socket'
  3. import { defineStore } from 'pinia'
  4. import { ref, computed } from 'vue'
  5. import * as R from 'ramda'
  6. // 这个store用来存储相对稳定的数据
  7. export const useSettingTestTubeStore = defineStore(
  8. 'settingTestTube',
  9. () => {
  10. const bloodTypes = ref<BloodTypeItem[] | undefined>(undefined)
  11. const selectedBloodTypeKey = ref()
  12. const setBloodTypes = (items: BloodTypeItem[]) => {
  13. bloodTypes.value = items
  14. }
  15. const projIdsBySampleMap = ref({})
  16. const supportedProjects = ref<ProjectInfo[] | undefined>(undefined)
  17. const setSupportedProjects = (projects: ProjectInfo[]) => {
  18. supportedProjects.value = projects
  19. const sampleMap = {}
  20. if (projects && projects.length) {
  21. projects.forEach(item => {
  22. const { supportBloodTypes } = item;
  23. if(supportBloodTypes && supportBloodTypes.length){
  24. supportBloodTypes.forEach(bloodItem => {
  25. if(sampleMap[bloodItem]){
  26. let list = [...sampleMap[bloodItem], item]
  27. sampleMap[bloodItem] = list
  28. }else{
  29. sampleMap[bloodItem] = [item]
  30. }
  31. })
  32. }
  33. })
  34. projIdsBySampleMap.value = sampleMap
  35. }
  36. }
  37. const projectIdMap = computed(() => {
  38. return R.reduce(
  39. (acc, curr) => {
  40. acc[curr.projId] = curr
  41. return acc
  42. },
  43. {},
  44. supportedProjects.value || [],
  45. )
  46. })
  47. const bloodTypeKeyMap = computed(() => {
  48. return R.reduce(
  49. (acc, curr) => {
  50. acc[curr.key] = curr
  51. return acc
  52. },
  53. {},
  54. bloodTypes.value || [],
  55. )
  56. })
  57. const setSelectedBloodTypeKey = (bloodType: string | undefined) => {
  58. selectedBloodTypeKey.value = bloodType
  59. }
  60. return {
  61. bloodTypes,
  62. setBloodTypes,
  63. supportedProjects,
  64. setSupportedProjects,
  65. projectIdMap,
  66. bloodTypeKeyMap,
  67. projIdsBySampleMap,
  68. selectedBloodTypeKey,
  69. setSelectedBloodTypeKey,
  70. }
  71. },
  72. {
  73. persist: true,
  74. },
  75. )