mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-02 08:06:38 +08:00
管理页面添加键盘监听选择日期
This commit is contained in:
parent
a2070067b0
commit
ea20ad1df0
@ -1,11 +1,13 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useEffect, useState, Dispatch, SetStateAction } from "react";
|
import React, { useEffect, useState, Dispatch, SetStateAction } from "react";
|
||||||
|
|
||||||
import * as echarts from "echarts";
|
import * as echarts from "echarts";
|
||||||
import { DatePicker, DatePickerValue } from "@tremor/react";
|
import { DatePicker, DatePickerValue } from "@tremor/react";
|
||||||
import { zhCN } from "date-fns/locale";
|
import { zhCN } from "date-fns/locale";
|
||||||
import { EChartsOption } from "echarts";
|
import { EChartsOption } from "echarts";
|
||||||
import { essos, walden } from "@/lib/charts_theme";
|
import { essos, walden } from "@/lib/charts_theme";
|
||||||
|
import { Path } from "@/app/constant";
|
||||||
|
import { subDays, addDays } from "date-fns";
|
||||||
|
|
||||||
interface ComponentProps {
|
interface ComponentProps {
|
||||||
currentDate: Date;
|
currentDate: Date;
|
||||||
@ -13,6 +15,36 @@ interface ComponentProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function DateSelectComponent({ currentDate, setCurrentDate }: ComponentProps) {
|
function DateSelectComponent({ currentDate, setCurrentDate }: ComponentProps) {
|
||||||
|
const maxDate = new Date();
|
||||||
|
// 增加键盘监听修改日期
|
||||||
|
useEffect(() => {
|
||||||
|
const keydownEvent = (e: KeyboardEvent) => {
|
||||||
|
switch (e.key) {
|
||||||
|
case "ArrowLeft":
|
||||||
|
if (currentDate) {
|
||||||
|
setCurrentDate(subDays(currentDate, 1));
|
||||||
|
}
|
||||||
|
// console.log(currentDate)
|
||||||
|
break;
|
||||||
|
case "ArrowRight":
|
||||||
|
if (currentDate) {
|
||||||
|
const temp_date = addDays(currentDate, 1);
|
||||||
|
if (temp_date < maxDate) {
|
||||||
|
setCurrentDate(temp_date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// console.log(currentDate)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.addEventListener("keydown", keydownEvent);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("keydown", keydownEvent);
|
||||||
|
};
|
||||||
|
}, [currentDate, setCurrentDate]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DatePicker
|
<DatePicker
|
||||||
className="max-w-sm mx-auto justify-center"
|
className="max-w-sm mx-auto justify-center"
|
||||||
@ -20,7 +52,7 @@ function DateSelectComponent({ currentDate, setCurrentDate }: ComponentProps) {
|
|||||||
locale={zhCN}
|
locale={zhCN}
|
||||||
defaultValue={new Date()}
|
defaultValue={new Date()}
|
||||||
onValueChange={(d) => d && setCurrentDate(d)}
|
onValueChange={(d) => d && setCurrentDate(d)}
|
||||||
maxDate={new Date()}
|
maxDate={maxDate}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -31,7 +63,7 @@ function EchartsComponent({ currentDate, setCurrentDate }: ComponentProps) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let ignore = false;
|
let ignore = false;
|
||||||
// console.log('windows', window.location.href)
|
// console.log('windows', window.location.href)
|
||||||
console.log("init", currentDate, searchDate);
|
// console.log("init", currentDate, searchDate);
|
||||||
const currentDateString = currentDate.toLocaleDateString();
|
const currentDateString = currentDate.toLocaleDateString();
|
||||||
if (searchDate != currentDateString) {
|
if (searchDate != currentDateString) {
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
@ -75,10 +107,10 @@ function EchartsComponent({ currentDate, setCurrentDate }: ComponentProps) {
|
|||||||
let myChart = echarts.init(chartDom, "default");
|
let myChart = echarts.init(chartDom, "default");
|
||||||
option && myChart.setOption(option);
|
option && myChart.setOption(option);
|
||||||
setSearchDate(currentDateString);
|
setSearchDate(currentDateString);
|
||||||
console.log("option计数", 1);
|
// console.log("option计数", 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log("搜索开始计数", 1, searchDate, currentDateString);
|
// console.log("搜索开始计数", 1, searchDate, currentDateString);
|
||||||
}
|
}
|
||||||
return () => {
|
return () => {
|
||||||
ignore = true;
|
ignore = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user