@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" />
72 lines (69 loc) • 2.84 kB
JavaScript
import { ElMessage } from 'element-plus';
import dayjs from 'dayjs';
import 'vue';
const messageBox = (msg, type) => {
ElMessage({
message: msg,
type: type || "warning",
duration: 2e3
});
};
const install = (comp, named) => {
comp.install = (app) => {
const name = comp.name || comp.__name || named;
app.component(name, comp);
};
return comp;
};
const getDateEndTime = (timeType, date) => {
let resDate;
if (timeType === "hour") {
resDate = dayjs(date).add(1, "hours").startOf("hour").format("x");
} else if (timeType === "day") {
resDate = dayjs(date).add(1, "days").startOf("day").format("x");
} else if (timeType === "week") {
resDate = dayjs(date).add(1, "week").startOf("week").format("x");
} else if (timeType === "month") {
resDate = dayjs(date).add(1, "month").startOf("day").format("x");
} else if (timeType === "year") {
resDate = dayjs(date).add(1, "year").startOf("year").format("x");
}
return resDate;
};
const getAlgaeTime = (val) => {
const { currentType, upToDate, currentTime, periodBeginTime, periodEndTime } = val;
const isCurrentPeriod = currentType !== "dailyControl";
const beginTime = isCurrentPeriod ? dayjs(currentTime).startOf("day").valueOf() : !upToDate ? dayjs().startOf("day").valueOf() : dayjs().add(-6, "months").startOf("month").valueOf();
const endTime = isCurrentPeriod ? dayjs(currentTime).endOf("day").valueOf() : !upToDate ? dayjs().endOf("day").valueOf() : dayjs().endOf("day").valueOf();
const beginWarningTime = currentTime ? periodBeginTime : dayjs().startOf("year").valueOf();
const endWarningTime = currentTime ? periodEndTime : dayjs().endOf("year").valueOf();
const beginDayWarningTime = currentTime ? dayjs(currentTime).startOf("day").valueOf() : dayjs().startOf("day").valueOf();
const endDayWarningTime = currentTime ? dayjs(currentTime).endOf("day").valueOf() : dayjs().endOf("day").valueOf();
const beginTimeNewRange = dayjs(currentTime || void 0).add(-6, "months").startOf("month").valueOf();
const endTimeNewRange = dayjs(currentTime || void 0).endOf("day").valueOf();
return {
beginTime,
endTime,
beginTimeNewRange,
// 入境断面藻情现状 开始
endTimeNewRange,
// 入境断面藻情现状 结束
isCurrentPeriod,
currentTime,
beginWarningTime,
// 预警周期
endWarningTime,
// 预警周期时间
beginDayWarningTime,
// 预警当天日数据 没选择历史就显示今日
endDayWarningTime
// 预警当天日数据 没选择历史就显示今日
};
};
const countDecimalPlaces = (number) => {
const numberAsString = number.toString();
if (numberAsString.includes("."))
return numberAsString.split(".")[1].length;
return 0;
};
export { countDecimalPlaces, getAlgaeTime, getDateEndTime, install, messageBox };