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.
196 lines
5.5 KiB
196 lines
5.5 KiB
import { defineStore } from 'pinia'
|
|
import { ref, computed } from 'vue'
|
|
import * as R from 'ramda'
|
|
// import type {
|
|
// BottleGroup,
|
|
// ConsumableState,
|
|
// ReactionPlate,
|
|
// Tip,
|
|
// } from '../../types/Index'
|
|
// import type { PersistenceOptions } from 'pinia-plugin-persistedstate'
|
|
import type {
|
|
ConsumablesStateMessage,
|
|
ReactionPlateGroup,
|
|
IdCardPrompt
|
|
} from '../../websocket/socket'
|
|
|
|
// id : 1,11,21,31 优先选用 Color10 的索引1的颜色
|
|
// 2,12,22,32 优先选用 Color10 的索引2的颜色
|
|
// 10,20,30,40 优先选用 Color10 的索引0的颜色
|
|
// 如果颜色已占用,就从扩展色(ColorExt)中选择一个
|
|
const projColorExt = ['#A98A7B', '#424E82', '#2D4E4A', '#493E25', '#001DDC']
|
|
const projColor10 = [
|
|
'#B9C950',
|
|
'#AC91D2',
|
|
'#CA9B36',
|
|
'#6BA4A6',
|
|
'#87957E',
|
|
'#4D86BA',
|
|
'#83746D',
|
|
'#785FA8',
|
|
'#AAA192',
|
|
'#F5B43F',
|
|
]
|
|
|
|
export const useConsumablesStore = defineStore(
|
|
'consumables',
|
|
() => {
|
|
const consumableData = ref<ConsumablesStateMessage['data']>({
|
|
tips: [{ tipNum: 0 }, { tipNum: 0 }, { tipNum: 0 }],
|
|
reactionPlateGroup: Array.from({ length: 6 }, () => ({
|
|
num: 0,
|
|
isInstall: false,
|
|
})),
|
|
littBottleGroup: Array.from({ length: 6 }, () => ({
|
|
num: 0,
|
|
isInstall: false,
|
|
})),
|
|
larBottleGroup: Array.from({ length: 6 }, () => ({
|
|
num: 0,
|
|
isInstall: false,
|
|
})),
|
|
})
|
|
|
|
//插入的当前ID卡信息
|
|
const idCardInfo = ref<IdCardPrompt | null>({
|
|
color: '',
|
|
expiryDate: 0,
|
|
id: 0,
|
|
lotId: '',
|
|
palteCode: 0,//palteCode 字段,接口命名错了。应该是plateCode
|
|
projId: 0,
|
|
projName: '',
|
|
updateChipVersion: '',
|
|
})
|
|
|
|
function setIdCardInfo(data: IdCardPrompt | null){
|
|
idCardInfo.value = data;
|
|
}
|
|
|
|
//id卡是否插入
|
|
const isIdCardInserted = ref(false)
|
|
|
|
let disableUpdateConsumableData: Boolean = false
|
|
const setDisableUpdateConsumableData = (disable: Boolean) => {
|
|
disableUpdateConsumableData = disable
|
|
}
|
|
|
|
function setConsumablesData(data: ConsumablesStateMessage['data']) {
|
|
if (disableUpdateConsumableData) {
|
|
return
|
|
}
|
|
if (!R.equals(consumableData.value, data)) {
|
|
consumableData.value = data
|
|
console.log('更新耗材:', data)
|
|
}
|
|
}
|
|
|
|
function updateTipNum(index: number, num: number) {
|
|
if (index < consumableData.value.tips.length && num >= 0) {
|
|
consumableData.value.tips[index].tipNum = num
|
|
}
|
|
}
|
|
function updateReactionPlateNum(index: number, num: number) {
|
|
if (index < consumableData.value.reactionPlateGroup.length && num >= 0) {
|
|
consumableData.value.reactionPlateGroup[index].num = num
|
|
}
|
|
}
|
|
function updateLittleBottomNum(index: number, num: number) {
|
|
if (index < consumableData.value.littBottleGroup.length && num >= 0) {
|
|
consumableData.value.littBottleGroup[index].num = num
|
|
}
|
|
}
|
|
|
|
function setIdCardInserted(status: boolean) {
|
|
isIdCardInserted.value = status
|
|
}
|
|
// 每种项目还能做多少次,也就是项目对应的耗材总数。
|
|
// 比如 如果有两组同类型的反应板和缓冲液(假设都是PCT),一个剩余20,一个剩余15. 那PCT耗材数目就是35.
|
|
// 也就是反应板组 要经过 分组(去重)、累加。
|
|
const projectsAvailable = computed(() => {
|
|
return R.pipe(
|
|
R.filter<ReactionPlateGroup>(g => !!g.projName && g.projName !== 'null'),
|
|
R.groupBy<ReactionPlateGroup>(g => g.projName!),
|
|
R.values,
|
|
(groupArr) => R.map(R.reduce<ReactionPlateGroup, ReactionPlateGroup>((acc, curr) => {
|
|
return { ...curr, num: (acc.num || 0) + (curr.num || 0) }
|
|
}, {}), groupArr as ReactionPlateGroup[][])
|
|
)(consumableData.value.reactionPlateGroup)
|
|
})
|
|
|
|
const tipCount = computed(() => {
|
|
return consumableData.value.tips.reduce((acc, curr) => {
|
|
return acc + curr.tipNum
|
|
}, 0)
|
|
})
|
|
|
|
const projectIds = computed(() => {
|
|
return R.pipe(
|
|
//@ts-ignore
|
|
R.filter((g) => g.projId !== null),
|
|
//@ts-ignore
|
|
R.map((g) => g.projId),
|
|
R.uniq,
|
|
R.sort((a, b) => {
|
|
return a - b
|
|
}),
|
|
)(consumableData.value.reactionPlateGroup)
|
|
})
|
|
|
|
const projIdColorMap = computed(() => {
|
|
const color10UsedMap = {}
|
|
const colorExtUsedMap = {}
|
|
|
|
const idColorMap = R.reduce(
|
|
(acc, pId) => {
|
|
const n = pId % 10
|
|
const color = projColor10[n]
|
|
if (!color10UsedMap[color]) {
|
|
color10UsedMap[color] = true
|
|
acc[pId] = color
|
|
} else {
|
|
const color = projColorExt.find((c) => {
|
|
if (!colorExtUsedMap[c]) {
|
|
colorExtUsedMap[c] = true
|
|
return true
|
|
}
|
|
return false
|
|
})
|
|
acc[pId] = color
|
|
}
|
|
return acc
|
|
},
|
|
{},
|
|
projectIds.value,
|
|
)
|
|
console.log('====== consumables : idColorMap :', idColorMap)
|
|
return idColorMap
|
|
})
|
|
|
|
return {
|
|
setIdCardInserted,
|
|
isIdCardInserted,
|
|
|
|
consumableData,
|
|
setConsumablesData,
|
|
updateReactionPlateNum,
|
|
updateTipNum,
|
|
updateLittleBottomNum,
|
|
setDisableUpdateConsumableData,
|
|
|
|
tipCount,
|
|
projectsAvailable,
|
|
|
|
projIdColorMap,
|
|
|
|
idCardInfo,
|
|
setIdCardInfo,
|
|
}
|
|
},
|
|
// {
|
|
// persist: <PersistenceOptions>{
|
|
// key: 'consumablesStore',
|
|
// storage: localStorage,
|
|
// },
|
|
// },
|
|
)
|