@ued_fpi/data-visual
Version:
<br /> <br /> <div style="text-align:center"> <b style="font-size:30px">@ued_fpi/data-visual</b> <p>基于Vite4+TypeScript的Vue3大屏组件库开发框架</p> <img style="display:inline" src="https://img.shields.io/npm/v/@ued_fpi/data-visual" />
145 lines (142 loc) • 4.36 kB
JavaScript
import { defineComponent, ref, onMounted, watch, openBlock, createElementBlock, normalizeClass, createElementVNode, createVNode, unref } from 'vue';
import { BASE_FACTOR } from 'fpi-tg-factor-tools';
import dayjs from 'dayjs';
import '../common/BasicEcharts/index.mjs';
import { getAirQualityStatis } from './api/index.mjs';
import _sfc_main$1 from '../common/BasicEcharts/index.vue.mjs';
import '../common/BasicEcharts/index.vue2.mjs';
const clsfix = "dv-aims-cieq-contributio-ratio";
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "index",
props: {
apiParams: { default: () => ({
time: dayjs().subtract(1, "h").valueOf(),
code: "0101000000",
codeType: "grid"
}) },
showCieq: { type: Boolean, default: false }
},
setup(__props) {
const props = __props;
const chartsFullOptions = ref({ options: null });
const generateOption = (list, cieq) => {
return {
options: {
title: [
{
show: props.showCieq,
text: `{cieq|${cieq}}`,
top: "62px",
left: "center",
textStyle: {
rich: {
cieq: {
fontSize: 16,
color: "#fff"
}
}
}
}
],
grid: {
left: 0,
right: 0
},
legend: {
show: true,
bottom: -4,
itemGap: 10,
textStyle: {
color: "var(--dv-color-text-primary)",
fontSize: "var(--dv-text-body2)"
},
icon: "circle",
itemWidth: 12,
itemHeight: 12
},
tooltip: {
trigger: "item",
padding: 8,
formatter: (params) => {
return `${params.marker} ${params.name} ${params.data.value2} ${params.value}%`;
},
background: "rgba(1, 11, 18, 0.6)"
},
series: [
{
type: "pie",
radius: props.showCieq ? ["28%", "60%"] : "60%",
center: ["50%", "44%"],
data: list,
label: {
position: "outside",
color: "var(--dv-color-text-primary)",
overflow: "none",
formatter: (params) => {
const { name, value, value2 } = params.data;
return `${name} ${value2} ${value}%`;
},
fontSize: "var(--dv-text-number1)",
fontFamily: "var(--dv-font-family-number)"
}
}
]
}
};
};
const fetchData = () => {
const colors = [
"#0062FF",
"#0AAEFF",
"#2AC94F",
"#FF792E",
"#F84439",
"#FFB443"
];
getAirQualityStatis(props.apiParams).then((res) => {
if (res.data && res.data.CIEQ) {
const data1 = res.data.CIEQ.CIEQYearValueRate;
const data2 = res.data.CIEQ.CIEQYearValue;
const cieq = res.data.CIEQ.CIEQYearValue.cieq;
const list = BASE_FACTOR.filter((item) => item.code !== "aqi").map((item, index) => {
const key = `V_ICIEQ_${item.key}`;
const value1 = data1[key] ?? 0;
const value2 = data2[key] ?? 0;
return {
name: item.name,
code: item.code,
value: value1,
value2,
itemStyle: {
color: colors[index]
}
};
});
chartsFullOptions.value = generateOption(list, cieq);
}
});
};
onMounted(() => {
fetchData();
});
watch(() => props.apiParams, () => {
fetchData();
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", {
class: normalizeClass(`${clsfix}-container`)
}, [
createElementVNode("div", {
class: normalizeClass(`${clsfix}-echarts`)
}, [
createVNode(unref(_sfc_main$1), {
height: "100%",
"full-options": chartsFullOptions.value,
loading: false
}, null, 8, ["full-options"])
], 2)
], 2);
};
}
});
export { _sfc_main as default };