UNPKG

@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" />

194 lines (191 loc) 5.17 kB
import { defineComponent, ref, reactive, onMounted, openBlock, createElementBlock, createVNode, unref } from 'vue'; import dayjs from 'dayjs'; import { useCssVar } from '@vueuse/core'; import requestControl from '../../service/request.mjs'; import _sfc_main$1 from '../common/Echarts.vue.mjs'; import '../common/Echarts.vue2.mjs'; import { setIntervalData } from '../../utils/hooks.mjs'; const _hoisted_1 = { class: "dv-ipes-vehicle-trend" }; const __default__ = { name: "DvIpesVehicleTrend", title: "近30日进/出场车辆数量变化" }; const _sfc_main = /* @__PURE__ */ defineComponent({ ...__default__, props: { // 时间类型,day-日,返回每小时的统计数据,month-月,返回每天的统计数据,year-年,返回每月的统计数据 flowTimeType: { type: String, default: "month" }, // 停车场id,指定停车场统计 parkId: { type: String, default: "" }, parkType: { type: String, default: "tcclx_2" }, // 开始时间 beginTime: { type: Number, default: dayjs().subtract(30, "d").valueOf() }, // 结束时间 endTime: { type: Number, default: Date.now() }, // 高度 height: { type: String, default: "132px" }, url: { type: String, default: "/ipes-pcip-server/api/v1/statistical/flow-car/line" } }, setup(__props) { const props = __props; ref({ value: 0, main: "" }); const xlabelEl = ref(null); useCssVar("--dv-color-text-primary", xlabelEl); const ylabelEl = ref(null); useCssVar("--dv-color-text-secondary", ylabelEl); const splitLineEl = ref(null); useCssVar("--dv-color-border-light", splitLineEl); const chartOption = reactive({ options: { tooltip: { show: true, trigger: "axis" }, grid: { top: "40px", left: "40px", right: "20px", bottom: "30px" }, legend: { show: true, top: 12, itemGap: 24, textStyle: { color: "var(--dv-color-text-primary)", fontSize: "var(--ipes-dv-text-body2)" }, itemWidth: 16, itemHeight: 8 }, xAxis: { type: "category", axisLabel: { color: "var(--dv-color-text-primary)" }, axisTick: { show: false }, axisLine: { lineStyle: { color: "var(--dv-color-border-light)" } }, data: [] }, yAxis: { type: "value", axisLabel: { color: "var(--dv-color-text-secondary)" }, splitLine: { lineStyle: { color: "var(--dv-color-border-light)" }, show: true } }, series: [ { data: [], type: "line", name: "进场车辆", itemStyle: { color: "#0AAEFF", lineStyle: { color: "#0AAEFF", borderWidth: 8 } } }, { data: [], type: "line", name: "出场车辆", itemStyle: { color: "#FFB443", lineStyle: { color: "#FFB443", borderWidth: 8 } } } ] } }); async function getData() { try { const { flowTimeType, parkId, beginTime, endTime, parkType, url } = props; const res = await requestControl({ method: "get", url, params: { parkType, flowTimeType, parkId, beginTime, endTime } }); const data = res?.data?.map((item) => { return { time: dayjs(item.time).format("MM-DD"), inNum: item.inNum, outNum: item.outNum }; }); setOptions(data); } catch (error) { console.log(error); } } function setOptions(data) { const inMaxData = data.map((ele) => ele.inNum); const outMaxData = data.map((ele) => ele.outNum); const maxValue = Math.max(...inMaxData, ...outMaxData); const maxLenth = isNaN(maxValue) ? 0 : maxValue.toString().length; chartOption.options.xAxis.data = data.map((ele) => ele.time); chartOption.options.series[0].data = inMaxData; chartOption.options.series[1].data = outMaxData; chartOption.options.grid.left = maxLenth < 4 ? "40px" : `${maxLenth * 12}px`; } onMounted(() => { getData(); }); setIntervalData(getData); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", _hoisted_1, [ createVNode(_sfc_main$1, { "full-options": unref(chartOption), loading: false, height: __props.height }, null, 8, ["full-options", "height"]) ]); }; } }); export { _sfc_main as default };