mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-04-09 16:03:14 +08:00
dashboard (#6)
* feat(dashboard): 增加dashboard示例 * feat(chart-ui): 增加图表UI组件库 * feat(dashboard): 完善dashboard示例
This commit is contained in:
37
packages/business/chart-ui/src/chart.vue
Normal file
37
packages/business/chart-ui/src/chart.vue
Normal file
@@ -0,0 +1,37 @@
|
||||
<script setup lang="ts">
|
||||
import { echartsInstance, ECOption } from './index';
|
||||
import { onMounted, ref, unref, warn } from 'vue';
|
||||
import { usePreferences } from '@vben-core/preferences';
|
||||
const { isDark } = usePreferences();
|
||||
interface Props {
|
||||
height?: string;
|
||||
width?: string;
|
||||
}
|
||||
withDefaults(defineProps<Props>(), {
|
||||
height: '500px',
|
||||
width: '100%',
|
||||
});
|
||||
|
||||
const instance = ref();
|
||||
const instanceRef = ref(HTMLElement);
|
||||
onMounted(() => {
|
||||
instance.value = echartsInstance.init(
|
||||
instanceRef.value,
|
||||
isDark.value ? 'dark' : '',
|
||||
);
|
||||
});
|
||||
const setChart = (option: ECOption, clear: boolean = true) => {
|
||||
const c = unref(instance);
|
||||
if (!c) {
|
||||
warn('instance is null');
|
||||
return;
|
||||
}
|
||||
if (clear) c.clear();
|
||||
c.setOption(option);
|
||||
};
|
||||
defineExpose({ setChart });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="instanceRef" :style="{ height, width }"></div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user