Skip to content

Commit

Permalink
feat(echarts): complete echarts component
Browse files Browse the repository at this point in the history
  • Loading branch information
YDKD committed Apr 7, 2022
1 parent efd98a1 commit 90f12e6
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@iconify/iconify": "^2.2.0",
"@vueuse/core": "^8.1.1",
"axios": "^0.25.0",
"echarts": "5.3.1",
"element-plus": "^2.1.4",
"less": "^4.1.2",
"lodash": "^4.17.21",
Expand Down
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/components/Echarts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* @Version: 1.0
* @Autor: YDKD
* @Date: 2022-04-06 11:13:32
* @LastEditors: YDKD
* @LastEditTime: 2022-04-06 11:13:32
*/
import Echart from './src/Echarts.vue'

export { Echart }
138 changes: 138 additions & 0 deletions src/components/Echarts/src/Echarts.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<!--
* @Version: 1.0
* @Autor: YDKD
* @Date: 2022-04-06 10:32:17
* @LastEditors: YDKD
* @LastEditTime: 2022-04-07 16:12:17
-->
<template>
<div ref="elRef" :class="[$attrs.class, prefixCls]" :style="styles"></div>
</template>

<script lang="ts" setup>
import {
PropType,
ref,
watch,
defineProps,
computed,
unref,
onMounted,
onBeforeUnmount,
onActivated
} from 'vue'
import { isString } from '@/utils/is'
import { debounce } from 'lodash'
import { useDesign } from '@/hooks'
import echarts from '@/plugins/echarts'
import type { EChartsOption } from 'echarts'
import { propTypes } from '@/utils/propTypes'

const prefixCls = useDesign('prefix', 'echarts')
const variables = useDesign('variables')
let namespace: any
if (typeof variables != 'string') {
namespace = variables.namespace
}

const props = defineProps({
options: {
type: Object as PropType<EChartsOption>,
required: true
},
width: propTypes.oneOfType([Number, String]).def(''),
height: propTypes.oneOfType([Number, String]).def('500px')
})

const options = computed(() => {
return Object.assign(props.options, {
darkMode: 'auto'
})
})

// eslint-disable-next-line no-undef
const elRef = ref<ElRef>()

// eslint-disable-next-line no-undef
let echartRef: Nullable<echarts.ECharts> = null

const contentEl = ref<Element>()

const styles = computed(() => {
const width = isString(props.width) ? props.width : `${props.width}px`
const height = isString(props.height) ? props.height : `${props.height}px`

return {
width,
height
}
})

const initChart = () => {
if (unref(elRef) && props.options) {
echartRef = echarts.init(unref(elRef) as HTMLElement)
echartRef?.setOption(unref(options))
}
}

watch(
() => options.value,
(options) => {
if (echartRef) {
echartRef?.setOption(options)
}
},
{
deep: true
}
)

const resizeHandler = debounce(() => {
if (echartRef) {
echartRef.resize()
}
}, 100)

const contentResizeHandler = async (e: TransitionEvent) => {
if (e.propertyName === 'width') {
resizeHandler()
}
}

onMounted(() => {
initChart()

window.addEventListener('resize', resizeHandler)

// contentEl.value = document.getElementsByClassName(
// `${namespace}-layout-content`
// )[0]
// unref(contentEl) &&
// (unref(contentEl) as HTMLElement).addEventListener(
// 'transitionend',
// contentResizeHandler
// )
})

onBeforeUnmount(() => {
window.removeEventListener('resize', resizeHandler)
// unref(contentEl) &&
// (unref(contentEl) as HTMLElement).removeEventListener(
// 'transitionend',
// contentResizeHandler
// )
})

onActivated(() => {
if (echartRef) {
echartRef.resize()
}
})
</script>

<style lang="less" scoped>
@prefix-cls: ~'@{namespace}-echarts';

.@{prefix-cls} {
}
</style>
2 changes: 1 addition & 1 deletion src/components/Menu/src/components/useRenderMenuTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useRenderMenuTitle = () => {
const renderMenuTitle = (meta?: RouteMeta) => {
let icon
const type = meta?.icon?.split('-')[0] == 'fa' ? 'iconify' : 'iconfont'
if (type == 'iconify' ) {
if (type == 'iconify') {
icon = meta?.icon?.split('-')[1]
} else {
icon = meta?.icon
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/web/useDesign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Autor: YDKD
* @Date: 2022-03-23 16:46:13
* @LastEditors: YDKD
* @LastEditTime: 2022-03-23 17:02:13
* @LastEditTime: 2022-04-07 15:43:59
*/
import variables from '@/styles/variables.module.less'

Expand All @@ -22,6 +22,6 @@ export const useDesign = (type: Type = 'prefix', componentScope?: string) => {
if (type == 'prefix') {
return getPrefixCls(componentScope!)
} else {
return lessVariables
return variables
}
}
31 changes: 31 additions & 0 deletions src/plugins/echarts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as echarts from 'echarts/core'

import { PieChart } from 'echarts/charts'

import {
TitleComponent,
TooltipComponent,
GridComponent,
PolarComponent,
AriaComponent,
ParallelComponent,
LegendComponent,
ToolboxComponent
} from 'echarts/components'

import { CanvasRenderer } from 'echarts/renderers'

echarts.use([
LegendComponent,
TitleComponent,
TooltipComponent,
GridComponent,
PolarComponent,
AriaComponent,
ParallelComponent,
PieChart,
CanvasRenderer,
ToolboxComponent
])

export default echarts
2 changes: 1 addition & 1 deletion src/views/analysis/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Autor: YDKD
* @Date: 2022-03-24 15:42:06
* @LastEditors: YDKD
* @LastEditTime: 2022-03-24 15:49:29
* @LastEditTime: 2022-04-06 10:53:25
-->
<template>
<div :class="prefixCls">
Expand Down
22 changes: 22 additions & 0 deletions src/views/attendance/components/count-panel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
* @Version: 1.0
* @Autor: YDKD
* @Date: 2022-04-06 10:11:27
* @LastEditors: YDKD
* @LastEditTime: 2022-04-07 16:30:18
-->
<template>
<div :class="prefixCls"></div>
</template>

<script lang="ts" setup>
import { useDesign } from '@/hooks'
const prefixCls = useDesign('prefix', 'count-panel')
</script>

<style lang="less" scoped>
@prefix-cls: ~'@{namespace}-count-panel';

.@{prefix-cls} {
}
</style>
25 changes: 25 additions & 0 deletions src/views/attendance/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
* @Version: 1.0
* @Autor: YDKD
* @Date: 2022-04-06 09:43:12
* @LastEditors: YDKD
* @LastEditTime: 2022-04-06 10:13:21
-->
<template>
<div :class="prefixCls">
<count-pnale />
</div>
</template>

<script lang="ts" setup>
import { useDesign } from '@/hooks'
import countPnale from './components/count-panel.vue'
const prefixCls = useDesign('prefix', 'person-attendance')
</script>

<style lang="less" scoped>
@prefix-cls: ~'@{namespace}-person-attendance';

.@{prefix-cls} {
}
</style>
6 changes: 1 addition & 5 deletions types/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@
declare module 'vue' {
export interface GlobalComponents {
ButtonSrcButton: typeof import('./../src/components/Button/src/Button.vue')['default']
EchartsSrcEcharts: typeof import('./../src/components/Echarts/src/Echarts.vue')['default']
ElAside: typeof import('element-plus/es')['ElAside']
ElAvatar: typeof import('element-plus/es')['ElAvatar']
ElButton: typeof import('element-plus/es')['ElButton']
ElCard: typeof import('element-plus/es')['ElCard']
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
ElContainer: typeof import('element-plus/es')['ElContainer']
ElDropdown: typeof import('element-plus/es')['ElDropdown']
ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
ElForm: typeof import('element-plus/es')['ElForm']
ElFormItem: typeof import('element-plus/es')['ElFormItem']
ElHeader: typeof import('element-plus/es')['ElHeader']
ElIcon: typeof import('element-plus/es')['ElIcon']
ElInput: typeof import('element-plus/es')['ElInput']
ElMain: typeof import('element-plus/es')['ElMain']
ElTable: typeof import('element-plus/es')['ElTable']
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
Expand Down
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export default defineConfig(({ command, mode }) => {
'@iconify/iconify',
'@vueuse/core',
'axios',
'vue-types'
'vue-types',
'echarts'
]
}
}
Expand Down

0 comments on commit 90f12e6

Please sign in to comment.