wangrong
2026-08-30 761e5c5fa871959f60e15c971c8d83f2b53d0af5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<script lang="ts" setup>
import { ref, reactive } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import dayjs from 'dayjs'
 
const { t } = useI18n()
const dialogFormVisible = ref(false)
const form = reactive({
  type: '',
  value: ''
})
const init = (type, value) => {
  dialogFormVisible.value = true
  form.type = type || 'year'
  form.value = type ? value : ''
}
 
const timeList = [
  {
    label: t('dynamic_time.year'),
    value: 'year'
  },
  {
    label: t('chart.y_M'),
    value: 'month'
  },
  {
    label: t('chart.y_M_d'),
    value: 'date'
  },
  {
    label: t('chart.y_M_d_H_m_s'),
    value: 'datetime'
  }
]
 
const formatMap = {
  datetime: 'YYYY/MM/DD HH:mm:ss',
  date: 'YYYY/MM/DD',
  month: 'YYYY/MM',
  year: 'YYYY'
}
 
const beforeClose = () => {
  form.type = ''
  form.value = ''
  dialogFormVisible.value = false
}
const emits = defineEmits(['saveTime'])
const formatValue = (val: any) => {
  if (!val) return ''
  return dayjs(val).format(formatMap[form.type])
}
const confirm = () => {
  const value = form.value
  if (value) emits('saveTime', form.type, formatValue(form.value))
  beforeClose()
}
 
defineExpose({
  init
})
</script>
 
<template>
  <el-dialog
    :before-close="beforeClose"
    v-model="dialogFormVisible"
    :title="$t('data_set.time')"
    width="600"
    append-to-body
  >
    <el-form label-position="top">
      <el-form-item :label="$t('v_query.time_granularity')">
        <el-select
          :placeholder="$t('v_query.the_time_granularity')"
          v-model="form.type"
          style="width: 58%"
        >
          <el-option
            v-for="ele in timeList"
            :key="ele.value"
            :label="ele.label"
            :value="ele.value"
          />
        </el-select>
        <el-date-picker style="margin-left: auto" v-model="form.value" :type="form.type" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="beforeClose">{{ t('common.cancel') }}</el-button>
        <el-button type="primary" @click="confirm">
          {{ t('dataset.confirm') }}
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>
 
<style lang="less" scoped></style>