From 6f0c05dd5074047b5a47aa5d87d62cb6da9a236e Mon Sep 17 00:00:00 2001 From: jinmao88 <50581550+jinmao88@users.noreply.github.com> Date: Sun, 23 Jun 2024 13:41:02 +0800 Subject: [PATCH] dashboard (#6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(dashboard): 增加dashboard示例 * feat(chart-ui): 增加图表UI组件库 * feat(dashboard): 完善dashboard示例 --- apps/web-antd/package.json | 1 + apps/web-antd/src/views/dashboard/index.vue | 244 +++++++++++++++++- packages/business/chart-ui/package.json | 50 ++++ packages/business/chart-ui/src/chart.vue | 37 +++ packages/business/chart-ui/src/index.ts | 59 +++++ packages/business/chart-ui/tsconfig.json | 6 + packages/business/chart-ui/vite.config.mts | 3 + packages/business/universal-ui/package.json | 1 + .../universal-ui/src/dashboard/card.vue | 45 ++++ .../universal-ui/src/dashboard/chartCard.vue | 24 ++ .../universal-ui/src/dashboard/chartTab.vue | 41 +++ .../universal-ui/src/dashboard/dashboard.vue | 152 +++++++++++ .../universal-ui/src/dashboard/index.ts | 3 + .../universal-ui/src/dashboard/layout.vue | 7 + .../universal-ui/src/dashboard/typings.ts | 17 ++ packages/business/universal-ui/src/index.ts | 1 + 16 files changed, 690 insertions(+), 1 deletion(-) create mode 100644 packages/business/chart-ui/package.json create mode 100644 packages/business/chart-ui/src/chart.vue create mode 100644 packages/business/chart-ui/src/index.ts create mode 100644 packages/business/chart-ui/tsconfig.json create mode 100644 packages/business/chart-ui/vite.config.mts create mode 100644 packages/business/universal-ui/src/dashboard/card.vue create mode 100644 packages/business/universal-ui/src/dashboard/chartCard.vue create mode 100644 packages/business/universal-ui/src/dashboard/chartTab.vue create mode 100644 packages/business/universal-ui/src/dashboard/dashboard.vue create mode 100644 packages/business/universal-ui/src/dashboard/index.ts create mode 100644 packages/business/universal-ui/src/dashboard/layout.vue create mode 100644 packages/business/universal-ui/src/dashboard/typings.ts diff --git a/apps/web-antd/package.json b/apps/web-antd/package.json index b577eb7a..5ebdcc9b 100644 --- a/apps/web-antd/package.json +++ b/apps/web-antd/package.json @@ -37,6 +37,7 @@ "@vben/styles": "workspace:*", "@vben/types": "workspace:*", "@vben/universal-ui": "workspace:*", + "@vben/chart-ui": "workspace:*", "@vben/utils": "workspace:*", "@vueuse/core": "^10.11.0", "ant-design-vue": "^4.2.3", diff --git a/apps/web-antd/src/views/dashboard/index.vue b/apps/web-antd/src/views/dashboard/index.vue index 1ede7cd2..617fb86f 100644 --- a/apps/web-antd/src/views/dashboard/index.vue +++ b/apps/web-antd/src/views/dashboard/index.vue @@ -1,7 +1,249 @@ diff --git a/packages/business/chart-ui/package.json b/packages/business/chart-ui/package.json new file mode 100644 index 00000000..7d3a4771 --- /dev/null +++ b/packages/business/chart-ui/package.json @@ -0,0 +1,50 @@ +{ + "name": "@vben/chart-ui", + "version": "5.0.0", + "homepage": "https://github.com/vbenjs/vue-vben-admin", + "bugs": "https://github.com/vbenjs/vue-vben-admin/issues", + "repository": { + "type": "git", + "url": "git+https://github.com/vbenjs/vue-vben-admin.git", + "directory": "packages/business/chart-ui" + }, + "license": "MIT", + "type": "module", + "scripts": { + "build": "pnpm vite build", + "prepublishOnly": "npm run build" + }, + "files": [ + "dist" + ], + "sideEffects": [ + "**/*.css" + ], + "main": "./dist/index.mjs", + "module": "./dist/index.mjs", + "exports": { + ".": { + "types": "./src/index.ts", + "development": "./src/index.ts", + "default": "./dist/index.mjs" + } + }, + "publishConfig": { + "exports": { + ".": { + "default": "./dist/index.mjs" + } + } + }, + "peerDependencies": { + "@vben-core/design": "workspace:*" + }, + "dependencies": { + "@vben-core/preferences": "workspace:*", + "echarts": "^5.5.0", + "vue": "^3.4.29" + }, + "devDependencies": { + "@vben/types": "workspace:*" + } +} diff --git a/packages/business/chart-ui/src/chart.vue b/packages/business/chart-ui/src/chart.vue new file mode 100644 index 00000000..d7134c97 --- /dev/null +++ b/packages/business/chart-ui/src/chart.vue @@ -0,0 +1,37 @@ + + + diff --git a/packages/business/chart-ui/src/index.ts b/packages/business/chart-ui/src/index.ts new file mode 100644 index 00000000..a2ab1e05 --- /dev/null +++ b/packages/business/chart-ui/src/index.ts @@ -0,0 +1,59 @@ +import * as echarts from 'echarts/core'; +import { BarChart, LineChart, PieChart, RadarChart } from 'echarts/charts'; +import { + TitleComponent, + TooltipComponent, + GridComponent, + + // 数据集组件 + DatasetComponent, + // 内置数据转换器组件 (filter, sort) + TransformComponent, + LegendComponent, + ToolboxComponent, +} from 'echarts/components'; +import { LabelLayout, UniversalTransition } from 'echarts/features'; +import { CanvasRenderer } from 'echarts/renderers'; +import type { + // 系列类型的定义后缀都为 SeriesOption + BarSeriesOption, + LineSeriesOption, +} from 'echarts/charts'; +import type { + // 组件类型的定义后缀都为 ComponentOption + TitleComponentOption, + TooltipComponentOption, + GridComponentOption, + DatasetComponentOption, +} from 'echarts/components'; +import type { ComposeOption } from 'echarts/core'; + +// 通过 ComposeOption 来组合出一个只有必须组件和图表的 Option 类型 +export type ECOption = ComposeOption< + | BarSeriesOption + | LineSeriesOption + | TitleComponentOption + | TooltipComponentOption + | GridComponentOption + | DatasetComponentOption +>; + +// 注册必须的组件 +echarts.use([ + TitleComponent, + PieChart, + RadarChart, + TooltipComponent, + GridComponent, + DatasetComponent, + TransformComponent, + BarChart, + LineChart, + LabelLayout, + UniversalTransition, + CanvasRenderer, + LegendComponent, + ToolboxComponent, +]); +export const echartsInstance = echarts; +export { default as chart } from './chart.vue'; diff --git a/packages/business/chart-ui/tsconfig.json b/packages/business/chart-ui/tsconfig.json new file mode 100644 index 00000000..ce1a891f --- /dev/null +++ b/packages/business/chart-ui/tsconfig.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@vben/tsconfig/web.json", + "include": ["src"], + "exclude": ["node_modules"] +} diff --git a/packages/business/chart-ui/vite.config.mts b/packages/business/chart-ui/vite.config.mts new file mode 100644 index 00000000..9a5f448e --- /dev/null +++ b/packages/business/chart-ui/vite.config.mts @@ -0,0 +1,3 @@ +import { defineConfig } from '@vben/vite-config'; + +export default defineConfig(); diff --git a/packages/business/universal-ui/package.json b/packages/business/universal-ui/package.json index d00dff98..63db3c9c 100644 --- a/packages/business/universal-ui/package.json +++ b/packages/business/universal-ui/package.json @@ -48,6 +48,7 @@ "@vben/locales": "workspace:*", "@vueuse/core": "^10.11.0", "@vueuse/integrations": "^10.11.0", + "@vben/chart-ui": "workspace:*", "qrcode": "^1.5.3", "vue": "^3.4.30", "vue-router": "^4.4.0" diff --git a/packages/business/universal-ui/src/dashboard/card.vue b/packages/business/universal-ui/src/dashboard/card.vue new file mode 100644 index 00000000..d82dd040 --- /dev/null +++ b/packages/business/universal-ui/src/dashboard/card.vue @@ -0,0 +1,45 @@ + + + diff --git a/packages/business/universal-ui/src/dashboard/chartCard.vue b/packages/business/universal-ui/src/dashboard/chartCard.vue new file mode 100644 index 00000000..c6f08fa3 --- /dev/null +++ b/packages/business/universal-ui/src/dashboard/chartCard.vue @@ -0,0 +1,24 @@ + + + diff --git a/packages/business/universal-ui/src/dashboard/chartTab.vue b/packages/business/universal-ui/src/dashboard/chartTab.vue new file mode 100644 index 00000000..66d27781 --- /dev/null +++ b/packages/business/universal-ui/src/dashboard/chartTab.vue @@ -0,0 +1,41 @@ + + + diff --git a/packages/business/universal-ui/src/dashboard/dashboard.vue b/packages/business/universal-ui/src/dashboard/dashboard.vue new file mode 100644 index 00000000..fb8fa5ec --- /dev/null +++ b/packages/business/universal-ui/src/dashboard/dashboard.vue @@ -0,0 +1,152 @@ + + + diff --git a/packages/business/universal-ui/src/dashboard/index.ts b/packages/business/universal-ui/src/dashboard/index.ts new file mode 100644 index 00000000..40e0c0d5 --- /dev/null +++ b/packages/business/universal-ui/src/dashboard/index.ts @@ -0,0 +1,3 @@ +export { default as DashboardLayout } from './layout.vue'; +export { default as Dashboard } from './dashboard.vue'; +export { default as chartCard } from './chartCard.vue'; diff --git a/packages/business/universal-ui/src/dashboard/layout.vue b/packages/business/universal-ui/src/dashboard/layout.vue new file mode 100644 index 00000000..fcda54f2 --- /dev/null +++ b/packages/business/universal-ui/src/dashboard/layout.vue @@ -0,0 +1,7 @@ + + + diff --git a/packages/business/universal-ui/src/dashboard/typings.ts b/packages/business/universal-ui/src/dashboard/typings.ts new file mode 100644 index 00000000..d6d96204 --- /dev/null +++ b/packages/business/universal-ui/src/dashboard/typings.ts @@ -0,0 +1,17 @@ +interface CardItem { + title: string; + extra: string; + leftContent: string; + rightContent: string; + color?: string; + leftFooter: string; + rightFooter: string; +} + +interface ChartItem { + name: string; + title: string; + options: any; +} + +export type { CardItem, ChartItem }; diff --git a/packages/business/universal-ui/src/index.ts b/packages/business/universal-ui/src/index.ts index 6bcbc03b..2c35a51f 100644 --- a/packages/business/universal-ui/src/index.ts +++ b/packages/business/universal-ui/src/index.ts @@ -8,3 +8,4 @@ export * from './notification'; export * from './preferences'; export * from './theme-toggle'; export * from './user-dropdown'; +export * from './dashboard';