Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

70 lignes
2.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.JSInterop;
  6. namespace AbrBlazorTools
  7. {
  8. public class BrowserTools : IBrowserTools
  9. {
  10. private readonly IJSRuntime _js;
  11. public BrowserTools(IJSRuntime js)
  12. {
  13. _js = js;
  14. }
  15. public async Task<BrowserDimension> GetDimensions()
  16. {
  17. return await _js.InvokeAsync<BrowserDimension>("methods.getDimensions");
  18. }
  19. public async Task<ValueTask> CopyText(string text)
  20. {
  21. return _js.InvokeVoidAsync("navigator.clipboard.writeText", text);
  22. }
  23. public async Task PrepareResponsiveTable()
  24. {
  25. await _js.InvokeVoidAsync("methods.PrepareResponsiveTable");
  26. }
  27. public async Task<string> GetInputValueById(string id)
  28. {
  29. return await _js.InvokeAsync<string>("AbrMethods.getInputValue",id);
  30. }
  31. public async Task<string> GetInputValueByIdAndReplacePersianNumbers(string id)
  32. {
  33. var text = await GetInputValueById(id);
  34. var digits = new string[] { "۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹" };
  35. var english = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
  36. for (var i = 0; i < digits.Length; i++)
  37. text = text.Replace(digits[i], english[i]);
  38. return text;
  39. }
  40. public async Task ScrollToEnd()
  41. {
  42. await _js.InvokeVoidAsync("methods.ScrollToEnd");
  43. }
  44. }
  45. public class BrowserDimension
  46. {
  47. public int Width { get; set; }
  48. public int Height { get; set; }
  49. }
  50. public interface IBrowserTools
  51. {
  52. Task<BrowserDimension> GetDimensions();
  53. Task<ValueTask> CopyText(string text);
  54. Task PrepareResponsiveTable();
  55. Task<string> GetInputValueById(string id);
  56. Task<string> GetInputValueByIdAndReplacePersianNumbers(string id);
  57. Task ScrollToEnd();
  58. }
  59. }