forked from drone/command-center-dashboard

罗广辉
2025-04-03 7635213630830c4cbb9ff6ada69ba9b5c8a35d42
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<template>
  <div class="common-date-time">
    <el-date-picker
      v-model="model"
      type="daterange"
      value-format="YYYY-MM-DD"
      range-separator="-"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      @change="change"
      disabled
    />
    <div class="time-card">
      <div
        class="card-item"
        :class="item === checked ? 'active' : ''"
        v-for="(item, index) in timeList"
        @click="timeClick(item,index)"
      >
        {{ timeListStr[index] }}
      </div>
    </div>
  </div>
</template>
 
<script setup>
import dayjs from 'dayjs';
import { ref, defineEmits } from 'vue';
 
const emit = defineEmits(['change']);
 
const model = defineModel();
 
let timeList = ['today', 'week', 'month', 'year'];
let timeListStr = ['今日', '本周', '本月', '本年'];
let timeListEnum = ['TODAY', 'CURRENT_WEEK', 'CURRENT_MONTH', 'CURRENT_YEAR'];
let checked = ref('today');
 
const getDateRange = unit => {
  if (unit === 'today') {
    return [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')];
  }
  return [dayjs().startOf(unit).format('YYYY-MM-DD'), dayjs().endOf(unit).format('YYYY-MM-DD')];
};
 
const dateRanges = {
  today: getDateRange('today'),
  week: getDateRange('week'),
  month: getDateRange('month'),
  year: getDateRange('year'),
};
 
const change = value => {
  // todo 我对接
  // emit('change', value);
};
 
let timeClick = (item,index) => {
  checked.value = item;
  model.value = dateRanges[item];
  emit('change', dateRanges[item],timeListEnum[index]);
};
</script>
 
<style scoped lang="scss">
.common-date-time {
  position: relative;
  display: flex;
  justify-content: space-between;
 
  :deep(.el-date-editor) {
    box-shadow: none;
    width: 0;
    flex: 1;
    margin-right: 4px;
 
    background: rgba(0, 15, 34, 0.5);
    border-radius: 0px 0px 0px 0px;
    border: 1px solid #306fca;
    height: 28px;
 
    .el-input__wrapper {
      background-color: transparent;
      box-shadow: 0 0 0 1px #0070ff;
 
      &.is-focus {
        box-shadow: 0 0 0 1px #0070ff;
      }
    }
 
    .el-range-input {
      background-color: transparent;
      color: #fff;
      height: 28px;
 
      &::placeholder {
        color: rgba(255, 255, 255, 0.6);
      }
    }
  }
 
  .time-card {
    text-align: center;
    background: linear-gradient(270deg, #195bad 0%, rgba(25, 91, 173, 0) 100%);
    border: 1px solid #306fca;
    font-family: Source Han Sans CN, Source Han Sans CN, serif;
    font-weight: 400;
    font-size: 14px;
    color: #ffffff;
    display: flex;
    height: 28px;
 
    .card-item {
      width: 39px;
      height: 100%;
      line-height: 26px;
      cursor: pointer;
    }
 
    .active {
      background: linear-gradient(270deg, #19ad8d 0%, rgba(25, 173, 141, 0) 100%);
      box-shadow: inset 0px 0px 8px 0px rgba(0, 255, 200, 0.6);
      border-radius: 0px 0px 0px 0px;
    }
  }
}
</style>