消毒机设备
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.

171 lines
4.1 KiB

2 months ago
3 weeks ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 weeks ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
4 weeks ago
4 weeks ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <script lang="ts" setup>
  2. import SelectModal from 'components/common/SelectModal/index.vue'
  3. import FormulaConfig from 'components/formula/FormulaConfig.vue'
  4. import { FtMessage } from 'libs/message'
  5. import { computed, onMounted, ref, watchEffect } from 'vue'
  6. import { convertValuesToInt } from '@/libs/utils'
  7. import { useFormulaStore } from '@/stores/formulaStore'
  8. import { useHomeStore } from '@/stores/homeStore'
  9. /**
  10. * 配方选择页面组件
  11. * @description 负责处理配方选择逻辑设备状态判断及界面交互
  12. */
  13. // 状态管理
  14. const formulaStore = useFormulaStore()
  15. const homeStore = useHomeStore()
  16. // 组件状态
  17. const recipes = ref<Formula.FormulaItem[]>([]) // 配方列表
  18. const isModalOpen = ref(false) // 选择模态框是否打开
  19. const selectedValue = ref() // 选中的配方ID
  20. const isDeviceIdle = ref(homeStore.isDeviceIdle) // 设备是否空闲状态
  21. /**
  22. * @hook 生命周期钩子 - 挂载完成时执行
  23. * @description 初始化时检查配方列表若为空则重新获取
  24. */
  25. onMounted(() => {
  26. if (!formulaStore.formulaList || !formulaStore.formulaList.length) {
  27. formulaStore.initFormulaList()
  28. }
  29. })
  30. /**
  31. * @hook 响应式依赖监听
  32. * @description 监听store数据变化同步更新组件状态
  33. */
  34. watchEffect(() => {
  35. recipes.value = [...formulaStore.formulaList]
  36. isDeviceIdle.value = homeStore.isDeviceIdle
  37. })
  38. /**
  39. * @computed 计算属性 - 生成选择框选项
  40. * @returns {System.Option[]} 包含label和value的选项数组
  41. */
  42. const options = computed(() => {
  43. const list = formulaStore.formulaList
  44. const optionList: System.Option[] = []
  45. list.forEach((item: Formula.FormulaItem) => {
  46. optionList.push({
  47. label: item.name.toString(),
  48. value: item.formula_id,
  49. })
  50. })
  51. return optionList
  52. })
  53. /**
  54. * @function 确认选择处理函数
  55. * @param {any} value - 选中的配方ID
  56. * @description 关闭模态框更新选中配方并转换数值类型
  57. */
  58. const handleConfirm = (value: any) => {
  59. if (!value) {
  60. FtMessage.error('请选择配方')
  61. return
  62. }
  63. console.log('value---', value)
  64. isModalOpen.value = false
  65. let selectedFormula = {}
  66. formulaStore.formulaList.forEach((item: Formula.FormulaItem) => {
  67. if (item.formula_id === value) {
  68. selectedFormula = item
  69. }
  70. })
  71. const selectedFormulaToInt = convertValuesToInt(selectedFormula)
  72. formulaStore.updateSelectedFormulaDataByList(selectedFormulaToInt as Formula.FormulaItem)
  73. }
  74. /**
  75. * @function 取消选择处理函数
  76. * @description 关闭模态框
  77. */
  78. const handleCancel = () => {
  79. isModalOpen.value = false
  80. }
  81. /**
  82. * @function 打开选择配方模态框
  83. * @description 触发模态框显示
  84. */
  85. const onChooseFormula = () => {
  86. isModalOpen.value = true
  87. }
  88. /**
  89. * @function 应用默认配方
  90. * @description 重置配方数据为默认配置
  91. */
  92. const onDefaultFormula = () => {
  93. formulaStore.initFormulaData()
  94. }
  95. </script>
  96. <template>
  97. <div class="main-content">
  98. <div v-if="isDeviceIdle">
  99. <bt-button
  100. type="primary"
  101. button-text="选择配方"
  102. width="12vw"
  103. height="5vh"
  104. @click="onChooseFormula"
  105. >
  106. <template #icon>
  107. <el-icon>
  108. <Plus />
  109. </el-icon>
  110. </template>
  111. </bt-button>
  112. <bt-button
  113. button-text="默认配置"
  114. height="5vh"
  115. width="12vw"
  116. @click="onDefaultFormula"
  117. >
  118. <template #icon>
  119. <el-icon>
  120. <Operation />
  121. </el-icon>
  122. </template>
  123. </bt-button>
  124. </div>
  125. <div class="formula-config">
  126. <FormulaConfig type="home" />
  127. </div>
  128. <SelectModal
  129. v-if="isModalOpen"
  130. :options="options"
  131. :selected-value="selectedValue"
  132. placeholder="请选择"
  133. @confirm="handleConfirm"
  134. @cancel="handleCancel"
  135. />
  136. </div>
  137. </template>
  138. <style lang="scss" scoped>
  139. .main-content{
  140. overflow: hidden;
  141. height: auto;
  142. //background: $gradient-color;
  143. padding: 15px;
  144. .formula-config{
  145. display: grid;
  146. padding: 10px;
  147. width: 100%;
  148. }
  149. .formula-config-form{
  150. display: grid;
  151. grid-template-columns: 1fr 1fr;
  152. gap: 5px;
  153. }
  154. .formdata-input{
  155. width: 10vw;
  156. }
  157. }
  158. </style>