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=""
value={this.type}
onChange={(value: string) => {
this.type = value;
flush();
}}
options={[
{value: 'BIN', label: 'BIN'},
{value: 'BIN_ID', label: 'BIN_ID'},
{value: 'AVR', label: 'AVR'},
{value: 'AVR_MLAT', label: 'AVR_MLAT'},
{value: 'SBS', label: 'SBS'},
]}
/>
{
(this.type == "BIN" || this.type == "BIN_ID") &&
{
this.use_status = e.target.checked;
flush();
}}>状态消息
}
{
(this.type == "SBS") &&
{
this.sbs_only_pos = e.target.checked;
flush();
}}>SBS只输出带位置的飞机
}
{
(this.type != "SBS") &&
<>
}
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 (
<>
}
popupMatchSelectWidth={false}
placeholder="展示所有连接"
onChange={(value) => {
console.log("你选择了:", value);
}}
value={""}
onOpenChange={(open) => {
if (open) {
this.startPolling(); // 展开:1 秒刷新
} else {
this.stopPolling(); // 收起:停止刷新
}
}}
>
{this.dataSource.map((item: any) => (
))}
>
);
}
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;
}