无人机管理后台前端(已迁走)
张含笑
2025-05-09 bec7efb74cb9350dc720fb1ea641f06d7316b4dc
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
<template>
  <div class="calenBox">
    <el-calendar ref="calendar" v-model="leftValue">
      <template #date-cell="{ data }">
        <div>
          <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"
            >
              <span></span>
              {{ event.name }}{{ event.value }}
            </div>
          </div>
        </div>
      </template>
    </el-calendar>
  </div>
</template>
 
<script setup>
import dayjs from 'dayjs';
import { jobEventBar, getCalen } from '@/api/home/index';
// 日历事件数据
// 格式: 'YYYY-MM-DD': [...events]
const events = ref({
  '2025-05-01': [
    { type: 'work-order', content: '工单26' },
    { type: 'task', content: '任务26' },
  ],
  '2025-05-04': [
    { type: 'task', content: '任务26' },
    { type: 'work-order', content: '工单26' },
  ],
});
const params = ref({
  end_date: undefined,
  start_date: undefined,
});
 
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 && dayjs(newV).isSame(dayjs(), 'day')) {
    }
 
    if (newV && oldV) {
      const newDate = dayjs(newV);
      const oldDate = dayjs(oldV);
      const newDateStr = newDate.format('YYYY-MM-DD HH:mm:ss');
      const oldDateStr = oldDate.format('YYYY-MM-DD HH:mm:ss');
      // console.log('新日期:', newDateStr, '旧日期:', oldDateStr);
      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 (newDate.isBefore(oldDate, 'month')) {
      //   console.log('点击了上个月', params.value);
      // } else if (newDate.isAfter(oldDate, 'month')) {
      //   console.log('点击了下个月', params.value);
      // }
       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;
    events.value = res.data.data
    // console.log('日历', res.data.data);
  });
};
onMounted(() => {
  getJobEventBar();
});
</script>
 
<style lang="scss" scoped>
.calenBox {
  margin-top: 10px;
  height: 546px;
  overflow: hidden;
  .event-item {
    font-size: 12px;
    padding: 2px;
    margin: 2px 0;
    border-radius: 3px;
    white-space: nowrap;
    // overflow: hidden;
    // text-overflow: ellipsis;
 
    &.work-order {
      // background: #ecf5ff;
      color: #409eff;
      span {
        display: inline-block;
        width: 7px;
        height: 7px;
        background: #1c5cff;
        border-radius: 50%;
        margin-right: 2px;
      }
    }
 
    &.task {
      // background: #f0f9eb;
      color: #67c23a;
      span {
        display: inline-block;
        width: 7px;
        height: 7px;
        background: #029d36;
        border-radius: 50%;
        margin-right: 2px;
      }
    }
  }
}
</style>