无人机管理后台前端(已迁走)
张含笑
2025-07-21 3be2e099bbc05e902dfcfabc403ade0a2aba8ef4
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<template>
  <div class="calenBox">
    <el-calendar ref="calendar" v-model="leftValue">
      <template #date-cell="{ data }">
        <div :class="data.isSelected ? 'is-selected' : ''">
          <div class="date-number">{{ data.day.slice(8, 10) }}</div>
          <div class="events">
            <div
              v-for="(event, index) in getEvents(data.day)"
              :key="index"
              class="event-item"
              :class="event.type"
              @click="jumpcalendar(event, data.day)"
            >
              <div class="imgBox"><img :src="getEventIcon(event.type)" alt="" /> {{ event.name }}</div>
              <span>{{ event.value }}</span>
            </div>
          </div>
        </div>
      </template>
    </el-calendar>
  </div>
</template>
 
<script setup>
import dayjs from 'dayjs';
import { jobEventBar, getCalen } from '@/api/home/index';
import { useRouter } from 'vue-router';
import ev1 from '@/assets/images/workbench/ev1.svg';
import ev2 from '@/assets/images/workbench/ev2.svg';
import { ElMessage } from 'element-plus';
const router = useRouter();
const events = ref({});
const params = ref({
  end_date: undefined,
  start_date: undefined,
});
const eventIcons = ref({
  'work-order': ev1,
  task: ev2,
});
const getEventIcon = type => {
  return eventIcons.value[type] || eventIcons.value.default;
};
function getCurrentMonthRange() {
  return {
    start_date: dayjs().startOf('month').format('YYYY-MM-DD HH:mm:ss'),
    end_date: dayjs().endOf('month').format('YYYY-MM-DD HH:mm:ss'),
  };
}
const leftValue = ref(new Date());
watch(
  () => leftValue.value,
  (newV, oldV) => {
    if (newV && oldV) {
      const newDate = dayjs(newV);
      params.value = {
        start_date: newDate.startOf('month').format('YYYY-MM-DD HH:mm:ss'),
        end_date: newDate.endOf('month').format('YYYY-MM-DD HH:mm:ss'),
      };
      getJobEventBar();
    }
  },
  { deep: true, immediate: true }
);
 
// 获取日期数字
const getDate = date => {
  return date.getDate();
};
 
// 获取对应日期的事件
const getEvents = dateString => {
  return events.value[dateString] || [];
};
const monthRange = getCurrentMonthRange();
params.value = monthRange;
 
const getJobEventBar = () => {
  getCalen(params.value).then(res => {
    if (res.data.code !== 0) return;
    const a = res.data.data;
    const filteredData = {};
    for (let date in a) {
      filteredData[date] = a[date].filter(item => item.type !== 'work-order');
    }
    events.value = filteredData;
    // events.value = res.data.data
  });
};
const jumpcalendar = (event, day) => {
  if (event.name === '工单') {
    router.push({
      path: '/tickets/ticket',
      query: {
        day: day,
      },
    });
  } else {
    router.push({
      path: '/job/jobstatistics',
      query: {
        day: day,
      },
    });
  }
};
onMounted(() => {
  getJobEventBar();
});
</script>
<style lang="scss">
.calenBox {
  //  height: 630px;
  height: pxToVh(660);
  // 隐藏按钮组中间按钮
  .el-button-group > .el-button:not(:first-child):not(:last-child) {
    display: none;
  }
  .date-number {
  font-size: 13px !important;}
}
</style>
 
<style lang="scss" scoped>
.calenBox {
  margin-top: 10px;
  // height: 630px;
  height: pxToVh(622);
  border-radius: 10px;
  overflow: hidden;
  background-color: #fff;
 
  ::v-deep(.el-calendar) {
    // height: 80%; // 日历填充容器
    // 标题样式
    .el-calendar__title {
      font-weight: bold;
      font-size: 14px;
      color: #363636;
    }
 
    // 日历主体
    // &__body {
    //   height: 98%; // 关键:继承父高度
 
    //   .el-calendar-table {
    //     height: 90% !important; // 百分比生效
    //   }
    // }
    .el-calendar-table .el-calendar-day {
   
       height: pxToVh(91) !important;
    }
 
    // 选中日期样式
    .el-calendar-table td.is-selected {
      background-color: #f0f7ff;
      border: 2px solid #409eff;
      border-radius: 4px;
 
      .date-number {
        font-weight: bold;
        color: #409eff;
      }
    }
  }
 
  .event-item {
    font-size: 12px;
    // padding: 2px;
    text-align: center;
    border-radius: 3px;
    white-space: nowrap;
 
    &.work-order {
      font-weight: 400;
      font-size: 12px;
      color: #7b7b7b;
 
      span {
        font-weight: 600;
        font-size: 14px;
        color: #1c5cff;
        margin-left: 2px;
      }
    }
 
    &.task {
      font-weight: 400;
      font-size: 12px;
      color: #7b7b7b;
 
      span {
        font-weight: 600;
        font-size: 18px;
        color: #029d36;
        margin-left: 2px;
      }
    }
    .imgBox {
   font-size: 12px;}
  }
}
</style>