Tabs.razor 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. @using System.IO;
  2. <div class="fr-webreport-tabs">
  3. @for (int i = 0; i < WebReport.Tabs.Count; i++)
  4. {
  5. int copyIndex = i;
  6. string active = (copyIndex == WebReport.CurrentTabIndex ? "active" : "");
  7. <div class="fr-webreport-tab @active">
  8. <a class="fr-webreport-tab-title" @onclick="() => SetTab(copyIndex)">
  9. @WebReport.GetTabName(copyIndex)
  10. </a>
  11. @if (WebReport.Tabs[copyIndex].Closeable)
  12. {
  13. <a class="fr-webreport-tab-close" title="Close" @onclick="() => CloseTab(copyIndex)">
  14. <img src="_content/FastReport.Web/Resources/close.svg"/>
  15. </a>
  16. }
  17. </div>
  18. }
  19. </div>
  20. @code {
  21. [Parameter]
  22. public WebReport WebReport { get; set; }
  23. private void SetTab(int i)
  24. {
  25. if(i != WebReport.CurrentTabIndex)
  26. {
  27. WebReport.SetTab(i);
  28. WebReport.OnUpdate(false);
  29. }
  30. }
  31. private void CloseTab(int i)
  32. {
  33. var activeTab = WebReport.CurrentTab;
  34. WebReport.Tabs[i].Report.Dispose();
  35. WebReport.Tabs.RemoveAt(i);
  36. if (activeTab == null)
  37. {
  38. WebReport.CurrentTabIndex = 0;
  39. }
  40. else
  41. {
  42. for (int j = 0; j < WebReport.Tabs.Count; j++)
  43. if (WebReport.Tabs[j] == activeTab)
  44. {
  45. WebReport.CurrentTabIndex = j;
  46. break;
  47. }
  48. }
  49. WebReport.OnUpdate(false);
  50. }
  51. }