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

220 lines
5.2 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 weeks ago
3 weeks ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
4 weeks ago
2 months ago
4 weeks ago
4 weeks ago
2 months ago
4 weeks ago
2 months ago
4 weeks ago
4 weeks ago
2 months ago
2 months ago
2 months ago
4 weeks ago
2 months ago
2 months ago
  1. <script lang="ts" setup>
  2. import { syncSendCmd } from 'apis/system'
  3. import { ElMessageBox } from 'element-plus'
  4. import { onMounted, ref, watch, watchEffect } from 'vue'
  5. import { FtMessage } from '@/libs/message'
  6. import { FtMessageBox } from '@/libs/messageBox'
  7. import { convertValuesToInt } from '@/libs/utils'
  8. import { useFormulaStore } from '@/stores/formulaStore'
  9. const formulaStore = useFormulaStore()
  10. const selectedIndex = ref<number | null>(0)
  11. const recipes = ref<Formula.FormulaItem[]>([])
  12. const currectFormula = ref<Formula.FormulaItem>()
  13. // 移除列表的选中
  14. const selectedIndexRest = async () => {
  15. selectedIndex.value = null
  16. console.log('子组件方法被调用')
  17. }
  18. // 暴露方法给父组件
  19. defineExpose({
  20. selectedIndexRest,
  21. })
  22. onMounted(() => {
  23. initFormulaList()
  24. })
  25. watchEffect(() => {
  26. recipes.value = formulaStore.formulaList
  27. if (formulaStore.formulaList) {
  28. selectedIndex.value = formulaStore.formulaList.length - 1
  29. }
  30. })
  31. watch(selectedIndex, () => {
  32. if (selectedIndex.value != null) {
  33. const currentIndex: number = selectedIndex.value
  34. const selectItem: Formula.FormulaItem = recipes.value[currentIndex]
  35. const item = convertValuesToInt(selectItem) as Formula.FormulaItem
  36. formulaStore.updateSelectedFormulaData(item)
  37. }
  38. })
  39. const initFormulaList = () => {
  40. if (formulaStore.formulaList && formulaStore.formulaList.length) {
  41. recipes.value = formulaStore.formulaList as Formula.FormulaItem[]
  42. }
  43. else {
  44. formulaStore.initFormulaList()
  45. }
  46. }
  47. const selectRecipe = (item: Formula.FormulaItem, index: number) => {
  48. selectedIndex.value = index
  49. formulaStore.updateSelectedIndex(index)
  50. console.log('selectedIndex--', selectedIndex.value)
  51. item = convertValuesToInt(item) as Formula.FormulaItem
  52. formulaStore.updateSelectedFormulaData(item)
  53. }
  54. const onStartFormula = (item: Formula.FormulaItem) => {
  55. formulaStore.updateSelectedFormulaData(item)
  56. // 执行配方时做设备的状态检查
  57. FtMessageBox.warning('请确认是否使用此配方进行消毒?').then(() => {
  58. currectFormula.value = item
  59. if (item.formula_id) {
  60. const params = {
  61. className: 'DisinfectionCtrlServiceExt',
  62. fnName: 'startWithFormula',
  63. params: {
  64. formulaid: item.formula_id,
  65. },
  66. }
  67. syncSendCmd(params).then((res) => {
  68. if (res.ackcode === 0) {
  69. // 把选择执行的配方同步至运行参数
  70. formulaStore.updateSelectedFormulaDataByList(item)
  71. FtMessage.success('已开始消毒')
  72. }
  73. })
  74. }
  75. })
  76. }
  77. const deleteRecipe = (item: Formula.FormulaItem) => {
  78. ElMessageBox.confirm('请确认是否删除?', '删除', {
  79. confirmButtonText: '确认',
  80. cancelButtonText: '取消',
  81. type: 'warning',
  82. }).then(() => {
  83. if (item.formula_id) {
  84. const delParams = {
  85. className: 'SettingMgrService',
  86. fnName: 'delFormula',
  87. params: {
  88. formula_id: item.formula_id,
  89. },
  90. }
  91. syncSendCmd(delParams).then(() => {
  92. FtMessage.success('操作成功')
  93. formulaStore.updateSelectedIndex(0)
  94. formulaStore.initFormulaList()
  95. })
  96. }
  97. })
  98. }
  99. </script>
  100. <template>
  101. <div v-if="recipes.length" class="recipe-management">
  102. <ul class="recipe-list">
  103. <li
  104. v-for="(item, index) in recipes"
  105. :key="index"
  106. :class="{ selected: selectedIndex === index }"
  107. @click="selectRecipe(item, index)"
  108. >
  109. <span class="formula-name">{{ item.name }}</span>
  110. <div class="actions">
  111. <el-button class="view-button" @click.stop="onStartFormula(item)">
  112. 执行配方
  113. </el-button>
  114. <el-button class="delete-button" @click.stop="deleteRecipe(item)">
  115. 删除
  116. </el-button>
  117. </div>
  118. </li>
  119. </ul>
  120. </div>
  121. <div v-else>
  122. <el-empty description="description">
  123. <template #description>
  124. <span style="color: #ababab">未配置配方</span>
  125. </template>
  126. </el-empty>
  127. </div>
  128. </template>
  129. <style scoped>
  130. .recipe-management {
  131. border: 1px solid #ccc;
  132. padding: 10px;
  133. border-radius: 5px;
  134. overflow: auto;
  135. width: 30vw;
  136. }
  137. .recipe-list {
  138. list-style: none;
  139. padding: 0;
  140. margin: 0;
  141. .formula-name {
  142. font-size: 1.2rem;
  143. color: var(--el-text-color-regular);
  144. width: 10rem;
  145. }
  146. }
  147. .recipe-list li {
  148. display: flex;
  149. align-items: center;
  150. justify-content: space-between;
  151. padding: 10px;
  152. border-radius: 4px;
  153. margin-bottom: 8px;
  154. transition: all 0.2s;
  155. cursor: pointer;
  156. }
  157. .recipe-list li:hover {
  158. background-color: #f5f7fa;
  159. }
  160. .recipe-list li.selected {
  161. background-color: #e6f7ff;
  162. border-left: 5px solid #1890ff;
  163. padding: 9px;
  164. }
  165. .actions {
  166. display: flex;
  167. align-items: center;
  168. }
  169. .view-button,
  170. .delete-button {
  171. font-size: 1rem;
  172. border: none;
  173. padding: 4px 8px;
  174. border-radius: 3px;
  175. cursor: pointer;
  176. margin-right: 5px;
  177. transition: all 0.3s;
  178. }
  179. .view-button {
  180. background-color: #e6f0ff;
  181. color: #1890ff;
  182. }
  183. .view-button:hover {
  184. background-color: #1890ff;
  185. color: white;
  186. }
  187. .delete-button {
  188. background-color: #ffe6e6;
  189. color: #ff4d4f;
  190. }
  191. .delete-button:hover {
  192. background-color: #ff4d4f;
  193. color: white;
  194. }
  195. .selected-icon {
  196. color: #0681f5;
  197. /* margin-left: 8px; */
  198. }
  199. </style>