MyCalendar.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view class="page">
  3. <cu-custom :backUrl="'/pages/index/index'" :isBack="true" bgColor="bg-gradual-blue" >
  4. <block slot="content">我的日程</block>
  5. </cu-custom>
  6. <el-calendar class="page">
  7. <template v-slot:dateCell="{ data }">
  8. <view
  9. @click.stop="selectHandler(data)"
  10. class="cell"
  11. :class="{ 'is-selected': data.isSelected }"
  12. >
  13. {{ data.day.split("-").slice(1).join("-") }} <br /><br />
  14. <!-- <div v-for="(event, index) in calendarEvents" :key="index" style="text-align: center;margin-top: -15px; overflow: hidden; white-space: nowrap;">-->
  15. <!-- <el-tag-->
  16. <!-- style="text-overflow: ellipsis; overflow: hidden; white-space: nowrap;"-->
  17. <!-- @click.stop="handleEventClick(event)"-->
  18. <!-- v-if="data.day === event.startDate.substring(0, 10)"-->
  19. <!-- >-->
  20. <!-- {{ event.title }}-->
  21. <!-- </el-tag>-->
  22. <!-- </div>-->
  23. <div style="text-align: center; margin-top: -15px;overflow: hidden; white-space: nowrap;">
  24. <el-tag
  25. v-for="(event, index) in calendarEvents"
  26. :key="index"
  27. :style="{ 'text-overflow': 'ellipsis', 'overflow': 'hidden', 'white-space': 'nowrap' }"
  28. @click.stop="handleEventClick(event)"
  29. v-if="data.day === event.startDate.substring(0, 10)"
  30. >
  31. {{ event.title }}
  32. </el-tag>
  33. </div>
  34. </view>
  35. </template>
  36. </el-calendar>
  37. </view>
  38. </template>
  39. <script>
  40. import myCalendarService from "@/api/calendar/myCalendarService";
  41. export default {
  42. data() {
  43. return {
  44. showForm: false,
  45. calendarDates: [], // 你的日期数据
  46. startDate: new Date(),
  47. endDate: new Date(),
  48. calendarEvents: [],
  49. };
  50. },
  51. components: {
  52. },
  53. activated() {
  54. this.refreshList();
  55. },
  56. created() {
  57. this.refreshList();
  58. },
  59. methods: {
  60. // 选择月份
  61. selectHandler(data) {
  62. this.startDate = data.day;
  63. this.endDate = data.day;
  64. // 使用 $nextTick 确保组件已经准备好
  65. // this.$nextTick(() => {
  66. // this.$refs.myCalendarForm.init(
  67. // "add",
  68. // "",
  69. // this.startDate,
  70. // this.endDate
  71. // );
  72. // });
  73. uni.navigateTo({
  74. url: '/pages/calendar/MyCalendarForm?method=' + 'add' + '&startDate=' + this.startDate + '&endDate=' + this.endDate // DialogPage 对应的页面路径
  75. });
  76. },
  77. handleEventClick(info) {
  78. uni.navigateTo({
  79. url: '/pages/calendar/MyCalendarForm?id=' + info.id + '&method=' + 'edit' // DialogPage 对应的页面路径
  80. });
  81. },
  82. refreshList() {
  83. myCalendarService.list().then((data) => {
  84. this.calendarEvents = data;
  85. });
  86. },
  87. formatStartDate(date) {
  88. const formattedDate = new Date(date);
  89. const year = formattedDate.getFullYear();
  90. const month = String(formattedDate.getMonth() + 1).padStart(2, '0');
  91. const day = String(formattedDate.getDate()).padStart(2, '0');
  92. const hours = String(formattedDate.getHours()).padStart(2, '0');
  93. const minutes = String(formattedDate.getMinutes()).padStart(2, '0');
  94. const seconds = String(formattedDate.getSeconds()).padStart(2, '0');
  95. return `${year}-${month}-${day}`;
  96. },
  97. },
  98. };
  99. </script>
  100. <style>
  101. .is-selected {
  102. color: #1989fa;
  103. }
  104. </style>