Skip to content

Commit

Permalink
feat: ✨添加点击连线事件
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjone committed May 15, 2023
1 parent cb3fba2 commit f4e5efa
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
7 changes: 6 additions & 1 deletion demo/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@row-click="onClickRow"
@move-slider="onMoveSlider"
@add-link="onAddLink"
@click-link="onClickLink"
>
<x-gantt-column label="group1">
<x-gantt-column prop="index" width="120px"></x-gantt-column>
Expand Down Expand Up @@ -100,7 +101,7 @@ let id = 0;
const ganttData = reactive<any>([]);
for (let i = 0; i < 5; i++) {
for (let i = 0; i < 15; i++) {
onAdd();
}
Expand Down Expand Up @@ -197,6 +198,10 @@ const onAddLink = (data: any) => {
console.log('add link', data);
};
const onClickLink = (data: any) => {
console.log('click link', data);
};
function onMove(data: any) {
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/common/GanttBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const { ganttBodyRef } = useElement();
height: 100%;
position: absolute;
z-index: 5;
pointer-events: none;
}
.xg-gantt-body-date-line {
Expand All @@ -96,6 +97,7 @@ const { ganttBodyRef } = useElement();
position: absolute;
top: 0;
opacity: 0.6;
pointer-events: none;
}
}
</style>
11 changes: 8 additions & 3 deletions src/components/common/Row.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
{
'xg-row__select':
props.renderStyle && $param.selectItem?.uuid === props.data?.uuid
}
},
{ 'xg-row__only': !props.renderStyle }
]"
:style="{
top: `${(props.data?.flatIndex ?? 0) * rowHeight}px`,
Expand All @@ -18,8 +19,8 @@
backgroundColor: props.renderStyle ? ($styleBox.levelColor[props.data!.level] ?? undefined) : undefined,
...$styleBox.getBorderColor()
}"
@pointerenter="onEnter"
@pointerleave="onLeave"
@pointerenter.stop="onEnter"
@pointerleave.stop="onLeave"
@click="onClick"
@dblclick="onDblClick"
>
Expand Down Expand Up @@ -69,6 +70,10 @@ function onDblClick() {
box-sizing: border-box;
}
.xg-row__only {
pointer-events: none;
}
.xg-row.xg-row__hover {
background-color: #f0f0f0aa !important;
}
Expand Down
43 changes: 39 additions & 4 deletions src/components/links/LinkPath.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<g>
<g
ref="svgRef"
:class="['xg-link', { 'xg-link__selected': selected }]"
@click.stop="onClick"
>
<path
:d="path"
fill="transparent"
Expand All @@ -15,7 +19,7 @@
:id="`triangle_${link.color}`"
markerWidth="5"
markerHeight="4"
refX="0"
refX="2"
refY="2"
orient="auto"
markerUnits="strokeWidth"
Expand Down Expand Up @@ -43,7 +47,8 @@ import useGanttHeader from '@/composables/useGanttHeader';
import useGanttWidth from '@/composables/useGanttWidth';
import useStyle from '@/composables/useStyle';
import { LinkItem } from '@/models/data/links';
import { computed, PropType } from 'vue';
import { computed, PropType, Ref, ref } from 'vue';
import { onClickOutside } from '@vueuse/core';
const props = defineProps({
link: {
Expand All @@ -52,6 +57,16 @@ const props = defineProps({
}
});
const selected = ref(false);
function onClick() {
selected.value = true;
}
const svgRef = ref(null) as Ref<SVGGElement | null>;
onClickOutside(svgRef, () => {
selected.value = false;
});
const { ganttHeader } = useGanttHeader();
const { ganttColumnWidth, currentMillisecond } = useGanttWidth();
const { rowHeight } = useStyle();
Expand Down Expand Up @@ -90,4 +105,24 @@ const path = computed(
);
</script>

<style scoped lang="scss"></style>
<style scoped lang="scss">
.xg-link {
cursor: pointer;
transition: filter 0.2s;
pointer-events: auto;
path {
transition: stroke-width 0.2s;
}
&:hover {
filter: brightness(1.2);
}
}
.xg-link__selected {
path {
stroke-width: 3;
}
}
</style>
7 changes: 3 additions & 4 deletions src/components/slider/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,8 @@ onDrag(outAnchorRef, {
const { EmitAddLink } = useEvent();
function onPointerUp() {
if (linking.startRow) {
if (linking.startRow?.uuid !== props.data?.uuid) {
const link = $links.addLink(linking.startRow, props.data!);
EmitAddLink(link);
}
const link = $links.addLink(linking.startRow, props.data!);
if (link) EmitAddLink(link);
setLinking({ startRow: null, endRow: null });
}
Expand All @@ -332,6 +330,7 @@ function onPointerUp() {
.xg-slider {
position: absolute;
transition: filter 0.2s;
pointer-events: auto;
.xg-slider-block {
overflow: hidden;
Expand Down
1 change: 0 additions & 1 deletion src/composables/useEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default () => {
);
}

// (e: 'add-link', data: LinkProps): void;
/**
* 添加连线事件
* @param data
Expand Down

0 comments on commit f4e5efa

Please sign in to comment.