mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-02-04 12:40:08 +00:00
@@ -1,5 +1,3 @@
|
|||||||
import { useMainStore } from "@/hooks/useMainStore";
|
|
||||||
|
|
||||||
interface CommonResponse<T> {
|
interface CommonResponse<T> {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
error: string;
|
error: string;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import { ScrollArea } from "@/components/ui/scroll-area"
|
|||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { ModelService, ModelServiceResponse } from "@/types"
|
import { ModelService } from "@/types"
|
||||||
import { createService, updateService } from "@/api/service"
|
import { createService, updateService } from "@/api/service"
|
||||||
import { Checkbox } from "@/components/ui/checkbox"
|
import { Checkbox } from "@/components/ui/checkbox"
|
||||||
import { Label } from "@/components/ui/label"
|
import { Label } from "@/components/ui/label"
|
||||||
@@ -48,7 +48,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
|
|
||||||
interface ServiceCardProps {
|
interface ServiceCardProps {
|
||||||
data?: ModelService;
|
data?: ModelService;
|
||||||
mutate: KeyedMutator<ModelServiceResponse>;
|
mutate: KeyedMutator<ModelService[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const serviceFormSchema = z.object({
|
const serviceFormSchema = z.object({
|
||||||
|
|||||||
@@ -9,10 +9,9 @@ import {
|
|||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { ModelServiceResponse, ModelServiceResponseItem as Service } from "@/types";
|
import { ModelService as Service } from "@/types";
|
||||||
import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";
|
import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import { conv } from "@/lib/utils";
|
|
||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import { serviceTypes } from "@/types";
|
import { serviceTypes } from "@/types";
|
||||||
import { ActionButtonGroup } from "@/components/action-button-group";
|
import { ActionButtonGroup } from "@/components/action-button-group";
|
||||||
@@ -24,8 +23,8 @@ import { useTranslation } from "react-i18next";
|
|||||||
|
|
||||||
export default function ServicePage() {
|
export default function ServicePage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { data, mutate, error, isLoading } = useSWR<ModelServiceResponse>(
|
const { data, mutate, error, isLoading } = useSWR<Service[]>(
|
||||||
"/api/v1/service",
|
"/api/v1/service/list",
|
||||||
swrFetcher
|
swrFetcher
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -62,33 +61,33 @@ export default function ServicePage() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "ID",
|
header: "ID",
|
||||||
accessorKey: "service.id",
|
accessorKey: "id",
|
||||||
accessorFn: (row) => row.service.id,
|
accessorFn: (row) => row.id,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: t("Name"),
|
header: t("Name"),
|
||||||
accessorFn: (row) => row.service.name,
|
accessorFn: (row) => row.name,
|
||||||
accessorKey: "service.name",
|
accessorKey: "name",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const s = row.original;
|
const s = row.original;
|
||||||
return <div className="max-w-24 whitespace-normal break-words">{s.service.name}</div>;
|
return <div className="max-w-24 whitespace-normal break-words">{s.name}</div>;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: t("Target"),
|
header: t("Target"),
|
||||||
accessorFn: (row) => row.service.target,
|
accessorFn: (row) => row.target,
|
||||||
accessorKey: "service.target",
|
accessorKey: "target",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const s = row.original;
|
const s = row.original;
|
||||||
return <div className="max-w-24 whitespace-normal break-words">{s.service.target}</div>;
|
return <div className="max-w-24 whitespace-normal break-words">{s.target}</div>;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: t("Coverage"),
|
header: t("Coverage"),
|
||||||
accessorKey: "service.cover",
|
accessorKey: "cover",
|
||||||
accessorFn: (row) => row.service.cover,
|
accessorFn: (row) => row.cover,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const s = row.original.service;
|
const s = row.original;
|
||||||
return (
|
return (
|
||||||
<div className="max-w-48 whitespace-normal break-words">
|
<div className="max-w-48 whitespace-normal break-words">
|
||||||
{(() => {
|
{(() => {
|
||||||
@@ -107,39 +106,39 @@ export default function ServicePage() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: t("SpecificServers"),
|
header: t("SpecificServers"),
|
||||||
accessorKey: "service.skipServers",
|
accessorKey: "skipServers",
|
||||||
accessorFn: (row) => Object.keys(row.service.skip_servers ?? {}),
|
accessorFn: (row) => Object.keys(row.skip_servers ?? {}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: t("Type"),
|
header: t("Type"),
|
||||||
accessorKey: "service.type",
|
accessorKey: "type",
|
||||||
accessorFn: (row) => row.service.type,
|
accessorFn: (row) => row.type,
|
||||||
cell: ({ row }) => serviceTypes[row.original.service.type] || "",
|
cell: ({ row }) => serviceTypes[row.original.type] || "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: t("Interval"),
|
header: t("Interval"),
|
||||||
accessorKey: "service.duration",
|
accessorKey: "duration",
|
||||||
accessorFn: (row) => row.service.duration,
|
accessorFn: (row) => row.duration,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: t("NotifierGroupID"),
|
header: t("NotifierGroupID"),
|
||||||
accessorKey: "service.ngroup",
|
accessorKey: "ngroup",
|
||||||
accessorFn: (row) => row.service.notification_group_id,
|
accessorFn: (row) => row.notification_group_id,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: t("Trigger"),
|
header: t("Trigger"),
|
||||||
accessorKey: "service.triggerTask",
|
accessorKey: "triggerTask",
|
||||||
accessorFn: (row) => row.service.enable_trigger_task ?? false,
|
accessorFn: (row) => row.enable_trigger_task ?? false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: t("TasksToTriggerOnAlert"),
|
header: t("TasksToTriggerOnAlert"),
|
||||||
accessorKey: "service.failTriggerTasks",
|
accessorKey: "failTriggerTasks",
|
||||||
accessorFn: (row) => row.service.fail_trigger_tasks,
|
accessorFn: (row) => row.fail_trigger_tasks,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: t("TasksToTriggerAfterRecovery"),
|
header: t("TasksToTriggerAfterRecovery"),
|
||||||
accessorKey: "service.recoverTriggerTasks",
|
accessorKey: "recoverTriggerTasks",
|
||||||
accessorFn: (row) => row.service.recover_trigger_tasks,
|
accessorFn: (row) => row.recover_trigger_tasks,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "actions",
|
id: "actions",
|
||||||
@@ -149,21 +148,21 @@ export default function ServicePage() {
|
|||||||
return (
|
return (
|
||||||
<ActionButtonGroup
|
<ActionButtonGroup
|
||||||
className="flex gap-2"
|
className="flex gap-2"
|
||||||
delete={{ fn: deleteService, id: s.service.id, mutate: mutate }}
|
delete={{ fn: deleteService, id: s.id, mutate: mutate }}
|
||||||
>
|
>
|
||||||
<ServiceCard mutate={mutate} data={s.service} />
|
<ServiceCard mutate={mutate} data={s} />
|
||||||
</ActionButtonGroup>
|
</ActionButtonGroup>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const dataArr = useMemo(() => {
|
const dataCache = useMemo(() => {
|
||||||
return conv.recordToArr(data?.services ?? {});
|
return data ?? [];
|
||||||
}, [data?.services]);
|
}, [data]);
|
||||||
|
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data: dataArr,
|
data: dataCache,
|
||||||
columns,
|
columns,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
});
|
});
|
||||||
@@ -178,7 +177,7 @@ export default function ServicePage() {
|
|||||||
className="flex-2 flex ml-auto gap-2"
|
className="flex-2 flex ml-auto gap-2"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteService,
|
fn: deleteService,
|
||||||
id: selectedRows.map((r) => r.original.service.id),
|
id: selectedRows.map((r) => r.original.id),
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -63,6 +63,12 @@ export interface GithubComNezhahqNezhaModelCommonResponseArrayModelServerGroupRe
|
|||||||
success: boolean;
|
success: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GithubComNezhahqNezhaModelCommonResponseArrayModelService {
|
||||||
|
data: ModelService[];
|
||||||
|
error: string;
|
||||||
|
success: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface GithubComNezhahqNezhaModelCommonResponseArrayModelServiceInfos {
|
export interface GithubComNezhahqNezhaModelCommonResponseArrayModelServiceInfos {
|
||||||
data: ModelServiceInfos[];
|
data: ModelServiceInfos[];
|
||||||
error: string;
|
error: string;
|
||||||
@@ -555,7 +561,7 @@ export interface ModelServiceResponseItem {
|
|||||||
current_up: number;
|
current_up: number;
|
||||||
delay: number[];
|
delay: number[];
|
||||||
down: number[];
|
down: number[];
|
||||||
service: ModelService;
|
service_name: string;
|
||||||
total_down: number;
|
total_down: number;
|
||||||
total_up: number;
|
total_up: number;
|
||||||
up: number[];
|
up: number[];
|
||||||
@@ -604,6 +610,7 @@ export interface ModelSettingResponse {
|
|||||||
jwt_secret_key: string;
|
jwt_secret_key: string;
|
||||||
/** 系统语言,默认 zh_CN */
|
/** 系统语言,默认 zh_CN */
|
||||||
language: string;
|
language: string;
|
||||||
|
listen_host: string;
|
||||||
listen_port: number;
|
listen_port: number;
|
||||||
/** 时区,默认为 Asia/Shanghai */
|
/** 时区,默认为 Asia/Shanghai */
|
||||||
location: string;
|
location: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user