MyCalendar.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <el-calendar class="page">
  3. <template #dateCell="{ data }">
  4. <p
  5. @click.stop="selectHandler(data)"
  6. style="height: 100%; width: 100%"
  7. :class="data.isSelected ? 'is-selected' : ''"
  8. >
  9. {{ data.day.split("-").slice(1).join("-") }} <br /><br />
  10. <template v-for="(event, index) in calendarEvents" :key="index">
  11. <el-tag
  12. @click.stop="handleEventClick(event)"
  13. v-if="
  14. data.day === event.startDate.substring(0, 10)
  15. "
  16. >
  17. {{ event.title }}
  18. </el-tag>
  19. </template>
  20. </p>
  21. </template>
  22. </el-calendar>
  23. <MyCalendarForm
  24. ref="myCalendarForm"
  25. @refreshDataList="refreshList"
  26. ></MyCalendarForm>
  27. </template>
  28. <script>
  29. import MyCalendarForm from "./MyCalendarForm";
  30. import myCalendarService from "@/api/calendar/myCalendarService";
  31. export default {
  32. data() {
  33. return {
  34. startDate: new Date(),
  35. endDate: new Date(),
  36. calendarEvents: [],
  37. };
  38. },
  39. components: {
  40. MyCalendarForm,
  41. },
  42. activated() {
  43. this.refreshList();
  44. },
  45. methods: {
  46. // 选择月份
  47. selectHandler(data) {
  48. this.startDate = data.day;
  49. this.endDate = data.day;
  50. this.$refs.myCalendarForm.init(
  51. "add",
  52. "",
  53. this.startDate,
  54. this.endDate
  55. );
  56. },
  57. handleEventClick(info) {
  58. this.$refs.myCalendarForm.init("edit", info.id);
  59. },
  60. refreshList() {
  61. myCalendarService.list().then((data) => {
  62. console.log('data', data)
  63. this.calendarEvents = data;
  64. });
  65. },
  66. },
  67. };
  68. </script>
  69. <style>
  70. .is-selected {
  71. color: #1989fa;
  72. }
  73. </style>