@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" />
104 lines (99 loc) • 3.71 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
const _1 = require('./images/1.png.js');
const _2 = require('./images/2.png.js');
const _3 = require('./images/3.png.js');
const _4 = require('./images/4.png.js');
const _5 = require('./images/5.png.js');
const _6 = require('./images/6.png.js');
const vue = require('vue');
const index = require('./api/index.js');
const _hoisted_1 = { class: "dv-wgms-common-flora-fauna" };
const _hoisted_2 = { class: "species-image-box" };
const _hoisted_3 = ["src", "alt"];
const _hoisted_4 = {
key: 1,
class: "species-image-placeholder"
};
const _hoisted_5 = ["src", "alt"];
const _hoisted_6 = { class: "species-name" };
const FILE_PREVIEW_BASE_URL = "/file-base-server/api/v1/sys/download";
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
...{
name: "DvWgmsCommonFloraFauna",
title: "常见动植物"
},
__name: "index",
props: {
data: {
type: Array,
default: () => []
}
},
setup(__props) {
const props = __props;
const fallbackData = [
{ name: "地黄", imageUrl: "" },
{ name: "牵牛", imageUrl: "" },
{ name: "蒲公英", imageUrl: "" },
{ name: "长耳鸮", imageUrl: "" },
{ name: "疣鼻天鹅", imageUrl: "" },
{ name: "白琵鹭", imageUrl: "" }
];
const localData = vue.ref([]);
const displayData = vue.computed(() => props.data?.length ? props.data : localData.value);
const loadData = async () => {
const res = await index.getCommonSpecies();
localData.value = (res?.data || []).map((item) => ({
name: item.speciesName,
imageUrl: formatImageUrl(item.speciesImageUrl)
}));
};
const formatImageUrl = (imageUrl) => {
if (!imageUrl)
return "";
if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://"))
return imageUrl;
return `${FILE_PREVIEW_BASE_URL}/${imageUrl}`;
};
const getAssetsFile = (url) => {
if (url.charAt(0) === "/")
url = url.slice(1);
return new URL((/* #__PURE__ */ Object.assign({"./images/1.png": _1.default,"./images/2.png": _2.default,"./images/3.png": _3.default,"./images/4.png": _4.default,"./images/5.png": _5.default,"./images/6.png": _6.default}))[`./images/${url}`], self.location).href;
};
vue.onMounted(() => {
if (!props.data?.length) {
loadData().catch(() => {
localData.value = fallbackData;
});
}
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(displayData.value, (item, index) => {
return vue.openBlock(), vue.createElementBlock("div", {
key: item.name,
class: "species-card"
}, [
vue.createElementVNode("div", _hoisted_2, [
item.imageUrl ? (vue.openBlock(), vue.createElementBlock("img", {
key: 0,
src: item.imageUrl,
alt: item.name,
class: "species-image"
}, null, 8, _hoisted_3)) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_4, [
vue.createElementVNode("img", {
src: getAssetsFile(`${index + 1}.png`),
alt: item.name,
class: "species-image"
}, null, 8, _hoisted_5)
]))
]),
vue.createElementVNode("div", _hoisted_6, vue.toDisplayString(item.name), 1)
]);
}), 128))
]);
};
}
});
exports.default = _sfc_main;