当前位置:   article > 正文

vue3甘特图ganttastic高级修改版(日程安排组件)_vue-ganttastic

vue-ganttastic

由于甘特图组件付费的太多晚上组件五花八门,所以我找了个还不错简单方便的组件进行了再封装和一些bug修复。原组件地址为Getting started | Vue-Ganttastic

上才艺:

可以拖到左右编辑更改时间,也可以双击它手动更改或删除日程

  1.先安装原版组件

npm install @infectoone/vue-ganttastic

2.vue3挂载组件

  1. import { createApp } from "vue"
  2. import App from "./App.vue"
  3. ...
  4. import ganttastic from '@infectoone/vue-ganttastic'
  5. ...
  6. createApp(App)
  7. .use(ganttastic)
  8. .mount('#app')

3.封装为组件(这里加了我自己更改所以封装成了组件,但是组件没有封装完成,数据传递都没写所以需要自己写这一部分因为每个人的后端返回数据不一样。)

  1. <!-- 此组件暂未完成封装,需要与后端交流数据格式 -->
  2. <!-- 具体怎么用呢?请看文档https://zunnzunn.github.io/vue-ganttastic/GGanttRow.html#slots -->
  3. <template>
  4. <div>
  5. <g-gantt-chart
  6. chart-start="00:00"
  7. chart-end="23:59"
  8. precision="hour"
  9. date-format="HH:mm"
  10. bar-start="myBeginDate"
  11. bar-end="myEndDate"
  12. grid="true"
  13. @dblclick-bar="dbRow"
  14. >
  15. <!-- 这行代码确实有用请别删 -->
  16. <template #upper-timeunit>
  17. <div></div>
  18. </template>
  19. <g-gantt-row :bars="item" v-for="(item, index) in context" :key="index">
  20. <template #label>
  21. <div>{{ item[0].week }}</div>
  22. <el-tag
  23. @click="addTimeLine(item)"
  24. v-show="item[0].myBeginDate == '00:00' && item[0].myEndDate == '00:00'"
  25. style="margin-left: 10px"
  26. >点击添加时间线</el-tag
  27. >
  28. </template>
  29. <template #bar-label="scope">
  30. <el-tooltip effect="dark" content="双击编辑" placement="top">
  31. <div> {{ scope.bar.myBeginDate + '--' + scope.bar.myEndDate }}</div>
  32. </el-tooltip>
  33. </template>
  34. </g-gantt-row>
  35. </g-gantt-chart>
  36. <!-- 修改时间 -->
  37. <el-dialog v-model="visible" title="操作时间线" width="500" align-center class="dia">
  38. <el-time-picker
  39. v-model="value1"
  40. is-range
  41. format="HH:mm"
  42. value-format="HH:mm"
  43. range-separator="To"
  44. start-placeholder="开始时间"
  45. end-placeholder="结束时间"
  46. />
  47. <template #footer>
  48. <div class="dialog-footer">
  49. <el-button type="primary" @click="updateTime">确定</el-button>
  50. <el-button type="danger" @click="deleteTime"> 删除 </el-button>
  51. </div>
  52. </template>
  53. </el-dialog>
  54. </div>
  55. </template>
  56. <script setup lang="ts">
  57. //组件封装思路,由于这个组件必须传一个ganttBarConfig属性作为位置项,
  58. //我估计后端会传回日期和起止时间,然后props接受日期和起止时间,还差一个ganttBarConfig参数,这里我
  59. //想的是通过计算属性再加上这个ganttBarConfig
  60. //双击row事件
  61. const dbRow = (a) => {
  62. value1.value = [a.bar.myBeginDate, a.bar.myEndDate]
  63. indexNow.value = a.bar.ganttBarConfig.id
  64. visible.value = true
  65. }
  66. //时间选择器组件值
  67. const value1 = ref<[string, string]>(['08:40', '09:50'])
  68. //当前处于星期几
  69. const indexNow = ref(0)
  70. //添加时间线
  71. const addTimeLine = (item) => {
  72. item[0].myBeginDate = '13:00'
  73. item[0].myEndDate = '18:00'
  74. }
  75. //更改时间线
  76. const updateTime = () => {
  77. context.value[indexNow.value][0].myBeginDate = value1.value[0]
  78. context.value[indexNow.value][0].myEndDate = value1.value[1]
  79. visible.value = false
  80. }
  81. //删除操作及将时间设置为'00:00'
  82. const deleteTime = () => {
  83. context.value[indexNow.value][0].myBeginDate = '00:00'
  84. context.value[indexNow.value][0].myEndDate = '00:00'
  85. visible.value = false
  86. }
  87. const visible = ref(false)
  88. const context = ref([
  89. [
  90. {
  91. week: '星期一',
  92. myBeginDate: '00:00',
  93. myEndDate: '00:00',
  94. ganttBarConfig: {
  95. id: '0', //唯一标识不能一样
  96. hasHandles: true
  97. }
  98. }
  99. ],
  100. [
  101. {
  102. week: '星期二',
  103. myBeginDate: '13:00',
  104. myEndDate: '19:00',
  105. ganttBarConfig: {
  106. id: '1',
  107. hasHandles: true
  108. }
  109. }
  110. ],
  111. [
  112. {
  113. week: '星期三',
  114. myBeginDate: '13:00',
  115. myEndDate: '19:00',
  116. ganttBarConfig: {
  117. id: '2',
  118. hasHandles: true
  119. }
  120. }
  121. ],
  122. [
  123. {
  124. week: '星期四',
  125. myBeginDate: '13:00',
  126. myEndDate: '19:00',
  127. ganttBarConfig: {
  128. id: '3',
  129. hasHandles: true
  130. }
  131. }
  132. ],
  133. [
  134. {
  135. week: '星期五',
  136. myBeginDate: '13:00',
  137. myEndDate: '19:00',
  138. ganttBarConfig: {
  139. id: '4',
  140. hasHandles: true
  141. }
  142. }
  143. ],
  144. [
  145. {
  146. week: '星期六',
  147. myBeginDate: '13:00',
  148. myEndDate: '19:00',
  149. ganttBarConfig: {
  150. id: '5',
  151. hasHandles: true
  152. }
  153. }
  154. ],
  155. [
  156. {
  157. week: '星期天',
  158. myBeginDate: '13:00',
  159. myEndDate: '19:00',
  160. ganttBarConfig: {
  161. id: '6',
  162. hasHandles: true
  163. }
  164. }
  165. ]
  166. ])
  167. // const row2BarList = ref()
  168. </script>
  169. <style scoped lang="scss">
  170. .dialog-footer{
  171. display: flex;
  172. justify-content: center;
  173. }
  174. :deep(.g-upper-timeunit) {
  175. height: 0 !important;
  176. }
  177. :deep(.g-timeaxis) {
  178. height: auto !important;
  179. min-height: 0 !important;
  180. }
  181. :deep(.g-gantt-row-label) {
  182. height: 100% !important;
  183. }
  184. :deep(.dia .el-dialog__body) {
  185. padding: 20px !important;
  186. }
  187. :deep(.el-date-editor) {
  188. display: flex;
  189. margin: 0 auto;
  190. }
  191. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/499557
推荐阅读
相关标签
  

闽ICP备14008679号