@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" />
212 lines (207 loc) • 6.69 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
const vue = require('vue');
const fpiTgFactorTools = require('fpi-tg-factor-tools');
const dayjs = require('dayjs');
require('../common/BasicEcharts/index.js');
require('../common/BasicNoData/index.js');
const index$1 = require('./api/index.js');
const index_vue_vue_type_script_setup_true_lang = require('../common/BasicEcharts/index.vue.js');
require('../common/BasicEcharts/index.vue2.js');
const index = require('../common/BasicNoData/index.vue.js');
const clsfix = "dv-aims-cieq-contributio-ratio";
const noDataColor = "var(--dv-color-text-secondary)";
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
__name: "index",
props: {
apiParams: { default: () => ({
time: dayjs().subtract(1, "h").valueOf(),
code: "0101000000",
codeType: "grid"
}) }
},
setup(__props) {
const props = __props;
const chartsFullOptions = vue.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 total = params[0] ? params[0].data.total : "";
const strArr = params.map((item) => {
return `<div>
${item.marker}
<span style="display: inline-block;width: 60px;">${item.seriesName}</span>
<span style="display: inline-block;text-align: right;width: 30px;margin-right:10px;">${Number.isNaN(Number(item.data.value2)) ? "--" : `${item.data.value2}天`}</span>
<span style="display: inline-block;text-align: right;width: 40px;">${typeof item.data.value === "number" ? `${item.data.value}%` : "--%"}</span>
</div>`;
});
const str = strArr.join("");
return `<div>
<div>${title}</div>
<div><span style="display: inline-block;width: 50px;">总天数</span><span>${total}</span></div>
${str}
</div>`;
}
},
xAxis: {
type: "category",
axisTick: {
show: false
},
axisLine: {
show: false
},
axisLabel: {
color: "var(--dv-color-text-primary)",
fontFamily: "var(--dv-font-family-number)",
fontSize: "var(--dv-text-number2)",
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)",
fontFamily: "var(--dv-font-family-number)",
fontSize: "var(--dv-text-number2)"
},
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 list = [
{
name: "优",
key: "veryGood",
value: 0
},
{
name: "良",
key: "good",
value: 0
},
{
name: "轻度污染",
key: "mild",
value: 0
},
{
name: "中度污染",
key: "medium",
value: 0
},
{
name: "重度污染",
key: "serious",
value: 0
},
{
name: "严重污染",
key: "verySerious",
value: 0
}
];
const fetchData = () => {
index$1.getAirQualityStatis(props.apiParams).then((res) => {
if (res.data && res.data.airQualityLevel) {
const data1 = res.data.airQualityLevel.levelMonthSumRate;
const data2 = res.data.airQualityLevel.levelMonthSum;
const xData = data2.times;
const tatol = data2.total;
chartsFullOptions.value = generateOption(xData, list.map((item) => {
const obj = fpiTgFactorTools.FACTOR_LEVEL_TEXT.find((c) => item.name.includes(c.label));
const value1 = data1[item.key];
const value2 = data2[item.key];
return {
name: item.name,
type: "bar",
stack: "x",
data: value1.map((item2, index) => {
return {
value: item2,
value2: value2[index],
total: tatol[index]
};
}),
color: obj ? obj.color : noDataColor,
barWidth: 15
};
}));
}
});
};
vue.onMounted(() => {
fetchData();
});
vue.watch(() => props.apiParams, () => {
fetchData();
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div", {
class: vue.normalizeClass(`${clsfix}-container`)
}, [
vue.createElementVNode("div", {
class: vue.normalizeClass(`${clsfix}-echarts`)
}, [
Boolean(vue.unref(chartsFullOptions).options) ? (vue.openBlock(), vue.createBlock(vue.unref(index_vue_vue_type_script_setup_true_lang.default), {
key: 0,
height: "100%",
"full-options": vue.unref(chartsFullOptions),
loading: false
}, null, 8, ["full-options"])) : (vue.openBlock(), vue.createBlock(vue.unref(index.default), { key: 1 }))
], 2)
], 2);
};
}
});
exports.default = _sfc_main;