修改BUG:个人中心头像无法删除 closed #ITBVU
#Issue https://gitee.com/LongbowEnterprise/BootstrapAdmin/issues/ITBVU
This commit is contained in:
parent
301fdf6dba
commit
07accedcfb
|
@ -15,9 +15,63 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
[ApiController]
|
||||
public class ProfilesController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除头像按钮调用
|
||||
/// </summary>
|
||||
/// <param name="id">Delete</param>
|
||||
/// <param name="env"></param>
|
||||
/// <param name="files">表单数据集合</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("{id}")]
|
||||
public JsonResult Post(string id, [FromServices]IHostingEnvironment env, [FromForm]DeleteFileCollection files)
|
||||
{
|
||||
if (!id.Equals("Delete", StringComparison.OrdinalIgnoreCase) || files.Key.Equals("default.jpg", StringComparison.OrdinalIgnoreCase)) return new JsonResult(new object());
|
||||
|
||||
var previewUrl = string.Empty;
|
||||
long fileSize = 0;
|
||||
var userName = User.Identity.Name;
|
||||
var error = string.Empty;
|
||||
var fileName = files.Key;
|
||||
|
||||
fileName = Path.Combine(env.WebRootPath, $"images{Path.DirectorySeparatorChar}uploader{Path.DirectorySeparatorChar}{fileName}");
|
||||
try
|
||||
{
|
||||
if (System.IO.File.Exists(fileName)) System.IO.File.Delete(fileName);
|
||||
fileName = "default.jpg";
|
||||
var webSiteUrl = DictHelper.RetrieveIconFolderPath();
|
||||
var fileUrl = string.Format("{0}{1}", webSiteUrl, fileName);
|
||||
var filePath = Path.Combine(env.WebRootPath, webSiteUrl.Replace("~", string.Empty).Replace('/', Path.DirectorySeparatorChar).TrimStart(Path.DirectorySeparatorChar) + fileName);
|
||||
fileSize = new FileInfo(filePath).Length;
|
||||
previewUrl = string.Format("{0}?q={1}", Url.Content(fileUrl), DateTime.Now.Ticks);
|
||||
UserHelper.SaveUserIconByName(userName, fileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.Message;
|
||||
}
|
||||
|
||||
return new JsonResult(new
|
||||
{
|
||||
error = string.IsNullOrEmpty(error) ? error : $"服务器端错误-{error}",
|
||||
initialPreview = new string[] { previewUrl },
|
||||
initialPreviewConfig = new object[] {
|
||||
new { caption = "现在头像", size = fileSize, showZoom = true, key = "default.jpg" }
|
||||
},
|
||||
append = false
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class DeleteFileCollection
|
||||
{
|
||||
public string Key { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传头像按钮调用
|
||||
/// </summary>
|
||||
/// <param name="env"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <returns></returns>
|
||||
|
@ -47,25 +101,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
previewUrl = string.Format("{0}?q={1}", Url.Content(fileUrl), DateTime.Now.Ticks);
|
||||
UserHelper.SaveUserIconByName(userName, fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// delete file
|
||||
fileName = files["key"];
|
||||
if (!fileName.Equals("default.jpg"))
|
||||
{
|
||||
fileName = Path.Combine(env.WebRootPath, $"images{Path.DirectorySeparatorChar}uploader{Path.DirectorySeparatorChar}{fileName}");
|
||||
try
|
||||
{
|
||||
if (System.IO.File.Exists(fileName)) System.IO.File.Delete(fileName);
|
||||
fileName = "default.jpg";
|
||||
UserHelper.SaveUserIconByName(userName, fileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new JsonResult(new
|
||||
{
|
||||
error = string.IsNullOrEmpty(error) ? error : $"服务器端错误-{error}",
|
||||
|
|
|
@ -230,7 +230,8 @@ $(function () {
|
|||
|
||||
// Profiles
|
||||
Profiles = {
|
||||
url: 'api/Profiles'
|
||||
url: 'api/Profiles',
|
||||
del: 'api/Profiles/Delete'
|
||||
};
|
||||
|
||||
// Settings
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
var defFileName = $file.attr('data-file');
|
||||
$file.fileinput({
|
||||
uploadUrl: $.formatUrl(Profiles.url),
|
||||
deleteUrl: $.formatUrl(Profiles.url),
|
||||
deleteUrl: $.formatUrl(Profiles.del),
|
||||
browseOnZoneClick: true,
|
||||
theme: 'fa',
|
||||
language: 'zh',
|
||||
|
|
|
@ -226,7 +226,7 @@ namespace Bootstrap.DataAccess
|
|||
public static bool SaveUserCssByName(string userName, string cssName)
|
||||
{
|
||||
var ret = DbContextManager.Create<User>().SaveUserCssByName(userName, cssName);
|
||||
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{UserHelper.RetrieveUsersDataKey}*");
|
||||
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue