无人机管理后台前端(已迁走)
张含笑
2025-09-01 2ca94de8ede18ac07ccfd8dec7b6f6a707adde9b
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<template>
  <div class="calenBox">
    <el-calendar ref="calendar" v-model="currentMonth"  :class="{
    'five-rows': weeksNeeded === 5,
    'six-rows': weeksNeeded === 6
  }">
      <template #header="{ date }">
        <div>
          <img :src="caleft" alt="" @click="selectDate('prev-month')" />
          <el-date-picker
            v-model="currentMonth"
            type="month"
            :clearable="false"
            :prefix-icon="''"
            @change="handleMonthChange"
            :format="'YYYY年M月'"
          />
          <img :src="caright" alt="" @click="selectDate('next-month')" />
        </div>
      </template>
      <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 { ref, watch, onMounted, nextTick } from 'vue';
import { 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 caleft from '@/assets/images/workbench/caleft.png';
import caright from '@/assets/images/workbench/caright.png';
const router = useRouter();
const calendar = ref();
const events = ref({});
const currentMonth = ref(new Date()); // 控制当前显示的月份
const selectedDate = ref(null); // 控制选中的日期
const params = ref({
  end_date: undefined,
  start_date: undefined,
});
 
const eventIcons = ref({
  'work-order': ev1,
  task: ev2,
});
 
const monthRange = getCurrentMonthRange();
params.value = monthRange;
// 检查日期是否是当前月份
const isCurrentMonth = date => {
  return dayjs(date).isSame(dayjs(), 'month');
};
// 处理月份选择器变化
const handleMonthChange = val => {
  const selectedMonth = new Date(val);
  currentMonth.value = selectedMonth;
  
  // 如果是当前月份,则选中当天;否则不选中
  if (isCurrentMonth(selectedMonth)) {
    selectedDate.value = new Date();
  } else {
    selectedDate.value = null;
  }
  
  // 强制更新日历视图
  nextTick(() => {
    updateCalendarSelection();
  });
};
 
// 获取日历数据
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;
  });
};
 
// 获取事件图标
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 selectDate = async val => {
  if (!calendar.value) return;
 
  if (val === 'prev-month') {
    currentMonth.value = dayjs(currentMonth.value).subtract(1, 'month').toDate();
  } else if (val === 'next-month') {
    currentMonth.value = dayjs(currentMonth.value).add(1, 'month').toDate();
  }
 
  // 如果是当前月份,则选中当天;否则不选中
  if (isCurrentMonth(currentMonth.value)) {
    selectedDate.value = new Date();
  } else {
    selectedDate.value = null;
  }
 
  await nextTick();
  updateCalendarSelection();
};
const updateCalendarSelection = () => {
  // 清除所有选中状态
  const selectedCells = document.querySelectorAll('.el-calendar-table td.is-selected');
  selectedCells.forEach(cell => {
    cell.classList.remove('is-selected');
  });
 
  // 如果是当前月份,设置当前日为选中状态
  if (isCurrentMonth(currentMonth.value) && selectedDate.value) {
    const currentDay = dayjs(selectedDate.value).date();
    const calendarCells = document.querySelectorAll('.el-calendar-table td');
    
    calendarCells.forEach(cell => {
      const day = parseInt(cell.querySelector('.date-number').textContent);
      if (day === currentDay) {
        cell.classList.add('is-selected');
      }
    });
  }
};
 
// 监听当前月份变化
watch(
  () => currentMonth.value,
  newMonth => {
    const newDate = dayjs(newMonth);
    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'),
    };
    // 如果是当前月份,则选中当天;否则清除选中
    if (isCurrentMonth(newMonth)) {
      selectedDate.value = new Date();
    } else {
      selectedDate.value = null;
    }
    nextTick(() => {
      updateCalendarSelection();
    });
    
    getJobEventBar();
  },
  { deep: true, immediate: true }
);
 
// 获取日期数字
const getDate = date => {
  return date.getDate();
};
 
// 获取对应日期的事件
const getEvents = dateString => {
  return events.value[dateString] || [];
};
const jumpcalendar = (event, day) => {
  if (event.name === '工单') {
    router.push({
      path: '/tickets/ticket',
      query: {
        day: day,
      },
    });
  } else {
    router.push({
      path: '/job/jobstatistics',
      query: {
        day: day,
      },
    });
  }
};
 
const weeksNeeded = computed(() => {
  const date = dayjs(currentMonth.value);
  const firstDay = date.startOf('month').day(); // 0-6 (周日到周六)
  const days = date.daysInMonth();
 
  // 强制 2025 年 6 月显示六行
   //if (date.year() === 2025 && date.month() === 5) {
   //  return 6;
  // }
 
  // 其他月份按原逻辑计算
  return Math.ceil((firstDay + days) / 7);
})
const isSixRows = computed(() => weeksNeeded.value > 5);
onMounted(() => {
  // 初始化时如果是当前月份,选中当天;否则不选中
  if (isCurrentMonth(currentMonth.value)) {
    selectedDate.value = new Date();
  } else {
    selectedDate.value = null;
  }
  
  nextTick(() => {
    updateCalendarSelection();
  });
  
  getJobEventBar();
});
</script>
 
<style lang="scss">
.calenBox {
  height: pxToVh(670);
  // 隐藏按钮组中间按钮
  .el-button-group > .el-button:not(:first-child):not(:last-child) {
    display: none;
  }
  .el-calendar__body {
    padding-top: 0 !important;
  }
  .date-number {
    font-size: 13px !important;
  }
  .el-calendar__header {
    justify-content: center;
    margin-top: 10px;
    padding-bottom: 0;
    border-bottom: transparent;
    div {
      display: flex;
      justify-content: center;
      align-items: center;
      img {
        width: 28px;
        height: 28px;
        cursor: pointer;
      }
      span {
        font-weight: bold;
        font-size: 14px;
        color: #363636;
        margin: 0 18px;
      }
    }
  }
  .el-calendar-table td {
    border: none;
  }
  .el-calendar-table tr td {
    border: none;
  }
  .el-calendar-table .el-calendar-day {
    box-sizing: border-box;
    padding: 0.4rem 0.8rem 0.8rem 0.8rem;
    background: #f5f7fa;
    border-radius: 6px 6px 6px 6px;
    border: 1px solid #efefef;
    margin-right: 5px;
    margin-bottom: 8px;
  }
  .el-input__prefix-inner {
    display: none !important;
  }
  .el-input__suffix {
    width: 0 !important;
  }
  .el-input__wrapper {
    align-items: center !important;
    cursor: text;
    box-shadow: none !important;
    display: inline-flex !important;
    flex-grow: 1;
    justify-content: center;
  }
  .el-input__inner {
    font-weight: bold;
    font-size: 14px;
    color: #363636;
  }
  .el-date-editor.el-input,
  .el-date-editor.el-input__wrapper {
    height: var(--el-input-height, var(--el-component-size));
 
    width: 170px !important;
  }
}
</style>
 
<style lang="scss" scoped>
.calenBox {
  margin-top: 10px;
  height: pxToVh(632);
  border-radius: 10px;
  overflow: hidden;
  background-color: #fff;
  :deep(.el-date-picker .el-input__prefix-inner) {
    display: none !important;
  }
  ::v-deep(.el-calendar) {
    // 标题样式
    .el-calendar__title {
      font-weight: bold;
      font-size: 14px;
      color: #363636;
    }
   
 &.five-rows .el-calendar-table .el-calendar-day {
    height: pxToVh(92) !important;
  }
  
  &.six-rows .el-calendar-table .el-calendar-day {
    height: pxToVh(78) !important;
  }
    // 选中日期样式
    .el-calendar-table td.is-selected {
      .el-calendar-day {
        outline: 2px solid #409eff;
        outline-offset: -2px;
        border: none !important;
        .date-number {
          font-weight: bold;
          color: #409eff;
        }
      }
    }
    .el-calendar-table td.is-selected {
      background-color: transparent;
    }
    
  }
 
  .event-item {
    font-size: 12px;
    text-align: center;
    border-radius: 3px;
    white-space: nowrap;
    position: relative;
    z-index: 2;
 
    &.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: 17px;
        color: #029d36;
        margin-left: 2px;
      }
    }
    .imgBox {
      font-size: 12px;
    }
  }
}
</style>