riku
2025-02-21 c35074e0e33054bb6c5ada22f8104422ae953b17
src/components/search/SearchBar.vue
@@ -2,11 +2,15 @@
  <BaseCard size="middle-s" direction="down">
    <template #content>
      <el-form :inline="true">
        <OptionMission v-model="mission"></OptionMission>
        <OptionType v-model="formSearch.deviceType"></OptionType>
        <OptionMission v-model="mission" @init-over="initOver"></OptionMission>
        <OptionType
          v-model="formSearch.deviceType"
          @init-over="initOver"
        ></OptionType>
        <OptionDevice
          :type="formSearch.deviceType"
          v-model="formSearch.deviceCode"
          @init-over="initOver"
        ></OptionDevice>
        <OptionTime
          v-model="formSearch.timeArray"
@@ -27,6 +31,12 @@
</template>
<script>
// 可能会有延时初始化的选项总数,包括走航任务、设备类型、设备编号
const MAX_INIT = 3;
// 已初始化的选项数
let initCount = 0;
let initEvents = [];
// 搜索框
export default {
  props: {
@@ -54,24 +64,43 @@
    },
    mission(nV, oV) {
      if (nV != oV) {
        this.formSearch.timeArray = [
          new Date(nV.startTime),
          new Date(nV.endTime)
        ];
        this.dateRange = [new Date(nV.startTime), new Date(nV.endTime)];
        this.formSearch.deviceType = nV.deviceType;
        this.formSearch.deviceCode = nV.deviceCode;
        this.onInit(() => {
          this.formSearch.timeArray = [
            new Date(nV.startTime),
            new Date(nV.endTime)
          ];
          this.dateRange = [new Date(nV.startTime), new Date(nV.endTime)];
          this.formSearch.deviceType = nV.deviceType;
          this.formSearch.deviceCode = nV.deviceCode;
        // 代表首次进入界面,此时自动执行首个任务的数据查询操作
        if (oV == undefined) {
          setTimeout(() => {
            this.handleClick();
          }, 500);
        }
          // 代表首次进入界面,此时自动执行首个任务的数据查询操作
          if (oV == undefined) {
            setTimeout(() => {
              this.handleClick();
            }, 500);
          }
        });
      }
    }
  },
  methods: {
    // 各选项初始化加载完成判定
    initOver() {
      initCount++;
      if (initCount == MAX_INIT && initEvents.length > 0) {
        initEvents.forEach((e) => {
          e();
        });
        initEvents = [];
      }
    },
    onInit(event) {
      if (initCount == MAX_INIT) {
        event();
      } else {
        initEvents.push(event);
      }
    },
    handleClick() {
      this.$emit('search', { ...this.formSearch, mission: this.mission });
    }