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.

244 lines
5.5 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. <script lang="ts" setup>
  2. import type { Craft, StepCmd, StepStruct, TubeSolStruct } from './craftType'
  3. import { ElMessage } from 'element-plus'
  4. import { ref } from 'vue'
  5. import { StepCmdDescMap } from './craftType'
  6. import TransferLeft from './TransferLeft.vue'
  7. import TransferRight from './TransferRight.vue'
  8. const emit = defineEmits<{
  9. (e: 'ok', craft: Craft): void
  10. }>()
  11. const visible = ref(false)
  12. const stepStructs = ref<StepStruct[]>([])
  13. const craftObj = ref<Craft>({})
  14. const stepCmds: StepCmd[] = [
  15. // 'upTray',
  16. // 'downTray',
  17. 'addLiquid',
  18. // 'moveToSol',
  19. // 'moveToHeat',
  20. 'shaking',
  21. 'startHeating',
  22. // 'stopHeating',
  23. 'takePhoto',
  24. // 'delay',
  25. ]
  26. const openDialog = () => {
  27. visible.value = true
  28. }
  29. const closeDialog = () => {
  30. stepStructs.value = []
  31. craftObj.value.name = ''
  32. visible.value = false
  33. }
  34. const editDialog = (craftInfo: Craft) => {
  35. craftObj.value = { ...craftInfo }
  36. if (craftInfo && craftInfo.steps) {
  37. const step = JSON.parse(craftInfo.steps)
  38. /* eslint-disable no-debugger */
  39. if (step && step.length) {
  40. step.forEach((item: StepStruct) => {
  41. if (item.method === 'addLiquid') {
  42. const list = item.params.tubeSolList
  43. if (list && list.length === 16 && item.params.tubeSolList) {
  44. item.params.tubeSolList = [{
  45. tubeNum: 0,
  46. addLiquidList: item.params.tubeSolList[0].addLiquidList,
  47. }]
  48. }
  49. }
  50. })
  51. }
  52. stepStructs.value = step
  53. }
  54. openDialog()
  55. }
  56. function onConfirm() {
  57. if (!craftObj.value.name) {
  58. ElMessage.warning('请输入工艺名称')
  59. return
  60. }
  61. for (const step of stepStructs.value) {
  62. if (step.method === 'addLiquid') {
  63. const list = step.params.tubeSolList
  64. if (list && list.length) {
  65. list.forEach((item) => {
  66. const tubeNum = item.tubeNum
  67. if (tubeNum === 0) {
  68. const tubeSolList: TubeSolStruct[] = []
  69. for (let index = 0; index < 16; index++) {
  70. tubeSolList.push({
  71. tubeNum: index + 1,
  72. addLiquidList: item.addLiquidList,
  73. })
  74. }
  75. step.params.tubeSolList = tubeSolList
  76. }
  77. })
  78. }
  79. }
  80. }
  81. craftObj.value.steps = JSON.stringify(stepStructs.value)
  82. emit('ok', craftObj.value)
  83. }
  84. function addStep(step: StepCmd) {
  85. let st: StepStruct
  86. if (step === 'addLiquid') {
  87. st = {
  88. method: step,
  89. params: {
  90. tubeSolList: [{
  91. tubeNum: 0,
  92. addLiquidList: [{
  93. solId: 1,
  94. volume: 10,
  95. }],
  96. }],
  97. },
  98. }
  99. }
  100. else if (step === 'startHeating') {
  101. st = {
  102. method: step,
  103. params: {
  104. temperature: 100,
  105. },
  106. }
  107. }
  108. else if (step === 'delay') {
  109. st = {
  110. method: step,
  111. params: {
  112. second: 10,
  113. },
  114. }
  115. }
  116. else if (step === 'shaking') {
  117. st = {
  118. method: step,
  119. params: {
  120. second: 30,
  121. },
  122. }
  123. }
  124. else {
  125. st = {
  126. method: step,
  127. }
  128. }
  129. stepStructs.value = [...stepStructs.value, st]
  130. }
  131. function onStepItemDel(order: number) {
  132. stepStructs.value = stepStructs.value.filter((s, i) => i !== order - 1)
  133. }
  134. function transferChange(stepData: StepStruct, order: number) {
  135. console.log('order === ', stepStructs.value, stepData, order)
  136. }
  137. defineExpose({
  138. openDialog,
  139. closeDialog,
  140. editDialog,
  141. })
  142. </script>
  143. <template>
  144. <el-dialog v-model="visible" title="添加工艺" style="width:70vw; height:70vh">
  145. <div>
  146. <div class="mt-5 mb-8 flex items-center">
  147. <label class="font-medium mr-4">工艺名称</label>
  148. <el-input
  149. v-model.trim="craftObj.name"
  150. style="width: 200px"
  151. size="small"
  152. type="text"
  153. placeholder="请输入名称"
  154. class="flex-auto bg-[#f6f6f6] h-11 leading-10 rounded-sm px-4"
  155. />
  156. </div>
  157. <div class="craft-title">
  158. <div>
  159. 工艺步骤
  160. </div>
  161. <div class="title-right">
  162. 选择的步骤
  163. </div>
  164. </div>
  165. <div class="step-content">
  166. <div class="transfer-left">
  167. <TransferLeft v-for="cmd in stepCmds" :key="cmd" :title="StepCmdDescMap[cmd]" @click="addStep(cmd)" />
  168. </div>
  169. <div v-if="stepStructs && stepStructs.length" class="transfer-right">
  170. <TransferRight v-for="(step, idx) in stepStructs" :key="idx" :order="idx + 1" :step="step" type="add" @del="onStepItemDel" @transfer-change="transferChange" />
  171. </div>
  172. <div v-else>
  173. <el-empty description="description">
  174. <template #description>
  175. 未选择工艺步骤
  176. </template>
  177. </el-empty>
  178. </div>
  179. </div>
  180. <div class="footer">
  181. <el-button size="small" @click="closeDialog">
  182. 取消
  183. </el-button>
  184. <el-button type="primary" size="small" @click="onConfirm">
  185. 确定
  186. </el-button>
  187. </div>
  188. </div>
  189. </el-dialog>
  190. </template>
  191. <style lang="scss" scoped>
  192. .transfer-left{
  193. display: grid;
  194. grid-template-columns: 1fr 1fr;
  195. gap: 1.4rem;
  196. width: 12.5rem;
  197. place-items: center;
  198. height: 3rem;
  199. }
  200. .transfer-right{
  201. max-height: 40vh;
  202. overflow: auto;
  203. }
  204. .step-content{
  205. margin-top:1rem;
  206. display: grid;
  207. grid-template-columns: 1fr 1fr;
  208. height: 21rem;
  209. }
  210. .footer{
  211. display: flex;
  212. height: 5rem;
  213. justify-content: center;
  214. align-items: center;
  215. }
  216. .craft-title{
  217. display: grid;
  218. grid-template-columns: 1fr 1fr;
  219. div{
  220. font-size:12px;
  221. margin-top: 5px;
  222. }
  223. .title-right{
  224. display: flex;
  225. justify-content: center;
  226. }
  227. }
  228. </style>