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.

284 lines
8.0 KiB

6 days ago
6 days ago
6 days ago
6 days ago
6 days ago
6 days ago
6 days ago
6 days ago
6 days ago
6 days ago
5 days ago
6 days ago
6 days ago
6 days ago
6 days ago
6 days ago
6 days ago
  1. <script setup lang="ts">
  2. import { createCraft, delCraft, getCraftList as getCraftListApi, updateCraft } from 'apis/crafts'
  3. import { getSolsList } from 'apis/solution'
  4. import { ElMessageBox } from 'element-plus'
  5. import { FtMessage } from 'libs/message'
  6. import { socket } from 'libs/socket'
  7. import { useHomeStore } from 'stores/homeStore'
  8. import { onMounted, onUnmounted, ref } from 'vue'
  9. const loading = ref(false)
  10. const statisticNumber = ref(0)
  11. const homeStore = useHomeStore()
  12. onMounted(async () => {
  13. loading.value = true
  14. await getSolutionList()
  15. await getCraftList()
  16. loading.value = false
  17. socket.init(receiveMessage, 'pump_position')
  18. })
  19. /* onUnmounted(() => {
  20. socket.unregisterCallback(receiveMessage, 'pump_position')
  21. }) */
  22. const receiveMessage = (data: number) => {
  23. console.log(`接收到泵的转数${data}`)
  24. statisticNumber.value = statisticNumber.value + data
  25. }
  26. const form = ref<Craft.CraftItem>({})
  27. const formRef = ref()
  28. const rules = {
  29. solutionId: [
  30. { required: true, message: '请选择溶液', trigger: 'change' },
  31. ],
  32. concentration: [
  33. { required: true, message: '请输入溶液浓度', trigger: 'blur' },
  34. ],
  35. volume: [
  36. { required: true, message: '请输入加液量', trigger: 'blur' },
  37. ],
  38. revolutions: [
  39. { required: true, message: '请输入蠕动泵转速', trigger: 'blur' },
  40. ],
  41. }
  42. const solutionList = ref<Solution.SolutionItem[]>([])
  43. const getSolutionList = async () => {
  44. solutionList.value = (await getSolsList()).list
  45. }
  46. const craftList = ref<Craft.CraftItem[]>([])
  47. const getCraftList = async () => {
  48. craftList.value = (await getCraftListApi()).list
  49. form.value = {}
  50. }
  51. const save = async () => {
  52. const valid = await formRef.value.validate()
  53. if (!valid) {
  54. return
  55. }
  56. if (form.value.id) {
  57. await updateCraft(form.value)
  58. }
  59. else {
  60. await createCraft(form.value)
  61. }
  62. loading.value = true
  63. await getCraftList()
  64. loading.value = false
  65. FtMessage.success('保存成功')
  66. }
  67. const formatName = (data: Craft.CraftItem) => {
  68. const item = solutionList.value.find(item => item.id === data.solutionId)
  69. return `${item?.name}-${data.concentration}%-${data.volume}mL`
  70. }
  71. const nameClick = (item: Craft.CraftItem) => {
  72. const solution = solutionList.value.find(s => s.id === item.solutionId)
  73. form.value = {
  74. ...item,
  75. }
  76. }
  77. const delHandle = async (id: number | undefined) => {
  78. if (!id) {
  79. return
  80. }
  81. await ElMessageBox.confirm('确定删除吗?', '提示', {
  82. confirmButtonText: '确定',
  83. cancelButtonText: '取消',
  84. type: 'warning',
  85. })
  86. await delCraft(`${id}`)
  87. loading.value = true
  88. await getCraftList()
  89. loading.value = false
  90. FtMessage.success('删除成功')
  91. }
  92. let currentCommandId = ''
  93. // 正转 反转
  94. const pumpRotate = async (direction: string) => {
  95. const valid = await formRef.value.validate()
  96. if (!valid) {
  97. return
  98. }
  99. currentCommandId = Date.now().toString()
  100. const params = {
  101. commandId: currentCommandId,
  102. command: 'pump_rotate_start',
  103. params: {
  104. direction,
  105. position: form.value.revolutions,
  106. solutionId: form.value.solutionId,
  107. concentration: form.value.concentration,
  108. },
  109. }
  110. await homeStore.sendControl(params)
  111. }
  112. // 停止
  113. const pumpStop = async () => {
  114. const valid = await formRef.value.validate()
  115. if (!valid) {
  116. return
  117. }
  118. currentCommandId = Date.now().toString()
  119. const params = {
  120. commandId: currentCommandId,
  121. command: 'pump_rotate_stop',
  122. params: {
  123. solutionId: form.value.solutionId,
  124. concentration: form.value.concentration,
  125. },
  126. }
  127. await homeStore.sendControl(params)
  128. }
  129. // 预充
  130. const pumpPreFill = async () => {
  131. const valid = await formRef.value.validate()
  132. if (!valid) {
  133. return
  134. }
  135. currentCommandId = Date.now().toString()
  136. const params = {
  137. commandId: currentCommandId,
  138. command: 'solution_pre_fill_start',
  139. params: {
  140. solutionId: form.value.solutionId,
  141. concentration: form.value.concentration,
  142. },
  143. }
  144. await homeStore.sendControl(params)
  145. }
  146. // 加液
  147. const pumpAddSolution = async () => {
  148. const valid = await formRef.value.validate()
  149. if (!valid) {
  150. return
  151. }
  152. currentCommandId = Date.now().toString()
  153. const params = {
  154. commandId: currentCommandId,
  155. command: 'solution_add_start',
  156. params: {
  157. solutionId: form.value.solutionId,
  158. concentration: form.value.concentration,
  159. position: form.value.revolutions,
  160. },
  161. }
  162. await homeStore.sendControl(params)
  163. }
  164. </script>
  165. <template lang="pug">
  166. div(class="craft-box")
  167. el-card(v-loading="loading")
  168. div(class="button-box")
  169. ft-button(type="primary" @click="() => form = {}")
  170. | 添加配方
  171. ft-button(type="danger" :disabled="!form.id" :click-handle="() => delHandle(form.id)")
  172. | 删除配方
  173. div(class="list-box")
  174. p(v-for="item in craftList" :key="item.id" class="name" :class="{ 'active-name': item.id === form.id }" @click="() => nameClick(item)")
  175. | {{ formatName(item) }}
  176. el-card(v-loading="loading")
  177. template(#header)
  178. span(v-show="form.id") 编辑配方
  179. span(v-show="!form.id") 新增配方
  180. el-form(ref="formRef" size="large" :model="form" :rules="rules" label-width="auto")
  181. el-form-item(label="溶液名称" prop="solutionId")
  182. el-select(v-model="form.solutionId" placeholder="请选择溶液")
  183. el-option(v-for="item in solutionList" :key="item.id" :label="item.name" :value="item.id")
  184. el-form-item(label="溶液浓度" prop="concentration")
  185. ft-input(v-model="form.concentration" placeholder="请输入溶液浓度" layoutName="number")
  186. template(#append)
  187. span %
  188. el-form-item(label="加液量" prop="volume")
  189. ft-input(v-model="form.volume" placeholder="请输入加液量" layoutName="number")
  190. template(#append)
  191. span mL
  192. el-form-item(label="蠕动泵转数" prop="revolutions")
  193. ft-input(v-model="form.revolutions" placeholder="请输入蠕动泵转数" layoutName="number")
  194. template(#append)
  195. span r
  196. div.statistic-box
  197. ft-button(type="default" size="small" :click-handle="()=>statisticNumber=0")
  198. | 重置
  199. span 蠕动泵体积及转数统计
  200. el-statistic(:value="statisticNumber")
  201. ft-button(type="default" size="small" :click-handle="()=>form.revolutions=statisticNumber")
  202. | 设置
  203. div.form-button-box
  204. div
  205. ft-button(type="primary" size="large" :click-handle="()=>pumpRotate('FORWARD')")
  206. | 加液
  207. ft-button(type="danger" size="large" :click-handle="()=>pumpStop()")
  208. | 停止
  209. div
  210. ft-button(type="primary" size="large" :click-handle="()=>pumpPreFill()")
  211. | 预充
  212. ft-button(type="primary" size="large" :click-handle="save")
  213. | 保存
  214. </template>
  215. <style scoped lang="stylus">
  216. .craft-box
  217. background transparent !important
  218. box-shadow none !important
  219. display grid
  220. grid-template-columns 1fr 2.5fr
  221. grid-gap 20px
  222. .el-card
  223. display flex
  224. flex-direction column
  225. border-radius 10px
  226. :deep(.el-card__body)
  227. display flex
  228. flex-direction column
  229. justify-content space-between
  230. height 100%
  231. padding 0
  232. overflow hidden
  233. .button-box
  234. display flex
  235. justify-content center
  236. padding 20px 0
  237. .list-box
  238. flex 1
  239. padding 0 0 10px
  240. overflow auto
  241. border-top 1px solid #EBEEF5
  242. .name
  243. padding 10px 20px
  244. cursor pointer
  245. border-bottom 1px solid #EBEEF5
  246. border-left 3px solid transparent
  247. transition all 0.5s
  248. .active-name
  249. border-left 3px solid #409EFF
  250. background rgba(64, 158, 255, 0.2)
  251. .el-form
  252. padding 20px 150px
  253. .statistic-box
  254. display flex
  255. justify-content center
  256. align-items center
  257. .el-statistic
  258. margin 0 30px
  259. .form-button-box
  260. display flex
  261. justify-content space-evenly
  262. margin-bottom 30px
  263. .ft-button
  264. width 90px
  265. :deep(.el-input-group__append)
  266. width 50px
  267. </style>