diff --git a/src/BootstrapBlazor/Components/Validate/ValidateBase.cs b/src/BootstrapBlazor/Components/Validate/ValidateBase.cs index 8d613579c05..6245ba47840 100644 --- a/src/BootstrapBlazor/Components/Validate/ValidateBase.cs +++ b/src/BootstrapBlazor/Components/Validate/ValidateBase.cs @@ -485,7 +485,7 @@ public virtual void ToggleMessage(IEnumerable results) private JSModule? ValidateModule { get; set; } - private Task LoadValidateModule() => JSRuntime.LoadModule("./_content/BootstrapBlazor/modules/validate.js"); + private Task LoadValidateModule() => JSRuntime.LoadModuleByName("validate"); /// /// 增加客户端 Tooltip 方法 diff --git a/src/BootstrapBlazor/Components/WebSpeech/WebSpeechService.cs b/src/BootstrapBlazor/Components/WebSpeech/WebSpeechService.cs index cca0f0351ee..99b897f7065 100644 --- a/src/BootstrapBlazor/Components/WebSpeech/WebSpeechService.cs +++ b/src/BootstrapBlazor/Components/WebSpeech/WebSpeechService.cs @@ -10,7 +10,7 @@ namespace BootstrapBlazor.Components; /// /// Web Speech 服务 /// -public class WebSpeechService(IJSRuntime runtime, IComponentIdGenerator ComponentIdGenerator, ILogger logger) +public class WebSpeechService(IJSRuntime runtime, IComponentIdGenerator ComponentIdGenerator) { private JSModule? SynthesisModule { get; set; } @@ -24,9 +24,7 @@ public async Task CreateSynthesizerAsync() { if (SynthesisModule == null) { - var moduleName = "./_content/BootstrapBlazor/modules/synthesis.js"; - logger.LogInformation("load module {moduleName}", moduleName); - SynthesisModule = await runtime.LoadModule(moduleName); + SynthesisModule = await runtime.LoadModuleByName("synthesis"); } return new WebSpeechSynthesizer(SynthesisModule, ComponentIdGenerator); } @@ -39,9 +37,7 @@ public async Task CreateRecognitionAsync() { if (RecognitionModule == null) { - var moduleName = "./_content/BootstrapBlazor/modules/recognition.js"; - logger.LogInformation("load module {moduleName}", moduleName); - RecognitionModule = await runtime.LoadModule(moduleName); + RecognitionModule = await runtime.LoadModuleByName("recognition"); } return new WebSpeechRecognition(RecognitionModule, ComponentIdGenerator); } diff --git a/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs b/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs index 035cb1a005f..92d9049ad03 100644 --- a/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs +++ b/src/BootstrapBlazor/Extensions/JSModuleExtensions.cs @@ -16,10 +16,23 @@ public static class JSModuleExtensions /// /// /// A ]]> 模块加载器 - public static Task LoadUtility(this IJSRuntime jsRuntime, string? version = null) => LoadModule(jsRuntime, "./_content/BootstrapBlazor/modules/utility.js", version); + public static Task LoadUtility(this IJSRuntime jsRuntime, string? version = null) => LoadModuleByName(jsRuntime, "utility", version); /// - /// IJSRuntime 扩展方法 动态加载脚本 脚本目录为 modules + /// 通过名称导入内置脚本模块 + /// + /// + /// + /// + /// A ]]> 模块加载器 + public static Task LoadModuleByName(this IJSRuntime jsRuntime, string moduleName, string? version = null) + { + var fileName = $"./_content/BootstrapBlazor/modules/{moduleName}.js"; + return LoadModule(jsRuntime, fileName, version); + } + + /// + /// IJSRuntime 扩展方法 动态加载脚本 /// /// /// diff --git a/src/BootstrapBlazor/Services/AjaxService.cs b/src/BootstrapBlazor/Services/AjaxService.cs index a1898b9cc27..b03db8e7821 100644 --- a/src/BootstrapBlazor/Services/AjaxService.cs +++ b/src/BootstrapBlazor/Services/AjaxService.cs @@ -15,7 +15,7 @@ public class AjaxService(IJSRuntime jSRuntime) [NotNull] private JSModule? _module = null; - private Task LoadModule() => jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/ajax.js"); + private Task LoadModule() => jSRuntime.LoadModuleByName("ajax"); /// /// 调用Ajax方法发送请求 diff --git a/src/BootstrapBlazor/Services/Bluetooth/DefaultBluetooth.cs b/src/BootstrapBlazor/Services/Bluetooth/DefaultBluetooth.cs index 16d97b78aec..62a7ecff80e 100644 --- a/src/BootstrapBlazor/Services/Bluetooth/DefaultBluetooth.cs +++ b/src/BootstrapBlazor/Services/Bluetooth/DefaultBluetooth.cs @@ -44,7 +44,7 @@ public DefaultBluetooth(IJSRuntime jsRuntime) private async Task LoadModule() { - var module = await _runtime.LoadModule("./_content/BootstrapBlazor/modules/bt.js"); + var module = await _runtime.LoadModuleByName("bt"); IsSupport = await module.InvokeAsync("init"); return module; diff --git a/src/BootstrapBlazor/Services/ClipboardService.cs b/src/BootstrapBlazor/Services/ClipboardService.cs index 7076e06b813..c276179dd9c 100644 --- a/src/BootstrapBlazor/Services/ClipboardService.cs +++ b/src/BootstrapBlazor/Services/ClipboardService.cs @@ -13,7 +13,7 @@ public class ClipboardService(IJSRuntime jSRuntime) [NotNull] private JSModule? _module = null; - private Task LoadModule() => jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/utility.js"); + private Task LoadModule() => jSRuntime.LoadUtility(); /// /// 获取剪切板数据方法 diff --git a/src/BootstrapBlazor/Services/DefaultBrowserFingerService.cs b/src/BootstrapBlazor/Services/DefaultBrowserFingerService.cs index 45a18d7229e..b99da81f736 100644 --- a/src/BootstrapBlazor/Services/DefaultBrowserFingerService.cs +++ b/src/BootstrapBlazor/Services/DefaultBrowserFingerService.cs @@ -13,14 +13,12 @@ class DefaultBrowserFingerService(IJSRuntime jSRuntime) : IBrowserFingerService [NotNull] private JSModule? _module = null; - private Task LoadModule() => jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/utility.js"); - /// /// 获取剪切板数据方法 /// public async Task GetFingerCodeAsync(CancellationToken token = default) { - _module ??= await LoadModule(); + _module ??= await jSRuntime.LoadUtility(); return await _module.InvokeAsync("getFingerCode", token); } } diff --git a/src/BootstrapBlazor/Services/DefaultGeoLocationService.cs b/src/BootstrapBlazor/Services/DefaultGeoLocationService.cs index 739f921b65a..f03c3c87b4f 100644 --- a/src/BootstrapBlazor/Services/DefaultGeoLocationService.cs +++ b/src/BootstrapBlazor/Services/DefaultGeoLocationService.cs @@ -28,7 +28,7 @@ public DefaultGeoLocationService(IJSRuntime jsRuntime) Interop = DotNetObjectReference.Create(this); } - private Task LoadModule() => JSRuntime.LoadModule("./_content/BootstrapBlazor/modules/geo.js"); + private Task LoadModule() => JSRuntime.LoadModuleByName("geo"); /// /// get the current position of the device diff --git a/src/BootstrapBlazor/Services/EyeDropperService.cs b/src/BootstrapBlazor/Services/EyeDropperService.cs index a6ff6dc59ef..747108868c6 100644 --- a/src/BootstrapBlazor/Services/EyeDropperService.cs +++ b/src/BootstrapBlazor/Services/EyeDropperService.cs @@ -19,7 +19,7 @@ public class EyeDropperService(IJSRuntime jSRuntime) /// public async Task PickAsync(CancellationToken token = default) { - _module ??= await jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/eye-dropper.js"); + _module ??= await jSRuntime.LoadModuleByName("eye-dropper"); return await _module.InvokeAsync("open", token); } } diff --git a/src/BootstrapBlazor/Services/FullScreenService.cs b/src/BootstrapBlazor/Services/FullScreenService.cs index 03f856db0e2..8161350ea69 100644 --- a/src/BootstrapBlazor/Services/FullScreenService.cs +++ b/src/BootstrapBlazor/Services/FullScreenService.cs @@ -21,7 +21,7 @@ public class FullScreenService(IJSRuntime jSRuntime) /// public async Task Toggle(FullScreenOption? option = null, CancellationToken token = default) { - _module ??= await jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/fullscreen.js"); + _module ??= await jSRuntime.LoadModuleByName("fullscreen"); await _module.InvokeVoidAsync("toggle", token, option); } } diff --git a/src/BootstrapBlazor/Services/NotificationService.cs b/src/BootstrapBlazor/Services/NotificationService.cs index 98d4ea6b0ee..eb8f781fcff 100644 --- a/src/BootstrapBlazor/Services/NotificationService.cs +++ b/src/BootstrapBlazor/Services/NotificationService.cs @@ -32,7 +32,7 @@ public NotificationService(IJSRuntime runtime, ICacheManager cache) Interop = DotNetObjectReference.Create(this); } - private Task LoadModule() => JSRuntime.LoadModule("./_content/BootstrapBlazor/modules/noti.js"); + private Task LoadModule() => JSRuntime.LoadModuleByName("noti"); /// /// 检查浏览器通知权限状态 diff --git a/src/BootstrapBlazor/Services/Serial/DefaultSerialService.cs b/src/BootstrapBlazor/Services/Serial/DefaultSerialService.cs index 8173e854786..9ef4800bba4 100644 --- a/src/BootstrapBlazor/Services/Serial/DefaultSerialService.cs +++ b/src/BootstrapBlazor/Services/Serial/DefaultSerialService.cs @@ -28,7 +28,7 @@ public DefaultSerialService(IJSRuntime jsRuntime) private async Task LoadModule() { - var module = await _runtime.LoadModule("./_content/BootstrapBlazor/modules/serial.js"); + var module = await _runtime.LoadModuleByName("serial"); IsSupport = await module.InvokeAsync("init", _serialPortId); return module; diff --git a/src/BootstrapBlazor/Services/TitleService.cs b/src/BootstrapBlazor/Services/TitleService.cs index f5f0edf4d18..b1227cde523 100644 --- a/src/BootstrapBlazor/Services/TitleService.cs +++ b/src/BootstrapBlazor/Services/TitleService.cs @@ -19,7 +19,7 @@ public class TitleService(IJSRuntime jSRuntime) /// public async Task SetTitle(string title, CancellationToken token = default) { - _module ??= await jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/utility.js"); + _module ??= await jSRuntime.LoadUtility(); await _module.InvokeVoidAsync("setTitle", token, title); } } diff --git a/src/BootstrapBlazor/Services/WebClientService.cs b/src/BootstrapBlazor/Services/WebClientService.cs index 34c25d1b0ee..d545a21967b 100644 --- a/src/BootstrapBlazor/Services/WebClientService.cs +++ b/src/BootstrapBlazor/Services/WebClientService.cs @@ -42,7 +42,7 @@ public async Task GetClientInfo() try { - _jsModule ??= await runtime.LoadModule("./_content/BootstrapBlazor/modules/client.js"); + _jsModule ??= await runtime.LoadModuleByName("client"); _interop ??= DotNetObjectReference.Create(this); await _jsModule.InvokeVoidAsync("ping", "ip.axd", _interop, nameof(SetData));