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

8 months ago
7 months ago
8 months ago
8 months ago
7 months ago
8 months ago
8 months ago
4 months ago
4 months ago
8 months ago
8 months ago
7 months ago
8 months ago
8 months ago
  1. import { defineStore } from 'pinia'
  2. import { ref, computed } from 'vue'
  3. import * as R from 'ramda'
  4. // import type {
  5. // BottleGroup,
  6. // ConsumableState,
  7. // ReactionPlate,
  8. // Tip,
  9. // } from '../../types/Index'
  10. // import type { PersistenceOptions } from 'pinia-plugin-persistedstate'
  11. import type {
  12. ConsumablesStateMessage,
  13. ReactionPlateGroup,
  14. IdCardPrompt
  15. } from '../../websocket/socket'
  16. // id : 1,11,21,31 优先选用 Color10 的索引1的颜色
  17. // 2,12,22,32 优先选用 Color10 的索引2的颜色
  18. // 10,20,30,40 优先选用 Color10 的索引0的颜色
  19. // 如果颜色已占用,就从扩展色(ColorExt)中选择一个
  20. const projColorExt = ['#A98A7B', '#424E82', '#2D4E4A', '#493E25', '#001DDC']
  21. const projColor10 = [
  22. '#B9C950',
  23. '#AC91D2',
  24. '#CA9B36',
  25. '#6BA4A6',
  26. '#87957E',
  27. '#4D86BA',
  28. '#83746D',
  29. '#785FA8',
  30. '#AAA192',
  31. '#F5B43F',
  32. ]
  33. export const useConsumablesStore = defineStore(
  34. 'consumables',
  35. () => {
  36. const consumableData = ref<ConsumablesStateMessage['data']>({
  37. tips: [{ tipNum: 0 }, { tipNum: 0 }, { tipNum: 0 }],
  38. reactionPlateGroup: Array.from({ length: 6 }, () => ({
  39. num: 0,
  40. isInstall: false,
  41. })),
  42. littBottleGroup: Array.from({ length: 6 }, () => ({
  43. num: 0,
  44. isInstall: false,
  45. })),
  46. larBottleGroup: Array.from({ length: 6 }, () => ({
  47. num: 0,
  48. isInstall: false,
  49. })),
  50. })
  51. //插入的当前ID卡信息
  52. const idCardInfo = ref<IdCardPrompt | null>({
  53. color: '',
  54. expiryDate: 0,
  55. id: 0,
  56. lotId: '',
  57. palteCode: 0,//palteCode 字段,接口命名错了。应该是plateCode
  58. projId: 0,
  59. projName: '',
  60. updateChipVersion: '',
  61. })
  62. function setIdCardInfo(data: IdCardPrompt | null){
  63. idCardInfo.value = data;
  64. }
  65. //id卡是否插入
  66. const isIdCardInserted = ref(false)
  67. let disableUpdateConsumableData: Boolean = false
  68. const setDisableUpdateConsumableData = (disable: Boolean) => {
  69. disableUpdateConsumableData = disable
  70. }
  71. function setConsumablesData(data: ConsumablesStateMessage['data']) {
  72. if (disableUpdateConsumableData) {
  73. return
  74. }
  75. if (!R.equals(consumableData.value, data)) {
  76. consumableData.value = data
  77. console.log('更新耗材:', data)
  78. }
  79. }
  80. function updateTipNum(index: number, num: number) {
  81. if (index < consumableData.value.tips.length && num >= 0) {
  82. consumableData.value.tips[index].tipNum = num
  83. }
  84. }
  85. function updateReactionPlateNum(index: number, num: number) {
  86. if (index < consumableData.value.reactionPlateGroup.length && num >= 0) {
  87. consumableData.value.reactionPlateGroup[index].num = num
  88. }
  89. }
  90. function updateLittleBottomNum(index: number, num: number) {
  91. if (index < consumableData.value.littBottleGroup.length && num >= 0) {
  92. consumableData.value.littBottleGroup[index].num = num
  93. }
  94. }
  95. function setIdCardInserted(status: boolean) {
  96. isIdCardInserted.value = status
  97. }
  98. // 每种项目还能做多少次,也就是项目对应的耗材总数。
  99. // 比如 如果有两组同类型的反应板和缓冲液(假设都是PCT),一个剩余20,一个剩余15. 那PCT耗材数目就是35.
  100. // 也就是反应板组 要经过 分组(去重)、累加。
  101. const projectsAvailable = computed(() => {
  102. return R.pipe(
  103. R.filter<ReactionPlateGroup>(g => !!g.projName && g.projName !== 'null'),
  104. R.groupBy<ReactionPlateGroup>(g => g.projName!),
  105. R.values,
  106. (groupArr) => R.map(R.reduce<ReactionPlateGroup, ReactionPlateGroup>((acc, curr) => {
  107. return { ...curr, num: (acc.num || 0) + (curr.num || 0) }
  108. }, {}), groupArr as ReactionPlateGroup[][])
  109. )(consumableData.value.reactionPlateGroup)
  110. })
  111. const tipCount = computed(() => {
  112. return consumableData.value.tips.reduce((acc, curr) => {
  113. return acc + curr.tipNum
  114. }, 0)
  115. })
  116. const projectIds = computed(() => {
  117. return R.pipe(
  118. //@ts-ignore
  119. R.filter((g) => g.projId !== null),
  120. //@ts-ignore
  121. R.map((g) => g.projId),
  122. R.uniq,
  123. R.sort((a, b) => {
  124. return a - b
  125. }),
  126. )(consumableData.value.reactionPlateGroup)
  127. })
  128. const projIdColorMap = computed(() => {
  129. const color10UsedMap = {}
  130. const colorExtUsedMap = {}
  131. const idColorMap = R.reduce(
  132. (acc, pId) => {
  133. const n = pId % 10
  134. const color = projColor10[n]
  135. if (!color10UsedMap[color]) {
  136. color10UsedMap[color] = true
  137. acc[pId] = color
  138. } else {
  139. const color = projColorExt.find((c) => {
  140. if (!colorExtUsedMap[c]) {
  141. colorExtUsedMap[c] = true
  142. return true
  143. }
  144. return false
  145. })
  146. acc[pId] = color
  147. }
  148. return acc
  149. },
  150. {},
  151. projectIds.value,
  152. )
  153. console.log('====== consumables : idColorMap :', idColorMap)
  154. return idColorMap
  155. })
  156. return {
  157. setIdCardInserted,
  158. isIdCardInserted,
  159. consumableData,
  160. setConsumablesData,
  161. updateReactionPlateNum,
  162. updateTipNum,
  163. updateLittleBottomNum,
  164. setDisableUpdateConsumableData,
  165. tipCount,
  166. projectsAvailable,
  167. projIdColorMap,
  168. idCardInfo,
  169. setIdCardInfo,
  170. }
  171. },
  172. // {
  173. // persist: <PersistenceOptions>{
  174. // key: 'consumablesStore',
  175. // storage: localStorage,
  176. // },
  177. // },
  178. )