StaffStaticsReport.razor.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using AntDesign;
  2. using Microsoft.AspNetCore.Components;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text.Json;
  8. using System.Threading.Tasks;
  9. using wispro.sp.web.Services;
  10. using Blazor.ECharts.Options;
  11. using Blazor.ECharts.Options.Enum;
  12. using L = Blazor.ECharts.Options.Series.Line;
  13. namespace wispro.sp.web.Pages.Report
  14. {
  15. public partial class StaffStaticsReport
  16. {
  17. private int iType = 0;
  18. private EChartsOption<L.Line> option;
  19. private Blazor.ECharts.Components.ELine chart;
  20. internal class TJType
  21. {
  22. public string Name { get; set; }
  23. public int value { get; set; }
  24. }
  25. List<TJType> Types = new List<TJType>
  26. {
  27. new TJType { value = 0,Name = "人员每月绩效统计" },
  28. new TJType { value = 2,Name = "人员每年绩效统计" },
  29. new TJType { value = 1,Name = "部门每月绩效统计" },
  30. new TJType { value = 3,Name = "部门每年绩效统计" },
  31. new TJType { value = 4,Name = "人员专案绩效统计" },
  32. };
  33. share.ChartDatas Datas = new share.ChartDatas()
  34. {
  35. Title = "初始化标题",
  36. Datas = new List<share.ChartData>() {
  37. new share.ChartData(){ type ="部门一", value =1, year="2022-01", CustomerType ="", CustomerYear=""},
  38. new share.ChartData(){ type ="部门一",value =5, year="2022-02",CustomerType ="", CustomerYear=""},
  39. new share.ChartData(){ type ="部门二", value =3, year="2022-01", CustomerType ="", CustomerYear=""},
  40. new share.ChartData(){ type ="部门二",value =4, year="2022-02",CustomerType ="", CustomerYear=""},
  41. new share.ChartData(){ type ="部门三",value =2.5, year="2022-02",CustomerType ="", CustomerYear=""}
  42. },
  43. ATitle = "部门",
  44. BTitle = "申诉月份"
  45. };
  46. private void GetOption()
  47. {
  48. if (Datas != null)
  49. {
  50. List<object> series = new List<object>();
  51. DataTable dt = Datas.GetTableData();
  52. foreach (DataRow row in dt.Rows)
  53. {
  54. L.Line l = new L.Line();
  55. l.Name = row[0].ToString();
  56. List<double> data = new List<double>();
  57. for (int i = 1; i < dt.Columns.Count; i++)
  58. {
  59. double dTem = 0;
  60. if(!double.TryParse(row[i].ToString(), out dTem))
  61. {
  62. dTem = 0;
  63. }
  64. data.Add(dTem);
  65. }
  66. l.Data = data;
  67. series.Add(l);
  68. }
  69. option = new EChartsOption<L.Line>()
  70. {
  71. //Legend = new() {
  72. // Show = true,
  73. //},
  74. Toolbox = new()
  75. {
  76. Show = true,
  77. Feature = new()
  78. {
  79. DataView = new()
  80. {
  81. ReadOnly = false
  82. },
  83. Restore = new(),
  84. MagicType = new() {
  85. Type = new()
  86. {
  87. MagicTypeType.Bar,
  88. MagicTypeType.Line,
  89. MagicTypeType.Stack,
  90. MagicTypeType.Tiled,
  91. }
  92. },
  93. SaveAsImage = new()
  94. {
  95. PixelRatio = 2,
  96. Name = "保存图片"
  97. }
  98. }
  99. },
  100. Tooltip = new()
  101. {
  102. Trigger = TooltipTrigger.Item,
  103. Formatter = "{a} <br/>{b}: {c}"
  104. },
  105. Title = new()
  106. {
  107. Text = Datas.Title
  108. },
  109. YAxis = new()
  110. {
  111. new()
  112. {
  113. Type = AxisType.Value,
  114. Name = "绩效",
  115. Position = PositionY.Start,
  116. AxisLine = new()
  117. {
  118. Show = true,
  119. }
  120. }
  121. },
  122. XAxis = new()
  123. {
  124. new()
  125. {
  126. Type = AxisType.Category,
  127. Data = Datas.GetYear(),
  128. Name = Datas.BTitle,
  129. NameLocation = Location.Middle,
  130. AxisLabel = new()
  131. {
  132. Show = true
  133. },
  134. }
  135. },
  136. Series = series
  137. };
  138. }
  139. }
  140. [Inject] ReportService reportService { get; set; }
  141. [Inject] MessageService msgService { get; set; }
  142. private bool _noIconLoading;
  143. private async Task OnButtonClick()
  144. {
  145. //option = null;
  146. await GetChartDatas();
  147. Console.WriteLine(chart.OptionRaw);
  148. }
  149. private async Task OnButtonClick_1()
  150. {
  151. Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(option, new JsonSerializerOptions()
  152. {
  153. DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
  154. }));
  155. await msgService.Success(chart.OptionRaw);
  156. }
  157. private async Task GetChartDatas()
  158. {
  159. _noIconLoading = true;
  160. Datas = await reportService.GetStaticReportData(iType);
  161. GetOption();
  162. StateHasChanged();
  163. _noIconLoading = false;
  164. }
  165. [Inject] protected IAuthService _authService { get; set; }
  166. protected async override Task OnInitializedAsync()
  167. {
  168. await _authService.CanVisitResource();
  169. await GetChartDatas();
  170. await base.OnInitializedAsync();
  171. }
  172. private EchartsEventArgs callbackArgs;
  173. private List<EventType> EventTypes = new List<EventType> { EventType.click };
  174. private void OnEchartsEvent(EchartsEventArgs args)
  175. {
  176. msgService.Info($"您点击了:[{args.SeriesName},{args.Name}]!");
  177. callbackArgs = args;
  178. }
  179. }
  180. }