forked from gzt/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
84 lines
2.1 KiB
import { BloodTypeItem } from '@/services/Index/testTube'
|
|
import { ProjectInfo } from '@/websocket/socket'
|
|
import { defineStore } from 'pinia'
|
|
import { ref, computed } from 'vue'
|
|
import * as R from 'ramda'
|
|
|
|
// 这个store用来存储相对稳定的数据
|
|
export const useSettingTestTubeStore = defineStore(
|
|
'settingTestTube',
|
|
() => {
|
|
const bloodTypes = ref<BloodTypeItem[] | undefined>(undefined)
|
|
const selectedBloodTypeKey = ref()
|
|
const setBloodTypes = (items: BloodTypeItem[]) => {
|
|
bloodTypes.value = items
|
|
}
|
|
const projIdsBySampleMap = ref({})
|
|
const supportedProjects = ref<ProjectInfo[] | undefined>(undefined)
|
|
const setSupportedProjects = (projects: ProjectInfo[]) => {
|
|
supportedProjects.value = projects
|
|
const sampleMap = {}
|
|
if (projects && projects.length) {
|
|
projects.forEach(item => {
|
|
const { supportBloodTypes } = item;
|
|
if(supportBloodTypes && supportBloodTypes.length){
|
|
supportBloodTypes.forEach(bloodItem => {
|
|
if(sampleMap[bloodItem]){
|
|
let list = [...sampleMap[bloodItem], item]
|
|
sampleMap[bloodItem] = list
|
|
}else{
|
|
sampleMap[bloodItem] = [item]
|
|
}
|
|
})
|
|
}
|
|
})
|
|
projIdsBySampleMap.value = sampleMap
|
|
}
|
|
}
|
|
|
|
const projectIdMap = computed(() => {
|
|
return R.reduce(
|
|
(acc, curr) => {
|
|
acc[curr.projId] = curr
|
|
return acc
|
|
},
|
|
{},
|
|
supportedProjects.value || [],
|
|
)
|
|
})
|
|
|
|
const bloodTypeKeyMap = computed(() => {
|
|
return R.reduce(
|
|
(acc, curr) => {
|
|
acc[curr.key] = curr
|
|
return acc
|
|
},
|
|
{},
|
|
bloodTypes.value || [],
|
|
)
|
|
})
|
|
|
|
const setSelectedBloodTypeKey = (bloodType: string | undefined) => {
|
|
selectedBloodTypeKey.value = bloodType
|
|
}
|
|
|
|
return {
|
|
bloodTypes,
|
|
setBloodTypes,
|
|
|
|
supportedProjects,
|
|
setSupportedProjects,
|
|
|
|
projectIdMap,
|
|
bloodTypeKeyMap,
|
|
|
|
projIdsBySampleMap,
|
|
|
|
selectedBloodTypeKey,
|
|
setSelectedBloodTypeKey,
|
|
}
|
|
},
|
|
{
|
|
persist: true,
|
|
},
|
|
)
|