<template>
<div
class="gantt-container"
:style="{ width: containerWidth, height: containerHeight }"
>
<div class="gantt-table" id="table" ref="table">
<table style="width: 100%">
<div
class="header"
:style="{
height: timeLineHeight * 3 - 2 + 'px;',
lineHeight: timeLineHeight * 3 - 2 + 'px;',
}"
>
<thead :style="{ height: timeLineHeight * 3 - 2 + 'px' }">
<tr :style="{ lineHeight: timeLineHeight * 3 - 2 + 'px' }">
<th
:width="col.width"
v-for="(col, i) in ganttConfig.columns"
:key="`th${i}`"
style="color: #33333"
>
{{ col.title }}
<!-- <span v-el-if="col.field === 'tools'" class="create-icon">{{
col.title
}}</span> -->
</th>
</tr>
</thead>
</div>
<div class="body">
<tbody>
<!-- v-if="row.show" -->
<tr
v-for="(row, i) in ganttConfig.data"
:key="`tr${i}`"
class="row"
@click="scrollToBar(row)"
:style="{ lineHeight: lineHeight + 'px' }"
>
<td
v-for="(col, index) in ganttConfig.columns"
:key="'td' + index"
:width="col.width"
:style="{ lineHeight: lineHeight + 'px' }"
>
<!-- <div v-show="row.show"> -->
<div v-if="col.field === 'icon'">
<span
v-if="!row.open && !row.parentId"
style="color: #1e80ff; cursor: pointer"
>▶</span
>
<span
v-else-if="row.show && !row.parentId"
style="cursor: pointer"
>▼</span
>
</div>
<div v-else>
{{ row[col.field] }}
</div>
<!-- </div> -->
</td>
</tr>
</tbody>
</div>
</table>
</div>
<div class="gantt-chart" id="chart" ref="chart">
<!-- 时间轴 -->
<div class="header" :style="{ width: dateConfig.svgWidth + 'px' }">
<!-- 月数据 -->
<svg :width="dateConfig.svgWidth" :height="timeLineHeight">
<g
class="date"
v-for="(month, index) in dateConfig.monthList"
:key="'mg' + index"
>
<!-- 文字 -->
<text
:x="month.left * squareWidth + 5"
:y="timeLineHeight / 2 + 4"
style="font-size: 12px"
>
{{ month.text }}
</text>
<!-- 时间轴边框 -->
<path
:d="'M ' + month.left * squareWidth + ' 0 V 30'"
stroke="#d9dde0"
></path>
<line
x1="0"
y1="30"
:x2="dateConfig.svgWidth"
y2="30"
stroke="#d9dde0"
></line>
</g>
</svg>
<!-- 日数据 -->
<svg :width="dateConfig.svgWidth" :height="timeLineHeight">
<g
class="date"
v-for="(date, index) in dateConfig.dateList"
:key="'dg' + index"
>
<text
:x="index * squareWidth + 5"
:y="timeLineHeight / 2 + 4"
style="font-size: 12px"
>
{{ date.text }}
</text>
<text
:x="index * squareWidth + 20"
:y="timeLineHeight / 2 + 4"
style="font-size: 8px; margin-left: 4px"
>
{{ date.day }}
</text>
<path
:d="'M ' + index * squareWidth + ' 0 V 30'"
stroke="#d9dde0"
></path>
</g>
</svg>
<!-- 自定义时间轴 -->
<svg :width="dateConfig.svgWidth" :height="timeLineHeight">
<g
v-for="(item, index) in dateConfig.customisedList"
:key="'cdg' + index"
>
<rect
:x="item.start * squareWidth"
y="0"
:width="item.length * squareWidth"
:height="timeLineHeight"
:fill="index % 2 === 0 ? '#ddd' : '#eee'"
></rect>
<text
:x="(item.start + item.length / 2) * squareWidth - 12"
:y="timeLineHeight / 2 + 4"
style="font-size: 12px"
>
{{ item.title }}
</text>
</g>
</svg>
</div>
<!-- 进度图 -->
<div class="body">
<svg
:width="dateConfig.svgWidth"
:height="ganttConfig.chartData.length * lineHeight"
>
<!-- 背景图 -->
<rect
v-for="(row, index) in ganttConfig.chartData"
:key="'rect' + index"
x="0"
:y="lineHeight * index"
:width="dateConfig.svgWidth"
:height="lineHeight"
:fill="index % 2 === 0 ? '#fff' : '#f9fafb'"
></rect>
<path
v-for="(date, index) in dateConfig.dateList"
:key="'path' + index"
:d="
'M ' +
index * squareWidth +
' 0 V' +
ganttConfig.chartData.length * lineHeight
"
stoke="#d9dde0"
></path>
<line
v-for="(row, index) in ganttConfig.chartData"
:key="'line' + index"
x1="0"
:y1="lineHeight * index + lineHeight"
:x2="dateConfig.svgWidth"
:y2="lineHeight * index + lineHeight"
stoke="#d9dde0"
></line>
<!-- 进度图 bar 绘制 -->
<g
class="bar"
v-for="(row, index) in ganttConfig.chartData"
:key="'gg' + index"
@click="showDetailed(index)"
>
<!-- 全部 -->
<rect
:id="'bar_' + index"
:x="row.startDay * squareWidth"
:y="index * lineHeight + (lineHeight - barHeight) / 2 - 3"
:width="row.duration * squareWidth"
:height="barHeight + 6"
:rx="barHeight / 2"
:ry="barHeight / 2"
:fill="
index > 20
? barColorList[index - 20][1]
: barColorList[index][1]
"
></rect>
<!-- 进度 -->
<rect
v-for="(item, i) in row.list"
:key="'jd' + i"
:x="item.startDay * squareWidth"
:y="index * lineHeight + (lineHeight - barHeight) / 2"
:width="item.duration * squareWidth * item.progress"
:height="barHeight"
:rx="barHeight / 2"
:ry="barHeight / 2"
:opacity="item.progress"
:fill="
index > 20
? barColorList[index - 20][0]
: barColorList[index][0]
"
></rect>
<text
:x="row.startDay * squareWidth + 20"
:y="(index + 0.5) * lineHeight + 5"
:fill="barFontColor"
style="font-size: 12px; mix-blend-mode: difference"
>
{{ row.name }}
</text>
<text
v-for="(item, i) in row.list"
:key="'jdwz' + i"
:x="item.startDay * squareWidth + 10"
:y="(index
没有合适的资源?快使用搜索试试~ 我知道了~
前端Vue2自制甘特图组件源码
共2个文件
vue:2个
需积分: 0 9 下载量 109 浏览量
2023-03-15
15:12:26
上传
评论
收藏 7KB ZIP 举报
温馨提示
根据该https://blog.csdn.net/PorkCanteen/article/details/128075399的文章,修改为vue版本的甘特图源码,增加实际业务的多段显示,更贴合工作日常需要
资源推荐
资源详情
资源评论
收起资源包目录
Desktop.zip (2个子文件)
子组件.vue 23KB
父页面.vue 3KB
共 2 条
- 1
资源评论
WalkInJava
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功