transferConfigMqtt.vue 5.04 KB
<template>
  <div class="transfer-config-mode">
    <BasicForm :showSubmitButton="false" @register="register">
      <template #uploadAdd1="{ field }">
        <span style="display: none">{{ field }}</span>
        <a-upload-dragger
          v-model:fileList="fileList"
          name="file"
          :multiple="true"
          action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
          @change="handleChange"
        >
          <p class="ant-upload-drag-icon">
            <InboxOutlined />
          </p>
          <p class="ant-upload-text">Click or drag file to this area to upload</p>
          <p class="ant-upload-hint">
            Support for a single or bulk upload. Strictly prohibit from uploading company data or
            other band files
          </p>
        </a-upload-dragger>
      </template>
      <template #uploadAdd2="{ field }">
        <span style="display: none">{{ field }}</span>
        <a-upload-dragger
          v-model:fileList="fileList"
          name="file"
          :multiple="true"
          action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
          @change="handleChange"
        >
          <p class="ant-upload-drag-icon">
            <InboxOutlined />
          </p>
          <p class="ant-upload-text">Click or drag file to this area to upload</p>
          <p class="ant-upload-hint">
            Support for a single or bulk upload. Strictly prohibit from uploading company data or
            other band files
          </p>
        </a-upload-dragger>
      </template>
      <template #uploadAdd3="{ field }">
        <span style="display: none">{{ field }}</span>
        <a-upload-dragger
          v-model:fileList="fileList"
          name="file"
          :multiple="true"
          action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
          @change="handleChange"
        >
          <p class="ant-upload-drag-icon">
            <InboxOutlined />
          </p>
          <p class="ant-upload-text">Click or drag file to this area to upload</p>
          <p class="ant-upload-hint">
            Support for a single or bulk upload. Strictly prohibit from uploading company data or
            other band files
          </p>
        </a-upload-dragger>
      </template>
    </BasicForm>
  </div>
</template>
<script lang="ts">
  import { defineComponent, ref, reactive, nextTick } from 'vue';
  import { BasicForm, useForm } from '/@/components/Form';
  import { CredentialsEnum, modeMqttForm } from '../config';
  import { InboxOutlined } from '@ant-design/icons-vue';
  import { Alert, Divider, Descriptions, Upload } from 'ant-design-vue';

  export default defineComponent({
    components: {
      BasicForm,
      [Alert.name]: Alert,
      [Divider.name]: Divider,
      [Descriptions.name]: Descriptions,
      [Descriptions.Item.name]: Descriptions.Item,
      InboxOutlined,
      [Upload.Dragger.name]: Upload.Dragger,
    },
    emits: ['next', 'prev', 'register'],
    setup(_, { emit }) {
      const fileList = ref<[]>([]);
      const credentialsV = reactive({
        credentials: {
          type: '',
        },
      });
      const sonValues: any = reactive({
        configuration: {},
      });
      const [register, { validate, setFieldsValue, resetFields: defineClearFunc }] = useForm({
        labelWidth: 80,
        schemas: modeMqttForm,
        actionColOptions: {
          span: 14,
        },
        resetButtonOptions: {
          text: '上一步',
          type: 'primary',
        },

        resetFunc: customResetFunc,
        submitFunc: customSubmitFunc,
      });
      const setStepTwoFieldsValueFunc = (v, v1) => {
        setFieldsValue(v);
        setFieldsValue({
          name: v1,
        });
        setFieldsValue({
          password: v.credentials.password,
          type: v.credentials.type,
          username: v.credentials.username,
        });
      };
      const customClearStepTwoValueFunc = async () => {
        nextTick(() => {
          defineClearFunc();
        });
      };
      async function customResetFunc() {
        emit('prev');
      }
      async function customSubmitFunc() {
        try {
          const values = await validate();
          emit('next', values);
        } catch (error) {
        } finally {
        }
      }
      const handleChange = () => {};
      const getSonValueFunc = async () => {
        sonValues.configuration = await validate();
        credentialsV.credentials.type = sonValues.configuration.type;
        if (credentialsV.credentials.type == CredentialsEnum.IS_BASIC) {
          credentialsV.credentials.username = sonValues.configuration.username;
          credentialsV.credentials.password = sonValues.configuration.password;
          sonValues.configuration.username = undefined;
          sonValues.configuration.password = undefined;
        }
        Object.assign(sonValues.configuration, credentialsV);
        return sonValues;
      };
      return {
        getSonValueFunc,
        register,
        setStepTwoFieldsValueFunc,
        customClearStepTwoValueFunc,
        fileList,
        handleChange,
      };
    },
  });
</script>