@page "/" @rendermode InteractiveServer @using BlazorWeb1.Models @using BlazorWeb1.Server @using System.Timers @inject PizzaService PizzaSvc @inject NavigationManager Navigation @* @inject UdpListenerService us *@ @* *@ Blazing Pizza
@{ int i = 0; foreach (var item in items) { i++; int num_page = ShowNozzleItem_Row * ShowNozzle_Col; if (i >= currentPage * num_page+1 && i <= (currentPage + 1) * num_page) {
} } }
@if (showModal) { }
@code { private Dictionary alertLevels = new Dictionary { ["oilTankPressure"] = 0, ["concentrationInfo"] = 0, ["pipelinePressure"] = 0, ["oilTankTemperature"] = 0 }; private bool showModal = false; private string selectedSensor = ""; bool _visible_sensordetail = false; // 示例传感器数据 private Dictionary> sensorData = new Dictionary> { ["oilTankPressure"] = new List { new SensorRecord { Sensor = "PT-101A", Value = "2.5 MPa", Status = 0, Message = "正常" }, new SensorRecord { Sensor = "PT-101B", Value = "2.3 MPa", Status = 1, Message = "轻微波动" }, new SensorRecord { Sensor = "PT-102", Value = "2.7 MPa", Status = 2, Message = "高压预警" } }, ["concentrationInfo"] = new List { new SensorRecord { Sensor = "CT-201", Value = "85%", Status = 0, Message = "正常" }, new SensorRecord { Sensor = "CT-202", Value = "87%", Status = 1, Message = "接近上限" }, new SensorRecord { Sensor = "CT-203", Value = "92%", Status = 2, Message = "浓度过高" } }, ["pipelinePressure"] = new List { new SensorRecord { Sensor = "PL-301", Value = "3.2 MPa", Status = 0, Message = "正常" }, new SensorRecord { Sensor = "PL-302", Value = "3.0 MPa", Status = 0, Message = "稳定" }, new SensorRecord { Sensor = "PL-303", Value = "3.8 MPa", Status = 2, Message = "超压警报" } }, ["oilTankTemperature"] = new List { new SensorRecord { Sensor = "TT-401", Value = "45°C", Status = 0, Message = "正常" }, new SensorRecord { Sensor = "TT-402", Value = "52°C", Status = 1, Message = "温度升高" }, new SensorRecord { Sensor = "TT-403", Value = "68°C", Status = 2, Message = "高温警告" } } }; private void HandleAlertChange(string sensorType, int level) { alertLevels[sensorType] = level; StateHasChanged(); } private void ShowDetailModal(string sensorType) { selectedSensor = sensorType; showModal = true; _visible_sensordetail = true; } private void CloseModal() { showModal = false; selectedSensor = ""; } public class SensorRecord { public string Sensor { get; set; } public string Value { get; set; } public int Status { get; set; } public string Message { get; set; } } } @code { private Dictionary items = new Dictionary(); private const int ShowNozzleItem_Row = 8;//每行显示的枪数 private const int ShowNozzle_Col = 4;//每页显示的行数 int totalpage = 0; int currentPage = 0; private void OnPageChanged(int pageIndex) { currentPage = pageIndex; } private Timer timer; private bool isAutoRefreshEnabled = true; private DateTime lastUpdateTime = DateTime.Now; protected override async Task OnInitializedAsync() { await RefreshData(); StartTimer(); } private void StartTimer() { timer = new Timer(1000); // 1秒间隔 timer.Elapsed += async (sender, e) => await RefreshData(); timer.Start(); } private async Task RefreshData() { var nozzlestates = GlobalTool.g_mNozzleState;//us.GetNozzleState(); try { // 更新UI await InvokeAsync(() => { items = nozzlestates;// mockData; lastUpdateTime = DateTime.Now; StateHasChanged(); }); } catch (Exception ex) { Console.WriteLine($"数据刷新失败: {ex.Message}"); } } private void ToggleAutoRefresh() { isAutoRefreshEnabled = !isAutoRefreshEnabled; if (isAutoRefreshEnabled) { StartTimer(); } else { timer?.Stop(); } } public void Dispose() { timer?.Stop(); timer?.Dispose(); } public class NozzleData { public string IconUrl { get; set; } public string Title { get; set; } public string Description { get; set; } public int warnstate { get; set; } public string Line1 { get; set; } public string Line2 { get; set; } public string Line3 { get; set; } } } @* *@ @* @foreach (var pizza in todaysPizzas) { }
Pizza Name Description Vegetarian? Vegan? Price
@pizza.Name @pizza.Description @pizza.Vegetarian @pizza.Vegan @pizza.Price
*@ @*
    @if (specials != null) { @foreach (var special in specials) {
  • @special.Name @special.Description @special.GetFormattedBasePrice()
  • } }
*@ @code { string NickName = "ES"; private Pizza[] todaysPizzas; // protected override async Task OnInitializedAsync() // { // todaysPizzas = PizzaSvc.GetPizzasAsync(); // } List specials = new(); // protected override void OnInitialized() // { // specials.AddRange(new List // { // new PizzaSpecial { Name = "The Baconatorizor", BasePrice = 11.99M, Description = "It has EVERY kind of bacon", ImageUrl="img/pizzas/bacon.jpg"}, // new PizzaSpecial { Name = "Buffalo chicken", BasePrice = 12.75M, Description = "Spicy chicken, hot sauce, and blue cheese, guaranteed to warm you up", ImageUrl="img/pizzas/meaty.jpg"}, // new PizzaSpecial { Name = "Veggie Delight", BasePrice = 11.5M, Description = "It's like salad, but on a pizza", ImageUrl="img/pizzas/salad.jpg"}, // new PizzaSpecial { Name = "Margherita", BasePrice = 9.99M, Description = "Traditional Italian pizza with tomatoes and basil", ImageUrl="img/pizzas/margherita.jpg"}, // new PizzaSpecial { Name = "Basic Cheese Pizza", BasePrice = 11.99M, Description = "It's cheesy and delicious. Why wouldn't you want one?", ImageUrl="img/pizzas/cheese.jpg"}, // new PizzaSpecial { Name = "Classic pepperoni", BasePrice = 10.5M, Description = "It's the pizza you grew up with, but Blazing hot!", ImageUrl="img/pizzas/pepperoni.jpg" } // }); // } }