From fb4d82201fcd06fd8fc9325e85e9e4f239947861 Mon Sep 17 00:00:00 2001 From: inter Date: Mon, 8 Sep 2025 16:37:47 +0800 Subject: [PATCH] Add File --- frontend/src/views/chat/component/index.ts | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 frontend/src/views/chat/component/index.ts diff --git a/frontend/src/views/chat/component/index.ts b/frontend/src/views/chat/component/index.ts new file mode 100644 index 0000000..4e10061 --- /dev/null +++ b/frontend/src/views/chat/component/index.ts @@ -0,0 +1,32 @@ +import { BaseChart } from '@/views/chat/component/BaseChart.ts' +import { Bar } from '@/views/chat/component/charts/Bar.ts' +import { Column } from '@/views/chat/component/charts/Column.ts' +import { Line } from '@/views/chat/component/charts/Line.ts' +import { Table } from '@/views/chat/component/charts/Table.ts' +import { Pie } from '@/views/chat/component/charts/Pie.ts' + +const CHART_TYPE_MAP: { [key: string]: any } = { + table: Table, + column: Column, + bar: Bar, + line: Line, + pie: Pie, +} + +const isParent = (type: any, parentType: any) => { + let _type = type + while (_type) { + if (_type === parentType) { + return true + } + _type = _type.__proto__ + } + return false +} + +export function getChartInstance(type: string, id: string): BaseChart | undefined { + if (isParent(CHART_TYPE_MAP[type], BaseChart)) { + return new CHART_TYPE_MAP[type](id) as BaseChart + } + return undefined +}