Browse Source

fix: 时间选择问题

main
betaqi 2 months ago
parent
commit
644504f952
  1. 2
      src/views/stationData/components/offTransferDlg.vue
  2. 116
      src/views/stationData/components/onLineTransferDlg.vue

2
src/views/stationData/components/offTransferDlg.vue

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<template>
<EdfsDialog :title="'数据迁移'" :is-show="visible" width="50%" @on-close="close" @on-save="onSave">
<EdfsDialog :title="'数据迁移'" :is-show="visible" width="580px" @on-close="close" @on-save="onSave">
<div class="flex-col gap-10 w-80% m-x-30px">
<el-row>
<div class="label">

116
src/views/stationData/components/onLineTransferDlg.vue

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
<EdfsDialog
:title="isBatchTransfer ? '批量迁移' : '数据迁移'"
:is-show="visible"
width="50%"
width="580px"
@on-close="close"
@on-save="onSave"
>
@ -10,17 +10,38 @@ @@ -10,17 +10,38 @@
<el-row>
<div class="label">
<span class="require">*</span>
数据时间范围:
数据开始时间:
</div>
<el-date-picker
v-model="form.timeArr"
type="datetimerange"
v-model="startTime"
value-format="YYYY-MM-DD HH:mm"
format="YYYY-MM-DD HH:mm"
class="flex-1"
start-placeholder="开始时间"
end-placeholder="结束时间"
:default-value="(defaultDateRange as any)"
:disabled-date="disabledAfterToday"
/></el-row>
type="datetime"
placeholder="请选择开始时间"
:disabled-date="disabledDate"
:disabled-time="disabledStartTime"
@change="handleStartTimeChange"
/>
</el-row>
<el-row>
<div class="label">
<span class="require">*</span>
数据结束时间:
</div>
<el-date-picker
v-model="endTime"
class="flex-1"
value-format="YYYY-MM-DD HH:mm"
format="YYYY-MM-DD HH:mm"
type="datetime"
placeholder="请选择结束时间"
:disabled-date="disabledDate"
:disabled-time="disabledEndTime"
@change="handleEndTimeChange"
/>
</el-row>
</div>
</EdfsDialog>
</template>
@ -28,17 +49,10 @@ @@ -28,17 +49,10 @@
<script setup lang="ts">
import dayjs from 'dayjs'
import { getPubInitData, type PublishMsg } from '@/utils/zmq'
import { cloneDeep } from 'lodash-es'
import type { IOnlineDevice } from '../type'
import { useMessage } from '@/composables/useMessage'
const message = useMessage()
const disabledAfterToday = (time: { getTime: () => number }) => {
return time.getTime() > Date.now() //
}
const defaultDateRange = [
dayjs().subtract(1, 'month').startOf('month'),
dayjs().endOf('month'),
] //
const emit = defineEmits<{
'on-save': [PublishMsg<'export'>, IOnlineDevice]
}>()
@ -48,12 +62,60 @@ const props = defineProps<{ @@ -48,12 +62,60 @@ const props = defineProps<{
}>()
const visible = ref(false)
const fromData = {
timeArr: [],
const startTime = ref('')
const endTime = ref('')
const disabledDate = (time: Date) => {
return dayjs(time).isAfter(dayjs())
}
const disabledStartTime = (date: Date) => {
if (endTime.value) {
const end = dayjs(endTime.value)
const current = dayjs(date)
if (current.isSame(end, 'day')) {
return {
hours: () => Array.from({ length: 24 }, (_, i) => i).filter(h => h > end.hour()),
minutes: () => Array.from({ length: 60 }, (_, i) => i).filter(m => m > end.minute())
}
}
}
return {}
}
const disabledEndTime = (date: Date) => {
if (startTime.value) {
const start = dayjs(startTime.value)
const current = dayjs(date)
if (current.isSame(start, 'day')) {
return {
hours: () => Array.from({ length: 24 }, (_, i) => i).filter(h => h < start.hour()),
minutes: () => Array.from({ length: 60 }, (_, i) => i).filter(m => m < start.minute())
}
}
}
return {}
}
function handleStartTimeChange(val: string) {
if (val && endTime.value) {
if (dayjs(val).isAfter(dayjs(endTime.value))) {
message.warning('开始时间不能晚于结束时间')
startTime.value = ''
}
}
}
function handleEndTimeChange(val: string) {
if (val && startTime.value) {
if (dayjs(val).isBefore(dayjs(startTime.value))) {
message.warning('结束时间不能早于开始时间')
endTime.value = ''
}
}
}
const curDevice = ref<IOnlineDevice>()
const form = ref(cloneDeep(fromData))
const batchClientIp = ref('')
const batchPath = ref('')
@ -83,7 +145,7 @@ function onSave() { @@ -83,7 +145,7 @@ function onSave() {
? batchPath.value
: `${curDevice.value.site_id}/${curDevice.value.sn}`
}`,
`${dayjs(form.value.timeArr[0]).valueOf()},${dayjs(form.value.timeArr[1]).valueOf()}`,
`${dayjs(startTime.value).valueOf()},${dayjs(endTime.value).valueOf()}`,
]
const msg = getPubInitData<'export'>('export', params)
emit('on-save', msg, curDevice.value as IOnlineDevice)
@ -91,7 +153,8 @@ function onSave() { @@ -91,7 +153,8 @@ function onSave() {
}
function close() {
form.value = cloneDeep(fromData)
startTime.value = ''
endTime.value = ''
visible.value = false
curDevice.value = undefined
batchClientIp.value = ''
@ -99,8 +162,13 @@ function close() { @@ -99,8 +162,13 @@ function close() {
}
function verifyData() {
if (!form.value.timeArr.length) {
message.error('请选择数据时间范围')
if(!startTime.value) {
message.error('请选择开始时间')
return false
}
if(!endTime.value) {
message.error('请选择结束时间')
return false
}

Loading…
Cancel
Save