Home.razor 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. @page "/"
  2. @rendermode InteractiveServer
  3. @using EasyTemplate.Tool.Util
  4. @attribute [ReuseTabsPage(Title = "主页", Pin = true, Closable = false, Order = 0)]
  5. @using Microsoft.AspNetCore.Components
  6. @using EasyTemplate.Service
  7. @using System.Timers
  8. @* @inject UdpListenerService us *@
  9. @*
  10. <p>@udpdata</p> *@
  11. <head>
  12. <meta charset="utf-8" />
  13. @* <link href="css/site.css" rel="stylesheet" /> *@
  14. <title>Blazing Pizza</title>
  15. </head>
  16. <div class="main">
  17. <div class="container">
  18. <div class="nozzle-content">
  19. <div class="grid-container">
  20. @{
  21. int i = 0;
  22. foreach (var item in items)
  23. {
  24. i++;
  25. int num_page = ShowNozzleItem_Row * ShowNozzle_Col;
  26. if (i >= currentPage * num_page+1 && i <= (currentPage + 1) * num_page)
  27. {
  28. <div class="grid-item">
  29. <Nozzle BottomText=""
  30. warnstate="@item.Value.warnstate"
  31. NozNo="@item.Value.noz.ToString()"
  32. VLR="@item.Value.VLR"
  33. nozzlestate="@item.Value.nozzlestate"
  34. OilName="@item.Value.oil" />
  35. </div>
  36. }
  37. }
  38. }
  39. </div>
  40. </div>
  41. </div>
  42. <PageSwitcher CurrentPage="@currentPage"
  43. PageChanged="OnPageChanged" />
  44. <div class="infoctainer">
  45. <div class="sensorcontainer">
  46. <!-- 传感器按钮网格 -->
  47. <div class="button-row">
  48. <SensorButton SensorName="油罐压力"
  49. AlertLevel="@alertLevels["oilTankPressure"]"
  50. OnClick="@(() => ShowDetailModal("oilTankPressure"))" />
  51. <SensorButton SensorName="浓度信息"
  52. AlertLevel="@alertLevels["concentrationInfo"]"
  53. OnClick="@(() => ShowDetailModal("concentrationInfo"))" />
  54. </div>
  55. <div class="button-row">
  56. <SensorButton SensorName="管线压力"
  57. AlertLevel="@alertLevels["pipelinePressure"]"
  58. OnClick="@(() => ShowDetailModal("pipelinePressure"))" />
  59. <SensorButton SensorName="油罐温度"
  60. AlertLevel="@alertLevels["oilTankTemperature"]"
  61. OnClick="@(() => ShowDetailModal("oilTankTemperature"))" />
  62. </div>
  63. <!-- 详细信息模态框 -->
  64. @if (showModal)
  65. {
  66. <Modal Title="BasicModal"
  67. Style="top: 20px"
  68. @bind-Visible="@_visible_sensordetail">
  69. <SensorDetailModal SensorType="@selectedSensor"
  70. SensorData="@sensorData[selectedSensor]"
  71. OnClose="@CloseModal" />
  72. </Modal>
  73. }
  74. </div>
  75. <div class="remoteinfocontainer">
  76. <div class="button-row">
  77. <button class="info-button">北京</button>
  78. <button class ="info-button-state"> 不开启上传</button>
  79. </div>
  80. <div class="button-row">
  81. <button class="info-button">无设置</button>
  82. <button class="info-button-state"> 不开启上传</button>
  83. </div>
  84. <div class="button-row">
  85. <button class="info-button">无设置</button>
  86. <button class="info-button-state"> 不开启上传</button>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. @code {
  92. private Dictionary<string, int> alertLevels = new Dictionary<string, int>
  93. {
  94. ["oilTankPressure"] = 0,
  95. ["concentrationInfo"] = 0,
  96. ["pipelinePressure"] = 0,
  97. ["oilTankTemperature"] = 0
  98. };
  99. private bool showModal = false;
  100. private string selectedSensor = "";
  101. bool _visible_sensordetail = false;
  102. // 示例传感器数据
  103. private Dictionary<string, List<SensorRecord>> sensorData = new Dictionary<string, List<SensorRecord>>
  104. {
  105. ["oilTankPressure"] = new List<SensorRecord>
  106. {
  107. new SensorRecord { Sensor = "PT-101A", Value = "2.5 MPa", Status = 0, Message = "正常" },
  108. new SensorRecord { Sensor = "PT-101B", Value = "2.3 MPa", Status = 1, Message = "轻微波动" },
  109. new SensorRecord { Sensor = "PT-102", Value = "2.7 MPa", Status = 2, Message = "高压预警" }
  110. },
  111. ["concentrationInfo"] = new List<SensorRecord>
  112. {
  113. new SensorRecord { Sensor = "CT-201", Value = "85%", Status = 0, Message = "正常" },
  114. new SensorRecord { Sensor = "CT-202", Value = "87%", Status = 1, Message = "接近上限" },
  115. new SensorRecord { Sensor = "CT-203", Value = "92%", Status = 2, Message = "浓度过高" }
  116. },
  117. ["pipelinePressure"] = new List<SensorRecord>
  118. {
  119. new SensorRecord { Sensor = "PL-301", Value = "3.2 MPa", Status = 0, Message = "正常" },
  120. new SensorRecord { Sensor = "PL-302", Value = "3.0 MPa", Status = 0, Message = "稳定" },
  121. new SensorRecord { Sensor = "PL-303", Value = "3.8 MPa", Status = 2, Message = "超压警报" }
  122. },
  123. ["oilTankTemperature"] = new List<SensorRecord>
  124. {
  125. new SensorRecord { Sensor = "TT-401", Value = "45°C", Status = 0, Message = "正常" },
  126. new SensorRecord { Sensor = "TT-402", Value = "52°C", Status = 1, Message = "温度升高" },
  127. new SensorRecord { Sensor = "TT-403", Value = "68°C", Status = 2, Message = "高温警告" }
  128. }
  129. };
  130. private void HandleAlertChange(string sensorType, int level)
  131. {
  132. alertLevels[sensorType] = level;
  133. StateHasChanged();
  134. }
  135. private void ShowDetailModal(string sensorType)
  136. {
  137. selectedSensor = sensorType;
  138. showModal = true;
  139. _visible_sensordetail = true;
  140. }
  141. private void CloseModal()
  142. {
  143. showModal = false;
  144. selectedSensor = "";
  145. }
  146. public class SensorRecord
  147. {
  148. public string Sensor { get; set; }
  149. public string Value { get; set; }
  150. public int Status { get; set; }
  151. public string Message { get; set; }
  152. }
  153. }
  154. @code {
  155. private Dictionary<int, NozzleState> items = new Dictionary<int, NozzleState>();
  156. private const int ShowNozzleItem_Row = 8;//每行显示的枪数
  157. private const int ShowNozzle_Col = 4;//每页显示的行数
  158. int totalpage = 0;
  159. int currentPage = 0;
  160. private void OnPageChanged(int pageIndex)
  161. {
  162. currentPage = pageIndex;
  163. }
  164. private Timer timer;
  165. private bool isAutoRefreshEnabled = true;
  166. private DateTime lastUpdateTime = DateTime.Now;
  167. protected override async Task OnInitializedAsync()
  168. {
  169. await RefreshData();
  170. StartTimer();
  171. }
  172. private void StartTimer()
  173. {
  174. timer = new Timer(1000); // 1秒间隔
  175. timer.Elapsed += async (sender, e) => await RefreshData();
  176. timer.Start();
  177. }
  178. private async Task RefreshData()
  179. {
  180. var nozzlestates = GlobalTool.g_mNozzleState;//us.GetNozzleState();
  181. try
  182. {
  183. // 更新UI
  184. await InvokeAsync(() =>
  185. {
  186. items = nozzlestates;// mockData;
  187. lastUpdateTime = DateTime.Now;
  188. StateHasChanged();
  189. });
  190. }
  191. catch (Exception ex)
  192. {
  193. Console.WriteLine($"数据刷新失败: {ex.Message}");
  194. }
  195. }
  196. private void ToggleAutoRefresh()
  197. {
  198. isAutoRefreshEnabled = !isAutoRefreshEnabled;
  199. if (isAutoRefreshEnabled)
  200. {
  201. StartTimer();
  202. }
  203. else
  204. {
  205. timer?.Stop();
  206. }
  207. }
  208. public void Dispose()
  209. {
  210. timer?.Stop();
  211. timer?.Dispose();
  212. }
  213. public class NozzleData
  214. {
  215. public string IconUrl { get; set; }
  216. public string Title { get; set; }
  217. public string Description { get; set; }
  218. public int warnstate { get; set; }
  219. public string Line1 { get; set; }
  220. public string Line2 { get; set; }
  221. public string Line3 { get; set; }
  222. }
  223. }
  224. <style>
  225. .main {
  226. background-color: white;
  227. }
  228. .container {
  229. padding: 5px;
  230. font-family: Arial, sans-serif;
  231. background-color: white;
  232. }
  233. .nozzle-content {
  234. grid-area: main;
  235. padding: 5px;
  236. overflow-y: auto;
  237. /* 固定主要内容区域大小 */
  238. /* width: calc(100vw - 250px);
  239. height: calc(100vh - 110px); */
  240. width:950px;
  241. height: 340px;
  242. border-radius: 6px;
  243. border: 1px solid lightblue;
  244. }
  245. .grid-container {
  246. display: grid;
  247. grid-template-columns: repeat(8, 1fr);
  248. gap: 5px;
  249. margin-top: 5px;
  250. }
  251. .grid-item {
  252. background-color: #f0f8ff;
  253. border: 1px solid #b0e0e6;
  254. border-radius: 5px;
  255. padding: 5px;
  256. text-align: center;
  257. /* min-height: 60px; */
  258. display: flex;
  259. align-items: center;
  260. justify-content: center;
  261. }
  262. .infoctainer {
  263. display: flex;
  264. margin-top: 10px;
  265. flex-direction: row;
  266. gap: 5px;
  267. padding: 10px;
  268. background-color: lightblue
  269. }
  270. .sensorcontainer {
  271. display: flex;
  272. flex-direction: column;
  273. gap: 5px;
  274. padding: 10px;
  275. background-color:lightblue
  276. }
  277. .remoteinfocontainer {
  278. display: flex;
  279. flex-direction: column;
  280. gap: 5px;
  281. padding: 10px;
  282. background-color: lightblue
  283. }
  284. .button-row {
  285. display: flex;
  286. gap: 5px;
  287. }
  288. .custom-button {
  289. padding: 5px 10px;
  290. border: none;
  291. width:150px;
  292. height:50px;
  293. border-radius: 8px;
  294. font-size: 16px;
  295. cursor: pointer;
  296. transition: transform 0.2s ease, box-shadow 0.2s ease;
  297. }
  298. .info-button {
  299. border: none;
  300. width: 80px;
  301. height: 40px;
  302. font-size: 16px;
  303. cursor: pointer;
  304. background: lightblue;
  305. }
  306. .info-button-state {
  307. border: none;
  308. width: 120px;
  309. height: 40px;
  310. font-size: 16px;
  311. cursor: pointer;
  312. background: lightblue;
  313. }
  314. .custom-button:hover {
  315. transform: translateY(-2px);
  316. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  317. }
  318. .green {
  319. background-color: #4CAF50;
  320. color: white;
  321. }
  322. .yellow {
  323. background-color: #FFEB3B;
  324. color: black;
  325. }
  326. .red {
  327. background-color: #F44336;
  328. color: white;
  329. }
  330. .default {
  331. background-color: #e0e0e0;
  332. color: black;
  333. }
  334. </style>
  335. @*
  336. <GridContent>
  337. <Row Type="flex" Gutter="24">
  338. <AntDesign.Col Xs="24" Sm="12" Md="12" Lg="12" Xl="6" Style="margin-bottom: 24px;">
  339. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.ChartCard Title="Total Sales"
  340. Total="$ 126,560"
  341. ContentHeight="46">
  342. <ChildContent>
  343. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Trend Flag="up">
  344. WoW Change
  345. <span class="trendText">12%</span>
  346. </EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Trend>
  347. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Trend Flag="down">
  348. DoD Change
  349. <span class="trendText">11%</span>
  350. </EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Trend>
  351. </ChildContent>
  352. <Footer>
  353. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.Field Label="Daily Sale" Value="$12,423" />
  354. </Footer>
  355. </EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.ChartCard>
  356. </AntDesign.Col>
  357. <AntDesign.Col Xs="24" Sm="12" Md="12" Lg="12" Xl="6" Style="margin-bottom: 24px;">
  358. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.ChartCard Title="今日Api访问次数"
  359. Total="@SystemStatistics.ApiDaily.ToString()"
  360. ContentHeight="46">
  361. <Footer>
  362. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.Field Label="Api访问总数" Value="@SystemStatistics.ApiTotal.ToString()" />
  363. </Footer>
  364. </EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.ChartCard>
  365. </AntDesign.Col>
  366. <AntDesign.Col Xs="24" Sm="12" Md="12" Lg="12" Xl="6" Style="margin-bottom: 24px;">
  367. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.ChartCard Title="Payments"
  368. Total="6560"
  369. ContentHeight="46">
  370. <ChildContent>
  371. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.MiniBar />
  372. </ChildContent>
  373. <Footer>
  374. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.Field Label="Conversion Rate" Value="60%" />
  375. </Footer>
  376. </EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.ChartCard>
  377. </AntDesign.Col>
  378. <AntDesign.Col Xs="24" Sm="12" Md="12" Lg="12" Xl="6" Style="margin-bottom: 24px;">
  379. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.ChartCard Title="Operational Effect"
  380. Total="78%"
  381. ContentHeight="46">
  382. <ChildContent>
  383. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.MiniProgress Percent="78"
  384. StrokeWidth="8"
  385. Target="80"
  386. Color="#13C2C2" />
  387. </ChildContent>
  388. <Footer>
  389. <EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.Field Label="Conversion Rate" Value="60%" />
  390. </Footer>
  391. </EasyTemplate.Blazor.Web.Components.Pages.Dashboard.Components.Charts.ChartCard>
  392. </AntDesign.Col>
  393. </Row>
  394. <div class="salesCard">
  395. <Card>
  396. <Tabs TabBarStyle="margin-bottom: 24px;">
  397. <TabPane Key="1" Tab="服务管理">
  398. <Descriptions Bordered>
  399. <DescriptionsItem Title="Mysql服务" Span="3">
  400. <Badge Status="@MySqlStatus" Text="@MySqlText"></Badge>
  401. </DescriptionsItem>
  402. <DescriptionsItem Title="账号异常更新状态服务" Span="3">
  403. <Badge Status="BadgeStatus.Success" Text="运行中"></Badge>
  404. </DescriptionsItem>
  405. </Descriptions>
  406. </TabPane>
  407. <TabPane Key="2" Tab="服务器信息">
  408. <Descriptions Bordered>
  409. <DescriptionsItem Title="服务器名称" Span="3">@Environment.MachineName</DescriptionsItem>
  410. <DescriptionsItem Title="操作系统" Span="3">@System.Runtime.InteropServices.RuntimeInformation.OSDescription</DescriptionsItem>
  411. <DescriptionsItem Title="系统架构" Span="3">@System.Runtime.InteropServices.RuntimeInformation.OSArchitecture</DescriptionsItem>
  412. <DescriptionsItem Title="已使用内存/总内存" Span="3">@ComputerInfo.RAMUsage</DescriptionsItem>
  413. <DescriptionsItem Title="内存使用率" Span="3">
  414. <Badge Status="@RAMStatus" Text="@ComputerInfo.RAMUsageRate"></Badge>
  415. </DescriptionsItem>
  416. <DescriptionsItem Title="系统盘占用/系统盘总空间" Span="3">@ComputerInfo.SystemDiskUsage</DescriptionsItem>
  417. <DescriptionsItem Title="系统盘使用率" Span="3">
  418. <Badge Status="@SystemDiskStatus" Text="@ComputerInfo.SystemDiskUsageRate"></Badge>
  419. </DescriptionsItem>
  420. </Descriptions>
  421. </TabPane>
  422. <TabPane Key="3" Tab="项目框架">
  423. <Descriptions Bordered>
  424. <DescriptionsItem Title="环境变量" Span="3">@Environment.MachineName</DescriptionsItem>
  425. <DescriptionsItem Title=".Net版本" Span="3">@System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription</DescriptionsItem>
  426. <DescriptionsItem Title="启动时间" Span="3">@System.Diagnostics.Process.GetCurrentProcess().StartTime.ToString("yyyy-MM-dd HH:mm:ss")</DescriptionsItem>
  427. </Descriptions>
  428. </TabPane>
  429. </Tabs>
  430. </Card>
  431. </div>
  432. </GridContent>
  433. @inject NavigationManager NavigationManager;
  434. @inject IMessageService MessageService;
  435. @inject IJSRuntime IJSRuntime;
  436. @code {
  437. protected override async Task OnAfterRenderAsync(bool firstRender)
  438. {
  439. if (firstRender)
  440. {
  441. await NavigationManager.RedirectLogin(IJSRuntime);
  442. await Statistics();
  443. await Information();
  444. await ServiceStatistics();
  445. }
  446. }
  447. private async Task ServiceStatistics()
  448. {
  449. try
  450. {
  451. using var con = Sql.Connect();
  452. await con.Queryable<SystemUser>().FirstAsync();
  453. MySqlStatus = BadgeStatus.Success;
  454. MySqlText = "运行中";
  455. }
  456. catch (Exception ex)
  457. {
  458. MySqlStatus = BadgeStatus.Error;
  459. MySqlText = $"服务异常({ex.Message})";
  460. }
  461. StateHasChanged();
  462. }
  463. private async Task Statistics()
  464. {
  465. SystemStatistics.ApiDaily = await Cache.Get<int>($"request_{DateTime.Now.ToString("yyyyMMdd")}");
  466. SystemStatistics.ApiTotal = await Cache.Get<int>($"request_total");
  467. }
  468. private async Task Information()
  469. {
  470. //windows环境
  471. ComputerInfo = Computer.GetComputerInfo();
  472. switch (ComputerInfo.RAMStatus)
  473. {
  474. default:
  475. case ComputerStatus.Normal: RAMStatus = BadgeStatus.Success; break;
  476. case ComputerStatus.Error: RAMStatus = BadgeStatus.Error; break;
  477. case ComputerStatus.Warning: RAMStatus = BadgeStatus.Warning; break;
  478. }
  479. switch (ComputerInfo.SystemDiskStatus)
  480. {
  481. default:
  482. case ComputerStatus.Normal: SystemDiskStatus = BadgeStatus.Success; break;
  483. case ComputerStatus.Error: SystemDiskStatus = BadgeStatus.Error; break;
  484. case ComputerStatus.Warning: SystemDiskStatus = BadgeStatus.Warning; break;
  485. }
  486. }
  487. IChartComponent chart1;
  488. private async Task OnTabChanged(string activeKey)
  489. {
  490. if (activeKey == "1")
  491. {
  492. }
  493. // await _saleChart.ChangeData(data.SalesData);
  494. //else
  495. // await _visitChart.ChangeData(data.SalesData);
  496. }
  497. private async Task onChart1_FirstRender(IChartComponent chart)
  498. {
  499. //var data1 = await ChartsDemoData.FireworksSalesAsync(NavigationManager, HttpClient);
  500. //chart1.ChangeData(data1);
  501. }
  502. readonly AreaConfig config1 = new AreaConfig()
  503. {
  504. XField = "Date",
  505. YField = "scales",
  506. XAxis = new ValueCatTimeAxis()
  507. {
  508. Range = new[] { 0, 1 },
  509. TickCount = 5
  510. },
  511. AreaStyle = new GraphicStyle()
  512. {
  513. Fill = "l(270) 0:#ffffff 0.5:#7ec2f3 1:#1890ff"
  514. }
  515. };
  516. /// <summary>
  517. ///
  518. /// </summary>
  519. private SystemStatistics SystemStatistics = new SystemStatistics();
  520. /// <summary>
  521. ///
  522. /// </summary>
  523. private ComputerInfo ComputerInfo = new ComputerInfo();
  524. /// <summary>
  525. ///
  526. /// </summary>
  527. private BadgeStatus RAMStatus { get; set; }
  528. /// <summary>
  529. ///
  530. /// </summary>
  531. private BadgeStatus SystemDiskStatus { get; set; }
  532. /// <summary>
  533. ///
  534. /// </summary>
  535. private BadgeStatus MySqlStatus { get; set; }
  536. /// <summary>
  537. ///
  538. /// </summary>
  539. private string MySqlText { get; set; }
  540. } *@