消毒机设备
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.

205 lines
5.8 KiB

2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
  1. <script lang="ts" setup>
  2. import { formulaNameMap } from 'libs/constant'
  3. import { inject, onMounted, ref, watchEffect } from 'vue'
  4. import { convertValuesToInt, convertValuesToString } from '@/libs/utils'
  5. import { useFormulaStore } from '@/stores/formulaStore'
  6. const props = defineProps<{
  7. formulaNameVisible: boolean
  8. }>()
  9. const formulaStore = useFormulaStore()
  10. /**
  11. * 获取当前表单数据将值转换为字符串格式
  12. * @returns {Record<string, string>} 转换后的表单数据
  13. */
  14. const getFormData = () => {
  15. return convertValuesToString(formData.value, 'name')
  16. }
  17. /**
  18. * 注册孙子组件方法的注入函数
  19. */
  20. const registerGrandsonMethods = inject<(methods: any) => void>('registerGrandsonMethods', () => {})
  21. onMounted(() => {
  22. registerGrandsonMethods && registerGrandsonMethods({ getFormData })
  23. })
  24. /**
  25. * 当前表单数据
  26. * - home: 当前选中的配方 或者默认配方
  27. */
  28. const formData = ref<Record<string, any>>({})
  29. /**
  30. * 标签单位映射表用于显示各参数的单位
  31. */
  32. const labelUnitMap: Record<string, any> = formulaStore.labelUnitMap
  33. /**
  34. * 监听事件
  35. */
  36. watchEffect(() => {
  37. formData.value = formulaStore.selectedFormulaInfo !== null ? convertValuesToInt(formulaStore.selectedFormulaInfo) : convertValuesToInt(formulaStore.defaultFormulaInfo)
  38. })
  39. /**
  40. * 配方配置列表
  41. */
  42. const formulaConfigList = formulaStore.formulaConfigList
  43. const size = 'default'
  44. const validatePass = (rule: any, value: any, callback: any, config: Formula.FormulaConfig) => {
  45. if (!value && value !== 0 && value !== '0') {
  46. callback(new Error('此为必填项'))
  47. }
  48. else if (config.val_type === 'int' || config.val_type === 'float') {
  49. const temp = Number(value)
  50. if (temp < config.val_lower_limit || temp > config.val_upper_limit) {
  51. callback(new Error(`输入范围为${config.val_lower_limit}-${config.val_upper_limit}`))
  52. }
  53. }
  54. callback()
  55. }
  56. </script>
  57. <template>
  58. <div class="formula-form">
  59. <el-form
  60. :model="formData"
  61. label-width="auto"
  62. label-position="right"
  63. :size="size"
  64. inline
  65. >
  66. <el-form-item v-if="props.formulaNameVisible" label="配方名称" style="width: 93%">
  67. <el-input
  68. v-model="formData.name"
  69. v-prevent-keyboard
  70. name="name"
  71. placeholder="配方名称"
  72. :disabled="true"
  73. />
  74. </el-form-item>
  75. <el-form-item
  76. v-for="item in formulaConfigList.filter((data) => data.is_visible_in_rt_page)"
  77. :key="item.setting_id"
  78. :label="formulaNameMap[item.setting_id]"
  79. style="width: 50%"
  80. :prop="item.setting_id"
  81. :rules="[
  82. {
  83. required: true,
  84. validator: (rule, value, callback) => validatePass(rule, value, callback, item),
  85. trigger: 'blur',
  86. },
  87. ]"
  88. >
  89. <template v-if="item.val_type === 'int'">
  90. <el-input
  91. v-model.number="formData[item.setting_id]"
  92. v-prevent-keyboard
  93. style="width: 80%"
  94. type="number"
  95. :name="item.setting_id"
  96. :controls="false"
  97. :disabled="!(item.is_editable && !props.formulaNameVisible)"
  98. >
  99. <template v-if="labelUnitMap[item.setting_id]" #append>
  100. {{ labelUnitMap[item.setting_id] }}
  101. </template>
  102. </el-input>
  103. </template>
  104. <template v-if="item.val_type === 'float'">
  105. <el-input
  106. v-model.number="formData[item.setting_id]"
  107. v-prevent-keyboard
  108. style="width: 80%"
  109. type="number"
  110. :name="item.setting_id"
  111. :controls="false"
  112. :disabled="!(item.is_editable && !props.formulaNameVisible)"
  113. >
  114. <template v-if="labelUnitMap[item.setting_id]" #append>
  115. {{ labelUnitMap[item.setting_id] }}
  116. </template>
  117. </el-input>
  118. </template>
  119. <template v-else-if="item.val_type === 'enum'">
  120. <el-select
  121. v-model="formData[item.setting_id]"
  122. v-prevent-keyboard
  123. style="width: 80%;height:40px"
  124. placeholder="请选择"
  125. :disabled="!(item.is_editable && !props.formulaNameVisible)"
  126. readonly
  127. >
  128. <el-option v-for="log in item.enums" :key="log" :label="log" :value="log" />
  129. </el-select>
  130. </template>
  131. <template v-else-if="item.val_type === 'boolean'">
  132. <el-radio-group v-model="formData[item.setting_id]" :disabled="!item.is_editable">
  133. <el-radio :label="true">
  134. </el-radio>
  135. <el-radio :label="false">
  136. </el-radio>
  137. </el-radio-group>
  138. </template>
  139. </el-form-item>
  140. </el-form>
  141. </div>
  142. </template>
  143. <style lang="scss" scoped>
  144. .formula-form {
  145. font-size: 20px !important;
  146. padding: 5px;
  147. padding-left: 15px;
  148. align-items: center;
  149. .default-btn {
  150. margin-top: 1rem;
  151. }
  152. .config-btn {
  153. height: 3rem;
  154. width: 8rem;
  155. }
  156. }
  157. .formula-form-item {
  158. display: grid;
  159. grid-template-columns: 1fr 1fr;
  160. }
  161. .formData-input-config {
  162. width: 10vw;
  163. }
  164. :deep(.el-input__inner) {
  165. text-align: left;
  166. height: 40px;
  167. }
  168. :deep(.el-form-item) {
  169. margin-right: 0;
  170. align-items: center;
  171. }
  172. /* 进入动画的初始状态 */
  173. .slide-right-enter-from {
  174. transform: translateX(100%);
  175. }
  176. /* 进入动画的结束状态(也可以理解为激活状态) */
  177. .slide-right-enter-to {
  178. transform: translateX(0);
  179. }
  180. /* 进入动画的过渡曲线等 */
  181. .slide-right-enter-active {
  182. transition: transform 0.3s ease-in-out;
  183. }
  184. /* 离开动画的初始状态(激活状态) */
  185. .slide-right-leave-from {
  186. transform: translateX(0);
  187. }
  188. /* 离开动画的结束状态 */
  189. .slide-right-leave-to {
  190. transform: translateX(100%);
  191. }
  192. /* 离开动画的过渡曲线等 */
  193. .slide-right-leave-active {
  194. transition: transform 0.3s ease-in-out;
  195. }
  196. </style>