调整数据库结构,实现消息模板管理

This commit is contained in:
2025-12-16 11:26:55 +08:00
parent 98e3f7ab73
commit ed32b98867
45 changed files with 1100 additions and 1319 deletions

View File

@@ -1,144 +1,162 @@
@page "/setting/messagetemplate/list"
@page "/{locale}/setting/messagetemplate/list"
@inject ILogger<MessageTemplateList> Logger
@attribute [Authorize]
<PageTitle>消息模板</PageTitle>
<Title Level="4">消息模版管理</Title>
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Key" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item" style="width:200px;display:flex;">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<PageContainer Title="消息模板">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
<BreadcrumbItem>系统设置</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Key" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item" style="width:200px;display:flex;">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<br />
<Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
菜单列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c => c.Type" Title="模版类型" Width="150px">
@if (context.Type == (int)MessageTemplateType.Message)
{
<AntDesign.Text>站内信</AntDesign.Text>
}
else if (context.Type == (int)MessageTemplateType.Email)
{
<AntDesign.Text>邮件</AntDesign.Text>
}
else if (context.Type == (int)MessageTemplateType.Sms)
{
<AntDesign.Text>短信</AntDesign.Text>
}
</PropertyColumn>
<PropertyColumn Property="c => c.Name" Title="模版名称" />
<PropertyColumn Property="c => c.LanguageId" Title="语言">
@GetLanuageName(context.LanguageId)
</PropertyColumn>
<PropertyColumn Property="c => c.Key" Title="模版Code" Width="100px" />
<PropertyColumn Property="c => c.Title" Title="模版标题" />
<PropertyColumn Property="c => c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Enabled)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
<Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
菜单列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c => c.Type" Title="模版类型" Width="150px">
@if (context.Type == (int)MessageTemplateType.Message)
{
<AntDesign.Text>站内信</AntDesign.Text>
}
else if (context.Type == (int)MessageTemplateType.Email)
{
<AntDesign.Text>邮件</AntDesign.Text>
}
else if (context.Type == (int)MessageTemplateType.Sms)
{
<AntDesign.Text>短信</AntDesign.Text>
}
</PropertyColumn>
<PropertyColumn Property="c => c.Name" Title="模版名称" />
<PropertyColumn Property="c => c.Key" Title="模版Code" Width="100px" />
<PropertyColumn Property="c => c.Title" Title="模版标题" />
<PropertyColumn Property="c => c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Enabled)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c => c.CreateTime" Title="时间" Width="190px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="160px">
<Space>
<SpaceItem>
<Dropdown Trigger="@(new Trigger[] { Trigger.Click })">
<Overlay>
<Menu>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c => c.CreateTime" Title="时间" Width="190px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="160px">
<Space>
<SpaceItem>
<Dropdown Trigger="@(new Trigger[] { Trigger.Click })">
<Overlay>
<Menu>
<MenuItem>
<a @onclick="(e) => HandleEdit(context)"> <Icon Type="@IconType.Outline.Edit" /> 编辑</a>
</MenuItem>
<MenuDivider />
<MenuItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a> <Icon Type="@IconType.Outline.Delete" /> 删除</a>
</Popconfirm>
</MenuItem>
</Menu>
</Overlay>
<ChildContent>
<a class="ant-dropdown-link" @onclick:preventDefault>
<Icon Type="@IconType.Outline.Menu" />
</a>
</ChildContent>
</Dropdown>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
<Row Justify="RowJustify.End">
<Pagination PageIndex="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
</Row>
</Card>
<MenuItem>
<a @onclick="(e) => HandleEdit(context)"> <Icon Type="@IconType.Outline.Edit" /> 编辑</a>
</MenuItem>
<MenuDivider />
<MenuItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a> <Icon Type="@IconType.Outline.Delete" /> 删除</a>
</Popconfirm>
</MenuItem>
</Menu>
</Overlay>
<ChildContent>
<a class="ant-dropdown-link" @onclick:preventDefault>
<Icon Type="@IconType.Outline.Menu" />
</a>
</ChildContent>
</Dropdown>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination PageIndex="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
</Row>
</Card>
<Modal Title="@("消息模版设置")" Visible="@modalVisible" Width="700" MaskClosable="true" OkText="@("保存")" CancelText="@("取消")" OnOk="@HandleModalOk" OnCancel="@HandleCancel">
<Form Model="@template" @ref="@editForm" LabelCol="new ColLayoutParam { Span = 5 }" WrapperCol="new ColLayoutParam { Span = 15 }" Name="modalForm" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="消息模版类型">
<SimpleSelect DefaultValue="" Style="width:120px;" @bind-Value="@context.Type">
<SelectOptions>
<SimpleSelectOption Value="" Label="请选择消息模版类型"></SimpleSelectOption>
<SimpleSelectOption Value="@(((int)MessageTemplateType.Message).ToString())" Label="站内信"></SimpleSelectOption>
<SimpleSelectOption Value="@(((int)MessageTemplateType.Email).ToString())" Label="邮件模版"></SimpleSelectOption>
<SimpleSelectOption Value="@(((int)MessageTemplateType.Sms).ToString())" Label="短信模版"></SimpleSelectOption>
</SelectOptions>
</SimpleSelect>
</FormItem>
<FormItem Label="消息模版名称">
<Input Placeholder="消息模版名称" @bind-Value="@context.Name" />
</FormItem>
<FormItem Label="模版Code">
<Input Placeholder="模版Code" @bind-Value="@context.Key" Disabled="@(context.Id > 0)" />
</FormItem>
<FormItem Label="消息标题">
<Input Placeholder="消息标题" @bind-Value="@context.Title" />
</FormItem>
<FormItem Label="消息内容">
<TextArea Placeholder="消息内容" @bind-Value="@context.Body" />
</FormItem>
<FormItem Label="状态">
<Checkbox @bind-Value="@context.Enabled" Disabled=false>
启用
</Checkbox>
</FormItem>
</Form>
</Modal>
<Modal Title="@("消息模版设置")" Visible="@modalVisible" Width="700" MaskClosable="true" OkText="@("保存")" CancelText="@("取消")" OnOk="@HandleModalOk" OnCancel="@HandleCancel">
<Form Model="@model" @ref="@editForm" LabelCol="new ColLayoutParam { Span = 5 }" WrapperCol="new ColLayoutParam { Span = 15 }" Name="modalForm" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="消息模版类型">
<SimpleSelect DefaultValue="" Style="width:120px;" @bind-Value="@context.Type">
<SelectOptions>
<SimpleSelectOption Value="" Label="请选择消息模版类型"></SimpleSelectOption>
<SimpleSelectOption Value="@(((int)MessageTemplateType.Message).ToString())" Label="站内信"></SimpleSelectOption>
<SimpleSelectOption Value="@(((int)MessageTemplateType.Email).ToString())" Label="邮件模版"></SimpleSelectOption>
<SimpleSelectOption Value="@(((int)MessageTemplateType.Sms).ToString())" Label="短信模版"></SimpleSelectOption>
</SelectOptions>
</SimpleSelect>
</FormItem>
<FormItem Label="消息模版名称">
<Input Placeholder="消息模版名称" @bind-Value="@context.Name" />
</FormItem>
<FormItem Label="语言">
<Select DataSource="@languages" @bind-Value="@context.LanguageId" ItemValue="p => p.Id" ItemLabel="p => p.Title" Disabled="@(context.Id > 0)">
</Select>
</FormItem>
<FormItem Label="模版Code">
<Input Placeholder="模版Code" @bind-Value="@context.Key" Disabled="@(context.Id > 0)" />
</FormItem>
<FormItem Label="消息标题">
<Input Placeholder="消息标题" @bind-Value="@context.Title" />
</FormItem>
<FormItem Label="消息内容">
<TextArea Placeholder="消息内容" @bind-Value="@context.Body" />
</FormItem>
<FormItem Label="状态">
<Checkbox @bind-Value="@context.Enabled" Disabled=false>
启用
</Checkbox>
</FormItem>
</Form>
</Modal>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[SupplyParameterFromQuery]
int? Page { get; set; }
@@ -147,10 +165,10 @@
Form<MessageTemplateSearch> searchForm = null!;
[SupplyParameterFromForm]
MessageTemplateModel template { get; set; } = new();
MessageTemplateModel model { get; set; } = new();
Form<MessageTemplateModel> editForm = null!;
List<Language> languages = new();
PagingList<MessageTemplate> PagingList = new();
bool loading { get; set; } = true;
bool searchExpand { get; set; } = false;
@@ -166,7 +184,7 @@
{
loadQueryString();
LoadList();
_ = LoadLanguages();
base.OnParametersSet();
}
@@ -177,6 +195,20 @@
search.Key = query.GetQueryString("Key");
}
private async Task LoadLanguages()
{
var url = $"/api/language/enabled";
var apiResult = await HttpService.Get<ApiResult<List<Language>>>(url);
if (apiResult.Success)
{
if (apiResult.Data != null)
{
languages = apiResult.Data;
StateHasChanged();
}
}
}
private async void LoadList()
{
@@ -265,13 +297,13 @@
void OnCreateClick()
{
template = new();
model = new();
modalVisible = true;
}
void HandleEdit(MessageTemplate model)
void HandleEdit(MessageTemplate data)
{
template = model.Adapt<MessageTemplateModel>();
model = data.Adapt<MessageTemplateModel>();
modalVisible = true;
}
@@ -285,18 +317,8 @@
if (editForm.Validate())
{
var result = new ApiResult<string>();
var data = template.Adapt<MessageTemplate>();
if (template.Id > 0)
{
var url = $"api/messagetemplate/edit";
result = await HttpService.Post<ApiResult<string>>(url, data);
}
else
{
var url = $"api/messagetemplate/add";
result = await HttpService.Post<ApiResult<string>>(url, data);
}
var url = $"api/messagetemplate/save";
result = await HttpService.Post<ApiResult<string>>(url, model);
if (result.Code == (int)ResultCode.Success)
{
@@ -314,4 +336,14 @@
{
modalVisible = false;
}
string GetLanuageName(int languageId)
{
var language = languages.FirstOrDefault(l => l.Id == languageId);
if (language != null)
{
return language.Title;
}
return "-";
}
}