|
|
@@ -1,6 +1,7 @@
|
|
|
@using AI.Platform.Page.Pages.Media.Model
|
|
|
@using System.Threading.Tasks
|
|
|
@using System.Text.Json
|
|
|
+@using System.Net.Http.Headers
|
|
|
|
|
|
@if (IsVisible && Model != null)
|
|
|
{
|
|
|
@@ -86,7 +87,7 @@
|
|
|
<div class="filter_colume">
|
|
|
<div class="filter_row_around">
|
|
|
<span>下发油站</span>
|
|
|
- <SimpleSelect DefaultValue="@Model.BusinessUnitID.ToString()" OnSelectedItemChanged="@(data => OnSelectItemChange(2, data, editContext))" style="width:80%">
|
|
|
+ <SimpleSelect DefaultValue="@Model.BusinessUnitID.ToString()" Disabled="@(Model.Type == 2)" OnSelectedItemChanged="@(data => OnSelectItemChange(2, data, editContext))" style="width:80%">
|
|
|
<SelectOptions>
|
|
|
@foreach (var department in Model.siteInfos)
|
|
|
{
|
|
|
@@ -108,20 +109,25 @@
|
|
|
</div>
|
|
|
|
|
|
@if (Model?.Type == 1)
|
|
|
- {
|
|
|
- <Upload class="filter_row" Name="file" style="justify-content:center" Action="@Global.MediaUploadUrl"
|
|
|
- Headers="uploadFileHeader"
|
|
|
- @bind-FileList="fileList" ListType="UploadListType.PictureCard"
|
|
|
- ShowUploadList="true" ShowDownloadIcon="true" ShowPreviewIcon="true" ShowRemoveIcon="true" ShowButton="fileList.Count < 1"
|
|
|
- OnCompleted="OnUploadCompleted" OnRemove="OnRemove">
|
|
|
- <div>
|
|
|
- <Icon Type="plus" />
|
|
|
- <div className="ant-upload-text">上传文件</div>
|
|
|
+ {
|
|
|
+ <div class="upload_box">
|
|
|
+ <div class="upload-container">
|
|
|
+ <div class="custom-upload-content">
|
|
|
+ <Icon Type="upload" />
|
|
|
+ <div>点击上传文件</div>
|
|
|
+ @if (selectedFile != null)
|
|
|
+ {
|
|
|
+ <div class="file-name">@selectedFile.Name</div>
|
|
|
+ }
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <InputFile OnChange="OnFileSelected"
|
|
|
+ Class="transparent-input-file" />
|
|
|
</div>
|
|
|
- </Upload>
|
|
|
+ </div>
|
|
|
}
|
|
|
|
|
|
- <div class="filter_row" style="justify-content:end;margin-top:5%;">
|
|
|
+ <div class="filter_row" style="justify-content:end;margin-top:1%;">
|
|
|
<button Icon="plus" type="button" @onclick="() => HandleSubmit(editContext)" style="margin-right:2%">确定</button>
|
|
|
<button Icon="reload" @onclick="Close" style="margin-right:2%">取消</button>
|
|
|
</div>
|
|
|
@@ -129,7 +135,13 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ @if (isUploading)
|
|
|
+ {
|
|
|
+ <div style="position: absolute; inset: 0; background: rgba(255,255,255,0.6); z-index: 100;">
|
|
|
+ <Spin Tip="上传中..."
|
|
|
+ Style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);" />
|
|
|
+ </div>
|
|
|
+ }
|
|
|
|
|
|
@if(Model?.Type == 3)
|
|
|
{
|
|
|
@@ -196,9 +208,16 @@
|
|
|
|
|
|
private Dictionary<string, string> uploadFileHeader = new Dictionary<string, string>();
|
|
|
|
|
|
+ [Inject] public HttpClient Http { get; set; } = default!;
|
|
|
+ [Inject] public MessageService Message { get; set; } = default!;
|
|
|
+ private ElementReference inputFileRef;
|
|
|
+ private IBrowserFile? selectedFile;
|
|
|
+ private bool isUploading = false;
|
|
|
+
|
|
|
protected override void OnParametersSet()
|
|
|
{
|
|
|
fileList.Clear();
|
|
|
+ selectedFile = null;
|
|
|
uploadFileHeader["Authorization"] = Global.GetToken();
|
|
|
EffecitiveTime = new DateTime?[]
|
|
|
{
|
|
|
@@ -242,6 +261,70 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void OnFileSelected(InputFileChangeEventArgs e)
|
|
|
+ {
|
|
|
+ // if (e.Value is not IBrowserFile file) return;
|
|
|
+ var siteinfo = Model.siteInfos.Find(it => it.Id == Model.BusinessUnitID);
|
|
|
+ if (siteinfo != null && e.File.Size > siteinfo.MaxSize)
|
|
|
+ {
|
|
|
+ Message.Error("上传文件超过限制大小");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ selectedFile = e.File;
|
|
|
+ Model.FileName = e.File.Name;
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task UploadFile()
|
|
|
+ {
|
|
|
+ if (isUploading || selectedFile == null) return;
|
|
|
+
|
|
|
+ isUploading = true;
|
|
|
+ StateHasChanged();
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ const long maxFileSize = 300 * 1024 * 1024; // 300 MB
|
|
|
+
|
|
|
+ using var stream = selectedFile.OpenReadStream(maxFileSize);
|
|
|
+ using var content = new MultipartFormDataContent();
|
|
|
+
|
|
|
+ content.Add(new StreamContent(stream), "file", selectedFile.Name);
|
|
|
+ content.Add(new StringContent(Model.BusinessUnitID.ToString()), "siteId");
|
|
|
+
|
|
|
+ var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:5076/api/File/UploadMedia")
|
|
|
+ {
|
|
|
+ Content = content
|
|
|
+ };
|
|
|
+ request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Global.Token);
|
|
|
+
|
|
|
+ // 发送请求
|
|
|
+ var httpResponse = await Http.SendAsync(request);
|
|
|
+ httpResponse.EnsureSuccessStatusCode();
|
|
|
+
|
|
|
+ var responseJson = await httpResponse.Content.ReadAsStringAsync();
|
|
|
+ var response = JsonSerializer.Deserialize<Service.Output.Response<Service.Output.MediaFileUploadOutput>>(responseJson);
|
|
|
+
|
|
|
+ Model.FileName = response?.data.fileName ?? "";
|
|
|
+ Model.SavePath = response?.data.savePath ?? "";
|
|
|
+ Model.GuidFileName = response?.data.guidName ?? "";
|
|
|
+ Model.FileExtension = response?.data.extension ?? "";
|
|
|
+
|
|
|
+
|
|
|
+ // Message.Success("上传成功!");
|
|
|
+ // selectedFile = null; // 清空
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Message.Error( $"上传失败: {ex.Message}");
|
|
|
+ Model.FileName = "";
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ isUploading = false;
|
|
|
+ StateHasChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 上传文件完毕
|
|
|
@@ -249,6 +332,7 @@
|
|
|
/// <param name="info"></param>
|
|
|
private void OnUploadCompleted(UploadInfo info)
|
|
|
{
|
|
|
+ // _upload.StartUpload()
|
|
|
string responseJson = info.File.Response;
|
|
|
var response = JsonSerializer.Deserialize<Service.Output.Response<Service.Output.MediaFileUploadOutput>>(responseJson);
|
|
|
|
|
|
@@ -259,6 +343,11 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 文件上传组件——删除事件
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="fileItem"></param>
|
|
|
+ /// <returns></returns>
|
|
|
private async Task<bool> OnRemove(UploadFileItem fileItem)
|
|
|
{
|
|
|
Console.WriteLine(fileItem);
|
|
|
@@ -286,6 +375,12 @@
|
|
|
var siteinfo = Model.siteInfos.Find(it => it.Id.ToString().Equals(value));
|
|
|
if (siteinfo != null)
|
|
|
{
|
|
|
+ if(selectedFile != null && selectedFile.Size > siteinfo.MaxSize)
|
|
|
+ {
|
|
|
+ Message.Error("上传文件超过限制大小");
|
|
|
+ selectedFile = null;
|
|
|
+ Model.FileName = "";
|
|
|
+ }
|
|
|
Model.GroupID = siteinfo.ParentId;
|
|
|
Model.BusinessUnitID = siteinfo.Id;
|
|
|
|
|
|
@@ -311,7 +406,7 @@
|
|
|
{
|
|
|
Model.MachineStateList = values.ToList();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
editContext.NotifyFieldChanged(FieldIdentifier.Create(() => Model.MachineStateList));
|
|
|
}
|
|
|
|
|
|
@@ -349,10 +444,18 @@
|
|
|
|
|
|
private async Task HandleSubmit(EditContext editContext)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
if(editContext.Validate())
|
|
|
{
|
|
|
+ if(Model.BusinessUnitID <= 0)
|
|
|
+ {
|
|
|
+ Message.Error("请绑定油站");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ await UploadFile();
|
|
|
await onSure();
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -437,4 +540,46 @@
|
|
|
width: 100%;
|
|
|
margin-top: 2%;
|
|
|
}
|
|
|
+
|
|
|
+ .upload_box{
|
|
|
+ display:flex;
|
|
|
+ flex-direction:column;
|
|
|
+ justify-content:center;
|
|
|
+ align-items:center;
|
|
|
+ margin-top:1%;
|
|
|
+ }
|
|
|
+
|
|
|
+ .upload-container {
|
|
|
+ position: relative;
|
|
|
+ display: inline-block;
|
|
|
+ width: 50%;
|
|
|
+ height:160px;
|
|
|
+ padding:3%;
|
|
|
+ }
|
|
|
+
|
|
|
+ .custom-upload-content {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ border: 2px dashed #d9d9d9;
|
|
|
+ border-radius: 8px;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ cursor: pointer;
|
|
|
+ background-color: #fafafa;
|
|
|
+ z-index: 1;
|
|
|
+ position: relative;
|
|
|
+ }
|
|
|
+
|
|
|
+ .transparent-input-file {
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ opacity: 0;
|
|
|
+ cursor: pointer;
|
|
|
+ z-index: 2;
|
|
|
+ }
|
|
|
</style>
|