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.

371 lines
9.5 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. <script setup lang="ts">
  2. import { list as listMatrix } from 'apis/matrix'
  3. import { getDeviceStatus, getSprayStatus, setParams } from 'apis/system'
  4. import SprayParams from 'components//spray/sprayParams/index.vue'
  5. import TrayGraph from 'components/spray/trayGraph/index.vue'
  6. import { FtMessage } from 'libs/message'
  7. import { socket } from 'libs/socket'
  8. import { colors, sendControl } from 'libs/utils'
  9. import { cloneDeep } from 'lodash'
  10. import { useSprayStore } from 'stores/useSprayStore'
  11. import { useSystemStore } from 'stores/useSystemStore'
  12. import { nextTick, onMounted, onUnmounted, ref } from 'vue'
  13. const systemStore = useSystemStore()
  14. const sprayStore = useSprayStore()
  15. onMounted(async () => {
  16. socket.init(sprayPointReceiveMessage, 'spray_point')
  17. socket.init(finishMessage, 'cmd_response')
  18. await getMatrixList()
  19. await getDeviceStatus().then((res: any) => {
  20. systemStore.updateSystemStatus(res)
  21. if (systemStore.systemStatus.spraying) {
  22. FtMessage.info('正在喷涂中...')
  23. maskVisible.value = true
  24. getSpraying()
  25. }
  26. })
  27. })
  28. onUnmounted(() => {
  29. socket.unregisterCallback(sprayPointReceiveMessage, 'spray_point')
  30. socket.unregisterCallback(finishMessage, 'cmd_response')
  31. })
  32. const matrixList = ref<{ name: string, id: number }[]>([])
  33. const getMatrixList = async () => {
  34. const res = await listMatrix({ pageNum: 1, pageSize: 100, matrixName: '' })
  35. matrixList.value = res.list
  36. }
  37. const getSpraying = async () => {
  38. const res: any = await getSprayStatus()
  39. cmdId = res.cmdId
  40. res.sprayTaskParams.forEach((item: any) => {
  41. sprayStore.updateSprayForm(item, item.index)
  42. })
  43. res.sprayTaskSprayedList
  44. .forEach((task: any) => {
  45. nextTick(() => {
  46. drawLine(task.index, { x: task.sprayedPoints.x * 5, y: task.sprayedPoints.y * 5 }, task.number)
  47. })
  48. })
  49. }
  50. const sprayRefs = ref<any>([])
  51. const maskVisible = ref(false)
  52. const startWork = async () => {
  53. const data = sprayStore.sprayTaskParams.filter(item => item.select)
  54. if (!data.length) {
  55. FtMessage.error('至少选择一个喷涂玻片')
  56. return
  57. }
  58. const errIndex = []
  59. data.forEach((item, index) => {
  60. if (!item.hasSet) {
  61. errIndex.push(index)
  62. FtMessage.error(`玻片${index + 1}: 请设置喷涂参数`)
  63. }
  64. })
  65. if (errIndex.length) {
  66. return
  67. }
  68. sprayStore.sprayTaskParams.forEach((item, index) => {
  69. if (item.select) {
  70. sprayRefs.value[index].clearLines()
  71. }
  72. })
  73. await setParams({ sprayTaskParams: sprayStore.sprayTaskParams.filter(item => item.select) })
  74. cmdId = Date.now().toString()
  75. const params = {
  76. cmdCode: 'matrix_spray_start',
  77. cmdId,
  78. params: {
  79. },
  80. }
  81. await sendControl(params)
  82. maskVisible.value = true
  83. // currentSpeed = Number(form.value.movingSpeed)
  84. }
  85. const pauseWork = async () => {
  86. const params = {
  87. cmdCode: 'matrix_spray_pause',
  88. cmdId: '',
  89. }
  90. await sendControl(params)
  91. }
  92. const continueWork = async () => {
  93. const params = {
  94. cmdCode: 'matrix_spray_continue',
  95. cmdId: '',
  96. params: {
  97. },
  98. }
  99. await sendControl(params)
  100. // currentSpeed = Number(form.value.movingSpeed)
  101. }
  102. const stopWork = async () => {
  103. const params = {
  104. cmdCode: 'matrix_spray_stop',
  105. cmdId: '',
  106. }
  107. await sendControl(params)
  108. sprayStore.sprayTaskParams.forEach((item, index) => {
  109. if (item.select) {
  110. sprayRefs.value[index].clearLines()
  111. item.select = false
  112. }
  113. })
  114. }
  115. // let currentSpeed = 0
  116. // console.log(currentSpeed)
  117. // let poll: ReturnType<typeof setInterval>
  118. let cmdId = ''
  119. const sprayPointReceiveMessage = (data: any) => {
  120. if (data.cmdId === cmdId) {
  121. const { currentPoint, index, number } = data
  122. drawLine(index, { x: currentPoint.x * 5, y: currentPoint.y * 5 }, number)
  123. }
  124. // if (poll) {
  125. // clearInterval(poll)
  126. // }
  127. // const { currentPoint, nextPoint, index } = data
  128. // // 计算累加的mm
  129. // const moveDistance = currentSpeed / 2
  130. // // y轴移动
  131. // if (currentPoint.x === nextPoint.x) {
  132. // let currentY = currentPoint.y
  133. // poll = setInterval(() => {
  134. // currentY += moveDistance
  135. // if (currentY >= nextPoint.y) {
  136. // clearInterval(poll)
  137. // }
  138. // drawLine(index, { x: currentPoint.x * 5, y: currentY * 5 })
  139. // }, 500)
  140. // }
  141. // else if (currentPoint.y === nextPoint.y) {
  142. // // x轴移动
  143. // let currentX = currentPoint.x
  144. // poll = setInterval(() => {
  145. // currentX += moveDistance
  146. // if (currentX >= nextPoint.x) {
  147. // clearInterval(poll)
  148. // }
  149. // drawLine(index, { x: currentX * 5, y: currentPoint.y * 5 })
  150. // }, 500)
  151. // }
  152. }
  153. const finishMessage = (data: any) => {
  154. console.log(data, cmdId)
  155. if (data.cmdId === cmdId) {
  156. if (data.status === 'fail') {
  157. FtMessage.error(data.title)
  158. }
  159. if (data.status === 'success') {
  160. FtMessage.success('喷涂执行成功')
  161. }
  162. if (data.status === 'spray_task_finish') {
  163. sprayStore.sprayTaskParams.forEach((item, index) => {
  164. if (item.select) {
  165. sprayRefs.value[index].clearLines()
  166. item.select = false
  167. }
  168. })
  169. maskVisible.value = false
  170. }
  171. }
  172. }
  173. const drawLine = async (index: number, point: { x: number, y: number }, number: number) => {
  174. console.log('drawLine', sprayRefs.value[index], index, point, number)
  175. await nextTick(() => {
  176. if (!sprayRefs.value[index].hasLine(number)) {
  177. sprayRefs.value[index].addLine(colors[number])
  178. }
  179. sprayRefs.value[index].updateLine(point, number, colors[number])
  180. })
  181. }
  182. const selectCraftVisible = ref(false)
  183. const ok = async (data: any) => {
  184. selectCraftVisible.value = false
  185. sprayStore.updateSprayForm(data, selectIndex.value)
  186. }
  187. const sprayParamsCancelHandle = () => {
  188. selectCraftVisible.value = false
  189. }
  190. const selectIndex = ref(0)
  191. const currentFormData = ref()
  192. const openSetting = (index: number) => {
  193. selectIndex.value = index
  194. currentFormData.value = cloneDeep(sprayStore.sprayTaskParams[index])
  195. sprayParamsDisabled.value = false
  196. selectCraftVisible.value = true
  197. }
  198. const checkChange = (index: number, checked: boolean) => {
  199. // if (checked) {
  200. // selectCraftVisible.value = true
  201. // }
  202. console.log(checked, index)
  203. }
  204. const sprayParamsDisabled = ref(false)
  205. const viewParams = (index: number) => {
  206. selectIndex.value = index
  207. currentFormData.value = cloneDeep(sprayStore.sprayTaskParams[index])
  208. sprayParamsDisabled.value = true
  209. selectCraftVisible.value = true
  210. }
  211. </script>
  212. <template>
  213. <div class="spray-container">
  214. <div class="button-box">
  215. <ft-button type="primary" :disabled="systemStore.systemStatus.spraying" @click="startWork">
  216. 开始喷涂
  217. </ft-button>
  218. <!-- <ft-button type="primary" :disabled="!systemStore.systemStatus.spraying" @click="updateParam"> -->
  219. <!-- 调整参数 -->
  220. <!-- </ft-button> -->
  221. <ft-button type="primary" :disabled="!systemStore.systemStatus.spraying" @click="pauseWork">
  222. 暂停喷涂
  223. </ft-button>
  224. <ft-button type="primary" :disabled="!systemStore.systemStatus.paused" @click="continueWork">
  225. 继续喷涂
  226. </ft-button>
  227. <ft-button type="primary" :disabled="!systemStore.systemStatus.spraying" @click="stopWork">
  228. 结束喷涂
  229. </ft-button>
  230. </div>
  231. <div class="spray-box">
  232. <div v-show="maskVisible" class="mask-box" />
  233. <div
  234. v-for="(p, index) in sprayStore.sprayTaskParams"
  235. :key="index"
  236. style="height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly"
  237. >
  238. <p class="tray-name">
  239. <el-checkbox v-model="p.select" @change="val => checkChange(index, val)" />
  240. <span>玻片{{ index + 1 }}</span>
  241. </p>
  242. <TrayGraph ref="sprayRefs" :key="index" :container="`spray-${index + 1}`" :edit-select="false" />
  243. <ft-button v-if="!systemStore.systemStatus.spraying" type="primary" @click="() => openSetting(index)">
  244. 喷涂设置
  245. </ft-button>
  246. <ft-button v-else type="primary" @click="() => viewParams(index)">
  247. 运行参数
  248. </ft-button>
  249. </div>
  250. </div>
  251. <SprayParams
  252. v-if="selectCraftVisible"
  253. :disabled="sprayParamsDisabled"
  254. :form-data="currentFormData"
  255. @ok="ok"
  256. @cancel="sprayParamsCancelHandle"
  257. />
  258. </div>
  259. </template>
  260. <style scoped lang="scss">
  261. .spray-container {
  262. width: 100%;
  263. height: 100%;
  264. padding: 30px 10px !important;
  265. display: flex;
  266. flex-direction: column;
  267. align-items: center;
  268. .button-box {
  269. width: 100%;
  270. display: flex;
  271. justify-content: center;
  272. height: 120px;
  273. gap: 50px;
  274. }
  275. .spray-box {
  276. position: relative;
  277. width: 100%;
  278. flex: 1;
  279. display: flex;
  280. align-items: center;
  281. justify-content: space-evenly;
  282. //gap: 200px;
  283. }
  284. }
  285. .el-input,
  286. .el-select {
  287. width: 400px;
  288. margin: 0 40px;
  289. }
  290. .unit-text {
  291. font-size: 40px;
  292. color: #0349a8;
  293. font-weight: 500;
  294. }
  295. .select-box {
  296. display: flex;
  297. margin: 40px;
  298. }
  299. .route-img {
  300. display: flex;
  301. img {
  302. width: 70px;
  303. }
  304. }
  305. .voltage-box {
  306. display: flex;
  307. align-items: center;
  308. margin-left: 40px;
  309. height: 100px;
  310. .voltage-input {
  311. width: 280px;
  312. }
  313. }
  314. :deep(.el-form-item__error) {
  315. font-size: 22px;
  316. margin-left: 50px;
  317. }
  318. .mask-box {
  319. position: absolute;
  320. width: 100%;
  321. top: 0;
  322. height: 50%;
  323. background: rgba(255, 255, 255, 0.01);
  324. z-index: 2000;
  325. }
  326. .tray-name {
  327. color: var(--el-color-primary);
  328. display: flex;
  329. align-items: center;
  330. justify-content: center;
  331. width: 100%;
  332. }
  333. :deep(.ft-button) {
  334. margin: 0;
  335. }
  336. :deep(.el-drawer) {
  337. width: 33% !important;
  338. }
  339. :deep(.el-tabs) {
  340. margin: 0;
  341. }
  342. :deep(.el-tabs__content) {
  343. display: none;
  344. }
  345. </style>