From 9c1d136e4f5ed9b5bce100147edbb52486da985a Mon Sep 17 00:00:00 2001 From: zmc <zmc_li@foxmail.com> Date: 星期五, 08 十二月 2023 13:57:32 +0800 Subject: [PATCH] 对飞行巡检和审核辅助对话框逻辑写成组件 --- src/utils/time.js | 99 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 98 insertions(+), 1 deletions(-) diff --git a/src/utils/time.js b/src/utils/time.js index c416595..eac1bd6 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,81 @@ 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 } } -- Gitblit v1.9.3