GSTC.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="gstc" ref="gstc"></div>
  3. </template>
  4. <style lang="scss">
  5. .gantt-schedule-timeline-calendar__list-column-row {
  6. .gantt-schedule-timeline-calendar__list-column-row-content {
  7. display: flex;
  8. cursor: pointer;
  9. &:hover {
  10. .gantt-schedule-timeline-calendar-goto {
  11. display: flex;
  12. }
  13. }
  14. .gantt-schedule-timeline-calendar-overdue {
  15. display: flex;
  16. align-items: center;
  17. margin-right: 2px;
  18. em {
  19. font-size: 12px;
  20. height: 22px;
  21. line-height: 22px;
  22. color: #ffffff;
  23. padding: 0 4px;
  24. border-radius: 3px;
  25. background: #ff0000;
  26. transform: scale(0.9);
  27. transform-origin: 0 center;
  28. }
  29. }
  30. .gantt-schedule-timeline-calendar-title {
  31. flex: 1;
  32. padding-right: 6px;
  33. &.complete-title {
  34. text-decoration: line-through;
  35. }
  36. }
  37. .gantt-schedule-timeline-calendar-goto {
  38. font-family: Ionicons;
  39. font-weight: 400;
  40. text-align: center;
  41. display: none;
  42. justify-content: center;
  43. align-items: center;
  44. width: 32px;
  45. margin-right: 8px;
  46. font-size: 16px;
  47. color: #888888;
  48. &:before {
  49. content: "\F216";
  50. }
  51. &:hover {
  52. color: #333333;
  53. }
  54. }
  55. }
  56. }
  57. </style>
  58. <script>
  59. import GSTC from "gantt-schedule-timeline-calendar";
  60. import "gantt-schedule-timeline-calendar/dist/style.css";
  61. export default {
  62. name: "GSTC",
  63. props: ["config"],
  64. data() {
  65. return {
  66. state: null,
  67. gstc: null,
  68. }
  69. },
  70. mounted() {
  71. this.state = GSTC.api.stateFromConfig(this.config);
  72. this.$emit("state", this.state);
  73. this.$refs.gstc.addEventListener('gstc-loaded', () => {
  74. this.gstc.api.scrollToTime(new Date().getTime());
  75. });
  76. this.gstc = GSTC({
  77. element: this.$refs.gstc,
  78. state: this.state
  79. });
  80. if (this.isMac()) {
  81. this.$refs.gstc.addEventListener('mousewheel', this.mouseHandler, { passive: false });
  82. }
  83. //
  84. this.$watch(
  85. "config",
  86. (config) => {
  87. this.state.update("config", current => {
  88. if (current !== config) {
  89. return GSTC.api.mergeDeep({}, current, config);
  90. } else {
  91. return current;
  92. }
  93. });
  94. },
  95. {deep: true}
  96. );
  97. },
  98. destroyed() {
  99. this.gstc.app.destroy();
  100. },
  101. methods: {
  102. isMac() {
  103. return /macintosh|mac os x/i.test(navigator.userAgent);
  104. },
  105. mouseHandler(e) {
  106. e.preventDefault();
  107. },
  108. getGstc() {
  109. return this.gstc;
  110. },
  111. getState() {
  112. return this.state;
  113. },
  114. setPeriod(val) {
  115. GSTC.api.setPeriod(val);
  116. },
  117. updateTime(id, time) {
  118. this.state.update('config.chart.items', items => {
  119. for (let itemId in items) {
  120. if (items.hasOwnProperty(itemId) && itemId == id) {
  121. items[itemId].time = $A.cloneData(time);
  122. }
  123. }
  124. return items;
  125. });
  126. }
  127. }
  128. };
  129. </script>