Files
oqtane.framework/Oqtane.Client/Modules/HtmlText/Index.razor
2026-01-20 14:44:06 -05:00

100 lines
2.8 KiB
Plaintext

@using Oqtane.Modules.HtmlText.Services
@namespace Oqtane.Modules.HtmlText
@inherits ModuleBase
@inject IHtmlTextService HtmlTextService
@inject ISettingService SettingService
@inject IStringLocalizer<Index> Localizer
@for (int i = 1; i < 6; i++)
{
string product = $"product{i}";
<div>
<input type="checkbox" id="@($"product{i}")" @onchange="@(() => ProductChanged(product))" />
<label for="@($"product{i}")">@GetLabel($"product{i}")</label>
</div>
}
@if (PageState.EditMode)
{
<div class="text-center mb-2">
<ActionLink Action="Edit" EditMode="true" ResourceKey="Edit" />
</div>
}
@((MarkupString)content)
@if (PageState.EditMode && content.Length > 3000)
{
<div class="text-center mt-2">
<ActionLink Action="Edit" EditMode="true" ResourceKey="Edit" />
</div>
}
@code {
private string content = "";
//public override string RenderMode => RenderModes.Static;
Dictionary<string, string> _labels = new Dictionary<string, string> {
{ ":product1", "成为顾问 (FIA)"},
{ ":product2", "Market Shield Savings Plan (MS)"},
{ ":product3", "Global Term Life Insurance"},
{ ":product4", "Protection Advantage Universal Life Insurance"},
{ ":product5", "Summit Indexed Universal Life Insurance"}
};
private List<string> _products = new List<string>();
private void ProductChanged(string product)
{
if (_products.Contains(product))
{
_products.Remove(product);
}
else
{
_products.Add(product);
}
}
private string GetLabel(string key)
{
if (_labels.ContainsKey($"{PageState.Alias.Path}:{key}"))
{
return _labels[$"{PageState.Alias.Path}:{key}"];
}
else
{
return "";
}
}
protected override async Task OnParametersSetAsync()
{
try
{
if (ShouldRender())
{
var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
content = htmltext.Content;
content = Utilities.FormatContent(content, PageState.Alias, "render");
if (bool.Parse(SettingService.GetSetting(ModuleState.Settings, "DynamicTokens", "false")))
{
content = ReplaceTokens(content);
}
}
else
{
content = "";
}
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Content {Error}", ex.Message);
AddModuleMessage(Localizer["Error.Content.Load"], MessageType.Error);
}
}
}