2020-05-16 23:27:40 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.JSInterop;
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign.JsInterop
|
2020-05-16 23:27:40 +08:00
|
|
|
|
{
|
|
|
|
|
public class InteropService
|
|
|
|
|
{
|
|
|
|
|
private readonly IJSRuntime _js;
|
|
|
|
|
|
|
|
|
|
public InteropService(IJSRuntime js)
|
|
|
|
|
{
|
|
|
|
|
_js = js;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async ValueTask Copy(string text)
|
|
|
|
|
{
|
2020-09-09 00:52:14 +08:00
|
|
|
|
await this.JsInvokeAsync(JSInteropConstants.Copy, text);
|
2020-05-16 23:27:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<T> JsInvokeAsync<T>(string code, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return await _js.InvokeAsync<T>(code, args);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task JsInvokeAsync(string code, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _js.InvokeVoidAsync(code, args);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|