import enhance from "../core/enhance.tsx"; import {Button, Checkbox, CheckboxChangeEvent, message, Select, Space, Switch, Tag, Typography} from "antd"; import {SettingOutlined} from "@ant-design/icons"; import axios from "axios"; import {baseURL, Prefix} from "../Global.tsx"; import React from "react"; import {Input_Port_Number, Input_String, Switch_Bool} from "../A_Global.tsx"; import { State_Shower } from "../State_Shower.tsx"; const {Option} = Select; const { Text } = Typography; class Output_Format { type: string = ""; use_status: boolean = false; mode_s_output_type: string = ""; use_mode_ac: boolean = false; sbs_only_pos: boolean = false; output(flush) { return (<> } defaultValue="" style={{ width: '100%' }} value={this.mode_s_output_type} onChange={(value: string) => { this.mode_s_output_type = value; flush(); }} options={[ {value: 'ALL_Mode_S', label: '全部的mode_s'}, {value: 'DF_11_17_18', label: 'DF_11_17_18'}, {value: 'NO_POS_Mode_S', label: '无位置的mode_s'}, ]} /> { this.use_mode_ac = e.target.checked; flush(); }}>Mode_AC } ); } } export class Data_Feed extends enhance.Base { key: string = "未命名"; enable: boolean = false; type: string = ""; output_format: Output_Format = new Output_Format(); state: State_Shower = new State_Shower(`${baseURL}/get_data_feed_state`, () => this.key); onClick(that) { } center_with_add(): React.JSX.Element { return <> } center(): React.JSX.Element { return <> } render(props: any) { return (
{ this.center_with_add() } { this.center() }
); } } class Data_Feed_Server extends Data_Feed { port: number = 0; dataSource: any[] = []; // 新增:轮询定时器 private pollTimer: number | null = null; private pollIntervalMs = 1000; private fetchConnections = async () => { try { // 你原来这里用 post 并把 this 作为 body,我保留这个行为 const res = await axios.post(`${baseURL}/get_data_feed_server_connect`, this); this.dataSource = (res.data ?? []).map((item: any, index: number) => ({ ...item, key: String(index), })); this.flush(); } catch (e) { // 可选:失败不打断轮询 // console.error(e); } }; private startPolling = () => { if (this.pollTimer !== null) return; // 已经在轮询 void this.fetchConnections(); // 先立刻拉一次 this.pollTimer = window.setInterval(() => { void this.fetchConnections(); }, this.pollIntervalMs); }; private stopPolling = () => { if (this.pollTimer === null) return; window.clearInterval(this.pollTimer); this.pollTimer = null; }; refresh() { // refresh 保持可用:手动刷新一次 void this.fetchConnections(); } center(): React.JSX.Element { return ( <> ); } center_with_add(): React.JSX.Element { return ( <> ); } // 可选:如果这个对象有生命周期/销毁点,记得调用,避免内存泄漏 destroy() { this.stopPolling(); } } class Data_Feed_Client extends Data_Feed { url: string = ""; port: number = 0; center_with_add() { return <> } } export class Data_Feed_TCP_Server extends Data_Feed_Server { } export class Data_Feed_UDP_Server extends Data_Feed_Server { } export class Data_Feed_TCP_Client extends Data_Feed_Client { } export class Data_Feed_UDP_Client extends Data_Feed_Client { } export function create_data_feed_from_type(type: string) { let ret: Data_Feed if (type === "Data_Feed_TCP_Server") { ret = new Data_Feed_TCP_Server(); } if (type === "Data_Feed_TCP_Client") { ret = new Data_Feed_TCP_Client(); } if (type === "Data_Feed_UDP_Server") { ret = new Data_Feed_UDP_Server(); } if (type === "Data_Feed_UDP_Client") { ret = new Data_Feed_UDP_Client(); } return ret; }