@page "/app/product"
@attribute [ReuseTabsPage(Title = "商品管理")]
@inject ModalService ModalService;
@inject ConfirmService ComfirmService;
@inject IMessageService MessageService;
@code {
///
/// 富文本配置项
/// 在这里注册获取key:https://www.tiny.cloud/
///
public static Dictionary TinyMCEConfig { get; set; } = new()
{
// 配置项
{ "language_url", "/lib/tinymce/langs/zh_CN.js" },
{ "language", "zh_CN" },
{ "min_width", 500 },
//{ "max_width", 1000 },
{ "min_height", 500 },
//{ "max_height", 1000 },
{ "plugins", "table image code link lists insertdatetime preview searchreplace wordcount" },
{ "toolbar", "undo redo | searchreplace removeformat | bold italic underline strikethrough subscript superscript | alignleft aligncenter alignright outdent indent blockquote | code codesample | fontsize fontfamily styles forecolor backcolor | hr bullist numlist | link image charmap preview anchor pagebreak insertdatetime table emoticons | fullscreen" },
{ "toolbar_mode", "wrap" },
{ "promotion", false },//关闭升级付费提示
{ "paste_data_images", true },//内存中的图片粘贴为base64文本格式
{ "image_uploadtab", true },
{ "images_file_types", "jpg,jpeg,png,gif" },
{ "images_upload_credentials", "false" },//同域名下基于Cookie鉴权
{ "images_upload_url", Global.UploadUrl },//图片上传地址
};
private void StartEdit(TProduct row)
{
tProduct = row ?? new();
InitFormData(row);
IForm form = default;
modalRef = ModalService.CreateModal(new()
{
Width = "1300px",
Title = tProduct.Id > 0 ? "编辑" : "新增",
Content =
@
,
OnOk = async (e) =>
{
if (!form.Validate())
{
return;
}
if (FileList?.Count == 0)
{
MessageService.Warning("必须上传预览图");
return;
}
modalRef.SetConfirmLoading(true);
var flag = InsertOrUpdate(tProduct);
if (flag)
{
TPropertyItems.Clear();
MessageService.Success("操作成功");
await modalRef.CloseAsync();
_Table.ReloadData(Pi, Ps);
StateHasChanged();
}
else
{
MessageService.Error("操作失败");
}
modalRef.SetConfirmLoading(false);
},
OnCancel = async (e) =>
{
if (form.IsModified && (!await Comfirm("已修改内容,确定退出吗?")))
{
return;
}
await modalRef.CloseAsync();
}
});
modalRef.UpdateConfigAsync();
}
private string GetImageUrl(TProductSku row, string imageUrl)
{
if (!string.IsNullOrEmpty(imageUrl))
{
return imageUrl;
}
else
{
var image = row.Image;
return image;
}
}
private async Task Comfirm(string message)
{
return await ComfirmService.Show(message, "提示", ConfirmButtons.YesNo, ConfirmIcon.Warning) == ConfirmResult.Yes;
}
}