无人机管理后台前端(已迁走)
张含笑
2025-07-22 2c0b7e851fb277487e5e8d08b27034b8ed891b7f
feat:日历调整
1 files modified
2 files added
131 ■■■■ changed files
src/assets/images/workbench/caleft.png patch | view | raw | blame | history
src/assets/images/workbench/caright.png patch | view | raw | blame | history
src/views/wel/components/calendarBox.vue 131 ●●●● patch | view | raw | blame | history
src/assets/images/workbench/caleft.png
src/assets/images/workbench/caright.png
src/views/wel/components/calendarBox.vue
@@ -1,6 +1,13 @@
<template>
  <div class="calenBox">
    <el-calendar ref="calendar" v-model="leftValue">
      <template #header="{ date }">
        <div>
          <img :src="caleft" alt="" @click="selectDate('prev-month')" />
          <span>{{ date }}</span>
          <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>
@@ -12,7 +19,9 @@
              :class="event.type"
              @click="jumpcalendar(event, data.day)"
            >
              <div class="imgBox"><img :src="getEventIcon(event.type)" alt="" /> {{ event.name }}</div>
              <div class="imgBox">
                <img :src="getEventIcon(event.type)" alt="" /> {{ event.name }}
              </div>
              <span>{{ event.value }}</span>
            </div>
          </div>
@@ -28,13 +37,20 @@
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';
import { ElMessage } from 'element-plus';
const calendar = ref();
const router = useRouter();
const events = ref({});
const params = ref({
  end_date: undefined,
  start_date: undefined,
});
const isCurrentMonth = (date) => {
  return dayjs(date).isSame(dayjs(), 'month');
};
const leftValue = ref(null);
const eventIcons = ref({
  'work-order': ev1,
  task: ev2,
@@ -48,22 +64,49 @@
    end_date: dayjs().endOf('month').format('YYYY-MM-DD HH:mm:ss'),
  };
}
const leftValue = ref(new Date());
const selectDate = val => {
  if (!calendar.value) return;
  calendar.value.selectDate(val);
};
// 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 }
// );
watch(
  () => leftValue.value,
  (newV, oldV) => {
    if (newV && oldV) {
    if (newV) {
      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'),
      };
      // 新增:如果是当前月份,自动选中当天
      if (isCurrentMonth(newV)) {
        nextTick(() => {
          if (calendar.value) {
            calendar.value.selectDate(new Date());
          }
        });
      }
      getJobEventBar();
    }
  },
  { deep: true, immediate: true }
);
// 获取日期数字
const getDate = date => {
  return date.getDate();
@@ -106,19 +149,64 @@
  }
};
onMounted(() => {
  // 新增:挂载时如果是当前月份,设置默认选中
  if (isCurrentMonth(leftValue.value)) {
    leftValue.value = new Date();
  }
  getJobEventBar();
});
</script>
<style lang="scss">
.calenBox {
  //  height: 630px;
  height: pxToVh(660);
  // 隐藏按钮组中间按钮
  .el-button-group > .el-button:not(:first-child):not(:last-child) {
    display: none;
  }
  .el-calendar__body {
    padding-top: 0;
  }
  .date-number {
  font-size: 13px !important;}
    font-size: 13px !important;
  }
  .el-calendar__header {
    justify-content: center;
    margin-top: 18px;
    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.8rem;
    background: #f5f7fa;
    border-radius: 6px 6px 6px 6px;
    border: 1px solid #efefef;
    margin-right: 5px;
    margin-bottom: 8px;
  }
}
</style>
@@ -132,43 +220,35 @@
  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;
      height: pxToVh(88) !important;
    }
    // 选中日期样式
    .el-calendar-table td.is-selected {
      background-color: #f0f7ff;
      border: 2px solid #409eff;
      border-radius: 4px;
    .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;
    // padding: 2px;
    text-align: center;
    border-radius: 3px;
    white-space: nowrap;
@@ -199,7 +279,8 @@
      }
    }
    .imgBox {
   font-size: 12px;}
      font-size: 12px;
    }
  }
}
</style>