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.

479 lines
14 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. <script setup lang="ts">
  2. import AddLiquid from 'components/home/AddLiquid/index.vue'
  3. import SelectCraft from 'components/home/SelectCraft/index.vue'
  4. import SetTemperature from 'components/home/SetTemperature/index.vue'
  5. import StartExperiment from 'components/home/StartExperiment/index.vue'
  6. import Tube from 'components/home/Tube/index.vue'
  7. import { ElMessageBox } from 'element-plus'
  8. import { FtMessage } from 'libs/message'
  9. import { socket } from 'libs/socket'
  10. import { useHomeStore } from 'stores/homeStore'
  11. import { useSystemStore } from 'stores/systemStore'
  12. import { onMounted, onUnmounted, ref } from 'vue'
  13. const homeStore = useHomeStore()
  14. const systemStore = useSystemStore()
  15. onMounted(() => {
  16. socket.init(receiveMessage, 'cmd_debug')
  17. socket.init(receiveMessage, 'cmd_response')
  18. })
  19. onUnmounted(() => {
  20. socket.unregisterCallback(receiveMessage, 'cmd_debug')
  21. socket.unregisterCallback(receiveMessage, 'cmd_response')
  22. })
  23. let currentCommandId = ''
  24. const receiveMessage = (data: Socket.cmdData) => {
  25. data.commandId === currentCommandId && systemStore.pushSystemList(data)
  26. }
  27. const startVisible = ref(false)
  28. // const startExperimentHandle = () => {
  29. // // TODO 需要判断有没有进行中的实验
  30. // startVisible.value = true
  31. // }
  32. // const selectCraftVisible = ref(false)
  33. // const selectCraft = () => {
  34. // const count = homeStore.heatAreaList.filter(item => item.selected).length
  35. // if (!count) {
  36. // FtMessage.warning('请选择加热区')
  37. // return
  38. // }
  39. // selectCraftVisible.value = true
  40. // }
  41. //
  42. // const executeCraftHandle = async () => {
  43. // const selectedHeatAreas = homeStore.heatAreaList.filter(item => item.selected)
  44. // if (!selectedHeatAreas.length) {
  45. // FtMessage.warning('请选择加热区')
  46. // return
  47. // }
  48. // // TODO 需要判断有没有选择工艺
  49. // for (let i = 0; i < selectedHeatAreas.length; i++) {
  50. // await startCraft({
  51. // heatId: selectedHeatAreas[i].value,
  52. // })
  53. // }
  54. // FtMessage.success('工艺已开始执行')
  55. // }
  56. const setTemperatureVisible = ref(false)
  57. const currentTemperatureId = ref('')
  58. const setTemperature = (id: string) => {
  59. currentTemperatureId.value = id
  60. setTemperatureVisible.value = true
  61. }
  62. const addLiquidVisible = ref(false)
  63. const addLiquid = async () => {
  64. await ElMessageBox.confirm(
  65. '请确认加液区是否有托盘?',
  66. '提示',
  67. {
  68. confirmButtonText: '确认',
  69. cancelButtonText: '取消',
  70. showClose: false,
  71. closeOnClickModal: false,
  72. type: 'warning',
  73. },
  74. )
  75. addLiquidVisible.value = true
  76. // if (!systemStore.systemStatus.solutionModule.trayStatus) {
  77. // FtMessage.warning('加液区无托盘')
  78. // return
  79. // }
  80. }
  81. const door_open = async () => {
  82. if (systemStore.systemStatus.door.open) {
  83. FtMessage.warning('门已经是开启状态了')
  84. return
  85. }
  86. currentCommandId = Date.now().toString()
  87. const params = {
  88. commandId: currentCommandId,
  89. command: 'door_open',
  90. params: { },
  91. }
  92. await homeStore.sendControl(params)
  93. }
  94. const door_close = async () => {
  95. if (!systemStore.systemStatus.door.open) {
  96. FtMessage.warning('门已经是关闭状态了')
  97. return
  98. }
  99. currentCommandId = Date.now().toString()
  100. const params = {
  101. commandId: currentCommandId,
  102. command: 'door_close',
  103. params: { },
  104. }
  105. await homeStore.sendControl(params)
  106. }
  107. const move_to_heat_area = async () => {
  108. // if (systemStore.systemStatus.solutionModule.trayStatus === 0) {
  109. // FtMessage.warning('加液区无托盘')
  110. // return
  111. // }
  112. const selectedHeatAreas = homeStore.heatAreaList.filter(item => item.selected)
  113. if (!selectedHeatAreas.length || selectedHeatAreas.length > 1) {
  114. FtMessage.warning('请选择一个加热区')
  115. return
  116. }
  117. await ElMessageBox.confirm(
  118. '请确认加液区是否有托盘?',
  119. '提示',
  120. {
  121. confirmButtonText: '确认',
  122. cancelButtonText: '取消',
  123. showClose: false,
  124. closeOnClickModal: false,
  125. type: 'warning',
  126. },
  127. )
  128. currentCommandId = Date.now().toString()
  129. const params = {
  130. commandId: currentCommandId,
  131. command: 'move_to_heat_area',
  132. params: {
  133. heatId: selectedHeatAreas[0].value,
  134. },
  135. }
  136. await homeStore.sendControl(params)
  137. }
  138. const move_to_solution_area = async () => {
  139. const selectedHeatAreas = homeStore.heatAreaList.filter(item => item.selected)
  140. if (!selectedHeatAreas.length || selectedHeatAreas.length > 1) {
  141. FtMessage.warning('请选择一个加热区')
  142. return
  143. }
  144. await ElMessageBox.confirm(
  145. '请确认加液区无托盘?',
  146. '提示',
  147. {
  148. confirmButtonText: '确认',
  149. cancelButtonText: '取消',
  150. showClose: false,
  151. closeOnClickModal: false,
  152. type: 'warning',
  153. },
  154. )
  155. // if (systemStore.systemStatus.solutionModule.trayStatus === 1) {
  156. // FtMessage.warning('加液区有托盘')
  157. // return
  158. // }
  159. currentCommandId = Date.now().toString()
  160. const params = {
  161. commandId: currentCommandId,
  162. command: 'move_to_solution_area',
  163. params: {
  164. heatId: selectedHeatAreas[0].value,
  165. },
  166. }
  167. await homeStore.sendControl(params)
  168. }
  169. const heat_start = async () => {
  170. const selectedHeatAreas = homeStore.heatAreaList.filter(item => item.selected)
  171. if (!selectedHeatAreas.length || selectedHeatAreas.length > 1) {
  172. FtMessage.warning('请选择一个加热区')
  173. return
  174. }
  175. if (systemStore.systemStatus.heatModule.find(item => item.moduleCode === selectedHeatAreas[0].value)?.targetTemperature) {
  176. FtMessage.warning('请先设置温度')
  177. return
  178. }
  179. currentCommandId = Date.now().toString()
  180. const params = {
  181. commandId: currentCommandId,
  182. command: 'heat_start',
  183. params: {
  184. heatId: selectedHeatAreas[0].value,
  185. temperature: systemStore.systemStatus.heatModule.find(item => item.moduleCode === selectedHeatAreas[0].value)?.targetTemperature,
  186. },
  187. }
  188. await homeStore.sendControl(params)
  189. }
  190. const heat_stop = async () => {
  191. const selectedHeatAreas = homeStore.heatAreaList.filter(item => item.selected)
  192. if (!selectedHeatAreas.length || selectedHeatAreas.length > 1) {
  193. FtMessage.warning('请选择一个加热区')
  194. return
  195. }
  196. currentCommandId = Date.now().toString()
  197. const params = {
  198. commandId: currentCommandId,
  199. command: 'heat_stop',
  200. params: {
  201. heatId: selectedHeatAreas[0].value,
  202. },
  203. }
  204. await homeStore.sendControl(params)
  205. }
  206. const tray_up = async () => {
  207. const selectedHeatAreas = homeStore.heatAreaList.filter(item => item.selected)
  208. if (!selectedHeatAreas.length || selectedHeatAreas.length > 1) {
  209. FtMessage.warning('请选择一个加热区')
  210. return
  211. }
  212. currentCommandId = Date.now().toString()
  213. const params = {
  214. commandId: currentCommandId,
  215. command: 'tray_up',
  216. params: {
  217. heatId: selectedHeatAreas[0].value,
  218. },
  219. }
  220. await homeStore.sendControl(params)
  221. }
  222. const tray_down = async () => {
  223. const selectedHeatAreas = homeStore.heatAreaList.filter(item => item.selected)
  224. if (!selectedHeatAreas.length || selectedHeatAreas.length > 1) {
  225. FtMessage.warning('请选择一个加热区')
  226. return
  227. }
  228. currentCommandId = Date.now().toString()
  229. const params = {
  230. commandId: currentCommandId,
  231. command: 'tray_down',
  232. params: {
  233. heatId: selectedHeatAreas[0].value,
  234. },
  235. }
  236. await homeStore.sendControl(params)
  237. }
  238. const shake_start = async () => {
  239. currentCommandId = Date.now().toString()
  240. const params = {
  241. commandId: currentCommandId,
  242. command: 'shake_start',
  243. params: {
  244. },
  245. }
  246. await homeStore.sendControl(params)
  247. }
  248. const shake_stop = async () => {
  249. currentCommandId = Date.now().toString()
  250. const params = {
  251. commandId: currentCommandId,
  252. command: 'shake_stop',
  253. params: {
  254. },
  255. }
  256. await homeStore.sendControl(params)
  257. }
  258. const take_photo = async () => {
  259. currentCommandId = Date.now().toString()
  260. const params = {
  261. commandId: currentCommandId,
  262. command: 'take_photo',
  263. params: {
  264. },
  265. }
  266. await homeStore.sendControl(params)
  267. }
  268. </script>
  269. <template>
  270. <div class="home-page">
  271. <el-row :gutter="10">
  272. <el-col :span="15">
  273. <div class="page-left">
  274. <Tube v-for="(item, index) in systemStore.systemStatus.heatModule" :key="item.moduleCode" :data="item" @select-change="homeStore.selectChange(index)" @set-temperature="setTemperature" />
  275. </div>
  276. </el-col>
  277. <el-col :span="9">
  278. <div class="page-right">
  279. <div class="top">
  280. <div class="photo" @click="take_photo">
  281. <el-icon><Camera /></el-icon>
  282. <span>拍照</span>
  283. </div>
  284. </div>
  285. <div class="button-box">
  286. <el-row :gutter="10">
  287. <el-col :span="12">
  288. <ft-button :click-handle="door_open">
  289. 开门
  290. </ft-button>
  291. </el-col>
  292. <el-col :span="12">
  293. <ft-button :click-handle="door_close">
  294. 关门
  295. </ft-button>
  296. </el-col>
  297. </el-row>
  298. <!-- <el-row :gutter="10"> -->
  299. <!-- <el-col :span="12"> -->
  300. <!-- <ft-button @click="startExperimentHandle"> -->
  301. <!-- 开始实验 -->
  302. <!-- </ft-button> -->
  303. <!-- </el-col> -->
  304. <!-- <el-col :span="12"> -->
  305. <!-- <ft-button disabled> -->
  306. <!-- 停止实验 -->
  307. <!-- </ft-button> -->
  308. <!-- </el-col> -->
  309. <!-- </el-row> -->
  310. <!-- <el-row :gutter="10"> -->
  311. <!-- <el-col :span="12"> -->
  312. <!-- <ft-button @click="selectCraft"> -->
  313. <!-- 选择工艺 -->
  314. <!-- </ft-button> -->
  315. <!-- </el-col> -->
  316. <!-- <el-col :span="12"> -->
  317. <!-- <ft-button :click-handle="executeCraftHandle"> -->
  318. <!-- 执行工艺 -->
  319. <!-- </ft-button> -->
  320. <!-- </el-col> -->
  321. <!-- </el-row> -->
  322. <el-row :gutter="10">
  323. <el-col :span="24">
  324. <ft-button @click="addLiquid">
  325. 添加溶液
  326. </ft-button>
  327. </el-col>
  328. </el-row>
  329. <el-row :gutter="10">
  330. <el-col :span="12">
  331. <ft-button :click-handle="shake_start">
  332. 开始摇匀
  333. </ft-button>
  334. </el-col>
  335. <el-col :span="12">
  336. <ft-button :click-handle="shake_stop">
  337. 停止摇匀
  338. </ft-button>
  339. </el-col>
  340. </el-row>
  341. <el-row :gutter="10">
  342. <el-col :span="12">
  343. <ft-button :click-handle="move_to_heat_area">
  344. 移至加热
  345. </ft-button>
  346. </el-col>
  347. <el-col :span="12">
  348. <ft-button :click-handle="move_to_solution_area">
  349. 移至加液
  350. </ft-button>
  351. </el-col>
  352. </el-row>
  353. <el-row :gutter="10">
  354. <el-col :span="12">
  355. <ft-button :click-handle="heat_start">
  356. 开始加热
  357. </ft-button>
  358. </el-col>
  359. <el-col :span="12">
  360. <ft-button :click-handle="heat_stop">
  361. 停止加热
  362. </ft-button>
  363. </el-col>
  364. </el-row>
  365. <el-row :gutter="10">
  366. <el-col :span="12">
  367. <ft-button :click-handle="tray_up">
  368. 抬起托盘
  369. </ft-button>
  370. </el-col>
  371. <el-col :span="12">
  372. <ft-button :click-handle="tray_down">
  373. 降下托盘
  374. </ft-button>
  375. </el-col>
  376. </el-row>
  377. </div>
  378. </div>
  379. </el-col>
  380. </el-row>
  381. <StartExperiment v-if="startVisible" @ok="startVisible = false" @cancel="startVisible = false" />
  382. <SelectCraft v-if="selectCraftVisible" @ok="selectCraftVisible = false" @cancel="selectCraftVisible = false" />
  383. <SetTemperature v-if="setTemperatureVisible" :id="currentTemperatureId" @ok="setTemperatureVisible = false" @cancel="setTemperatureVisible = false" />
  384. <AddLiquid v-if="addLiquidVisible" @ok="addLiquidVisible = false" @cancel="addLiquidVisible = false" />
  385. </div>
  386. </template>
  387. <style scoped lang="scss">
  388. .home-page {
  389. background: rgba(0, 0, 0, 0) !important;
  390. padding: 0 !important;
  391. .el-row {
  392. height: 100%;
  393. .el-col {
  394. height: 100%;
  395. .page-left, .page-right {
  396. height: 100%;
  397. background: #fff;
  398. border-radius: 8px;
  399. padding: 10px;
  400. }
  401. .page-left {
  402. display: grid;
  403. grid-template-columns: repeat(3, 1fr); /* 创建3列等宽轨道 */
  404. grid-template-rows: repeat(2, auto); /* 创建2行自动高度 */
  405. gap: 10px;
  406. justify-content: center; /* 水平居中 */
  407. align-items: center;
  408. }
  409. .page-right {
  410. display: flex;
  411. flex-direction: column;
  412. height: 100%;
  413. .top {
  414. height: 50%;
  415. background: #4D6882;
  416. position: relative;
  417. border-radius: 8px;
  418. overflow: hidden;
  419. .photo {
  420. width: 100%;
  421. height: 40px;
  422. background: rgba(0, 0, 0, 0.3);
  423. position: absolute;
  424. bottom: 0;
  425. display: flex;
  426. justify-content: center;
  427. align-items: center;
  428. color: #fff;
  429. font-size: 15px;
  430. }
  431. }
  432. .button-box {
  433. height: 50%;
  434. display: flex;
  435. flex-direction: column;
  436. justify-content: flex-end;
  437. .el-row {
  438. height: fit-content;
  439. margin-bottom: 5px;
  440. }
  441. }
  442. }
  443. }
  444. }
  445. }
  446. .el-col {
  447. .ft-button {
  448. width: 100%;
  449. .my-button {
  450. padding: 0 !important;
  451. }
  452. }
  453. }
  454. </style>