@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" />
161 lines (158 loc) • 5.68 kB
JavaScript
import __vite_glob_0_0 from './images/icon-1.png.mjs';
import __vite_glob_0_1 from './images/icon-2.png.mjs';
import { defineComponent, ref, computed, onMounted, openBlock, createElementBlock, Fragment, renderList, createElementVNode, toDisplayString, normalizeClass, createCommentVNode } from 'vue';
import { getVegetationInstrumentTypes, getBiodiversityInstrumentTypes, getMeteorologicalInstrumentTypes, getSoilInstrumentTypes } from './api/index.mjs';
const _hoisted_1 = { class: "dv-wgms-monitoring-capacity-construction" };
const _hoisted_2 = { class: "section-title" };
const _hoisted_3 = {
key: 0,
class: "capacity-icon"
};
const _hoisted_4 = ["src"];
const _hoisted_5 = { class: "capacity-content" };
const _hoisted_6 = { class: "capacity-label" };
const _hoisted_7 = { class: "capacity-value" };
const _sfc_main = /* @__PURE__ */ defineComponent({
...{
name: "DvWgmsMonitoringCapacityConstruction",
title: "监测能力建设"
},
__name: "index",
props: {
data: {
type: Array,
default: () => []
}
},
setup(__props) {
const props = __props;
const fallbackData = [
{
title: "植被监测",
layout: "grid",
items: [
{ label: "径向生长仪", value: 1 },
{ label: "激光增高仪", value: 1 },
{ label: "植被冠层仪", value: 10 }
]
},
{
title: "生物多样性识别",
layout: "grid",
items: [
{ label: "红外相机", value: 20 },
{ label: "声纹仪", value: 20 },
{ label: "声纹相机", value: 20 }
]
},
{
title: "气象监测",
layout: "row",
items: [
{ label: "自动气象站", value: 3, icon: "icon-1.png" }
]
},
{
title: "土壤监测",
layout: "row",
items: [
{ label: "便携式土壤水分温度电导率测定仪", value: 1, icon: "icon-2.png" }
]
}
];
const localData = ref([]);
const sectionConfig = {
vegetation: {
title: "植被监测",
layout: "grid"
},
biodiversity: {
title: "生物多样性识别",
layout: "grid"
},
meteorological: {
title: "气象监测",
layout: "row",
icon: "icon-1.png"
},
soil: {
title: "土壤监测",
layout: "row",
icon: "icon-2.png"
}
};
const createSection = (type, items = []) => {
const config = sectionConfig[type];
return {
title: config.title,
layout: config.layout,
items: items.map((item) => ({
label: item.instrumentTypeName,
value: item.instrumentCount ?? 0,
icon: config.layout === "row" ? config.icon : void 0
}))
};
};
const displayData = computed(() => props.data?.length ? props.data : localData.value);
const getAssetsFile = (url) => {
if (url.charAt(0) === "/")
url = url.slice(1);
return new URL((/* #__PURE__ */ Object.assign({"./images/icon-1.png": __vite_glob_0_0,"./images/icon-2.png": __vite_glob_0_1}))[`./images/${url}`], self.location).href;
};
const loadData = async () => {
const [vegetation, biodiversity, meteorological, soil] = await Promise.all([
getVegetationInstrumentTypes(),
getBiodiversityInstrumentTypes(),
getMeteorologicalInstrumentTypes(),
getSoilInstrumentTypes()
]);
localData.value = [
createSection("vegetation", vegetation?.data?.instrumentTypes),
createSection("biodiversity", biodiversity?.data?.instrumentTypes),
createSection("meteorological", meteorological?.data?.instrumentTypes),
createSection("soil", soil?.data?.instrumentTypes)
];
};
onMounted(() => {
if (!props.data?.length) {
loadData().catch(() => {
localData.value = fallbackData;
});
}
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", _hoisted_1, [
(openBlock(true), createElementBlock(Fragment, null, renderList(displayData.value, (section) => {
return openBlock(), createElementBlock("section", {
key: section.title,
class: "capacity-section"
}, [
createElementVNode("div", _hoisted_2, toDisplayString(section.title), 1),
createElementVNode("div", {
class: normalizeClass(["section-grid", `layout-${section.layout || "grid"}`])
}, [
(openBlock(true), createElementBlock(Fragment, null, renderList(section.items, (item, index) => {
return openBlock(), createElementBlock("div", {
key: `${section.title}-${item.label}-${index}`,
class: normalizeClass(["capacity-card", [`card-${section.layout || "grid"}`, { "has-icon": !!item.icon }]])
}, [
item.icon ? (openBlock(), createElementBlock("div", _hoisted_3, [
createElementVNode("img", {
src: getAssetsFile(item.icon),
alt: ""
}, null, 8, _hoisted_4)
])) : createCommentVNode("", true),
createElementVNode("div", _hoisted_5, [
createElementVNode("div", _hoisted_6, toDisplayString(item.label), 1),
createElementVNode("div", _hoisted_7, toDisplayString(item.value), 1)
])
], 2);
}), 128))
], 2)
]);
}), 128))
]);
};
}
});
export { _sfc_main as default };