mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-22 23:32:49 +08:00
feat: 初始化 VChart
This commit is contained in:
parent
8d3ff7cc26
commit
0972ea0e28
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ dist-ssr
|
|||||||
*.local
|
*.local
|
||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
|
pnpm-lock
|
@ -21,6 +21,8 @@
|
|||||||
"@types/crypto-js": "^4.1.1",
|
"@types/crypto-js": "^4.1.1",
|
||||||
"@types/keymaster": "^1.6.30",
|
"@types/keymaster": "^1.6.30",
|
||||||
"@types/lodash": "^4.14.184",
|
"@types/lodash": "^4.14.184",
|
||||||
|
"@visactor/vchart": "^1.12.12",
|
||||||
|
"@visactor/vchart-theme": "^1.12.2",
|
||||||
"animate.css": "^4.1.1",
|
"animate.css": "^4.1.1",
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
"color": "^4.2.3",
|
"color": "^4.2.3",
|
||||||
@ -41,7 +43,7 @@
|
|||||||
"pinia": "^2.0.13",
|
"pinia": "^2.0.13",
|
||||||
"screenfull": "^6.0.1",
|
"screenfull": "^6.0.1",
|
||||||
"three": "^0.145.0",
|
"three": "^0.145.0",
|
||||||
"vue": "^3.2.31",
|
"vue": "^3.5.13",
|
||||||
"vue-demi": "^0.13.1",
|
"vue-demi": "^0.13.1",
|
||||||
"vue-i18n": "9.2.2",
|
"vue-i18n": "9.2.2",
|
||||||
"vue-router": "4.0.12",
|
"vue-router": "4.0.12",
|
||||||
|
6306
pnpm-lock.yaml
6306
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
BIN
src/assets/images/chart/vchart/vchart_bar_x.png
Normal file
BIN
src/assets/images/chart/vchart/vchart_bar_x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
3
src/components/GoVChart/index.ts
Normal file
3
src/components/GoVChart/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import GoVChart from './index.vue'
|
||||||
|
|
||||||
|
export { GoVChart }
|
218
src/components/GoVChart/index.vue
Normal file
218
src/components/GoVChart/index.vue
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
ref="vChartRef"
|
||||||
|
v-on="{
|
||||||
|
...Object.fromEntries(event.map(eventName => [eventName, (eventData: MouseEvent) => eventHandlers(eventData, eventName)]))
|
||||||
|
}"
|
||||||
|
></div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, PropType, watch, onMounted, onBeforeUnmount, nextTick } from 'vue'
|
||||||
|
import { VChart, type IVChart, type IInitOption, type ISpec } from '@visactor/vchart'
|
||||||
|
|
||||||
|
// 事件说明 v1.13.0 https://www.visactor.io/vchart/api/API/event
|
||||||
|
const event = [
|
||||||
|
'mousedown',
|
||||||
|
'mouseup',
|
||||||
|
'mouseupoutside',
|
||||||
|
'rightdown',
|
||||||
|
'rightup',
|
||||||
|
'rightupoutside',
|
||||||
|
'click',
|
||||||
|
'dblclick',
|
||||||
|
'mousemove',
|
||||||
|
'mouseover',
|
||||||
|
'mouseout',
|
||||||
|
'mouseenter',
|
||||||
|
'mouseleave',
|
||||||
|
'wheel',
|
||||||
|
'touchstart',
|
||||||
|
'touchend',
|
||||||
|
'touchendoutside',
|
||||||
|
'touchmove',
|
||||||
|
'touchcancel',
|
||||||
|
'tap',
|
||||||
|
'dragstart',
|
||||||
|
'dragend',
|
||||||
|
'drag',
|
||||||
|
'dragenter',
|
||||||
|
'dragleave',
|
||||||
|
'dragover',
|
||||||
|
'drop',
|
||||||
|
'pan',
|
||||||
|
'panstart',
|
||||||
|
'panend',
|
||||||
|
'press',
|
||||||
|
'pressup',
|
||||||
|
'pressend',
|
||||||
|
'pinch',
|
||||||
|
'pinchstart',
|
||||||
|
'pinchend',
|
||||||
|
'swipe',
|
||||||
|
'dimensionHover',
|
||||||
|
'dimensionClick',
|
||||||
|
'dataZoomChange',
|
||||||
|
'scrollBarChange',
|
||||||
|
'brushStart',
|
||||||
|
'brushChange',
|
||||||
|
'brushEnd',
|
||||||
|
'brushClear',
|
||||||
|
'drill',
|
||||||
|
'legendItemClick',
|
||||||
|
'legendItemHover',
|
||||||
|
'legendItemUnHover',
|
||||||
|
'legendFilter',
|
||||||
|
'initialized',
|
||||||
|
'rendered',
|
||||||
|
'renderFinished',
|
||||||
|
'animationFinished',
|
||||||
|
'layoutStart',
|
||||||
|
'layoutEnd',
|
||||||
|
'afterResizef'
|
||||||
|
]
|
||||||
|
const emit = defineEmits([
|
||||||
|
'mousedown',
|
||||||
|
'mouseup',
|
||||||
|
'mouseupoutside',
|
||||||
|
'rightdown',
|
||||||
|
'rightup',
|
||||||
|
'rightupoutside',
|
||||||
|
'click',
|
||||||
|
'dblclick',
|
||||||
|
'mousemove',
|
||||||
|
'mouseover',
|
||||||
|
'mouseout',
|
||||||
|
'mouseenter',
|
||||||
|
'mouseleave',
|
||||||
|
'wheel',
|
||||||
|
'touchstart',
|
||||||
|
'touchend',
|
||||||
|
'touchendoutside',
|
||||||
|
'touchmove',
|
||||||
|
'touchcancel',
|
||||||
|
'tap',
|
||||||
|
'dragstart',
|
||||||
|
'dragend',
|
||||||
|
'drag',
|
||||||
|
'dragenter',
|
||||||
|
'dragleave',
|
||||||
|
'dragover',
|
||||||
|
'drop',
|
||||||
|
'pan',
|
||||||
|
'panstart',
|
||||||
|
'panend',
|
||||||
|
'press',
|
||||||
|
'pressup',
|
||||||
|
'pressend',
|
||||||
|
'pinch',
|
||||||
|
'pinchstart',
|
||||||
|
'pinchend',
|
||||||
|
'swipe',
|
||||||
|
'dimensionHover',
|
||||||
|
'dimensionClick',
|
||||||
|
'dataZoomChange',
|
||||||
|
'scrollBarChange',
|
||||||
|
'brushStart',
|
||||||
|
'brushChange',
|
||||||
|
'brushEnd',
|
||||||
|
'brushClear',
|
||||||
|
'drill',
|
||||||
|
'legendItemClick',
|
||||||
|
'legendItemHover',
|
||||||
|
'legendItemUnHover',
|
||||||
|
'legendFilter',
|
||||||
|
'initialized',
|
||||||
|
'rendered',
|
||||||
|
'renderFinished',
|
||||||
|
'animationFinished',
|
||||||
|
'layoutStart',
|
||||||
|
'layoutEnd',
|
||||||
|
'afterResizef'
|
||||||
|
])
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
option: {
|
||||||
|
type: Object as PropType<ISpec>,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
initOptions: {
|
||||||
|
type: Object as PropType<
|
||||||
|
IInitOption & {
|
||||||
|
deepWatch?: boolean
|
||||||
|
}
|
||||||
|
>,
|
||||||
|
required: false,
|
||||||
|
default: () => ({})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const vChartRef = ref()
|
||||||
|
let chart: IVChart
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.option,
|
||||||
|
(chartProps: ISpec) => {
|
||||||
|
if (vChartRef.value) {
|
||||||
|
nextTick(() => {
|
||||||
|
createOrUpdateChart(chartProps)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deep: props.initOptions.deepWatch || false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// 更新
|
||||||
|
const createOrUpdateChart = (chartProps: ISpec) => {
|
||||||
|
if (vChartRef.value && !chart) {
|
||||||
|
chart = new VChart(chartProps, {
|
||||||
|
dom: vChartRef.value,
|
||||||
|
...props.initOptions
|
||||||
|
})
|
||||||
|
chart.renderSync()
|
||||||
|
return true
|
||||||
|
} else if (chart) {
|
||||||
|
chart.updateSpec(chartProps)
|
||||||
|
chart.renderSync()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 刷新
|
||||||
|
const refresh = () => {
|
||||||
|
if (chart) {
|
||||||
|
chart.release()
|
||||||
|
chart.renderSync()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 抛出事件
|
||||||
|
const eventHandlers = (eventData: MouseEvent, eventName: string) => {
|
||||||
|
if (event.includes(eventName)) emit(eventName as any, eventData)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 挂载
|
||||||
|
onMounted(() => {
|
||||||
|
createOrUpdateChart(props.option)
|
||||||
|
})
|
||||||
|
|
||||||
|
// 卸载
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (chart) {
|
||||||
|
chart.release()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
// 重刷新
|
||||||
|
refresh,
|
||||||
|
release: () => {
|
||||||
|
if (chart) {
|
||||||
|
chart.release()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
@ -0,0 +1,15 @@
|
|||||||
|
import { PublicConfigClass } from '@/packages/public'
|
||||||
|
import { VChartBarCommonConfig } from './index'
|
||||||
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
|
import cloneDeep from 'lodash/cloneDeep'
|
||||||
|
|
||||||
|
export const option = {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Config extends PublicConfigClass implements CreateComponentType {
|
||||||
|
public key = VChartBarCommonConfig.key
|
||||||
|
public chartConfig = cloneDeep(VChartBarCommonConfig)
|
||||||
|
// 图表配置项
|
||||||
|
public option = cloneDeep(option)
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
<template></template>
|
||||||
|
|
||||||
|
<script setup lang="ts"></script>
|
14
src/packages/components/VChart/Bars/VChartBarCommon/index.ts
Normal file
14
src/packages/components/VChart/Bars/VChartBarCommon/index.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d'
|
||||||
|
import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
|
||||||
|
|
||||||
|
export const VChartBarCommonConfig: ConfigType = {
|
||||||
|
key: 'VChartBarCommon',
|
||||||
|
chartKey: 'VVChartBarCommon',
|
||||||
|
conKey: 'VCVChartBarCommon',
|
||||||
|
title: 'VChart柱状图',
|
||||||
|
category: ChatCategoryEnum.BAR,
|
||||||
|
categoryName: ChatCategoryEnumName.BAR,
|
||||||
|
package: PackagesCategoryEnum.VCHART,
|
||||||
|
chartFrame: ChartFrameEnum.VCHART,
|
||||||
|
image: 'vchart_bar_x.png'
|
||||||
|
}
|
3
src/packages/components/VChart/Bars/index.ts
Normal file
3
src/packages/components/VChart/Bars/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { VChartBarCommonConfig } from './VChartBarCommon/index'
|
||||||
|
|
||||||
|
export default [VChartBarCommonConfig]
|
7
src/packages/components/VChart/index.d.ts
vendored
Normal file
7
src/packages/components/VChart/index.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export enum ChatCategoryEnum {
|
||||||
|
BAR = 'Bars',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ChatCategoryEnumName {
|
||||||
|
BAR = '柱状图',
|
||||||
|
}
|
3
src/packages/components/VChart/index.ts
Normal file
3
src/packages/components/VChart/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import Bars from './Bars'
|
||||||
|
|
||||||
|
export const VChartList = [...Bars]
|
5
src/packages/index.d.ts
vendored
5
src/packages/index.d.ts
vendored
@ -5,6 +5,8 @@ import type { RequestConfigType } from '@/store/modules/chartEditStore/chartEdit
|
|||||||
export enum ChartFrameEnum {
|
export enum ChartFrameEnum {
|
||||||
// 支持 dataset 的 echarts 框架
|
// 支持 dataset 的 echarts 框架
|
||||||
ECHARTS = 'echarts',
|
ECHARTS = 'echarts',
|
||||||
|
// VChart 框架
|
||||||
|
VCHART = 'VChart',
|
||||||
// UI 组件框架
|
// UI 组件框架
|
||||||
NAIVE_UI = 'naiveUI',
|
NAIVE_UI = 'naiveUI',
|
||||||
// 自定义带数据组件
|
// 自定义带数据组件
|
||||||
@ -173,6 +175,7 @@ export type PickCreateComponentType<T extends keyof CreateComponentType> = Pick<
|
|||||||
// 包分类枚举
|
// 包分类枚举
|
||||||
export enum PackagesCategoryEnum {
|
export enum PackagesCategoryEnum {
|
||||||
CHARTS = 'Charts',
|
CHARTS = 'Charts',
|
||||||
|
VCHART = 'VChart',
|
||||||
TABLES = 'Tables',
|
TABLES = 'Tables',
|
||||||
INFORMATIONS = 'Informations',
|
INFORMATIONS = 'Informations',
|
||||||
PHOTOS = 'Photos',
|
PHOTOS = 'Photos',
|
||||||
@ -183,6 +186,7 @@ export enum PackagesCategoryEnum {
|
|||||||
// 包分类名称
|
// 包分类名称
|
||||||
export enum PackagesCategoryName {
|
export enum PackagesCategoryName {
|
||||||
CHARTS = '图表',
|
CHARTS = '图表',
|
||||||
|
VCHART = 'VChart',
|
||||||
TABLES = '列表',
|
TABLES = '列表',
|
||||||
INFORMATIONS = '信息',
|
INFORMATIONS = '信息',
|
||||||
PHOTOS = '图片',
|
PHOTOS = '图片',
|
||||||
@ -199,6 +203,7 @@ export enum FetchComFlagType {
|
|||||||
// 图表包类型
|
// 图表包类型
|
||||||
export type PackagesType = {
|
export type PackagesType = {
|
||||||
[PackagesCategoryEnum.CHARTS]: ConfigType[]
|
[PackagesCategoryEnum.CHARTS]: ConfigType[]
|
||||||
|
[PackagesCategoryEnum.VCHART]: ConfigType[]
|
||||||
[PackagesCategoryEnum.INFORMATIONS]: ConfigType[]
|
[PackagesCategoryEnum.INFORMATIONS]: ConfigType[]
|
||||||
[PackagesCategoryEnum.TABLES]: ConfigType[]
|
[PackagesCategoryEnum.TABLES]: ConfigType[]
|
||||||
[PackagesCategoryEnum.PHOTOS]: ConfigType[]
|
[PackagesCategoryEnum.PHOTOS]: ConfigType[]
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { ChartList } from '@/packages/components/Charts/index'
|
import { ChartList } from '@/packages/components/Charts/index'
|
||||||
|
import { VChartList } from '@/packages/components/VChart/index'
|
||||||
import { DecorateList } from '@/packages/components/Decorates/index'
|
import { DecorateList } from '@/packages/components/Decorates/index'
|
||||||
import { InformationList } from '@/packages/components/Informations/index'
|
import { InformationList } from '@/packages/components/Informations/index'
|
||||||
import { TableList } from '@/packages/components/Tables/index'
|
import { TableList } from '@/packages/components/Tables/index'
|
||||||
@ -19,6 +20,7 @@ const imagesModules: Record<string, { default: string }> = import.meta.glob('../
|
|||||||
// * 所有图表
|
// * 所有图表
|
||||||
export let packagesList: PackagesType = {
|
export let packagesList: PackagesType = {
|
||||||
[PackagesCategoryEnum.CHARTS]: ChartList,
|
[PackagesCategoryEnum.CHARTS]: ChartList,
|
||||||
|
[PackagesCategoryEnum.VCHART]: VChartList,
|
||||||
[PackagesCategoryEnum.INFORMATIONS]: InformationList,
|
[PackagesCategoryEnum.INFORMATIONS]: InformationList,
|
||||||
[PackagesCategoryEnum.TABLES]: TableList,
|
[PackagesCategoryEnum.TABLES]: TableList,
|
||||||
[PackagesCategoryEnum.DECORATES]: DecorateList,
|
[PackagesCategoryEnum.DECORATES]: DecorateList,
|
||||||
|
@ -102,7 +102,8 @@ import {
|
|||||||
Carbon3DSoftware as Carbon3DSoftwareIcon,
|
Carbon3DSoftware as Carbon3DSoftwareIcon,
|
||||||
Filter as FilterIcon,
|
Filter as FilterIcon,
|
||||||
FilterEdit as FilterEditIcon,
|
FilterEdit as FilterEditIcon,
|
||||||
Laptop as LaptopIcon
|
Laptop as LaptopIcon,
|
||||||
|
ChartPie as ChartPieIcon
|
||||||
} from '@vicons/carbon'
|
} from '@vicons/carbon'
|
||||||
|
|
||||||
const ionicons5 = {
|
const ionicons5 = {
|
||||||
@ -300,7 +301,9 @@ const carbon = {
|
|||||||
FilterIcon,
|
FilterIcon,
|
||||||
FilterEditIcon,
|
FilterEditIcon,
|
||||||
// 图层
|
// 图层
|
||||||
LaptopIcon
|
LaptopIcon,
|
||||||
|
// 柱状图
|
||||||
|
ChartPieIcon
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.xicons.org/#/ 还有很多
|
// https://www.xicons.org/#/ 还有很多
|
||||||
|
@ -7,7 +7,7 @@ import { usePackagesStore } from '@/store/modules/packagesStore/packagesStore'
|
|||||||
import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
|
import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
|
||||||
// 图标
|
// 图标
|
||||||
const { AirPlaneOutlineIcon, ImageIcon, BarChartIcon } = icon.ionicons5
|
const { AirPlaneOutlineIcon, ImageIcon, BarChartIcon } = icon.ionicons5
|
||||||
const { TableSplitIcon, RoadmapIcon, SpellCheckIcon, GraphicalDataFlowIcon } = icon.carbon
|
const { TableSplitIcon, RoadmapIcon, ChartPieIcon, SpellCheckIcon, GraphicalDataFlowIcon } = icon.carbon
|
||||||
|
|
||||||
// 图表
|
// 图表
|
||||||
export type MenuOptionsType = {
|
export type MenuOptionsType = {
|
||||||
@ -22,6 +22,10 @@ const packagesListObj = {
|
|||||||
icon: renderIcon(RoadmapIcon),
|
icon: renderIcon(RoadmapIcon),
|
||||||
label: PackagesCategoryName.CHARTS
|
label: PackagesCategoryName.CHARTS
|
||||||
},
|
},
|
||||||
|
[PackagesCategoryEnum.VCHART]: {
|
||||||
|
icon: renderIcon(ChartPieIcon),
|
||||||
|
label: PackagesCategoryName.VCHART
|
||||||
|
},
|
||||||
[PackagesCategoryEnum.INFORMATIONS]: {
|
[PackagesCategoryEnum.INFORMATIONS]: {
|
||||||
icon: renderIcon(SpellCheckIcon),
|
icon: renderIcon(SpellCheckIcon),
|
||||||
label: PackagesCategoryName.INFORMATIONS
|
label: PackagesCategoryName.INFORMATIONS
|
||||||
|
@ -39,6 +39,10 @@ export default defineConfig({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
define: {
|
||||||
|
// enable hydration mismatch details in production build
|
||||||
|
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true'
|
||||||
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
vue({
|
vue({
|
||||||
template: {
|
template: {
|
||||||
|
Loading…
Reference in New Issue
Block a user