Skip to content

Commit 73689a1

Browse files
committed
优化时间筛选交互
1 parent 32342ba commit 73689a1

File tree

8 files changed

+50
-12
lines changed

8 files changed

+50
-12
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@traptitech/markdown-it-katex": "^3.6.0",
2727
"@vueuse/core": "^9.13.0",
2828
"chart.js": "^4.3.0",
29+
"dayjs": "^1.11.7",
2930
"highlight.js": "^11.7.0",
3031
"html2canvas": "^1.4.1",
3132
"jwt-decode": "^3.1.2",

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/src/storage/mongo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export async function getUserStatisticsByDay(userId: ObjectId, start: number, en
219219
$match: {
220220
dateTime: {
221221
$gte: start,
222-
$lt: end,
222+
$lte: end,
223223
},
224224
userId,
225225
},

src/components/common/Setting/Statistics.vue

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { NCol, NDatePicker, NIcon, NNumberAnimation, NRow, NSpin, NStatistic } f
44
import type { ChartData, ChartOptions } from 'chart.js'
55
import { BarElement, CategoryScale, Chart as ChartJS, Legend, LinearScale, Title, Tooltip } from 'chart.js'
66
import { Bar } from 'vue-chartjs'
7+
import dayjs from 'dayjs'
78
import { t } from '@/locales'
89
import { fetchUserStatistics } from '@/api'
910
import { SvgIcon } from '@/components/common'
@@ -29,28 +30,45 @@ const chartData: ChartData<'bar'> = reactive({
2930
},
3031
],
3132
})
32-
3333
const chartOptions: ChartOptions<'bar'> = {
3434
responsive: true,
3535
}
36-
3736
const summary = ref({
3837
promptTokens: 0,
3938
completionTokens: 0,
4039
totalTokens: 0,
4140
})
4241
const loading = ref(false)
43-
const range = ref<[number, number]>([
44-
new Date().getTime() - 30 * 86400 * 1000,
45-
new Date().getTime(),
42+
const range = ref([
43+
dayjs().subtract(30, 'day').startOf('day').valueOf(),
44+
dayjs().endOf('day').valueOf(),
4645
])
46+
const rangeShortcuts: { [index: string]: [number, number] } = {}
47+
// last month
48+
rangeShortcuts[t('setting.statisticsPeriodLastMonth')] = [
49+
dayjs().subtract(1, 'month').startOf('month').valueOf(),
50+
dayjs().subtract(1, 'month').endOf('month').valueOf(),
51+
]
52+
// current month
53+
rangeShortcuts[t('setting.statisticsPeriodCurrentMonth')] = [
54+
dayjs().startOf('month').valueOf(),
55+
dayjs().endOf('month').valueOf(),
56+
]
57+
// last 30 days
58+
rangeShortcuts[t('setting.statisticsPeriodLast30Days')] = [
59+
dayjs().subtract(30, 'day').startOf('day').valueOf(),
60+
dayjs().endOf('day').valueOf(),
61+
]
4762
4863
const showChart = ref(true)
4964
5065
async function fetchStatistics() {
5166
try {
5267
loading.value = true
53-
const { data } = await fetchUserStatistics(...range.value)
68+
const { data } = await fetchUserStatistics(
69+
dayjs(range.value[0]).startOf('day').valueOf(),
70+
dayjs(range.value[1]).endOf('day').valueOf(),
71+
)
5472
5573
if (Object.keys(data.chartData).length) {
5674
summary.value.promptTokens = data.promptTokens
@@ -87,8 +105,8 @@ onMounted(() => {
87105
<div class="flex-1">
88106
<NDatePicker
89107
v-model:value="range"
90-
type="datetimerange"
91-
clearable
108+
type="daterange"
109+
:shortcuts="rangeShortcuts"
92110
@update:value="fetchStatistics"
93111
/>
94112
</div>
@@ -103,7 +121,7 @@ onMounted(() => {
103121
<SvgIcon class="text-lg" icon="ri-chat-upload-line" />
104122
</NIcon>
105123
</template>
106-
<NNumberAnimation :from="0" :to="summary.promptTokens" />
124+
<NNumberAnimation :duration="1000" :to="summary.promptTokens" />
107125
</NStatistic>
108126
</NCol>
109127
<NCol :span="8" class="text-center">
@@ -113,7 +131,7 @@ onMounted(() => {
113131
<SvgIcon class="text-lg" icon="ri-chat-download-line" />
114132
</NIcon>
115133
</template>
116-
<NNumberAnimation :from="0" :to="summary.completionTokens" />
134+
<NNumberAnimation :duration="1000" :to="summary.completionTokens" />
117135
</NStatistic>
118136
</NCol>
119137
<NCol :span="8" class="text-center">
@@ -123,7 +141,7 @@ onMounted(() => {
123141
<SvgIcon class="text-lg" icon="ri-question-answer-line" />
124142
</NIcon>
125143
</template>
126-
<NNumberAnimation :from="0" :to="summary.totalTokens" />
144+
<NNumberAnimation :duration="1000" :to="summary.totalTokens" />
127145
</NStatistic>
128146
</NCol>
129147
</NRow>

src/locales/en-US.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ export default {
9090
httpsProxy: 'HTTPS Proxy',
9191
balance: 'API Balance',
9292
statisticsPeriod: 'Statistics Period',
93+
statisticsPeriodLastMonth: 'Last Month',
94+
statisticsPeriodCurrentMonth: 'Current Month',
95+
statisticsPeriodLast30Days: 'Last 30 Days',
9396
statisticsPrompt: 'Prompt',
9497
statisticsCompletion: 'Response',
9598
statisticsTotal: 'Total',

src/locales/ko-KR.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export default {
8888
httpsProxy: 'HTTPS 프록시',
8989
balance: 'API 잔액',
9090
statisticsPeriod: '통계 기간',
91+
statisticsPeriodLastMonth: '지난달',
92+
statisticsPeriodCurrentMonth: '이번달',
93+
statisticsPeriodLast30Days: '최근 30일',
9194
statisticsPrompt: '질문',
9295
statisticsCompletion: '답변',
9396
statisticsTotal: '합계',

src/locales/zh-CN.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ export default {
9090
httpsProxy: 'HTTPS Proxy',
9191
balance: 'API余额',
9292
statisticsPeriod: '统计时间段',
93+
statisticsPeriodLastMonth: '上月',
94+
statisticsPeriodCurrentMonth: '本月',
95+
statisticsPeriodLast30Days: '最近30天',
9396
statisticsPrompt: '提问',
9497
statisticsCompletion: '回答',
9598
statisticsTotal: '总计',

src/locales/zh-TW.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ export default {
9090
httpsProxy: 'HTTPS Proxy',
9191
balance: 'API余額',
9292
statisticsPeriod: '統計時間段',
93+
statisticsPeriodLastMonth: '上月',
94+
statisticsPeriodCurrentMonth: '本月',
95+
statisticsPeriodLast30Days: '最近30天',
9396
statisticsPrompt: '提問',
9497
statisticsCompletion: '回答',
9598
statisticsTotal: '總計',

0 commit comments

Comments
 (0)