FormModal.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div class="vent-form">
  3. <BasicForm @register="registerForm" />
  4. <div class="j-box-bottom-button offset-20" style="margin-top: 30px">
  5. <div class="j-box-bottom-button-float">
  6. <a-button preIcon="ant-design:sync-outlined" @click="onReset">重置</a-button>
  7. <a-button type="primary" preIcon="ant-design:save-filled" @click="handleSubmit">保存</a-button>
  8. </div>
  9. </div>
  10. </div>
  11. </template>
  12. <script lang="ts" setup>
  13. import { inject, nextTick, watch, unref, onMounted } from 'vue';
  14. import { BasicForm, useForm } from '/@/components/Form/index';
  15. import { getRegulation as getRegulationList } from '/@/views/vent/deviceManager/substationTabel/substation.api';
  16. // 声明Emits
  17. const emit = defineEmits(['saveOrUpdate']);
  18. const testData = inject('formData') as any;
  19. const props = defineProps({
  20. deviceType: { type: String },
  21. record: { type: Object },
  22. });
  23. console.log(props.deviceType, '1111111111');
  24. const existingSchemas = unref(inject('formSchema')) || [];
  25. const newSchema = {
  26. label: '规程值',
  27. field: 'regulation',
  28. component: 'ApiSelect',
  29. componentProps: ({ formModel }) => {
  30. return {
  31. api: getRegulationList.bind(null, { deviceKind: props.deviceType }),
  32. labelField: 'name',
  33. valueField: 'id',
  34. onChange: (e, option) => {
  35. if (option) formModel['regulation'] = option['name'];
  36. },
  37. };
  38. },
  39. };
  40. // 在索引位置1处插入规程值配置
  41. const insertPosition = 3;
  42. const mergedSchemas = [...existingSchemas.slice(0, insertPosition), newSchema, ...existingSchemas.slice(insertPosition)];
  43. //表单配置
  44. const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
  45. schemas: mergedSchemas,
  46. showActionButtonGroup: false,
  47. });
  48. watch(
  49. testData,
  50. (newV) => {
  51. nextTick(() => {
  52. setFieldsValue({ ...newV });
  53. });
  54. },
  55. { immediate: true }
  56. );
  57. // 重置表单
  58. async function onReset() {
  59. await resetFields();
  60. await setFieldsValue({ ...testData });
  61. }
  62. //表单提交事件
  63. async function handleSubmit(v) {
  64. try {
  65. let values = await validate();
  66. emit('saveOrUpdate', values);
  67. } finally {
  68. // setModalProps({ confirmLoading: false });
  69. }
  70. }
  71. </script>
  72. <style lang="less" scoped>
  73. @ventSpace: zxm;
  74. .j-box-bottom-button-float {
  75. border: none !important;
  76. padding-bottom: 30px;
  77. left: 0px !important;
  78. right: 0px !important;
  79. bottom: 0px !important;
  80. }
  81. .vent-form {
  82. // width: 100%;
  83. max-height: 700px;
  84. overflow-y: auto;
  85. .@{ventSpace}-select-selection-item {
  86. color: rgba(255, 255, 255, 1) !important;
  87. }
  88. }
  89. </style>