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.

417 lines
11 KiB

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