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.

213 lines
5.8 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. '#5751c480',//'#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 ballColor = ref()
  37. const consumableData = ref<ConsumablesStateMessage['data']>({
  38. tips: [{ tipNum: 0 }, { tipNum: 0 }, { tipNum: 0 }],
  39. reactionPlateGroup: Array.from({ length: 6 }, () => ({
  40. num: 0,
  41. isInstall: false,
  42. })),
  43. littBottleGroup: Array.from({ length: 6 }, () => ({
  44. num: 0,
  45. isInstall: false,
  46. })),
  47. larBottleGroup: Array.from({ length: 6 }, () => ({
  48. num: 0,
  49. isInstall: false,
  50. })),
  51. })
  52. //插入的当前ID卡信息
  53. const idCardInfo = ref<IdCardPrompt | null>({
  54. color: '',
  55. expiryDate: 0,
  56. id: 0,
  57. lotId: '',
  58. palteCode: 0,//palteCode 字段,接口命名错了。应该是plateCode
  59. projId: 0,
  60. projName: '',
  61. updateChipVersion: '',
  62. })
  63. function setIdCardInfo(data: IdCardPrompt | null){
  64. idCardInfo.value = data;
  65. }
  66. //id卡是否插入
  67. const isIdCardInserted = ref(false)
  68. let disableUpdateConsumableData: Boolean = false
  69. const setDisableUpdateConsumableData = (disable: Boolean) => {
  70. disableUpdateConsumableData = disable
  71. }
  72. function setConsumablesData(data: ConsumablesStateMessage['data']) {
  73. if (disableUpdateConsumableData) {
  74. return
  75. }
  76. if (!R.equals(consumableData.value, data)) {
  77. consumableData.value = data
  78. console.log('更新耗材:', data)
  79. }
  80. }
  81. function updateTipNum(index: number, num: number) {
  82. if (index < consumableData.value.tips.length && num >= 0) {
  83. consumableData.value.tips[index].tipNum = num
  84. }
  85. }
  86. function updateReactionPlateNum(index: number, num: number) {
  87. if (index < consumableData.value.reactionPlateGroup.length && num >= 0) {
  88. consumableData.value.reactionPlateGroup[index].num = num
  89. }
  90. }
  91. function updateLittleBottomNum(index: number, num: number) {
  92. if (index < consumableData.value.littBottleGroup.length && num >= 0) {
  93. consumableData.value.littBottleGroup[index].num = num
  94. }
  95. }
  96. function setIdCardInserted(status: boolean) {
  97. isIdCardInserted.value = status
  98. }
  99. // 每种项目还能做多少次,也就是项目对应的耗材总数。
  100. // 比如 如果有两组同类型的反应板和缓冲液(假设都是PCT),一个剩余20,一个剩余15. 那PCT耗材数目就是35.
  101. // 也就是反应板组 要经过 分组(去重)、累加。
  102. const projectsAvailable = computed(() => {
  103. return R.pipe(
  104. R.filter<ReactionPlateGroup>(g => !!g.projName && g.projName !== 'null'),
  105. R.groupBy<ReactionPlateGroup>(g => g.projName!),
  106. R.values,
  107. (groupArr) => R.map(R.reduce<ReactionPlateGroup, ReactionPlateGroup>((acc, curr) => {
  108. return { ...curr, num: (acc.num || 0) + (curr.num || 0) }
  109. }, {}), groupArr as ReactionPlateGroup[][])
  110. )(consumableData.value.reactionPlateGroup)
  111. })
  112. const tipCount = computed(() => {
  113. return consumableData.value.tips.reduce((acc, curr) => {
  114. return acc + curr.tipNum
  115. }, 0)
  116. })
  117. const projectIds = computed(() => {
  118. return R.pipe(
  119. //@ts-ignore
  120. R.filter((g) => g.projId !== null),
  121. //@ts-ignore
  122. R.map((g) => g.projId),
  123. R.uniq,
  124. R.sort((a, b) => {
  125. return a - b
  126. }),
  127. )(consumableData.value.reactionPlateGroup)
  128. })
  129. const projIdColorMap = computed(() => {
  130. const color10UsedMap = {}
  131. const colorExtUsedMap = {}
  132. const idColorMap = R.reduce(
  133. (acc, pId) => {
  134. const n = pId % 10
  135. const color = projColor10[n]
  136. if (!color10UsedMap[color]) {
  137. color10UsedMap[color] = true
  138. acc[pId] = color
  139. } else {
  140. const color = projColorExt.find((c) => {
  141. if (!colorExtUsedMap[c]) {
  142. colorExtUsedMap[c] = true
  143. return true
  144. }
  145. return false
  146. })
  147. acc[pId] = color
  148. }
  149. return acc
  150. },
  151. {},
  152. projectIds.value,
  153. )
  154. console.log('====== consumables : idColorMap :', idColorMap)
  155. return idColorMap
  156. })
  157. const getBallColor = (projId: number) => {
  158. const color = projIdColorMap.value[projId]
  159. ballColor.value = color
  160. return color
  161. }
  162. const setBallColor = (color: string) => {
  163. console.log('color--', color)
  164. ballColor.value = color
  165. }
  166. return {
  167. setIdCardInserted,
  168. isIdCardInserted,
  169. consumableData,
  170. setConsumablesData,
  171. updateReactionPlateNum,
  172. updateTipNum,
  173. updateLittleBottomNum,
  174. setDisableUpdateConsumableData,
  175. tipCount,
  176. projectsAvailable,
  177. projIdColorMap,
  178. idCardInfo,
  179. setIdCardInfo,
  180. ballColor,
  181. getBallColor,
  182. setBallColor,
  183. }
  184. },
  185. // {
  186. // persist: <PersistenceOptions>{
  187. // key: 'consumablesStore',
  188. // storage: localStorage,
  189. // },
  190. // },
  191. )