-
Notifications
You must be signed in to change notification settings - Fork 23
fix(add):analytics #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
HUAHUAI23
merged 43 commits into
labring:main
from
huanglvjing:feature/analytics-dashboard
Oct 30, 2025
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
c79fd88
chore
HUAHUAI23 3ceea66
add app config
HUAHUAI23 2ae824f
chore change env
HUAHUAI23 9609b23
chore
HUAHUAI23 2008aca
refactor smart node,rag node
HUAHUAI23 6f4ebf3
chore
HUAHUAI23 34e0579
add ticket auto close job
HUAHUAI23 0b734ce
chore
HUAHUAI23 72cd354
update i18n
HUAHUAI23 f488ce7
chore
HUAHUAI23 cea406d
chore
HUAHUAI23 0f88905
add knowledge access log
HUAHUAI23 490b23f
update orm history
HUAHUAI23 4565780
chore
HUAHUAI23 e75f715
fix bun run typecheck
HUAHUAI23 6156b8d
chore
HUAHUAI23 726aa0c
chore
HUAHUAI23 d87eaed
chore
HUAHUAI23 df68988
fix(ci): complete build fixes for all packages
HUAHUAI23 89173c9
chore
HUAHUAI23 3c419a7
chore
HUAHUAI23 ac17db9
chore
HUAHUAI23 2979519
chore
HUAHUAI23 12c1e41
chore
HUAHUAI23 d6d86d8
Merge pull request #48 from HUAHUAI23/fee
HUAHUAI23 5ca30aa
fix(add):analytics
huanglvjing 171ac6b
fix1027
huanglvjing 9751d54
fix1027_3
huanglvjing c831c61
fix10_28
huanglvjing 1e83e02
fix1028_2
huanglvjing ac47ea5
fix1028_6
huanglvjing 9354fa9
Merge main branch into feature/analytics-dashboard
huanglvjing ecbb631
fix1029_1
huanglvjing 7a527ca
fix1029_2
huanglvjing c738ae3
fix21
huanglvjing 140751d
fix1030
huanglvjing 7eac12e
fix1030_2
huanglvjing eece6fd
fix1030_3
huanglvjing b30b11b
fix1030_5
huanglvjing d7f9959
fix1030_xiu
huanglvjing c04abc5
fix103033
huanglvjing de2da6e
fix1030fix
huanglvjing c8b37d4
fix1030_7
huanglvjing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { Button, Popover, PopoverContent, PopoverTrigger, Calendar } from "tentix-ui"; | ||
| import { CalendarIcon } from "lucide-react"; | ||
| import { cn } from "@lib/utils"; | ||
| import { useTranslation } from "i18n"; | ||
|
|
||
| interface DateRangePickerProps { | ||
| value?: { from: Date; to: Date };//日期范围 | ||
| onChange?: (dateRange: { from: Date; to: Date } | undefined) => void; | ||
| disabled?: boolean; | ||
| placeholder?: string; | ||
| className?: string; | ||
| formatDate?: (date: Date) => string; | ||
| numberOfMonths?: number; | ||
| } | ||
|
|
||
| //日期范围选择组件 | ||
| export function DateRangePicker({ | ||
| value, | ||
| onChange, | ||
| disabled = false, | ||
| placeholder, | ||
| className, | ||
| formatDate: customFormatDate, | ||
| numberOfMonths = 2, | ||
| }: DateRangePickerProps) { | ||
| const { t } = useTranslation(); | ||
|
|
||
| //格式化日期 | ||
| const defaultFormatDate = (date: Date) => { | ||
| return date.toLocaleString(undefined, { | ||
| year: "numeric", | ||
| month: "2-digit", | ||
| day: "2-digit", | ||
| hour: "2-digit", | ||
| minute: "2-digit", | ||
| }); | ||
| }; | ||
|
|
||
| const formatDate = customFormatDate || defaultFormatDate; | ||
|
|
||
| //日期范围选择 | ||
| const handleDateRangeChange = (newDateRange: { from: Date | undefined; to?: Date | undefined } | undefined) => { | ||
| if (newDateRange?.from && newDateRange?.to) { | ||
| const range = { from: newDateRange.from, to: newDateRange.to }; | ||
| onChange?.(range); | ||
| } else { | ||
| onChange?.(undefined); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Popover> | ||
| <PopoverTrigger asChild> | ||
| <Button | ||
| id="date-range-picker" | ||
| variant="outline" | ||
| className={cn( | ||
| "w-[300px] justify-start text-left font-normal h-10", | ||
| !value && "text-muted-foreground", | ||
| className | ||
| )} | ||
| disabled={disabled} | ||
| > | ||
| <CalendarIcon className="mr-2 h-4 w-4" /> | ||
| {value?.from ? ( | ||
| value.to ? ( | ||
| `${formatDate(value.from)} - ${formatDate(value.to)}` | ||
| ) : ( | ||
| formatDate(value.from) | ||
| ) | ||
| ) : ( | ||
| <span>{placeholder || t("select")}</span> | ||
| )} | ||
| </Button> | ||
| </PopoverTrigger> | ||
| <PopoverContent className="w-auto p-0" align="start"> | ||
| <Calendar | ||
| mode="range" | ||
| defaultMonth={value?.from} | ||
| selected={value} | ||
| onSelect={handleDateRangeChange} | ||
| numberOfMonths={numberOfMonths} | ||
| /> | ||
| </PopoverContent> | ||
| </Popover> | ||
| ); | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { useRef, useEffect } from "react"; | ||
| import * as echarts from 'echarts'; | ||
| import type { EChartsOption } from 'echarts'; | ||
|
|
||
| interface EChartsWrapperProps { | ||
| option: EChartsOption; | ||
| className?: string; | ||
| style?: React.CSSProperties; | ||
| renderer?: 'canvas' | 'svg'; | ||
| enableWindowResize?: boolean; | ||
| enableResizeObserver?: boolean; | ||
| } | ||
|
|
||
| export function EChartsWrapper({ | ||
| option, | ||
| className, | ||
| style, | ||
| renderer = 'svg', | ||
| enableWindowResize = true, | ||
| enableResizeObserver = false, | ||
| }: EChartsWrapperProps) { | ||
| const chartRef = useRef<HTMLDivElement>(null); | ||
| const chartInstanceRef = useRef<echarts.ECharts | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (!chartRef.current) return; | ||
|
|
||
| // 初始化图表 | ||
| const chart = echarts.init(chartRef.current, undefined, { renderer }); | ||
| chartInstanceRef.current = chart; | ||
|
|
||
| // 监听窗口大小变化 | ||
| const handleResize = () => chart.resize(); | ||
|
|
||
| if (enableWindowResize) { | ||
| window.addEventListener('resize', handleResize); | ||
| } | ||
|
|
||
| let resizeObserver: ResizeObserver | null = null; | ||
| if (enableResizeObserver && chartRef.current) { | ||
| resizeObserver = new ResizeObserver(handleResize); | ||
| resizeObserver.observe(chartRef.current); | ||
| } | ||
|
|
||
| return () => { | ||
| if (enableWindowResize) { | ||
| window.removeEventListener('resize', handleResize); | ||
| } | ||
| if (resizeObserver) { | ||
| resizeObserver.disconnect(); | ||
| } | ||
| chart.dispose(); | ||
| chartInstanceRef.current = null; | ||
| }; | ||
| }, [renderer, enableWindowResize, enableResizeObserver]); | ||
|
|
||
| useEffect(() => { | ||
| if (chartInstanceRef.current && option) { | ||
| chartInstanceRef.current.setOption(option, true); | ||
| } | ||
| }, [option]); | ||
|
|
||
| return <div ref={chartRef} className={className} style={style} />; | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
frontend/src/components/staff/tickets-analytics/analytics-filter.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import * as React from "react"; | ||
| import { Button, Checkbox, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "tentix-ui"; | ||
| import { staffListQueryOptions, useSuspenseQuery } from "@lib/query"; | ||
| import { useAuth } from "@hook/use-local-user.tsx"; | ||
| import { useTranslation } from "i18n"; | ||
| import { DateRangePicker } from "@comp/common/date-range-picker"; | ||
|
|
||
|
|
||
| interface AnalyticsFilterProps { | ||
| onDateRangeChange?: (dateRange: { from: Date; to: Date } | undefined) => void; | ||
| onEmployeeChange?: (employeeId: string) => void; | ||
| onRefresh?: () => void; | ||
| onTodayToggle?: (isToday: boolean) => void; | ||
| lastUpdated?: string; | ||
| } | ||
|
|
||
|
|
||
| //筛选逻辑 | ||
| export function AnalyticsFilter({ | ||
| onDateRangeChange, | ||
| onEmployeeChange, | ||
| onRefresh, | ||
| onTodayToggle, | ||
| lastUpdated, | ||
| }: AnalyticsFilterProps) { | ||
| const { t } = useTranslation(); | ||
| const [dateRange, setDateRange] = React.useState<{ from: Date; to: Date } | undefined>(); | ||
| const [isTodayChecked, setIsTodayChecked] = React.useState(false); | ||
| const [selectedEmployee, setSelectedEmployee] = React.useState("all_staff"); | ||
|
|
||
| const [initialTime] = React.useState(() => | ||
| new Date().toLocaleTimeString(undefined, { | ||
| hour: "2-digit", | ||
HUAHUAI23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| minute: "2-digit", | ||
| }) | ||
| ); | ||
|
|
||
| const displayTime = lastUpdated || initialTime; | ||
|
|
||
| const authContext = useAuth(); | ||
| const currentUser = authContext.user; | ||
|
|
||
| //获取员工列表 | ||
| const { data: staffList } = useSuspenseQuery(staffListQueryOptions()); | ||
|
|
||
| const employees = React.useMemo(() => { | ||
| return staffList?.map(staff => ({ | ||
| id: staff.id.toString(), | ||
| name: staff.name || staff.nickname, | ||
| })) || []; | ||
| }, [staffList]); | ||
|
|
||
| const employeeOptions = React.useMemo(() => { | ||
| const defaultOption = { id: "all_staff", name: t("all_staff") }; | ||
|
|
||
| if (currentUser?.role === "admin") { | ||
| return [defaultOption, ...employees]; | ||
| } | ||
|
|
||
| const currentUserOption = { | ||
| id: currentUser?.id.toString() || "", | ||
| name: currentUser?.name || currentUser?.nickname || t("my"), | ||
| }; | ||
|
|
||
| return [defaultOption, currentUserOption]; | ||
| }, [employees, currentUser, t]); | ||
|
|
||
| //日期范围选择 | ||
| const handleDateRangeChange = (newDateRange: { from: Date; to: Date } | undefined) => { | ||
| setDateRange(newDateRange); | ||
| if (newDateRange) { | ||
| setIsTodayChecked(false); | ||
| } | ||
| onDateRangeChange?.(newDateRange); | ||
| }; | ||
|
|
||
| //员工选择 | ||
| const handleEmployeeChange = (employeeId: string) => { | ||
| setSelectedEmployee(employeeId); | ||
| onEmployeeChange?.(employeeId); | ||
| }; | ||
|
|
||
| //今天筛选 | ||
| const handleTodayToggle = (checked: boolean) => { | ||
| setIsTodayChecked(checked); | ||
| if (checked) { | ||
| setDateRange(undefined); | ||
| } | ||
| onTodayToggle?.(checked); | ||
| }; | ||
|
|
||
| //格式化日期 | ||
| const formatDate = (date: Date) => { | ||
| return date.toLocaleString(undefined, { | ||
| year: "numeric", | ||
| month: "2-digit", | ||
| day: "2-digit", | ||
| hour: "2-digit", | ||
| minute: "2-digit", | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="flex flex-wrap items-center justify-between py-5 px-6 bg-white rounded-lg border border-zinc-200 gap-4"> | ||
| <div className="flex flex-wrap items-center space-x-4 gap-2"> | ||
| <span className="text-sm font-medium text-zinc-700">{t("analytics_filter")}</span> | ||
|
|
||
| <div className="flex items-center space-x-2 px-3 py-2 border border-zinc-200 rounded-md"> | ||
| {/* 今天筛选 */} | ||
| <Checkbox | ||
| id="today-filter" | ||
| checked={isTodayChecked} | ||
| onCheckedChange={handleTodayToggle} | ||
| /> | ||
| <Label htmlFor="today-filter" className="text-sm font-normal text-zinc-700"> | ||
| {t("today")} | ||
| </Label> | ||
| </div> | ||
|
|
||
| {/* 日期范围选择 */} | ||
| <DateRangePicker | ||
| value={dateRange} | ||
| onChange={handleDateRangeChange} | ||
| disabled={isTodayChecked} | ||
| formatDate={formatDate} | ||
| /> | ||
|
|
||
| <Select value={selectedEmployee} onValueChange={handleEmployeeChange}> | ||
| <SelectTrigger className="w-[180px] h-10"> | ||
| <SelectValue placeholder={t("select_employee")} /> | ||
| </SelectTrigger> | ||
| <SelectContent> | ||
| {employeeOptions.map((employee) => ( | ||
| <SelectItem key={employee.id} value={employee.id}> | ||
| {employee.name} | ||
| </SelectItem> | ||
| ))} | ||
| </SelectContent> | ||
| </Select> | ||
| </div> | ||
|
|
||
| {/* 右侧刷新和更新时间区域 */} | ||
| <div className="flex items-center space-x-4"> | ||
| <Button variant="outline" size="sm" onClick={onRefresh}> | ||
| {t("reload")} | ||
| </Button> | ||
| <span className="text-sm text-zinc-500">{t("updated_at")} {displayTime}</span> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.