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

287 lines
7.7 KiB

  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" :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. @select-area="area => onSelectArea(area, 0)" />
  66. <Spray
  67. :width="210"
  68. :height="610"
  69. :left-padding="4"
  70. :right-padding="4"
  71. :top-padding="4"
  72. :bottom-padding="4"
  73. :columns="1"
  74. :rows="3"
  75. :cell-num="25"
  76. @select-area="area => onSelectArea(area, 1)" />
  77. <Spray
  78. :width="210"
  79. :height="610"
  80. :left-padding="4"
  81. :right-padding="4"
  82. :top-padding="4"
  83. :bottom-padding="4"
  84. :columns="1"
  85. :rows="3"
  86. :cell-num="25"
  87. @select-area="area => onSelectArea(area, 2)" />
  88. <Spray
  89. :width="210"
  90. :height="610"
  91. :left-padding="4"
  92. :right-padding="4"
  93. :top-padding="4"
  94. :bottom-padding="4"
  95. :columns="1"
  96. :rows="3"
  97. :cell-num="25"
  98. @select-area="area => onSelectArea(area, 3)" />
  99. </section>
  100. <van-checkbox-group
  101. shape="square"
  102. v-model="checked"
  103. checked-color="#26509c"
  104. icon-size="28px"
  105. direction="horizontal"
  106. class="flex justify-around mt-3 w-[848px]">
  107. <van-checkbox name="0"></van-checkbox>
  108. <van-checkbox name="1"></van-checkbox>
  109. <van-checkbox name="2"></van-checkbox>
  110. <van-checkbox name="3"></van-checkbox>
  111. </van-checkbox-group>
  112. </section>
  113. </div>
  114. </div>
  115. </template>
  116. <script setup lang="ts">
  117. import Spray, { type GridArea } from "@/components/Spray.vue";
  118. import { onMounted, ref, useTemplateRef } from "vue";
  119. import { startSpray, stopWork } from "@/services/globalCmd/globalCmd";
  120. import { checkSprayParamValid, type PositionType, type WorkType } from "@/services/globalCmd/cmdTypes";
  121. import { ElMessage } from "element-plus";
  122. import { useSettingStore } from "@/stores/setting";
  123. import type { CraftItem } from "@/services/matrix/type";
  124. import { createCraft, getListByMatrixId, updateCraft } from "@/services/matrix/craft";
  125. import SprayParam from "@/components/SprayParam.vue";
  126. import { useEquipmentStatusStore } from "@/stores/equipmentStatus";
  127. const defaultCraft: Partial<CraftItem> = {
  128. id: 0,
  129. name: "default",
  130. matrixId: 0,
  131. routeType: 1,
  132. space: undefined,
  133. nitrogenFlowVelocity: undefined,
  134. nitrogenAirPressure: undefined,
  135. matrixFlowVelocity: undefined,
  136. voltage: undefined,
  137. needPower: false,
  138. height: undefined,
  139. movementSpeed: undefined,
  140. position: [],
  141. };
  142. const settingStore = useSettingStore();
  143. const statusStore = useEquipmentStatusStore();
  144. const selectMatrixId = ref<number>(settingStore.matrixList.length > 0 ? settingStore.matrixList[0].id : 0);
  145. const craftList = ref<CraftItem[]>([]);
  146. const selectCraftId = ref<number>(1);
  147. const selectCraft = ref<Partial<CraftItem>>(defaultCraft);
  148. const selectedArea = ref<GridArea[]>([
  149. { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 },
  150. { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 },
  151. { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 },
  152. { xStart: 8, yStart: 8, xEnd: 16, yEnd: 16 },
  153. ]);
  154. const checked = ref(["0"]);
  155. onMounted(() => {
  156. if (settingStore.matrixList.length > 0) {
  157. onMatrixChange(settingStore.matrixList[0].id);
  158. }
  159. });
  160. function onSelectArea(area: GridArea, index: number) {
  161. selectedArea.value[index] = area;
  162. }
  163. function onMatrixChange(val: number) {
  164. selectMatrixId.value = val;
  165. getListByMatrixId({ matrixId: val }).then(res => {
  166. if (res.success) {
  167. craftList.value = res.data || [];
  168. if (res.data.length > 0) {
  169. selectCraftId.value = res.data[0].id;
  170. selectCraft.value = { ...res.data[0], needPower: res.data[0].voltage > 0 };
  171. } else {
  172. selectCraftId.value = 0;
  173. selectCraft.value = defaultCraft;
  174. }
  175. } else {
  176. ElMessage.error(res.msg);
  177. }
  178. });
  179. }
  180. function onCraftChange(val: number) {
  181. const craft = craftList.value.find(item => item.id === val);
  182. selectCraft.value = { ...craft, needPower: craft!.voltage > 0 };
  183. }
  184. function mapAreaToPosition() {
  185. return checked.value.map(index => {
  186. const idx = +index;
  187. const pos: PositionType = {
  188. x1: selectedArea.value[idx].xStart,
  189. y1: selectedArea.value[idx].yStart,
  190. x2: selectedArea.value[idx].xEnd,
  191. y2: selectedArea.value[idx].yEnd,
  192. index: idx,
  193. };
  194. return pos;
  195. });
  196. }
  197. const sprayParamRef = ref();
  198. function onStartSpray() {
  199. if (checked.value.length === 0) {
  200. ElMessage.error("请至少选择一个玻片");
  201. return;
  202. }
  203. // 把参数弹窗中的数据 应用过来
  204. const params = { ...selectCraft.value, ...sprayParamRef.value.sprayParam };
  205. params.position = mapAreaToPosition();
  206. if (!params.needPower) {
  207. params.voltage = 0;
  208. }
  209. // console.log(params);
  210. const check = checkSprayParamValid(params);
  211. if (!check[0]) {
  212. ElMessage.error(check[1]);
  213. return;
  214. }
  215. startSpray({
  216. ...(params as CraftItem),
  217. matrixId: selectMatrixId.value,
  218. matrixCraftId: selectCraft.value.id || 0,
  219. }).then(res => {
  220. if (res.success) {
  221. } else {
  222. ElMessage.error(res.msg);
  223. }
  224. });
  225. }
  226. function onStopSpray() {
  227. stopWork().then(res => {
  228. if (res.success) {
  229. } else {
  230. ElMessage.error(res.msg);
  231. }
  232. });
  233. }
  234. function updateSprayParam(p: WorkType) {
  235. console.log(p);
  236. const params = !!p.needPower ? p : { ...p, voltage: 0 };
  237. if ((params as CraftItem).id === 0) {
  238. // 创建
  239. const p = { ...(params as CraftItem), matrixId: selectMatrixId.value };
  240. createCraft(p).then(res => {
  241. if (res.success) {
  242. onMatrixChange(selectMatrixId.value);
  243. } else {
  244. ElMessage.error(res.msg);
  245. }
  246. });
  247. } else {
  248. // 更新
  249. updateCraft(params as CraftItem).then(res => {
  250. if (res.success) {
  251. selectCraft.value = params as CraftItem;
  252. } else {
  253. ElMessage.error(res.msg);
  254. }
  255. });
  256. }
  257. }
  258. </script>
  259. <style lang="scss" scoped>
  260. :deep(.el-collapse-item__header) {
  261. background-color: transparent;
  262. }
  263. :deep(.el-collapse-item__wrap) {
  264. background-color: transparent;
  265. }
  266. </style>