Skip to content

Commit

Permalink
✨ 提取工具方法用于重置时间
Browse files Browse the repository at this point in the history
  • Loading branch information
WOSHIZHAZHA120 committed May 9, 2024
1 parent 0c47545 commit 637b33e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/components/info-tr-chart.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import point from '@/assets/images/chart/point.svg?url'
import type { TetraLeagueHistoryRecord } from '@/types/shared'
import { resetTime } from '@/utils/date.ts'
import type { LineSeriesOption } from 'echarts/charts'
import { LineChart } from 'echarts/charts'
import type { GridComponentOption, MarkLineComponentOption } from 'echarts/components'
Expand Down Expand Up @@ -57,7 +58,13 @@ const option = computed<ChartOption>(() => {
.toString()
.padStart(2, '0')
if (index === props.data.length - 1) {
const lastDay = Math.max(
...props.data.map(data => {
return +new Date(data.record_at)
})
)
if (value === lastDay) {
return `{last_month|${month}}\n{last_day|${day}}`
}
Expand Down Expand Up @@ -134,8 +141,10 @@ const option = computed<ChartOption>(() => {
series: [
{
data: props.data.map(data => {
const date = new Date(data.record_at)
return [
+data.record_at,
+resetTime(date),
Number(
Number(data.tr).toFixed(2)
)
Expand Down
6 changes: 2 additions & 4 deletions src/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts" setup>
import { resetTime } from '@/utils/date.ts'
import { useKeyModifier } from '@vueuse/core'
const controlPressed = useKeyModifier('Control')
Expand Down Expand Up @@ -118,10 +119,7 @@ const test_tetrio_info = () => {
}
].map(data => {
const date = new Date(data.record_at)
date.setHours(0)
date.setMinutes(0)
date.setSeconds(0)
data.record_at = date
data.record_at = resetTime(date)
return data
})
Expand Down
8 changes: 8 additions & 0 deletions src/utils/date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const resetTime = (date: Date) => {
const newDate = new Date(date)
newDate.setHours(0)
newDate.setMinutes(0)
newDate.setSeconds(0)
newDate.setMilliseconds(0)
return newDate
}

0 comments on commit 637b33e

Please sign in to comment.