index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <script setup lang="ts">
  2. import { ref } from "vue";
  3. // https://zunnzunn.github.io/vue-ganttastic/introduction.html
  4. import { GGanttChart, GGanttRow } from "@infectoone/vue-ganttastic";
  5. const context = ref([
  6. [
  7. {
  8. week: "星期一",
  9. beginDate: "06:00",
  10. endDate: "22:00",
  11. ganttBarConfig: {
  12. id: "0",
  13. hasHandles: true,
  14. label: "需求收集和分析 负责人:小张",
  15. style: {
  16. background: "#e96560"
  17. }
  18. }
  19. }
  20. ],
  21. [
  22. {
  23. week: "星期二",
  24. beginDate: "09:00",
  25. endDate: "18:00",
  26. ganttBarConfig: {
  27. id: "1",
  28. hasHandles: true,
  29. label: "系统设计 负责人:小强",
  30. style: {
  31. background: "#5ccfa3"
  32. }
  33. }
  34. }
  35. ],
  36. [
  37. {
  38. week: "星期三",
  39. beginDate: "07:00",
  40. endDate: "20:00",
  41. ganttBarConfig: {
  42. id: "2",
  43. hasHandles: true,
  44. label: "编码实现 负责人:老李",
  45. style: {
  46. background: "#77d6fa"
  47. }
  48. }
  49. }
  50. ],
  51. [
  52. {
  53. week: "星期四",
  54. beginDate: "06:00",
  55. endDate: "21:00",
  56. ganttBarConfig: {
  57. id: "3",
  58. hasHandles: true,
  59. label: "编码实现 负责人:小明",
  60. style: {
  61. color: "#fff",
  62. background: "#1b2a47"
  63. }
  64. }
  65. }
  66. ],
  67. [
  68. {
  69. week: "星期五",
  70. beginDate: "05:00",
  71. endDate: "19:00",
  72. ganttBarConfig: {
  73. id: "4",
  74. hasHandles: true,
  75. label: "内部测试 负责人:小雪",
  76. style: {
  77. background: "#5ccfa3"
  78. }
  79. }
  80. }
  81. ],
  82. [
  83. {
  84. week: "星期六",
  85. beginDate: "10:00",
  86. endDate: "22:00",
  87. ganttBarConfig: {
  88. id: "5",
  89. hasHandles: true,
  90. label: "系统优化和文档整理 负责人:小欣",
  91. style: {
  92. background: "#f8bc45"
  93. }
  94. }
  95. }
  96. ],
  97. [
  98. {
  99. week: "星期天",
  100. beginDate: "04:00",
  101. endDate: "23:59",
  102. ganttBarConfig: {
  103. id: "6",
  104. immobile: false,
  105. hasHandles: false,
  106. label: "部署和上线 负责人:老王",
  107. style: {
  108. background: "#f3953d"
  109. }
  110. }
  111. }
  112. ]
  113. ]);
  114. function getWeekRange() {
  115. const today = new Date();
  116. const dayOfWeek = today.getDay();
  117. const startDate = new Date(today);
  118. startDate.setDate(today.getDate() - dayOfWeek + 1);
  119. const endDate = new Date(startDate);
  120. endDate.setDate(startDate.getDate() + 6);
  121. const formatDate = date => {
  122. const year = date.getFullYear();
  123. const month = String(date.getMonth() + 1).padStart(2, "0");
  124. const day = String(date.getDate()).padStart(2, "0");
  125. return `${year}-${month}-${day}`;
  126. };
  127. const currentWeekStart = formatDate(startDate);
  128. const currentWeekEnd = formatDate(endDate);
  129. return {
  130. currentWeekStart,
  131. currentWeekEnd
  132. };
  133. }
  134. const weekRangeInChina = getWeekRange();
  135. </script>
  136. <template>
  137. <g-gantt-chart
  138. chart-start="00:00"
  139. chart-end="23:59"
  140. precision="hour"
  141. date-format="HH:mm"
  142. bar-start="beginDate"
  143. bar-end="endDate"
  144. grid
  145. >
  146. <template #upper-timeunit>
  147. <h1>
  148. {{
  149. `${weekRangeInChina.currentWeekStart} / ${weekRangeInChina.currentWeekEnd}`
  150. }}
  151. </h1>
  152. </template>
  153. <g-gantt-row
  154. v-for="(item, index) in context"
  155. :key="index"
  156. :bars="item"
  157. :label="item[0].week"
  158. highlight-on-hover
  159. />
  160. </g-gantt-chart>
  161. </template>