From b8b2820d1a0a55a5555434a3ec95f8bbec1db06d Mon Sep 17 00:00:00 2001 From: zmc <zmc_li@foxmail.com> Date: 星期四, 14 十二月 2023 15:22:54 +0800 Subject: [PATCH] 1.飞行巡检和审核辅助页面中的对话框写成组件 2.增加了数据请求和异常分析配置参数的可视化页面 3.修改了站点输入框,使能够模糊匹配 --- src/utils/time.js | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 115 insertions(+), 1 deletions(-) diff --git a/src/utils/time.js b/src/utils/time.js index c416595..adc38b1 100644 --- a/src/utils/time.js +++ b/src/utils/time.js @@ -1,7 +1,9 @@ /* 鏃堕棿鍑芥暟 */ -import dayjs from 'dayjs' import lineChart from '@/utils/chartFunction/lineChart.js' +import customParseFormat from 'dayjs/plugin/customParseFormat' +import dayjs from 'dayjs' +dayjs.extend(customParseFormat) export default { // 鍒ゆ柇宸查�夌殑鏈堜唤鏄惁澶т簬褰撳墠鏈堜唤 judgeDateValid(date) { @@ -83,7 +85,26 @@ return time }, + /** + * 杩斿洖鏈夋晥鐨勬椂闂寸偣 + * @param锛氭壃灏樻暟鎹� + * @returns锛氬崌搴忕殑鏃堕棿鐐� + */ + validTime(dustData) { + // 鍙傛暟涓虹┖鍒欓��鍑� + if (!dustData.length) { + return [] + } + let time = [] + dustData.forEach((item) => { + if (item.flag != 'A') { + time.push(item.lst) + } + }) + + return time + }, /** * 鍙栨寚瀹氶棿闅旂殑鏃堕棿涓鸿繛缁椂闂达紝鏀惧湪鏁扮粍涓�� 瀛ょ珛鐨勬椂闂寸偣涓庤嚜韬畻涓�涓繛缁� * 鐩殑鏄瀯閫犳湁鏁堢巼缂哄け鐨勯鑹茶儗鏅尯闂� @@ -142,5 +163,98 @@ result.push(temp) } return result + }, + + /** + *鍒ゆ柇鏄惁鏄湁鎰忎箟鐨勬棩鏈� + * @param锛� + * @returns锛� + */ + judgeTimeValid(time) { + let r1 = dayjs(time, 'YYYY-MM-DD HH:mm:ss', true).isValid() + let r2 = dayjs(time, 'YYYY-MM-DD', true).isValid() + // 涓ょ鏃ユ湡鏍煎紡閮芥棤鏁堟椂 + if (!r1 && !r2) { + return false + } + // 绗﹀悎浠绘剰涓�绉嶆牸寮� + return true + }, + /** + * 'YYYY-MM-DD HH:mm:ss'杩斿洖true + * @param锛� + * @returns锛� + */ + judgeTimeFormat(time) { + // 'YYYY-MM-DD HH:mm:ss' + const dateTimeRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/ + // 'YYYY-MM-DD' + const dateRegex = /^\d{4}-\d{2}-\d{2}$/ + + if (dateTimeRegex.test(time)) { + return true + } else if (dateRegex.test(time)) { + return false + } + }, + + /** + * 鎵惧埌鍦ㄧ粰瀹氱殑寮�濮嬫椂闂碽t鍜岀粨鏉熸椂闂磂t涔嬮棿缂哄け鐨勬椂闂村尯闂� + * @param锛氬紑濮嬫椂闂达紝缁撴潫鏃堕棿锛屽湪杩欎釜鏃堕棿鑼冨洿鍐呭凡鏈夌殑鏃堕棿锛堟椂闂村瓧绗︿覆鏁扮粍锛�,鏁扮粍涓椂闂寸殑闂撮殧 + * @returns锛� + */ + getMissingDays(bt, et, timeArr, minutesNum = 1440) { + // 鍒ゆ柇鏃ユ湡鏄惁鏈夋剰涔� + if (!this.judgeTimeValid(bt) || !this.judgeTimeValid(et)) { + return false + } + // 瀛樺偍缂哄け鐨勬椂闂村尯闂� + const r = [] + const begin = dayjs(bt) + const end = dayjs(et) + // 寮�濮嬫椂闂� + let current = begin + + for (const time of timeArr) { + const currentTime = dayjs(time) + if (currentTime.isBefore(current)) { + continue + } + + if (currentTime.isAfter(current)) { + r.push([current, currentTime]) + } + + current = currentTime.add(minutesNum, 'minute') + } + + if (end.isAfter(current)) { + r.push([current, end]) + } + + let f = this.judgeTimeFormat(bt) ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD' + for (let i = 0; i < r.length; i++) { + for (let j = 0; j < r[i].length; j++) { + r[i][j] = r[i][j].format(f) + } + } + return r + }, + /** + * 鏍规嵁鏃堕棿瀛楃涓茶繑鍥濽TC鏃堕棿 + * @param锛� + * @returns锛� + */ + utcTime(timeStr){ + return dayjs(timeStr).format() + }, + /** + * 灏唘tc鏃堕棿杞负鏃堕棿瀛楃涓� + * @param锛� + * @returns锛� + */ + utcToStr(dateTime){ + const r = dateTime ? dayjs(dateTime).format('YYYY-MM-DD HH:mm:ss') :false + return r } } -- Gitblit v1.9.3