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

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