refactor: package chart-ui integrated into plugins (#4238)

* refactor: package chart-ui integrated into plugins

* fix: lint error
This commit is contained in:
Vben 2024-08-26 21:42:56 +08:00 committed by GitHub
parent fd7b3479b4
commit 8a0b1e0c72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
37 changed files with 177 additions and 79 deletions

View File

@ -27,13 +27,13 @@
},
"dependencies": {
"@vben/access": "workspace:*",
"@vben/chart-ui": "workspace:*",
"@vben/common-ui": "workspace:*",
"@vben/constants": "workspace:*",
"@vben/hooks": "workspace:*",
"@vben/icons": "workspace:*",
"@vben/layouts": "workspace:*",
"@vben/locales": "workspace:*",
"@vben/plugins": "workspace:*",
"@vben/preferences": "workspace:*",
"@vben/request": "workspace:*",
"@vben/stores": "workspace:*",

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -27,13 +27,13 @@
},
"dependencies": {
"@vben/access": "workspace:*",
"@vben/chart-ui": "workspace:*",
"@vben/common-ui": "workspace:*",
"@vben/constants": "workspace:*",
"@vben/hooks": "workspace:*",
"@vben/icons": "workspace:*",
"@vben/layouts": "workspace:*",
"@vben/locales": "workspace:*",
"@vben/plugins": "workspace:*",
"@vben/preferences": "workspace:*",
"@vben/request": "workspace:*",
"@vben/stores": "workspace:*",

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -27,13 +27,13 @@
},
"dependencies": {
"@vben/access": "workspace:*",
"@vben/chart-ui": "workspace:*",
"@vben/common-ui": "workspace:*",
"@vben/constants": "workspace:*",
"@vben/hooks": "workspace:*",
"@vben/icons": "workspace:*",
"@vben/layouts": "workspace:*",
"@vben/locales": "workspace:*",
"@vben/plugins": "workspace:*",
"@vben/preferences": "workspace:*",
"@vben/request": "workspace:*",
"@vben/stores": "workspace:*",

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -43,7 +43,7 @@ The directory uses Monorepo management, and the project structure is as follows:
│   ├── constants # Constants
│   ├── effects # Effects related packages
│   │   ├── access # Access control
│   │   ├── chart-ui # Chart UI
│   │   ├── plugins # Plugins
│   │   ├── common-ui # Common UI
│   │   ├── hooks # Composable APIs
│   │   ├── layouts # Layouts

View File

@ -43,7 +43,7 @@
│   ├── constants # 常量
│   ├── effects # 副作用相关包
│   │   ├── access # 访问控制
│   │   ├── chart-ui # 图表 UI
│   │   ├── plugins # 第三方大型依赖插件
│   │   ├── common-ui # 通用 UI
│   │   ├── hooks # 组合式 API
│   │   ├── layouts # 布局

View File

@ -1 +0,0 @@
export * from './echarts';

View File

@ -0,0 +1,28 @@
# @vben/plugins
该目录用于存放项目中集成的第三方库及其相关插件。每个插件都包含了可重用的逻辑、配置和组件,方便在项目中进行统一管理和调用。
## 注意
所有的第三方插件都必须以 `subpath` 形式引入,例:
`echarts` 为例,引入方式如下:
**packages.json**
```json
"exports": {
"./echarts": {
"types": "./src/echarts/index.ts",
"default": "./src/echarts/index.ts"
}
}
```
**使用方式**
```ts
import { useEcharts } from '@vben/plugins/echarts';
```
这样做的好处是,应用可以自行选择是否使用插件,而不会因为插件的引入及副作用而导致打包体积增大,只引入需要的插件即可。

View File

@ -1,12 +1,12 @@
{
"name": "@vben/chart-ui",
"name": "@vben/plugins",
"version": "5.1.2",
"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/effects/chart-ui"
"directory": "packages/effects/plugins"
},
"license": "MIT",
"type": "module",
@ -14,9 +14,9 @@
"**/*.css"
],
"exports": {
".": {
"types": "./src/index.ts",
"default": "./src/index.ts"
"./echarts": {
"types": "./src/echarts/index.ts",
"default": "./src/echarts/index.ts"
}
},
"dependencies": {

View File

@ -5,11 +5,12 @@ import type EchartsUI from './echarts-ui.vue';
import type { Ref } from 'vue';
import { computed, nextTick, watch } from 'vue';
import { preferences, usePreferences } from '@vben/preferences';
import { usePreferences } from '@vben/preferences';
import {
tryOnUnmounted,
useDebounceFn,
useResizeObserver,
useTimeoutFn,
useWindowSize,
} from '@vueuse/core';
@ -86,6 +87,8 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
resizeHandler?.();
});
useResizeObserver(chartRef as never, resizeHandler);
watch(isDark, () => {
if (chartInstance) {
chartInstance.dispose();
@ -95,21 +98,6 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
}
});
watch(
[
() => preferences.sidebar.collapsed,
() => preferences.sidebar.extraCollapse,
() => preferences.sidebar.hidden,
() => preferences.app.contentCompact,
],
() => {
// 折叠动画200ms
setTimeout(() => {
resize();
}, 200);
},
);
tryOnUnmounted(() => {
// 销毁实例,释放资源
chartInstance?.dispose();

View File

@ -1,3 +1,6 @@
/**
* Returns the parent node of the given element or the document body if the element is not provided.it
*/
export function getPopupContainer(node?: HTMLElement): HTMLElement {
return (node?.parentNode as HTMLElement) ?? document.body;
}

View File

@ -27,13 +27,13 @@
},
"dependencies": {
"@vben/access": "workspace:*",
"@vben/chart-ui": "workspace:*",
"@vben/common-ui": "workspace:*",
"@vben/constants": "workspace:*",
"@vben/hooks": "workspace:*",
"@vben/icons": "workspace:*",
"@vben/layouts": "workspace:*",
"@vben/locales": "workspace:*",
"@vben/plugins": "workspace:*",
"@vben/preferences": "workspace:*",
"@vben/request": "workspace:*",
"@vben/stores": "workspace:*",

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);

View File

@ -135,9 +135,6 @@ importers:
'@vben/access':
specifier: workspace:*
version: link:../../packages/effects/access
'@vben/chart-ui':
specifier: workspace:*
version: link:../../packages/effects/chart-ui
'@vben/common-ui':
specifier: workspace:*
version: link:../../packages/effects/common-ui
@ -156,6 +153,9 @@ importers:
'@vben/locales':
specifier: workspace:*
version: link:../../packages/locales
'@vben/plugins':
specifier: workspace:*
version: link:../../packages/effects/plugins
'@vben/preferences':
specifier: workspace:*
version: link:../../packages/preferences
@ -198,9 +198,6 @@ importers:
'@vben/access':
specifier: workspace:*
version: link:../../packages/effects/access
'@vben/chart-ui':
specifier: workspace:*
version: link:../../packages/effects/chart-ui
'@vben/common-ui':
specifier: workspace:*
version: link:../../packages/effects/common-ui
@ -219,6 +216,9 @@ importers:
'@vben/locales':
specifier: workspace:*
version: link:../../packages/locales
'@vben/plugins':
specifier: workspace:*
version: link:../../packages/effects/plugins
'@vben/preferences':
specifier: workspace:*
version: link:../../packages/preferences
@ -265,9 +265,6 @@ importers:
'@vben/access':
specifier: workspace:*
version: link:../../packages/effects/access
'@vben/chart-ui':
specifier: workspace:*
version: link:../../packages/effects/chart-ui
'@vben/common-ui':
specifier: workspace:*
version: link:../../packages/effects/common-ui
@ -286,6 +283,9 @@ importers:
'@vben/locales':
specifier: workspace:*
version: link:../../packages/locales
'@vben/plugins':
specifier: workspace:*
version: link:../../packages/effects/plugins
'@vben/preferences':
specifier: workspace:*
version: link:../../packages/preferences
@ -900,21 +900,6 @@ importers:
specifier: 3.4.38
version: 3.4.38(typescript@5.5.4)
packages/effects/chart-ui:
dependencies:
'@vben/preferences':
specifier: workspace:*
version: link:../../preferences
'@vueuse/core':
specifier: ^11.0.1
version: 11.0.1(vue@3.4.38(typescript@5.5.4))
echarts:
specifier: ^5.5.1
version: 5.5.1
vue:
specifier: 3.4.38
version: 3.4.38(typescript@5.5.4)
packages/effects/common-ui:
dependencies:
'@vben-core/popup-ui':
@ -1033,6 +1018,21 @@ importers:
specifier: ^4.4.3
version: 4.4.3(vue@3.4.38(typescript@5.5.4))
packages/effects/plugins:
dependencies:
'@vben/preferences':
specifier: workspace:*
version: link:../../preferences
'@vueuse/core':
specifier: ^11.0.1
version: 11.0.1(vue@3.4.38(typescript@5.5.4))
echarts:
specifier: ^5.5.1
version: 5.5.1
vue:
specifier: 3.4.38
version: 3.4.38(typescript@5.5.4)
packages/effects/request:
dependencies:
'@vben/locales':
@ -1132,9 +1132,6 @@ importers:
'@vben/access':
specifier: workspace:*
version: link:../packages/effects/access
'@vben/chart-ui':
specifier: workspace:*
version: link:../packages/effects/chart-ui
'@vben/common-ui':
specifier: workspace:*
version: link:../packages/effects/common-ui
@ -1153,6 +1150,9 @@ importers:
'@vben/locales':
specifier: workspace:*
version: link:../packages/locales
'@vben/plugins':
specifier: workspace:*
version: link:../packages/effects/plugins
'@vben/preferences':
specifier: workspace:*
version: link:../packages/preferences

View File

@ -104,10 +104,6 @@
"name": "@vben/access",
"path": "packages/effects/access",
},
{
"name": "@vben/chart-ui",
"path": "packages/effects/chart-ui",
},
{
"name": "@vben/common-ui",
"path": "packages/effects/common-ui",
@ -120,6 +116,10 @@
"name": "@vben/layouts",
"path": "packages/effects/layouts",
},
{
"name": "@vben/plugins",
"path": "packages/effects/plugins",
},
{
"name": "@vben/request",
"path": "packages/effects/request",