fix: date number
This commit is contained in:
parent
0909d5a32c
commit
7b6e55e67a
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ dist-ssr
|
|||||||
node_modules
|
node_modules
|
||||||
.idea/
|
.idea/
|
||||||
*.log
|
*.log
|
||||||
|
*.7z
|
||||||
|
|||||||
@ -8,20 +8,71 @@
|
|||||||
</route>
|
</route>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
CalendarDate,
|
||||||
|
createCalendar,
|
||||||
|
DateFormatter,
|
||||||
|
type DateValue,
|
||||||
|
getLocalTimeZone,
|
||||||
|
toCalendar,
|
||||||
|
} from '@internationalized/date'
|
||||||
import DenseFramework from '~/components/DenseFramework.vue'
|
import DenseFramework from '~/components/DenseFramework.vue'
|
||||||
|
import { cn } from '~/lib/utils'
|
||||||
|
|
||||||
const selectedT = ref<'5' | '10' | '16'>('5')
|
const selectedT = ref<'5' | '10' | '16'>('5')
|
||||||
const selectedH = ref(50)
|
const selectedH = ref(50)
|
||||||
const selectedRange = ref('-30')
|
const selectedRange = ref('-30')
|
||||||
const selectedYear = ref('2008')
|
const selectedYear = ref('2008')
|
||||||
const ranges = ['-30', '-60', '30', '60']
|
const ranges = ['-30', '-60', '30', '60']
|
||||||
|
const df = new DateFormatter('zh-CN', {
|
||||||
|
dateStyle: 'long',
|
||||||
|
})
|
||||||
|
const ca = createCalendar('zh-CN')
|
||||||
|
const targetDate = ref<DateValue>()
|
||||||
|
|
||||||
|
function getDayOfYear(date: Date) {
|
||||||
|
const start = new Date(date.getFullYear(), 0, 0)
|
||||||
|
// @ts-expect-error date - start
|
||||||
|
const diff = date - start
|
||||||
|
const oneDay = 1000 * 60 * 60 * 24
|
||||||
|
return Math.floor(diff / oneDay)
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(selectedYear, () => {
|
||||||
|
targetDate.value = toCalendar(
|
||||||
|
new CalendarDate(Number.parseInt(selectedYear.value), 1, 1),
|
||||||
|
ca,
|
||||||
|
).add({ days: Math.floor(Number.parseInt(selectedT.value) * 1.5) })
|
||||||
|
})
|
||||||
|
|
||||||
|
const minDateValue = computed(() => {
|
||||||
|
const currentYearBeginDate = new CalendarDate(Number.parseInt(selectedYear.value), 1, 1)
|
||||||
|
return toCalendar(currentYearBeginDate, ca).add({ days: Math.floor(Number.parseInt(selectedT.value) * 1.5) })
|
||||||
|
})
|
||||||
|
|
||||||
|
const maxDateValue = computed(() => {
|
||||||
|
const currentYearBeginDate = new CalendarDate(Number.parseInt(selectedYear.value) + 1, 1, 1)
|
||||||
|
return toCalendar(currentYearBeginDate, ca).subtract({ days: Math.floor(Number.parseInt(selectedT.value) * 1.5) })
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
targetDate.value = toCalendar(
|
||||||
|
new CalendarDate(Number.parseInt(selectedYear.value), 1, 1),
|
||||||
|
ca,
|
||||||
|
).add({ days: Math.floor(Number.parseInt(selectedT.value) * 1.5) })
|
||||||
|
})
|
||||||
const fetchUrl = computed(() => {
|
const fetchUrl = computed(() => {
|
||||||
const query = new URLSearchParams()
|
const query = new URLSearchParams()
|
||||||
|
if (!targetDate.value) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
const targetDay = getDayOfYear(targetDate.value.toDate(getLocalTimeZone()))
|
||||||
|
const startDay = targetDay - Math.floor(1.5 * Number.parseInt(selectedT.value))
|
||||||
query.set('T', selectedT.value)
|
query.set('T', selectedT.value)
|
||||||
query.set('target_h', selectedH.value.toString())
|
query.set('target_h', selectedH.value.toString())
|
||||||
query.set('target_lat', selectedRange.value)
|
query.set('target_lat', selectedRange.value)
|
||||||
query.set('year', selectedYear.value)
|
query.set('year', selectedYear.value)
|
||||||
|
query.set('start_day', startDay.toString())
|
||||||
return `/cosmic/render/planet_wave/perday?${query}`
|
return `/cosmic/render/planet_wave/perday?${query}`
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@ -87,5 +138,33 @@ const fetchUrl = computed(() => {
|
|||||||
</SelectGroup>
|
</SelectGroup>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
<Label>日期</Label>
|
||||||
|
<Popover>
|
||||||
|
<PopoverTrigger as-child>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
:class="cn(
|
||||||
|
'w-full justify-start text-left font-normal',
|
||||||
|
!targetDate && 'text-muted-foreground',
|
||||||
|
)"
|
||||||
|
>
|
||||||
|
<span i-md-calendar />
|
||||||
|
{{ targetDate ? df.format(targetDate.toDate(getLocalTimeZone())) : "选择日期" }}
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent class="w-auto p-0">
|
||||||
|
<!-- @ts-expect-error dsa -->
|
||||||
|
<Calendar
|
||||||
|
v-model="targetDate " initial-focus
|
||||||
|
:is-date-disabled="(date:DateValue) => date < minDateValue || date > maxDateValue"
|
||||||
|
:prevent-deselect="true"
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
<div>
|
||||||
|
拟合起始日期 {{ targetDate?.subtract({ days: Math.floor(1.5 * Number.parseInt(selectedT)) }) }}
|
||||||
|
<br>
|
||||||
|
拟合结束日期 {{ targetDate?.add({ days: Math.floor(1.5 * Number.parseInt(selectedT)) }) }}
|
||||||
|
</div>
|
||||||
</DenseFramework>
|
</DenseFramework>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@ -51,12 +51,12 @@ watch(() => selected.year, () => {
|
|||||||
|
|
||||||
const minDateValue = computed(() => {
|
const minDateValue = computed(() => {
|
||||||
const currentYearBeginDate = new CalendarDate(Number.parseInt(selected.year), 1, 1)
|
const currentYearBeginDate = new CalendarDate(Number.parseInt(selected.year), 1, 1)
|
||||||
return toCalendar(currentYearBeginDate, ca).add({ days: Number.parseInt(selected.T) * 1.5 })
|
return toCalendar(currentYearBeginDate, ca).add({ days: Math.floor(Number.parseInt(selected.T) * 1.5) })
|
||||||
})
|
})
|
||||||
|
|
||||||
const maxDateValue = computed(() => {
|
const maxDateValue = computed(() => {
|
||||||
const currentYearBeginDate = new CalendarDate(Number.parseInt(selected.year) + 1, 1, 1)
|
const currentYearBeginDate = new CalendarDate(Number.parseInt(selected.year) + 1, 1, 1)
|
||||||
return toCalendar(currentYearBeginDate, ca).subtract({ days: Number.parseInt(selected.T) * 1.5 })
|
return toCalendar(currentYearBeginDate, ca).subtract({ days: Math.floor(Number.parseInt(selected.T) * 1.5) })
|
||||||
})
|
})
|
||||||
|
|
||||||
const ranges = [
|
const ranges = [
|
||||||
@ -70,7 +70,7 @@ onMounted(() => {
|
|||||||
targetDate.value = toCalendar(
|
targetDate.value = toCalendar(
|
||||||
new CalendarDate(Number.parseInt(selected.year), 1, 1),
|
new CalendarDate(Number.parseInt(selected.year), 1, 1),
|
||||||
ca,
|
ca,
|
||||||
).add({ days: Number.parseInt(selected.T) * 1.5 })
|
).add({ days: Math.floor(Number.parseInt(selected.T) * 1.5) })
|
||||||
})
|
})
|
||||||
|
|
||||||
const queryUrl = computed(() => {
|
const queryUrl = computed(() => {
|
||||||
@ -79,7 +79,7 @@ const queryUrl = computed(() => {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
const targetDay = getDayOfYear(targetDate.value.toDate(getLocalTimeZone()))
|
const targetDay = getDayOfYear(targetDate.value.toDate(getLocalTimeZone()))
|
||||||
const startDay = targetDay - 1.5 * Number.parseInt(selected.T)
|
const startDay = targetDay - Math.floor(1.5 * Number.parseInt(selected.T))
|
||||||
q.set('year', selected.year)
|
q.set('year', selected.year)
|
||||||
q.set('T', selected.T.toString())
|
q.set('T', selected.T.toString())
|
||||||
q.set('k', selected.k.toString())
|
q.set('k', selected.k.toString())
|
||||||
@ -176,9 +176,9 @@ const queryUrl = computed(() => {
|
|||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
<div>
|
<div>
|
||||||
拟合起始日期 {{ targetDate?.subtract({ days: 1.5 * Number.parseInt(selected.T) }) }}
|
拟合起始日期 {{ targetDate?.subtract({ days: Math.floor(1.5 * Number.parseInt(selected.T)) }) }}
|
||||||
<br>
|
<br>
|
||||||
拟合结束日期 {{ targetDate?.add({ days: (1.5 * Number.parseInt(selected.T)) }) }}
|
拟合结束日期 {{ targetDate?.add({ days: Math.floor(1.5 * Number.parseInt(selected.T)) }) }}
|
||||||
</div>
|
</div>
|
||||||
</DenseFramework>
|
</DenseFramework>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user