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
37 changed files with 177 additions and 79 deletions

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;
}