时间选择范围问题修复

This commit is contained in:
白菜
2025-08-16 23:15:33 +08:00
parent ffefc21d96
commit 5ea121abf0
5 changed files with 438 additions and 456 deletions

View File

@ -1,10 +1,10 @@
<template> <template>
<view class="time-range"> <view class="time-range">
<uni-datetime-picker v-model="dateRange" type="daterange" start="2000-01-01" :end="defaultDateRange[1]" <uni-datetime-picker v-model="dateRange" type="daterange" :end="defaultDateRange[1]" :clear-icon="false"
:clear-icon="false" rangeSeparator="至" @change="changeTime" /> rangeSeparator="至" @change="changeTime" />
<view class="btns-container"> <view class="btns-container">
<button size="mini" class="small" :disabled="loading" @click="reset">重置</button> <button size="mini" class="small" :disabled="loading" @click="reset">重置</button>
<button type="primary" class="small" size="mini" :disabled="loading" @click="search">搜索</button> <!-- <button type="primary" class="small" size="mini" :disabled="loading" @click="search">搜索</button> -->
<button type="primary" class="large" size="mini" :disabled="loading" <button type="primary" class="large" size="mini" :disabled="loading"
@click="timeLine('before')">上一时段</button> @click="timeLine('before')">上一时段</button>
<button type="primary" class="large" size="mini" @click="timeLine('next')" <button type="primary" class="large" size="mini" @click="timeLine('next')"
@ -41,6 +41,7 @@
}, },
changeTime(val) { changeTime(val) {
this.dateRange = val || [] this.dateRange = val || []
this.$emit('updateDate', this.dateRange)
}, },
showBtnLoading(status) { showBtnLoading(status) {
this.loading = status this.loading = status

View File

@ -1,11 +0,0 @@
<template>
<view class="">
一周功率曲线
</view>
</template>
<script>
</script>
<style>
</style>

View File

@ -1,16 +1,15 @@
<template> <template>
<uni-popup ref="popup" type="center" @maskClick="show = false"> <uni-popup ref="popup" type="center" @maskClick="show = false">
<view class="chart-popup"> <view class="chart-popup">
<uni-datetime-picker v-model="range" type="daterange" start="2000-01-01" :end="end" rangeSeparator="至" <uni-datetime-picker v-model="range" type="daterange" :end="end" rangeSeparator="至" @change="changeTime"
@change="changeTime" /> style="margin-bottom: 10px;" />
<view class="button-group" style="text-align: center;margin-top:20px;"> <!-- <view class="button-group" style="text-align: center;margin-top:20px;">
<button type="default" size="mini" @click="onReset">重置</button> <button type="default" size="mini" @click="onReset">重置</button>
<button type="primary" size="mini" @click="onSearch" style="margin-left: 20px;">搜索</button> <button type="primary" size="mini" @click="onSearch" style="margin-left: 20px;">搜索</button>
</view> </view> -->
<view class="chart-container"> <view class="chart-container">
<qiun-data-charts type="line" :reload="show" :chartData="chartsData" :canvas2d="true" <qiun-data-charts type="line" :reload="show" :chartData="chartsData" :optsWatch='false'
canvasId="scrollcolumnid" :optsWatch='false' :inScrollView="true" :pageScrollTop="pageScrollTop" :inScrollView="true" :pageScrollTop="pageScrollTop" :opts="options" :ontouch="true" />
:opts="options" :ontouch="true" />
</view> </view>
</view> </view>
</uni-popup> </uni-popup>
@ -44,7 +43,7 @@
}, },
show: false, show: false,
range: [], range: [],
end: "", end: Date.now(),
siteId: '', siteId: '',
deviceId: '', deviceId: '',
clusterDeviceId: '', clusterDeviceId: '',
@ -74,6 +73,7 @@
}, },
changeTime(val) { changeTime(val) {
this.range = val || [] this.range = val || []
this.getData()
}, },
onReset() { onReset() {
this.range = [] this.range = []
@ -149,13 +149,6 @@
console.log('this.chartsData', this.chartsData) console.log('this.chartsData', this.chartsData)
} }
}, },
mounted() {
const now = new Date(),
year = now.getFullYear(),
month = now.getMonth() + 1,
day = now.getDate()
this.end = year + '-' + month + '-' + day
}
} }
</script> </script>

View File

@ -42,8 +42,7 @@
<date-range-select ref="weekChartDateRangeSelect" @updateDate="updateWeekChartDate" /> <date-range-select ref="weekChartDateRangeSelect" @updateDate="updateWeekChartDate" />
<view style="width:100%;height: 250px;"> <view style="width:100%;height: 250px;">
<qiun-data-charts type="line" :chartData="weekChartData" :optsWatch='false' :inScrollView="true" <qiun-data-charts type="line" :chartData="weekChartData" :optsWatch='false' :inScrollView="true"
:canvas2d="true" canvasId="scrollcolumnid" :pageScrollTop="pageScrollTop" :opts="options" :pageScrollTop="pageScrollTop" :opts="options" :ontouch="true" />
:ontouch="true" />
</view> </view>
</uni-section> </uni-section>
<!-- 当日功率曲线 uchart的组件最好放在同级--> <!-- 当日功率曲线 uchart的组件最好放在同级-->
@ -51,15 +50,13 @@
<date-range-select ref="activeChartDateRangeSelect" @updateDate="updateActiveChartDate" /> <date-range-select ref="activeChartDateRangeSelect" @updateDate="updateActiveChartDate" />
<view style="width:100%;height: 250px;"> <view style="width:100%;height: 250px;">
<qiun-data-charts type="line" :chartData="activeChartData" :optsWatch='false' :inScrollView="true" <qiun-data-charts type="line" :chartData="activeChartData" :optsWatch='false' :inScrollView="true"
:canvas2d="true" canvasId="scrollcolumnid" :pageScrollTop="pageScrollTop" :opts="options" :pageScrollTop="pageScrollTop" :opts="options" :ontouch="true" />
:ontouch="true" />
</view> </view>
</uni-section> </uni-section>
</view> </view>
</template> </template>
<script> <script>
import WeekChart from './WeekChart.vue'
import DateRangeSelect from './DateRangeSelect.vue' import DateRangeSelect from './DateRangeSelect.vue'
import { import {
getAllSites, getAllSites,
@ -68,7 +65,6 @@
} from '@/api/ems/site.js' } from '@/api/ems/site.js'
export default { export default {
components: { components: {
WeekChart,
DateRangeSelect DateRangeSelect
}, },
data() { data() {

View File

@ -1,421 +1,424 @@
class Calendar { class Calendar {
constructor({ constructor({
selected, selected,
startDate, startDate,
endDate, endDate,
range, range,
} = {}) { } = {}) {
// 当前日期 // 当前日期
this.date = this.getDateObj(new Date()) // 当前初入日期 this.date = this.getDateObj(new Date()) // 当前初入日期
// 打点信息 // 打点信息
this.selected = selected || []; this.selected = selected || [];
// 起始时间 // 起始时间
this.startDate = startDate this.startDate = startDate
// 终止时间 // 终止时间
this.endDate = endDate this.endDate = endDate
// 是否范围选择 // 是否范围选择
this.range = range this.range = range
// 多选状态 // 多选状态
this.cleanMultipleStatus() this.cleanMultipleStatus()
// 每周日期 // 每周日期
this.weeks = {} this.weeks = {}
this.lastHover = false this.lastHover = false
} }
/** /**
* 设置日期 * 设置日期
* @param {Object} date * @param {Object} date
*/ */
setDate(date) { setDate(date) {
const selectDate = this.getDateObj(date) const selectDate = this.getDateObj(date)
this.getWeeks(selectDate.fullDate) this.getWeeks(selectDate.fullDate)
} }
/** /**
* 清理多选状态 * 清理多选状态
*/ */
cleanMultipleStatus() { cleanMultipleStatus() {
this.multipleStatus = { this.multipleStatus = {
before: '', before: '',
after: '', after: '',
data: [] data: []
} }
} }
setStartDate(startDate) { setStartDate(startDate) {
this.startDate = startDate this.startDate = startDate
} }
setEndDate(endDate) { setEndDate(endDate) {
this.endDate = endDate this.endDate = endDate
} }
getPreMonthObj(date) { getPreMonthObj(date) {
date = fixIosDateFormat(date) date = fixIosDateFormat(date)
date = new Date(date) date = new Date(date)
const oldMonth = date.getMonth() const oldMonth = date.getMonth()
date.setMonth(oldMonth - 1) date.setMonth(oldMonth - 1)
const newMonth = date.getMonth() const newMonth = date.getMonth()
if (oldMonth !== 0 && newMonth - oldMonth === 0) { if (oldMonth !== 0 && newMonth - oldMonth === 0) {
date.setMonth(newMonth - 1) date.setMonth(newMonth - 1)
} }
return this.getDateObj(date) return this.getDateObj(date)
} }
getNextMonthObj(date) { getNextMonthObj(date) {
date = fixIosDateFormat(date) date = fixIosDateFormat(date)
date = new Date(date) date = new Date(date)
const oldMonth = date.getMonth() const oldMonth = date.getMonth()
date.setMonth(oldMonth + 1) date.setMonth(oldMonth + 1)
const newMonth = date.getMonth() const newMonth = date.getMonth()
if (newMonth - oldMonth > 1) { if (newMonth - oldMonth > 1) {
date.setMonth(newMonth - 1) date.setMonth(newMonth - 1)
} }
return this.getDateObj(date) return this.getDateObj(date)
} }
/** /**
* 获取指定格式Date对象 * 获取指定格式Date对象
*/ */
getDateObj(date) { getDateObj(date) {
date = fixIosDateFormat(date) date = fixIosDateFormat(date)
date = new Date(date) date = new Date(date)
return { return {
fullDate: getDate(date), fullDate: getDate(date),
year: date.getFullYear(), year: date.getFullYear(),
month: addZero(date.getMonth() + 1), month: addZero(date.getMonth() + 1),
date: addZero(date.getDate()), date: addZero(date.getDate()),
day: date.getDay() day: date.getDay()
} }
} }
/** /**
* 获取上一个月日期集合 * 获取上一个月日期集合
*/ */
getPreMonthDays(amount, dateObj) { getPreMonthDays(amount, dateObj) {
const result = [] const result = []
for (let i = amount - 1; i >= 0; i--) { for (let i = amount - 1; i >= 0; i--) {
const month = dateObj.month - 1 const month = dateObj.month - 1
result.push({ result.push({
date: new Date(dateObj.year, month, -i).getDate(), date: new Date(dateObj.year, month, -i).getDate(),
month, month,
disable: true disable: true
}) })
} }
return result return result
} }
/** /**
* 获取本月日期集合 * 获取本月日期集合
*/ */
getCurrentMonthDays(amount, dateObj) { getCurrentMonthDays(amount, dateObj) {
const result = [] const result = []
const fullDate = this.date.fullDate const fullDate = this.date.fullDate
for (let i = 1; i <= amount; i++) { for (let i = 1; i <= amount; i++) {
const currentDate = `${dateObj.year}-${dateObj.month}-${addZero(i)}` const currentDate = `${dateObj.year}-${dateObj.month}-${addZero(i)}`
const isToday = fullDate === currentDate const isToday = fullDate === currentDate
// 获取打点信息 // 获取打点信息
const info = this.selected && this.selected.find((item) => { const info = this.selected && this.selected.find((item) => {
if (this.dateEqual(currentDate, item.date)) { if (this.dateEqual(currentDate, item.date)) {
return item return item
} }
}) })
// 日期禁用 // 日期禁用
let disableBefore = true let disableBefore = true
let disableAfter = true let disableAfter = true
if (this.startDate) { if (this.startDate) {
disableBefore = dateCompare(this.startDate, currentDate) disableBefore = dateCompare(this.startDate, currentDate)
} }
if (this.endDate) { if (this.endDate) {
disableAfter = dateCompare(currentDate, this.endDate) disableAfter = dateCompare(currentDate, this.endDate)
} }
let multiples = this.multipleStatus.data let multiples = this.multipleStatus.data
let multiplesStatus = -1 let multiplesStatus = -1
if (this.range && multiples) { if (this.range && multiples) {
multiplesStatus = multiples.findIndex((item) => { multiplesStatus = multiples.findIndex((item) => {
return this.dateEqual(item, currentDate) return this.dateEqual(item, currentDate)
}) })
} }
const checked = multiplesStatus !== -1 const checked = multiplesStatus !== -1
result.push({ result.push({
fullDate: currentDate, fullDate: currentDate,
year: dateObj.year, year: dateObj.year,
date: i, date: i,
multiple: this.range ? checked : false, multiple: this.range ? checked : false,
beforeMultiple: this.isLogicBefore(currentDate, this.multipleStatus.before, this.multipleStatus.after), beforeMultiple: this.isLogicBefore(currentDate, this.multipleStatus.before, this
afterMultiple: this.isLogicAfter(currentDate, this.multipleStatus.before, this.multipleStatus.after), .multipleStatus.after),
month: dateObj.month, afterMultiple: this.isLogicAfter(currentDate, this.multipleStatus.before, this
disable: (this.startDate && !dateCompare(this.startDate, currentDate)) || (this.endDate && !dateCompare( .multipleStatus.after),
currentDate, this.endDate)), month: dateObj.month,
isToday, disable: (this.startDate && !dateCompare(this.startDate, currentDate)) || (this.endDate && !
userChecked: false, dateCompare(
extraInfo: info currentDate, this.endDate)),
}) isToday,
} userChecked: false,
return result extraInfo: info
} })
/** }
* 获取下一个月日期集合 return result
*/ }
_getNextMonthDays(amount, dateObj) { /**
const result = [] * 获取下一个月日期集合
const month = dateObj.month + 1 */
for (let i = 1; i <= amount; i++) { _getNextMonthDays(amount, dateObj) {
result.push({ const result = []
date: i, const month = dateObj.month + 1
month, for (let i = 1; i <= amount; i++) {
disable: true result.push({
}) date: i,
} month,
return result disable: true
} })
}
/** return result
* 获取当前日期详情 }
* @param {Object} date
*/ /**
getInfo(date) { * 获取当前日期详情
if (!date) { * @param {Object} date
date = new Date() */
} getInfo(date) {
const res = this.calendar.find(item => item.fullDate === this.getDateObj(date).fullDate) if (!date) {
return res ? res : this.getDateObj(date) date = new Date()
} }
const res = this.calendar.find(item => item.fullDate === this.getDateObj(date).fullDate)
/** return res ? res : this.getDateObj(date)
* 比较时间是否相等 }
*/
dateEqual(before, after) { /**
before = new Date(fixIosDateFormat(before)) * 比较时间是否相等
after = new Date(fixIosDateFormat(after)) */
return before.valueOf() === after.valueOf() dateEqual(before, after) {
} before = new Date(fixIosDateFormat(before))
after = new Date(fixIosDateFormat(after))
/** return before.valueOf() === after.valueOf()
* 比较真实起始日期 }
*/
/**
isLogicBefore(currentDate, before, after) { * 比较真实起始日期
let logicBefore = before */
if (before && after) {
logicBefore = dateCompare(before, after) ? before : after isLogicBefore(currentDate, before, after) {
} let logicBefore = before
return this.dateEqual(logicBefore, currentDate) if (before && after) {
} logicBefore = dateCompare(before, after) ? before : after
}
isLogicAfter(currentDate, before, after) { return this.dateEqual(logicBefore, currentDate)
let logicAfter = after }
if (before && after) {
logicAfter = dateCompare(before, after) ? after : before isLogicAfter(currentDate, before, after) {
} let logicAfter = after
return this.dateEqual(logicAfter, currentDate) if (before && after) {
} logicAfter = dateCompare(before, after) ? after : before
}
/** return this.dateEqual(logicAfter, currentDate)
* 获取日期范围内所有日期 }
* @param {Object} begin
* @param {Object} end /**
*/ * 获取日期范围内所有日期
geDateAll(begin, end) { * @param {Object} begin
var arr = [] * @param {Object} end
var ab = begin.split('-') */
var ae = end.split('-') geDateAll(begin, end) {
var db = new Date() var arr = []
db.setFullYear(ab[0], ab[1] - 1, ab[2]) var ab = begin.split('-')
var de = new Date() var ae = end.split('-')
de.setFullYear(ae[0], ae[1] - 1, ae[2]) var db = new Date()
var unixDb = db.getTime() - 24 * 60 * 60 * 1000 db.setFullYear(ab[0], ab[1] - 1, ab[2])
var unixDe = de.getTime() - 24 * 60 * 60 * 1000 var de = new Date()
for (var k = unixDb; k <= unixDe;) { de.setFullYear(ae[0], ae[1] - 1, ae[2])
k = k + 24 * 60 * 60 * 1000 var unixDb = db.getTime() - 24 * 60 * 60 * 1000
arr.push(this.getDateObj(new Date(parseInt(k))).fullDate) var unixDe = de.getTime() - 24 * 60 * 60 * 1000
} for (var k = unixDb; k <= unixDe;) {
return arr k = k + 24 * 60 * 60 * 1000
} arr.push(this.getDateObj(new Date(parseInt(k))).fullDate)
}
/** return arr
* 获取多选状态 }
*/
setMultiple(fullDate) { /**
if (!this.range) return * 获取多选状态
*/
let { setMultiple(fullDate) {
before, if (!this.range) return
after
} = this.multipleStatus let {
if (before && after) { before,
if (!this.lastHover) { after
this.lastHover = true } = this.multipleStatus
return if (before && after) {
} if (!this.lastHover) {
this.multipleStatus.before = fullDate this.lastHover = true
this.multipleStatus.after = '' return
this.multipleStatus.data = [] }
this.multipleStatus.fulldate = '' this.multipleStatus.before = fullDate
this.lastHover = false this.multipleStatus.after = ''
} else { this.multipleStatus.data = []
if (!before) { this.multipleStatus.fulldate = ''
this.multipleStatus.before = fullDate this.lastHover = false
this.multipleStatus.after = undefined; } else {
this.lastHover = false if (!before) {
} else { this.multipleStatus.before = fullDate
this.multipleStatus.after = fullDate this.multipleStatus.after = undefined;
if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) { this.lastHover = false
this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus } else {
.after); this.multipleStatus.after = fullDate
} else { if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus
.before); .after);
} } else {
this.lastHover = true this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus
} .before);
} }
this.getWeeks(fullDate) this.lastHover = true
} }
}
/** this.getWeeks(fullDate)
* 鼠标 hover 更新多选状态 }
*/
setHoverMultiple(fullDate) { /**
//抖音小程序点击会触发hover事件需要避免一下 * 鼠标 hover 更新多选状态
// #ifndef MP-TOUTIAO */
if (!this.range || this.lastHover) return setHoverMultiple(fullDate) {
const { //抖音小程序点击会触发hover事件需要避免一下
before // #ifndef MP-TOUTIAO
} = this.multipleStatus if (!this.range || this.lastHover) return
const {
if (!before) { before
this.multipleStatus.before = fullDate } = this.multipleStatus
} else {
this.multipleStatus.after = fullDate if (!before) {
if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) { this.multipleStatus.before = fullDate
this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus.after); } else {
} else { this.multipleStatus.after = fullDate
this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus.before); if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
} this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus.after);
} } else {
this.getWeeks(fullDate) this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus.before);
// #endif }
}
} this.getWeeks(fullDate)
// #endif
/**
* 更新默认值多选状态 }
*/
setDefaultMultiple(before, after) { /**
this.multipleStatus.before = before * 更新默认值多选状态
this.multipleStatus.after = after */
if (before && after) { setDefaultMultiple(before, after) {
if (dateCompare(before, after)) { this.multipleStatus.before = before
this.multipleStatus.data = this.geDateAll(before, after); this.multipleStatus.after = after
this.getWeeks(after) if (before && after) {
} else { if (dateCompare(before, after)) {
this.multipleStatus.data = this.geDateAll(after, before); this.multipleStatus.data = this.geDateAll(before, after);
this.getWeeks(before) this.getWeeks(after)
} } else {
} this.multipleStatus.data = this.geDateAll(after, before);
} this.getWeeks(before)
}
/** }
* 获取每周数据 }
* @param {Object} dateData
*/ /**
getWeeks(dateData) { * 获取每周数据
const { * @param {Object} dateData
year, */
month, getWeeks(dateData) {
} = this.getDateObj(dateData) const {
year,
const preMonthDayAmount = new Date(year, month - 1, 1).getDay() month,
const preMonthDays = this.getPreMonthDays(preMonthDayAmount, this.getDateObj(dateData)) } = this.getDateObj(dateData)
const currentMonthDayAmount = new Date(year, month, 0).getDate() const preMonthDayAmount = new Date(year, month - 1, 1).getDay()
const currentMonthDays = this.getCurrentMonthDays(currentMonthDayAmount, this.getDateObj(dateData)) const preMonthDays = this.getPreMonthDays(preMonthDayAmount, this.getDateObj(dateData))
const nextMonthDayAmount = 42 - preMonthDayAmount - currentMonthDayAmount const currentMonthDayAmount = new Date(year, month, 0).getDate()
const nextMonthDays = this._getNextMonthDays(nextMonthDayAmount, this.getDateObj(dateData)) const currentMonthDays = this.getCurrentMonthDays(currentMonthDayAmount, this.getDateObj(dateData))
const calendarDays = [...preMonthDays, ...currentMonthDays, ...nextMonthDays] const nextMonthDayAmount = 42 - preMonthDayAmount - currentMonthDayAmount
const nextMonthDays = this._getNextMonthDays(nextMonthDayAmount, this.getDateObj(dateData))
const weeks = new Array(6)
for (let i = 0; i < calendarDays.length; i++) { const calendarDays = [...preMonthDays, ...currentMonthDays, ...nextMonthDays]
const index = Math.floor(i / 7)
if (!weeks[index]) { const weeks = new Array(6)
weeks[index] = new Array(7) for (let i = 0; i < calendarDays.length; i++) {
} const index = Math.floor(i / 7)
weeks[index][i % 7] = calendarDays[i] if (!weeks[index]) {
} weeks[index] = new Array(7)
}
this.calendar = calendarDays weeks[index][i % 7] = calendarDays[i]
this.weeks = weeks }
}
} this.calendar = calendarDays
this.weeks = weeks
function getDateTime(date, hideSecond) { }
return `${getDate(date)} ${getTime(date, hideSecond)}` }
}
function getDateTime(date, hideSecond) {
function getDate(date) { return `${getDate(date)} ${getTime(date, hideSecond)}`
date = fixIosDateFormat(date) }
date = new Date(date)
const year = date.getFullYear() function getDate(date) {
const month = date.getMonth() + 1 date = fixIosDateFormat(date)
const day = date.getDate() date = new Date(date)
return `${year}-${addZero(month)}-${addZero(day)}` const year = date.getFullYear()
} const month = date.getMonth() + 1
const day = date.getDate()
function getTime(date, hideSecond) { return `${year}-${addZero(month)}-${addZero(day)}`
date = fixIosDateFormat(date) }
date = new Date(date)
const hour = date.getHours() function getTime(date, hideSecond) {
const minute = date.getMinutes() date = fixIosDateFormat(date)
const second = date.getSeconds() date = new Date(date)
return hideSecond ? `${addZero(hour)}:${addZero(minute)}` : `${addZero(hour)}:${addZero(minute)}:${addZero(second)}` const hour = date.getHours()
} const minute = date.getMinutes()
const second = date.getSeconds()
function addZero(num) { return hideSecond ? `${addZero(hour)}:${addZero(minute)}` : `${addZero(hour)}:${addZero(minute)}:${addZero(second)}`
if (num < 10) { }
num = `0${num}`
} function addZero(num) {
return num if (num < 10) {
} num = `0${num}`
}
function getDefaultSecond(hideSecond) { return num
return hideSecond ? '00:00' : '00:00:00' }
}
function getDefaultSecond(hideSecond) {
function dateCompare(startDate, endDate) { return hideSecond ? '00:00' : '00:00:00'
startDate = new Date(fixIosDateFormat(startDate)) }
endDate = new Date(fixIosDateFormat(endDate))
return startDate <= endDate function dateCompare(startDate, endDate) {
} startDate = new Date(fixIosDateFormat(startDate && typeof startDate === 'string' ? startDate.trim() : startDate))
endDate = new Date(fixIosDateFormat(endDate && typeof endDate === 'string' ? endDate.trim() : endDate))
function checkDate(date) { return startDate <= endDate
const dateReg = /((19|20)\d{2})(-|\/)\d{1,2}(-|\/)\d{1,2}/g }
return date.match(dateReg)
} function checkDate(date) {
//ios低版本15及以下无法匹配 没有 ’秒‘ 时的情况,所以需要在末尾 秒 加上 问号 const dateReg = /((19|20)\d{2})(-|\/)\d{1,2}(-|\/)\d{1,2}/g
const dateTimeReg = /^\d{4}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])( [0-5]?[0-9]:[0-5]?[0-9](:[0-5]?[0-9])?)?$/; return date.match(dateReg)
}
function fixIosDateFormat(value) { //ios低版本15及以下无法匹配 没有 ’秒‘ 时的情况,所以需要在末尾 秒 加上 问号
if (typeof value === 'string' && dateTimeReg.test(value)) { const dateTimeReg = /^\d{4}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])( [0-5]?[0-9]:[0-5]?[0-9](:[0-5]?[0-9])?)?$/;
value = value.replace(/-/g, '/')
} function fixIosDateFormat(value) {
return value if (typeof value === 'string' && dateTimeReg.test(value)) {
} value = value.replace(/-/g, '/')
}
export { return value
Calendar, }
getDateTime,
getDate, export {
getTime, Calendar,
addZero, getDateTime,
getDefaultSecond, getDate,
dateCompare, getTime,
checkDate, addZero,
fixIosDateFormat getDefaultSecond,
} dateCompare,
checkDate,
fixIosDateFormat
}