GSTC.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. }
  34. .gantt-schedule-timeline-calendar-goto {
  35. font-family: Ionicons;
  36. font-weight: 400;
  37. text-align: center;
  38. display: none;
  39. justify-content: center;
  40. align-items: center;
  41. width: 32px;
  42. margin-right: 8px;
  43. font-size: 16px;
  44. color: #888888;
  45. &:before {
  46. content: "\F216";
  47. }
  48. &:hover {
  49. color: #333333;
  50. }
  51. }
  52. }
  53. }
  54. </style>
  55. <script>
  56. import GSTC from "gantt-schedule-timeline-calendar";
  57. import "gantt-schedule-timeline-calendar/dist/style.css";
  58. export default {
  59. name: "GSTC",
  60. props: ["config"],
  61. data() {
  62. return {
  63. state: null,
  64. gstc: null,
  65. }
  66. },
  67. mounted() {
  68. this.state = GSTC.api.stateFromConfig(this.config);
  69. this.$emit("state", this.state);
  70. this.$refs.gstc.addEventListener('gstc-loaded', () => {
  71. this.gstc.api.scrollToTime(new Date().getTime());
  72. });
  73. this.gstc = GSTC({
  74. element: this.$refs.gstc,
  75. state: this.state
  76. });
  77. if (this.isMac()) {
  78. this.$refs.gstc.addEventListener('mousewheel', this.mouseHandler, { passive: false });
  79. }
  80. //
  81. this.$watch(
  82. "config",
  83. (config) => {
  84. this.state.update("config", current => {
  85. if (current !== config) {
  86. return GSTC.api.mergeDeep({}, current, config);
  87. } else {
  88. return current;
  89. }
  90. });
  91. },
  92. {deep: true}
  93. );
  94. },
  95. destroyed() {
  96. this.gstc.app.destroy();
  97. },
  98. methods: {
  99. isMac() {
  100. return /macintosh|mac os x/i.test(navigator.userAgent);
  101. },
  102. mouseHandler(e) {
  103. e.preventDefault();
  104. },
  105. getGstc() {
  106. return this.gstc;
  107. },
  108. getState() {
  109. return this.state;
  110. },
  111. setPeriod(val) {
  112. GSTC.api.setPeriod(val);
  113. },
  114. updateTime(id, time) {
  115. this.state.update('config.chart.items', items => {
  116. for (let itemId in items) {
  117. if (items.hasOwnProperty(itemId) && itemId == id) {
  118. items[itemId].time = $A.cloneData(time);
  119. }
  120. }
  121. return items;
  122. });
  123. }
  124. }
  125. };
  126. </script>