mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 21:49:25 +08:00
refactor: style improve
This commit is contained in:
parent
e85937228d
commit
6cd21b155c
@ -92,15 +92,8 @@ export const useGanttBlockProps = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ctx?.service?.loading) {
|
if (!ctx?.service?.loading) {
|
||||||
const data = formatData(ctx.service.data?.data, ctx.fieldNames);
|
const data = formatData(ctx.service.data?.data, ctx.fieldNames);
|
||||||
const mergeTasks = data.map((v) => {
|
setTasks(data);
|
||||||
const task = ctx.field.data.find((k) => k.id === v.id) || { hideChildren: false };
|
ctx.field.data = data;
|
||||||
return {
|
|
||||||
...v,
|
|
||||||
hideChildren: task?.hideChildren,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
setTasks(mergeTasks);
|
|
||||||
ctx.field.data = mergeTasks;
|
|
||||||
}
|
}
|
||||||
}, [ctx?.service?.loading]);
|
}, [ctx?.service?.loading]);
|
||||||
return {
|
return {
|
||||||
|
@ -63,13 +63,13 @@ export const Gantt: any = (props: any) => {
|
|||||||
preStepsCount = 1,
|
preStepsCount = 1,
|
||||||
barFill = 60,
|
barFill = 60,
|
||||||
barCornerRadius = 3,
|
barCornerRadius = 3,
|
||||||
barProgressColor = '#a3a3ff',
|
barProgressColor = '#1890ff',
|
||||||
barProgressSelectedColor = '#8282f5',
|
barProgressSelectedColor = '#1890ff',
|
||||||
barBackgroundColor = '#b8c2cc',
|
barBackgroundColor = '#1890ff87',
|
||||||
barBackgroundSelectedColor = '#aeb8c2',
|
barBackgroundSelectedColor = '#aeb8c2',
|
||||||
projectProgressColor = '#7db59a',
|
projectProgressColor = '#7db59a',
|
||||||
projectProgressSelectedColor = '#59a985',
|
projectProgressSelectedColor = '#59a985',
|
||||||
projectBackgroundColor = '#fac465',
|
projectBackgroundColor = '#33831a5e',
|
||||||
projectBackgroundSelectedColor = '#f7bb53',
|
projectBackgroundSelectedColor = '#f7bb53',
|
||||||
milestoneBackgroundColor = '#f1c453',
|
milestoneBackgroundColor = '#f1c453',
|
||||||
milestoneBackgroundSelectedColor = '#f29e4c',
|
milestoneBackgroundSelectedColor = '#f29e4c',
|
||||||
|
@ -10,7 +10,7 @@ export const gridHeightRow = css`
|
|||||||
|
|
||||||
export const gridRowLine = css`
|
export const gridRowLine = css`
|
||||||
stroke: #f0f0f0;
|
stroke: #f0f0f0;
|
||||||
stroke-width:1.5;
|
stroke-width:0;
|
||||||
border-bottom: 1px solid #f0f0f0;
|
border-bottom: 1px solid #f0f0f0;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -1,35 +1,13 @@
|
|||||||
import React from "react";
|
import React from 'react';
|
||||||
import { cx } from '@emotion/css';
|
import { cx } from '@emotion/css';
|
||||||
import { TaskItemProps } from "../task-item";
|
import { TaskItemProps } from '../task-item';
|
||||||
import { projectWrapper,projectBackground,projectTop } from './style';
|
import { projectWrapper, projectBackground } from './style';
|
||||||
|
|
||||||
|
|
||||||
export const Project: React.FC<TaskItemProps> = ({ task, isSelected }) => {
|
export const Project: React.FC<TaskItemProps> = ({ task, isSelected }) => {
|
||||||
const barColor = isSelected
|
const barColor = isSelected ? task.styles.backgroundSelectedColor : task.styles.backgroundColor;
|
||||||
? task.styles.backgroundSelectedColor
|
const processColor = isSelected ? task.styles.progressSelectedColor : task.styles.progressColor;
|
||||||
: task.styles.backgroundColor;
|
|
||||||
const processColor = isSelected
|
|
||||||
? task.styles.progressSelectedColor
|
|
||||||
: task.styles.progressColor;
|
|
||||||
const projectWith = task.x2 - task.x1;
|
const projectWith = task.x2 - task.x1;
|
||||||
|
|
||||||
const projectLeftTriangle = [
|
|
||||||
task.x1,
|
|
||||||
task.y + task.height / 2 - 1,
|
|
||||||
task.x1,
|
|
||||||
task.y + task.height,
|
|
||||||
task.x1 + 15,
|
|
||||||
task.y + task.height / 2 - 1,
|
|
||||||
].join(",");
|
|
||||||
const projectRightTriangle = [
|
|
||||||
task.x2,
|
|
||||||
task.y + task.height / 2 - 1,
|
|
||||||
task.x2,
|
|
||||||
task.y + task.height,
|
|
||||||
task.x2 - 15,
|
|
||||||
task.y + task.height / 2 - 1,
|
|
||||||
].join(",");
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<g tabIndex={0} className={cx(projectWrapper)}>
|
<g tabIndex={0} className={cx(projectWrapper)}>
|
||||||
<rect
|
<rect
|
||||||
@ -51,26 +29,6 @@ export const Project: React.FC<TaskItemProps> = ({ task, isSelected }) => {
|
|||||||
rx={task.barCornerRadius}
|
rx={task.barCornerRadius}
|
||||||
fill={processColor}
|
fill={processColor}
|
||||||
/>
|
/>
|
||||||
<rect
|
|
||||||
fill={barColor}
|
|
||||||
x={task.x1}
|
|
||||||
width={projectWith}
|
|
||||||
y={task.y}
|
|
||||||
height={task.height / 2}
|
|
||||||
rx={task.barCornerRadius}
|
|
||||||
ry={task.barCornerRadius}
|
|
||||||
className={cx(projectTop)}
|
|
||||||
/>
|
|
||||||
<polygon
|
|
||||||
className={cx(projectTop)}
|
|
||||||
points={projectLeftTriangle}
|
|
||||||
fill={barColor}
|
|
||||||
/>
|
|
||||||
<polygon
|
|
||||||
className={cx(projectTop)}
|
|
||||||
points={projectRightTriangle}
|
|
||||||
fill={barColor}
|
|
||||||
/>
|
|
||||||
</g>
|
</g>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,17 @@ export const barLabel =css`
|
|||||||
user-select: none;
|
user-select: none;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
`
|
`
|
||||||
|
export const projectLabel =css`
|
||||||
|
fill: #130d0d;
|
||||||
|
font-weight: 600;
|
||||||
|
dominant-baseline: central;
|
||||||
|
-webkit-touch-callout: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-moz-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
pointer-events: none;
|
||||||
|
`
|
||||||
export const barLabelOutside =css`
|
export const barLabelOutside =css`
|
||||||
fill: #555;
|
fill: #555;
|
||||||
text-anchor: start;
|
text-anchor: start;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { cx } from '@emotion/css';
|
import { cx } from '@emotion/css';
|
||||||
import { BarTask } from "../../types/bar-task";
|
import { BarTask } from '../../types/bar-task';
|
||||||
import { GanttContentMoveAction } from "../../types/gantt-task-actions";
|
import { GanttContentMoveAction } from '../../types/gantt-task-actions';
|
||||||
import { Bar } from "./bar/bar";
|
import { Bar } from './bar/bar';
|
||||||
import { BarSmall } from "./bar/bar-small";
|
import { BarSmall } from './bar/bar-small';
|
||||||
import { Milestone } from "./milestone/milestone";
|
import { Milestone } from './milestone/milestone';
|
||||||
import { Project } from "./project/project";
|
import { Project } from './project/project';
|
||||||
import { barLabel,barLabelOutside } from './style';
|
import { barLabel, barLabelOutside, projectLabel } from './style';
|
||||||
|
|
||||||
export type TaskItemProps = {
|
export type TaskItemProps = {
|
||||||
task: BarTask;
|
task: BarTask;
|
||||||
@ -20,35 +20,27 @@ export type TaskItemProps = {
|
|||||||
onEventStart: (
|
onEventStart: (
|
||||||
action: GanttContentMoveAction,
|
action: GanttContentMoveAction,
|
||||||
selectedTask: BarTask,
|
selectedTask: BarTask,
|
||||||
event?: React.MouseEvent | React.KeyboardEvent
|
event?: React.MouseEvent | React.KeyboardEvent,
|
||||||
) => any;
|
) => any;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TaskItem: React.FC<TaskItemProps> = props => {
|
export const TaskItem: React.FC<TaskItemProps> = (props) => {
|
||||||
const {
|
const { task, arrowIndent, isDelete, taskHeight, isSelected, rtl, onEventStart } = {
|
||||||
task,
|
|
||||||
arrowIndent,
|
|
||||||
isDelete,
|
|
||||||
taskHeight,
|
|
||||||
isSelected,
|
|
||||||
rtl,
|
|
||||||
onEventStart,
|
|
||||||
} = {
|
|
||||||
...props,
|
...props,
|
||||||
};
|
};
|
||||||
const textRef = useRef<SVGTextElement>(null);
|
const textRef = useRef<SVGTextElement>(null);
|
||||||
const [taskItem, setTaskItem] = useState<JSX.Element>(<div />);
|
const [taskItem, setTaskItem] = useState<JSX.Element>(<div />);
|
||||||
const [isTextInside, setIsTextInside] = useState(true);
|
const [isTextInside, setIsTextInside] = useState(true);
|
||||||
|
const isProjectBar = task.typeInternal === 'project';
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
switch (task.typeInternal) {
|
switch (task.typeInternal) {
|
||||||
case "milestone":
|
case 'milestone':
|
||||||
setTaskItem(<Milestone {...props} />);
|
setTaskItem(<Milestone {...props} />);
|
||||||
break;
|
break;
|
||||||
case "project":
|
case 'project':
|
||||||
setTaskItem(<Project {...props} />);
|
setTaskItem(<Project {...props} />);
|
||||||
break;
|
break;
|
||||||
case "smalltask":
|
case 'smalltask':
|
||||||
setTaskItem(<BarSmall {...props} />);
|
setTaskItem(<BarSmall {...props} />);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -70,12 +62,7 @@ export const TaskItem: React.FC<TaskItemProps> = props => {
|
|||||||
return task.x1 + width * 0.5;
|
return task.x1 + width * 0.5;
|
||||||
}
|
}
|
||||||
if (rtl && textRef.current) {
|
if (rtl && textRef.current) {
|
||||||
return (
|
return task.x1 - textRef.current.getBBox().width - arrowIndent * +hasChild - arrowIndent * 0.2;
|
||||||
task.x1 -
|
|
||||||
textRef.current.getBBox().width -
|
|
||||||
arrowIndent * +hasChild -
|
|
||||||
arrowIndent * 0.2
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return task.x1 + width + arrowIndent * +hasChild + arrowIndent * 0.2;
|
return task.x1 + width + arrowIndent * +hasChild + arrowIndent * 0.2;
|
||||||
}
|
}
|
||||||
@ -83,40 +70,36 @@ export const TaskItem: React.FC<TaskItemProps> = props => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<g
|
<g
|
||||||
onKeyDown={e => {
|
onKeyDown={(e) => {
|
||||||
switch (e.key) {
|
switch (e.key) {
|
||||||
case "Delete": {
|
case 'Delete': {
|
||||||
if (isDelete) onEventStart("delete", task, e);
|
if (isDelete) onEventStart('delete', task, e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}}
|
}}
|
||||||
onMouseEnter={e => {
|
onMouseEnter={(e) => {
|
||||||
onEventStart("mouseenter", task, e);
|
onEventStart('mouseenter', task, e);
|
||||||
}}
|
}}
|
||||||
onMouseLeave={e => {
|
onMouseLeave={(e) => {
|
||||||
onEventStart("mouseleave", task, e);
|
onEventStart('mouseleave', task, e);
|
||||||
}}
|
}}
|
||||||
onDoubleClick={e => {
|
onDoubleClick={(e) => {
|
||||||
onEventStart("dblclick", task, e);
|
onEventStart('dblclick', task, e);
|
||||||
}}
|
}}
|
||||||
onClick={e => {
|
onClick={(e) => {
|
||||||
onEventStart("click", task, e);
|
onEventStart('click', task, e);
|
||||||
}}
|
}}
|
||||||
onFocus={() => {
|
onFocus={() => {
|
||||||
onEventStart("select", task);
|
onEventStart('select', task);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{taskItem}
|
{taskItem}
|
||||||
<text
|
<text
|
||||||
x={getX()}
|
x={isProjectBar ? task.x1 : getX()}
|
||||||
y={task.y + taskHeight * 0.5}
|
y={isProjectBar ? task.y-8 : task.y + taskHeight * 0.5}
|
||||||
className={
|
className={isProjectBar ? cx(projectLabel) : isTextInside ? cx(barLabel) : cx(barLabel) && cx(barLabelOutside)}
|
||||||
isTextInside
|
|
||||||
? cx(barLabel)
|
|
||||||
: cx(barLabel) && cx(barLabelOutside)
|
|
||||||
}
|
|
||||||
ref={textRef}
|
ref={textRef}
|
||||||
>
|
>
|
||||||
{task.name}
|
{task.name}
|
||||||
|
@ -105,7 +105,7 @@ const convertToBarTask = (
|
|||||||
dates,
|
dates,
|
||||||
columnWidth,
|
columnWidth,
|
||||||
rowHeight,
|
rowHeight,
|
||||||
taskHeight,
|
taskHeight*0.6,
|
||||||
barCornerRadius,
|
barCornerRadius,
|
||||||
handleWidth,
|
handleWidth,
|
||||||
rtl,
|
rtl,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user