Skip to content

Commit 4654a3b

Browse files
committed
feat: add chats type
1 parent e8af4a4 commit 4654a3b

6 files changed

Lines changed: 21 additions & 18 deletions

File tree

3.65 KB
Loading

src/frontend/platform/src/pages/Dashboard/components/editor/ComponentPicker.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Popover, PopoverContent, PopoverTrigger } from '@/components/bs-ui/popo
22
import { cn } from '@/utils';
33
import React, { useState } from 'react';
44
import { ChartType } from '../../types/dataConfig';
5-
import { useEditorDashboardStore } from '@/store/dashboardStore';
65

76
export const ChartItems = [
87
{
@@ -25,8 +24,9 @@ export const ChartItems = [
2524
label: '折线图',
2625
data: [
2726
{ type: ChartType.Line, label: '基础折线图' },
27+
{ type: ChartType.StackedLine, label: '堆叠折线图' },
2828
{ type: ChartType.Area, label: '面积图' },
29-
{ type: ChartType.StackedLine, label: '堆叠折线图' }
29+
{ type: ChartType.StackedArea, label: '堆叠面积图' }
3030
]
3131
},
3232
{
@@ -51,21 +51,16 @@ export interface PickerItem {
5151
}
5252

5353
interface ComponentPickerProps {
54-
items: PickerItem[];
55-
onSelect: (id: string) => void;
54+
onSelect: (data: { title: string, type: ChartType }) => void;
5655
children: React.ReactNode;
5756
className?: string;
5857
}
5958

60-
const ComponentPicker = ({ children, className }: ComponentPickerProps) => {
59+
const ComponentPicker = ({ children, className, onSelect }: ComponentPickerProps) => {
6160
const [open, setOpen] = useState(false);
62-
const { addComponentToLayout } = useEditorDashboardStore()
6361

6462
const handleItemClick = (item) => {
65-
addComponentToLayout({
66-
title: item.label,
67-
type: item.type
68-
});
63+
onSelect(item)
6964
setOpen(false);
7065
};
7166

@@ -75,7 +70,7 @@ const ComponentPicker = ({ children, className }: ComponentPickerProps) => {
7570
<div
7671
key={item.type}
7772
onClick={() => handleItemClick(item)}
78-
className="flex flex-col items-center group gap-2 outline-none cursor-pointer"
73+
className={`flex flex-col items-center group gap-2 outline-none cursor-pointer ${item.type === ChartType.StackedLine && 'mr-2'}`}
7974
>
8075
<div className="w-[88px] h-[86px] flex flex-col items-center justify-center border rounded-md group-hover:bg-blue-50 transition-colors group-hover:border-primary">
8176
<img src={`${__APP_ENV__.BASE_URL}/assets/dashboard/${item.type}.png`} className="w-8 h-8 mb-2" />

src/frontend/platform/src/pages/Dashboard/components/editor/EditorCanvas.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ export function EditorCanvas({ isLoading, isPreviewMode, dashboard }: EditorCanv
183183
backgroundImage: `url("data:image/svg+xml,${encodeURIComponent(svgString)}")`,
184184
backgroundRepeat: 'repeat',
185185
backgroundAttachment: 'local',
186-
backgroundPosition: `${0}px ${0}px`
186+
backgroundPosition: `${0}px ${0}px`,
187+
height: '100%'
187188
};
188189
}, [width, isPreviewMode, mounted]);
189190

src/frontend/platform/src/pages/Dashboard/components/editor/EditorHeader.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function EditorHeader({
3131
dashboard,
3232
dashboardId,
3333
}: EditorHeaderProps) {
34-
const { hasUnsavedChanges, isSaving, reset, setIsSaving, setHasUnsavedChanges } = useEditorDashboardStore()
34+
const { hasUnsavedChanges, isSaving, reset, setIsSaving, setHasUnsavedChanges, addComponentToLayout } = useEditorDashboardStore()
3535
const [isEditingTitle, setIsEditingTitle] = useState(false)
3636
const [title, setTitle] = useState(dashboard?.title || "")
3737
const inputRef = useRef<HTMLInputElement>(null)
@@ -251,11 +251,11 @@ export function EditorHeader({
251251
/>
252252
) : (
253253
<h1
254-
className="font-medium truncate cursor-pointer transition-colors"
254+
className="max-w-96 font-medium truncate cursor-pointer transition-colors"
255255
title={dashboard?.title}
256256
// onDoubleClick={handleTitleDoubleClick}
257257
>
258-
{dashboard?.title || "未命名看板"}
258+
{dashboard?.title}
259259
</h1>
260260
)}
261261
<Badge variant="outline" className=" font-normal bg-gray-100">{getSaveStatus()}</Badge>
@@ -264,7 +264,7 @@ export function EditorHeader({
264264
{/* Middle section */}
265265
<div className="flex items-center gap-4">
266266
{/* Add Component */}
267-
<ComponentPicker >
267+
<ComponentPicker onSelect={addComponentToLayout}>
268268
<Button variant="outline" size="sm" className="gap-2">
269269
<Grid2X2PlusIcon size="14" />
270270
添加图表

src/frontend/platform/src/pages/Dashboard/components/editor/Home.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useEditorDashboardStore } from "@/store/dashboardStore"
22
import { ChartItems } from "./ComponentPicker"
3+
import { cn } from "@/utils"
4+
import { ChartType } from "../../types/dataConfig"
35

46
export default function Home() {
57
const { addComponentToLayout } = useEditorDashboardStore()
@@ -13,7 +15,7 @@ export default function Home() {
1315

1416
return (
1517
<div className="h-full bg-background flex items-center justify-center p-8">
16-
<div className="w-full max-w-2xl">
18+
<div className="w-full max-w-[720px]">
1719
{/* Header */}
1820
<div className="text-center mb-10">
1921
<h1 className="text-lg text-foreground font-medium">请选择一个组件,开始搭建你的数据看板</h1>
@@ -25,7 +27,10 @@ export default function Home() {
2527
<div
2628
key={item.type}
2729
onClick={() => handleItemClick(item)}
28-
className="w-[88px] h-[86px] flex flex-col items-center justify-center border rounded-md shadow-sm hover:shadow-lg transition-colors cursor-pointer">
30+
className={cn('w-[88px] h-[86px] flex flex-col items-center justify-center border rounded-md shadow-sm hover:shadow-lg transition-colors cursor-pointer',
31+
item.type === ChartType.GroupedHorizontalBar && 'mr-10',
32+
item.type === ChartType.Bar && 'ml-10',
33+
)}>
2934
<img src={`${__APP_ENV__.BASE_URL}/assets/dashboard/${item.type}.png`} className="w-8 h-8 mb-2" />
3035
<span className="text-[12px] text-gray-600 whitespace-nowrap">{item.label}</span>
3136
</div>

src/frontend/platform/src/pages/Dashboard/types/dataConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ export enum ChartType {
109109
Line = 'line',
110110
/** 面积图 */
111111
Area = 'area',
112+
/** 堆叠面积图 */
113+
StackedArea = 'stacked-area',
112114
/** 堆叠折线图 */
113115
StackedLine = 'stacked-line',
114116
/** 饼状图 */

0 commit comments

Comments
 (0)