基质喷涂
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.

292 lines
7.9 KiB

5 months ago
  1. <template>
  2. <div class="px-6 pt-4 pb-3 flex justify-between">
  3. <div class="w-full">
  4. <div class="flex items-center mb-3 gap-5">
  5. <button :disabled="statusStore.workStatus !== 'idle'" class="btn-dark px-8 py-2 text-lg" @click="onStartSpray">
  6. 开始喷涂
  7. </button>
  8. <button
  9. :disabled="statusStore.workStatus !== 'spraying'"
  10. class="btn-light px-8 py-2 text-lg"
  11. @click="onStopSpray">
  12. 停止喷涂
  13. </button>
  14. <section class="flex items-center gap-3 px-4 text-base ml-auto">
  15. <div class="flex items-center">
  16. <span class="self-center text-right text-primary font-medium mr-3">选择基质</span>
  17. <el-select v-model="selectMatrixId" placeholder="Select" style="width: 120px" @change="onMatrixChange">
  18. <el-option
  19. v-for="item in settingStore.matrixList"
  20. :key="item.id"
  21. :label="item.name"
  22. :value="item.id" />
  23. </el-select>
  24. </div>
  25. <div class="flex items-center">
  26. <span class="self-center text-right text-primary font-medium mr-3">工艺</span>
  27. <el-select
  28. :disabled="craftList.length === 0"
  29. v-model="selectCraftId"
  30. placeholder="Select"
  31. style="width: 120px"
  32. @change="onCraftChange">
  33. <el-option v-for="item in craftList" :key="item.id" :label="item.name" :value="item.id" />
  34. </el-select>
  35. </div>
  36. <el-popover placement="bottom-end" :width="380" trigger="click">
  37. <template #reference>
  38. <div class="text-primary underline flex items-center gap-1">
  39. <span>{{ craftList.length === 0 ? "设置参数" : "详细参数" }}</span>
  40. <img src="@/assets/icon_info.svg" alt="info" />
  41. </div>
  42. </template>
  43. <template #default>
  44. <SprayParam
  45. ref="sprayParamRef"
  46. :sprayParam="selectCraft"
  47. save-title="保存至工艺"
  48. @save="updateSprayParam" />
  49. </template>
  50. </el-popover>
  51. </section>
  52. </div>
  53. <section class="flex flex-col items-start">
  54. <section class="flex">
  55. <Spray
  56. :width="210"
  57. :height="610"
  58. :left-padding="4"
  59. :right-padding="4"
  60. :top-padding="4"
  61. :bottom-padding="4"
  62. :columns="1"
  63. :rows="3"
  64. :cell-num="25"
  65. :hideGripper="!checked.find(c => c === '0')"
  66. @select-area="area => onSelectArea(area, 0)" />
  67. <Spray
  68. :width="210"
  69. :height="610"
  70. :left-padding="4"
  71. :right-padding="4"
  72. :top-padding="4"
  73. :bottom-padding="4"
  74. :columns="1"
  75. :rows="3"
  76. :cell-num="25"
  77. :hideGripper="!checked.find(c => c === '1')"
  78. @select-area="area => onSelectArea(area, 1)" />
  79. <Spray
  80. :width="210"
  81. :height="610"
  82. :left-padding="4"
  83. :right-padding="4"
  84. :top-padding="4"
  85. :bottom-padding="4"
  86. :columns="1"
  87. :rows="3"
  88. :cell-num="25"
  89. :hideGripper="!checked.find(c => c === '2')"
  90. @select-area="area => onSelectArea(area, 2)" />
  91. <Spray
  92. :width="210"
  93. :height="610"
  94. :left-padding="4"
  95. :right-padding="4"
  96. :top-padding="4"
  97. :bottom-padding="4"
  98. :columns="1"
  99. :rows="3"
  100. :cell-num="25"
  101. :hideGripper="!checked.find(c => c === '3')"
  102. @select-area="area => onSelectArea(area, 3)" />
  103. </section>
  104. <van-checkbox-group
  105. shape="square"
  106. v-model="checked"
  107. checked-color="#26509c"
  108. icon-size="28px"
  109. direction="horizontal"
  110. class="flex justify-around mt-3 w-[848px]">
  111. <van-checkbox name="0"></van-checkbox>
  112. <van-checkbox name="1"></van-checkbox>
  113. <van-checkbox name="2"></van-checkbox>
  114. <van-checkbox name="3"></van-checkbox>
  115. </van-checkbox-group>
  116. </section>
  117. </div>
  118. </div>
  119. </template>
  120. <script setup lang="ts">
  121. import Spray, { type GridArea } from "@/components/Spray.vue";
  122. import { onMounted, ref, useTemplateRef } from "vue";
  123. import { startSpray, stopWork } from "@/services/globalCmd/globalCmd";
  124. import { checkSprayParamValid, type PositionType, type WorkType } from "@/services/globalCmd/cmdTypes";
  125. import { ElMessage } from "element-plus";
  126. import { useSettingStore } from "@/stores/setting";
  127. import type { CraftItem } from "@/services/matrix/type";
  128. import { createCraft, getListByMatrixId, updateCraft } from "@/services/matrix/craft";
  129. import SprayParam from "@/components/SprayParam.vue";
  130. import { useEquipmentStatusStore } from "@/stores/equipmentStatus";
  131. const defaultCraft: Partial<CraftItem> = {
  132. id: 0,
  133. name: "default",
  134. matrixId: 0,
  135. routeType: 1,
  136. space: undefined,
  137. nitrogenFlowVelocity: undefined,
  138. nitrogenAirPressure: undefined,
  139. matrixFlowVelocity: undefined,
  140. voltage: undefined,
  141. needPower: false,
  142. height: undefined,
  143. movementSpeed: undefined,
  144. position: [],
  145. };
  146. const settingStore = useSettingStore();
  147. const statusStore = useEquipmentStatusStore();
  148. const selectMatrixId = ref<number>(settingStore.matrixList.length > 0 ? settingStore.matrixList[0].id : 0);
  149. const craftList = ref<CraftItem[]>([]);
  150. const selectCraftId = ref<number>(1);
  151. const selectCraft = ref<Partial<CraftItem>>(defaultCraft);
  152. const selectedArea = ref<GridArea[]>([
  153. { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 },
  154. { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 },
  155. { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 },
  156. { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 },
  157. ]);
  158. const checked = ref(["0"]);
  159. onMounted(() => {
  160. if (settingStore.matrixList.length > 0) {
  161. onMatrixChange(settingStore.matrixList[0].id);
  162. }
  163. });
  164. function onSelectArea(area: GridArea, index: number) {
  165. selectedArea.value[index] = area;
  166. }
  167. function onMatrixChange(val: number) {
  168. selectMatrixId.value = val;
  169. getListByMatrixId({ matrixId: val }).then(res => {
  170. if (res.success) {
  171. craftList.value = res.data || [];
  172. if (res.data.length > 0) {
  173. selectCraftId.value = res.data[0].id;
  174. selectCraft.value = { ...res.data[0], needPower: res.data[0].voltage > 0 };
  175. } else {
  176. selectCraftId.value = 0;
  177. selectCraft.value = defaultCraft;
  178. }
  179. } else {
  180. ElMessage.error(res.msg);
  181. }
  182. });
  183. }
  184. function onCraftChange(val: number) {
  185. const craft = craftList.value.find(item => item.id === val);
  186. selectCraft.value = { ...craft, needPower: craft!.voltage > 0 };
  187. }
  188. function mapAreaToPosition() {
  189. return checked.value.map(index => {
  190. const idx = +index;
  191. const pos: PositionType = {
  192. x1: selectedArea.value[idx].xStart,
  193. y1: selectedArea.value[idx].yStart,
  194. x2: selectedArea.value[idx].xEnd,
  195. y2: selectedArea.value[idx].yEnd,
  196. index: idx,
  197. };
  198. return pos;
  199. });
  200. }
  201. const sprayParamRef = ref();
  202. function onStartSpray() {
  203. if (checked.value.length === 0) {
  204. ElMessage.error("请至少选择一个玻片");
  205. return;
  206. }
  207. // 把参数弹窗中的数据 应用过来
  208. const params = { ...selectCraft.value, ...sprayParamRef.value.sprayParam };
  209. params.position = mapAreaToPosition();
  210. if (!params.needPower) {
  211. params.voltage = 0;
  212. }
  213. // console.log(params);
  214. const check = checkSprayParamValid(params);
  215. if (!check[0]) {
  216. ElMessage.error(check[1]);
  217. return;
  218. }
  219. startSpray({
  220. ...(params as CraftItem),
  221. matrixId: selectMatrixId.value,
  222. matrixCraftId: selectCraft.value.id || 0,
  223. }).then(res => {
  224. if (res.success) {
  225. ElMessage.success("已经开始喷涂");
  226. } else {
  227. ElMessage.error(res.msg);
  228. }
  229. });
  230. }
  231. function onStopSpray() {
  232. stopWork().then(res => {
  233. if (res.success) {
  234. } else {
  235. ElMessage.error(res.msg);
  236. }
  237. });
  238. }
  239. function updateSprayParam(p: WorkType) {
  240. console.log(p);
  241. const params = !!p.needPower ? p : { ...p, voltage: 0 };
  242. if ((params as CraftItem).id === 0) {
  243. // 创建
  244. const p = { ...(params as CraftItem), matrixId: selectMatrixId.value };
  245. createCraft(p).then(res => {
  246. if (res.success) {
  247. onMatrixChange(selectMatrixId.value);
  248. } else {
  249. ElMessage.error(res.msg);
  250. }
  251. });
  252. } else {
  253. // 更新
  254. updateCraft(params as CraftItem).then(res => {
  255. if (res.success) {
  256. selectCraft.value = params as CraftItem;
  257. } else {
  258. ElMessage.error(res.msg);
  259. }
  260. });
  261. }
  262. }
  263. </script>
  264. <style lang="scss" scoped>
  265. :deep(.el-collapse-item__header) {
  266. background-color: transparent;
  267. }
  268. :deep(.el-collapse-item__wrap) {
  269. background-color: transparent;
  270. }
  271. </style>