@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" />
190 lines (185 loc) • 6.23 kB
JavaScript
'use strict';
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
const vue = require('vue');
const dayjs = require('dayjs');
const BaseECharts_vue_vue_type_script_setup_true_lang = require('../../utils/echarts/BaseECharts.vue.js');
const echartsOptions = require('../../utils/echarts/echartsOptions.js');
const index = require('./api/index.js');
const _hoisted_1 = { class: "title" };
const _hoisted_2 = { class: "today-line" };
const _hoisted_3 = /* @__PURE__ */ vue.createElementVNode("div", { class: "label" }, " 今日 ", -1);
const _hoisted_4 = { class: "today-right" };
const _hoisted_5 = { class: "value" };
const _hoisted_6 = /* @__PURE__ */ vue.createElementVNode("div", { class: "text" }, " / ", -1);
const _hoisted_7 = { class: "label-num" };
const _hoisted_8 = { class: "chart" };
const _hoisted_9 = { class: "year-line" };
const _hoisted_10 = /* @__PURE__ */ vue.createElementVNode("div", { class: "year-label" }, " 年累计 ", -1);
const _hoisted_11 = { class: "year-right" };
const _hoisted_12 = { class: "year-value" };
const _hoisted_13 = /* @__PURE__ */ vue.createElementVNode("div", { class: "year-text" }, " / ", -1);
const _hoisted_14 = { class: "year-total" };
const _hoisted_15 = { class: "bottom-bar" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
__name: "index",
props: {
/**
* 当前年份
*/
year: {
type: String,
default: dayjs().format("YYYY")
},
/**
* 标题
*/
title: {
type: String,
default: "预警事件"
},
/**
* 高度
*/
height: {
type: Number,
default: 136
},
/**
* 宽度
*/
width: {
type: Number,
default: 182
},
/**
* 区域站点list
*/
regionCodeList: {
type: Array,
default: () => []
},
/**
* 环境要素
*/
envTypeCode: {
type: String,
default: "water"
},
// 是否使用内置接口进行数据查询
isUseBuiltInApi: {
type: Boolean,
default: true
},
// 不使用内部接口查询时,组件使用的数据
data: {
type: Object,
default: () => {
}
}
},
setup(__props) {
const props = __props;
const todayData = vue.reactive({
done: 0,
total: 0
});
const annualCumulativeData = vue.reactive({
done: 0,
total: 0,
percent: 0
});
const options = vue.ref();
vue.onMounted(async () => {
if (props.isUseBuiltInApi) {
getTodayData();
getAnnualCumulativeData();
} else {
todayData.done = props.data.todayData.done;
todayData.total = props.data.todayData.total;
drawChart(todayData);
annualCumulativeData.done = props.data.annualCumulativeData.done;
annualCumulativeData.total = props.data.annualCumulativeData.total;
annualCumulativeData.percent = Math.round(annualCumulativeData.done / annualCumulativeData.total * 100);
}
});
const getTodayData = async () => {
const startTime = dayjs().startOf("day").valueOf();
const endTime = dayjs().valueOf();
const { done, total } = await getData(startTime, endTime);
todayData.done = Number(done);
todayData.total = Number(total);
vue.nextTick(() => {
drawChart(todayData);
});
};
const getAnnualCumulativeData = async () => {
const startTime = dayjs(props.year).startOf("year").valueOf();
const endTime = dayjs(props.year).add(1, "years").startOf("year").valueOf();
const { done, total } = await getData(startTime, endTime);
annualCumulativeData.done = Number(done);
annualCumulativeData.total = Number(total);
annualCumulativeData.percent = Math.round(Number(done) / Number(total) * 100);
};
const drawChart = (pie) => {
const pieData = pie.total ? [
{ name: "完成", value: pie.done },
{ name: "未完成", value: pie.total - pie.done }
] : [];
options.value = echartsOptions.pieChartOptions(pieData);
};
const getData = async (startTime, endTime) => {
try {
const params = {
regionCodeList: props.regionCodeList,
startTime,
endTime,
envTypeCodeList: props.envTypeCode?.split(",")
};
const { data } = await index.countByTimeGapAndAllDisposalStatus(params);
return data || {
done: "0",
total: "0"
};
} catch (error) {
return {
done: "0",
total: "0"
};
}
};
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div", {
class: "dv-bmp-tab-item",
style: vue.normalizeStyle({ height: `${__props.height}px`, width: `${__props.width}px` })
}, [
vue.createElementVNode("div", _hoisted_1, vue.toDisplayString(__props.title), 1),
vue.createElementVNode("div", _hoisted_2, [
_hoisted_3,
vue.createElementVNode("div", _hoisted_4, [
vue.createElementVNode("div", _hoisted_5, vue.toDisplayString(todayData.done), 1),
_hoisted_6,
vue.createElementVNode("div", _hoisted_7, vue.toDisplayString(todayData.total), 1),
vue.createElementVNode("div", _hoisted_8, [
vue.createVNode(BaseECharts_vue_vue_type_script_setup_true_lang.default, { options: options.value }, null, 8, ["options"])
])
])
]),
vue.createElementVNode("div", _hoisted_9, [
_hoisted_10,
vue.createElementVNode("div", _hoisted_11, [
vue.createElementVNode("div", _hoisted_12, vue.toDisplayString(annualCumulativeData.done), 1),
_hoisted_13,
vue.createElementVNode("div", _hoisted_14, vue.toDisplayString(annualCumulativeData.total), 1)
])
]),
vue.createElementVNode("div", _hoisted_15, [
vue.createElementVNode("div", {
class: "bar-value",
style: vue.normalizeStyle({ width: `${annualCumulativeData.percent}%` })
}, null, 4)
])
], 4);
};
}
});
exports.default = _sfc_main;