MyCalendar.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. methods: {
  57. // 选择月份
  58. selectHandler(data) {
  59. this.startDate = data.day;
  60. this.endDate = data.day;
  61. // 使用 $nextTick 确保组件已经准备好
  62. // this.$nextTick(() => {
  63. // this.$refs.myCalendarForm.init(
  64. // "add",
  65. // "",
  66. // this.startDate,
  67. // this.endDate
  68. // );
  69. // });
  70. uni.navigateTo({
  71. url: '/pages/calendar/MyCalendarForm?method=' + 'add' + '&startDate=' + this.startDate + '&endDate=' + this.endDate // DialogPage 对应的页面路径
  72. });
  73. },
  74. handleEventClick(info) {
  75. uni.navigateTo({
  76. url: '/pages/calendar/MyCalendarForm?id=' + info.id + '&method=' + 'edit' // DialogPage 对应的页面路径
  77. });
  78. },
  79. refreshList() {
  80. myCalendarService.list().then((data) => {
  81. this.calendarEvents = data;
  82. });
  83. },
  84. formatStartDate(date) {
  85. const formattedDate = new Date(date);
  86. const year = formattedDate.getFullYear();
  87. const month = String(formattedDate.getMonth() + 1).padStart(2, '0');
  88. const day = String(formattedDate.getDate()).padStart(2, '0');
  89. const hours = String(formattedDate.getHours()).padStart(2, '0');
  90. const minutes = String(formattedDate.getMinutes()).padStart(2, '0');
  91. const seconds = String(formattedDate.getSeconds()).padStart(2, '0');
  92. return `${year}-${month}-${day}`;
  93. },
  94. },
  95. };
  96. </script>
  97. <style>
  98. .is-selected {
  99. color: #1989fa;
  100. }
  101. </style>