-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(echarts): complete echarts component
- Loading branch information
Showing
12 changed files
with
253 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters