DeviceProfileModal.vue 2.4 KB
<template>
  <BasicModal
    v-bind="$attrs"
    width="55rem"
    @register="register"
    :title="getTitle"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <div class="step-form-form">
      <a-steps :current="current">
        <a-step title="设备配置" />
        <a-step title="传输配置" />
        <a-step title="告警配置" />
      </a-steps>
    </div>
    <div class="mt-5">
      <DeviceProfileStep1 @next="handleStep1Next" v-if="current === 0" />
      <DeviceProfileStep2 @prev="handleStepPrev" @next="handleStep2Next" v-if="current === 1" />
      <DeviceProfileStep3 @prev="handleStepPrev" @redo="handleRedo" v-if="current === 2" />
    </div>
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, ref, computed, unref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import DeviceProfileStep1 from '/@/views/device/profile/step/DeviceProfileStep1.vue';
  import DeviceProfileStep2 from '/@/views/device/profile/step/DeviceProfileStep2.vue';
  import DeviceProfileStep3 from '/@/views/device/profile/step/DeviceProfileStep3.vue';
  import { Steps } from 'ant-design-vue';
  export default defineComponent({
    name: 'DeviceModal',
    components: {
      BasicModal,
      DeviceProfileStep1,
      DeviceProfileStep2,
      DeviceProfileStep3,
      [Steps.name]: Steps,
      [Steps.Step.name]: Steps.Step,
    },
    props: {
      userData: { type: Object },
    },
    setup(_) {
      const current = ref(0);
      const isUpdate = ref(true);
      const getTitle = computed(() => (!unref(isUpdate) ? '新增设备配置' : '编辑设备配置'));
      const [register] = useModalInner((data) => {
        isUpdate.value = !!data?.isUpdate;
        if (!unref(isUpdate)) {
          current.value = 0;
        }
      });
      function handleStepPrev() {
        current.value--;
      }
      function handleStep1Next() {
        current.value++;
      }
      function handleStep2Next() {
        current.value++;
      }
      function handleRedo() {
        current.value = 0;
      }
      const handleSubmit = () => {
        console.log();
      };
      const handleCancel = () => {
        console.log();
      };
      return {
        handleSubmit,
        handleCancel,
        register,
        getTitle,
        current,
        handleStepPrev,
        handleStep1Next,
        handleStep2Next,
        handleRedo,
      };
    },
  });
</script>