lcny-vue3-antd-admin/src/views/main/meteorological/components/LightIntensity.vue

103 lines
2.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<Card :loading="loading">
<template #title>
<div class="text-18px font-extrabold">光照强度</div>
</template>
<template #extra></template>
<div ref="chartRef" :style="{ width, height }"></div>
</Card>
</template>
<script lang="ts" setup>
import dayjs from 'dayjs'
import { Card } from 'ant-design-vue'
import { Ref, ref, watch } from 'vue'
import { useECharts } from '/@/hooks/web/useECharts'
const props = defineProps({
loading: Boolean,
width: {
type: String as PropType<string>,
default: '100%',
},
height: {
type: String as PropType<string>,
default: '300px',
},
data: {
type: Object as PropType<object>,
default: () => {},
},
company: {
type: String as PropType<string>,
default: '',
},
})
const chartRef = ref<HTMLDivElement | null>(null)
const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>)
watch(
() => props.data,
(e) => {
if (e) {
const format = props.company === 'day' ? 'HH:mm' : 'YYYY-MM-DD'
setOptions({
tooltip: {
trigger: 'axis',
axisPointer: {
lineStyle: {
width: 1,
color: '#019680',
},
},
},
xAxis: {
type: 'category',
data: Object.keys(e).map((e) => dayjs(e).format(format)),
axisTick: {
show: false,
},
axisLine: {
show: false,
},
},
yAxis: [
{
type: 'value',
axisTick: {
show: false,
},
splitLine: {
lineStyle: {
type: 'dashed',
},
},
},
],
grid: { left: '5%', right: '1%', top: '2 %', bottom: 0, containLabel: true },
series: [
{
symbolSize: 20,
type: 'scatter',
data: Object.values(e).map((e) => {
if (e === 0) return null
return e
}),
},
],
dataZoom: [
{
type: 'inside', //slider表示有滑动块的inside表示内置的
show: false,
xAxisIndex: 0,
},
],
})
}
},
{
immediate: true,
},
)
</script>
<style scoped></style>