config.vue 7.08 KB
<template>
  <collapse-item :name="t('information.demonstrations')" :expanded="true">
    <setting-item-box :name="t('information.selectBy')">
      <n-select v-model:value="optionData.isPanel" size="small" :options="panelOptions" />
    </setting-item-box>
  </collapse-item>
  <collapse-item :name="t('information.timeConfig')" :expanded="true">
    <setting-item-box :name="t('information.quickSelection')">
      <setting-item :name="t('information.date')">
        <n-select
          clearable
          @change="shortCutSelect"
          v-model:value="optionData.shortcut"
          size="small"
          :options="intervalOption"
        />
      </setting-item>
    </setting-item-box>
    <setting-item-box :name="t('common.foundationText')">
      <setting-item :name="t('common.typeText')">
        <n-select
          v-model:value="optionData.componentInteractEventKey"
          size="small"
          :options="datePickerTypeOptions"
          @update:value="datePickerTypeUpdate"
        />
      </setting-item>
    </setting-item-box>
    <setting-item-box :name="t('common.defaultValueText')">
      <setting-item :name="t('common.typeText')">
        <n-select
          v-model:value="optionData.defaultType"
          size="small"
          :options="defaultTypeOptions"
          @update:value="defaultTypeUpdate"
        />
      </setting-item>
    </setting-item-box>
    <setting-item-box v-if="optionData.defaultType === DefaultTypeEnum.STATIC" :alone="true">
      <setting-item :name="t('information.selectDefault')">
        <n-date-picker
          size="small"
          clearable
          v-model:value="optionData.dataset"
          :type="optionData.componentInteractEventKey"
        />
      </setting-item>
    </setting-item-box>
    <setting-item-box v-if="optionData.defaultType === DefaultTypeEnum.DYNAMIC">
      <template #name>
        <n-text></n-text>
        <n-tooltip trigger="hover">
          <template #trigger>
            <n-icon size="21" :depth="3">
              <help-outline-icon></help-outline-icon>
            </n-icon>
          </template>
          <span>{{t('information.openPageUnit')}}</span>
        </n-tooltip>
      </template>
      <setting-item :name="differValueName">
        <n-input-number v-model:value="optionData.differValue[0]" class="input-num-width" size="small">
          <template #suffix>
            {{ DifferUnitObject[optionData.differUnit[0]] }}
          </template>
        </n-input-number>
      </setting-item>
      <setting-item :name="differUnitName">
        <n-select v-model:value="optionData.differUnit[0]" size="small" :options="differUnitOptions" />
      </setting-item>
      <setting-item v-if="isRange" :name="t('information.endValueOffset')">
        <n-input-number v-model:value="optionData.differValue[1]" class="input-num-width" size="small">
          <template #suffix>
            {{ DifferUnitObject[optionData.differUnit[1]] }}
          </template>
        </n-input-number>
      </setting-item>
      <setting-item v-if="isRange" :name="t('information.endValueUnit')">
        <n-select v-model:value="optionData.differUnit[1]" size="small" :options="differUnitOptions" />
      </setting-item>
    </setting-item-box>
  </collapse-item>
</template>

<script lang="ts" setup>
import { PropType, computed, ref } from 'vue'
import { icon } from '@/plugins'
import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting'
import { option } from './config'
import { intervalOption } from './shortcutTime'
import { ComponentInteractEventEnum, DefaultTypeEnum, DifferUnitEnum, DifferUnitObject } from './interact'
import dayjs from 'dayjs'

const { HelpOutlineIcon } = icon.ionicons5

const props = defineProps({
  optionData: {
    type: Object as PropType<typeof option>,
    required: true
  }
})

const t = window['$t']

const panelOptions = [
  {
    label: t('information.dropDisplay'),
    value: 0
  },
  {
    label: t('information.panalDisplay'),
    value: 1
  }
]

const datePickerTypeOptions = [
  {
    label: t('information.date'),
    value: ComponentInteractEventEnum.DATE
  },
  {
    label: t('information.dateTime'),
    value: ComponentInteractEventEnum.DATE_TIME
  },
  {
    label: t('information.dateRange'),
    value: ComponentInteractEventEnum.DATE_RANGE
  },
  {
    label: t('information.dateTimeRange'),
    value: ComponentInteractEventEnum.DATE_TIME_RANGE
  },
  {
    label: t('information.month'),
    value: ComponentInteractEventEnum.MONTH
  },
  {
    label: t('information.monthRange'),
    value: ComponentInteractEventEnum.MONTH_RANGE
  },
  {
    label: t('information.year'),
    value: ComponentInteractEventEnum.YEAR
  },
  {
    label: t('information.yearRange'),
    value: ComponentInteractEventEnum.YEAR_RANGE
  },
  {
    label: t('information.quarter'),
    value: ComponentInteractEventEnum.QUARTER
  },
  {
    label: t('information.quarterRange'),
    value: ComponentInteractEventEnum.QUARTER_RANGE
  }
]

const defaultTypeOptions = [
  {
    label: t('information.staticState'),
    value: DefaultTypeEnum.STATIC
  },
  {
    label: t('information.trends'),
    value: DefaultTypeEnum.DYNAMIC
  },
  {
    label: t('common.notHaveText'),
    value: DefaultTypeEnum.NONE
  }
]

const differUnitOptions = [
  // ManipulateType
  {
    value: DifferUnitEnum.DAY,
    label: DifferUnitObject[DifferUnitEnum.DAY]
  },
  {
    value: DifferUnitEnum.WEEK,
    label: DifferUnitObject[DifferUnitEnum.WEEK]
  },
  {
    value: DifferUnitEnum.MONTH,
    label: DifferUnitObject[DifferUnitEnum.MONTH]
  },
  {
    value: DifferUnitEnum.QUARTER,
    label: DifferUnitObject[DifferUnitEnum.QUARTER]
  },
  {
    value: DifferUnitEnum.YEAR,
    label: DifferUnitObject[DifferUnitEnum.YEAR]
  },
  {
    value: DifferUnitEnum.HOUR,
    label: DifferUnitObject[DifferUnitEnum.HOUR]
  },
  {
    value: DifferUnitEnum.MINUTE,
    label: DifferUnitObject[DifferUnitEnum.MINUTE]
  },
  {
    value: DifferUnitEnum.SECOND,
    label: DifferUnitObject[DifferUnitEnum.SECOND]
  },
  {
    value: DifferUnitEnum.MILLISECOND,
    label: DifferUnitObject[DifferUnitEnum.MILLISECOND]
  }
]

const isRange = computed(() => {
  return props.optionData.componentInteractEventKey.endsWith('range')
})

const differValueName = computed(() => {
  return isRange.value ? t('information.startValueOffset') : t('information.dynamicOffset')
})

const differUnitName = computed(() => {
  return isRange.value ? t('information.startValueUnit') : t('information.offsetUnit')
})

const startTs = ref(0)
const endTs = ref(0)

const datePickerTypeUpdate = () => {
  props.optionData.dataset = isRange.value
    ? [startTs.value ? startTs.value : dayjs().valueOf(), endTs.value ? endTs.value : dayjs().valueOf()]
    : [dayjs().valueOf()]
}

const defaultTypeUpdate = (v: string) => {
  if (v === DefaultTypeEnum.STATIC) {
    datePickerTypeUpdate()
  } else {
    // DefaultTypeEnum.
    props.optionData.dataset = []
  }
}

const shortCutSelect = (value: number) => {
  console.log(value)
  startTs.value = Date.now() - value
  endTs.value = Date.now()
  props.optionData.dataset = [startTs.value, endTs.value] as any
}
// shortCutSelect(24*60*60*1000)//默认近1天
</script>