@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" />
182 lines (179 loc) • 5.87 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-main-pollution-year-ratio";
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "index",
props: {
apiParams: { default: () => ({
time: dayjs().subtract(1, "h").valueOf(),
code: "0101000000",
codeType: "grid"
}) }
},
setup(__props) {
const props = __props;
const chartsFullOptions = ref({ options: null });
const generateOption = (xData, series) => {
return {
options: {
grid: {
left: 10,
bottom: 30,
right: 10,
top: 30,
containLabel: true
},
tooltip: {
trigger: "axis",
padding: 8,
background: "rgba(1, 11, 18, 0.6)",
formatter: (params) => {
const title = params[0] ? params[0].name : "";
const totalArr = params.filter((item) => Number(item.value) > 0).map((item) => item.value);
const total = totalArr.reduce((a, b) => a + b, 0);
const strArr = params.map((item) => {
const rate = Number(item.value) > 0 ? (item.value / total * 100).toFixed(1) : "0.0";
return `<div>
${item.marker}
<span style="display: inline-block;width: 40px;">${item.seriesName}</span>
<span style="display: inline-block;text-align: right;width: 40px;">${typeof item.value === "number" ? `${item.value}天` : "--天"}</span>
<span style="display: inline-block;text-align: right;width: 50px;">${rate}%</span>
</div>`;
});
const str = strArr.join("");
return `<div>
<div>${title}</div>
<div><span style="display: inline-block;width: 80px;">统计总天数</span><span>${total}</span></div>
${str}
</div>`;
}
},
xAxis: {
type: "category",
axisTick: {
show: false
},
axisLine: {
show: false
},
axisLabel: {
color: "var(--dv-color-text-primary)",
fontSize: "var(--dv-text-number2)",
fontFamily: "var(--dv-font-family-number)",
interval: 0,
formatter: (value) => value.substr(5)
},
data: xData
},
yAxis: {
type: "value",
name: "天",
nameTextStyle: {
color: "var(--dv-color-text-secondary)",
padding: [0, 30, 0, 0]
},
splitNumber: 3,
axisTick: {
show: false
},
axisLine: {
show: false
},
axisLabel: {
show: true,
color: "var(--dv-color-text-secondary)",
fontSize: "var(--dv-text-number2)",
fontFamily: "var(--dv-font-family-number)"
},
splitLine: {
show: true,
lineStyle: {
color: ["var(--dv-color-border-light)"]
}
}
},
legend: {
show: true,
bottom: 0,
itemGap: 4,
textStyle: {
color: "var(--dv-color-text-primary)",
fontSize: 12
},
itemWidth: 12,
itemHeight: 12,
icon: "circle",
itemStyle: {
borderWidth: 0
}
},
series
}
};
};
const fetchData = () => {
const colors = [
"#0062FF",
"#0AAEFF",
"#2AC94F",
"#FF792E",
"#F84439",
"#FFB443",
"rgb(154, 154, 154)"
];
getAirQualityStatis(props.apiParams).then((res) => {
if (res.data && res.data.primaryPollutant.primaryMonthSum) {
const data = res.data.primaryPollutant.primaryMonthSum;
const xData = data.times;
const rawList = BASE_FACTOR.filter((item) => item.code !== "aqi");
rawList.push({
name: "无首污",
key: "noMainPollutant",
code: "noMainPollutant",
unit: "",
key3: ""
});
const series = rawList.map((item, index) => {
const values = data[item.key];
return {
name: item.name,
type: "bar",
stack: "x",
data: values,
color: colors[index],
barWidth: 15
};
});
chartsFullOptions.value = generateOption(xData, series);
}
});
};
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 };