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

224 lines
5.7 KiB

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