修复后台授权问题,调整后台列表批量操作例子
This commit is contained in:
@@ -424,7 +424,10 @@ namespace COMCMS.Core
|
||||
AdminLog log = AdminLog.FindByGUID(adminLogId);
|
||||
if (log != null)
|
||||
{
|
||||
log.Actions = log.Actions + $"|||{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}: {action}";
|
||||
if (string.IsNullOrEmpty(log.Actions))
|
||||
log.Actions = $"{DateTime.Now:yyyy-MM-dd HH:mm}: {action}";
|
||||
else
|
||||
log.Actions = log.Actions + $"|||{DateTime.Now:yyyy-MM-dd HH:mm}: {action}";
|
||||
log.LastUpdateTime = DateTime.Now;
|
||||
log.Update();
|
||||
|
||||
|
||||
@@ -717,5 +717,51 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||
return Json(tip);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 批量删除文章
|
||||
[HttpPost]
|
||||
[MyAuthorize("batch", "article", "JSON")]
|
||||
public IActionResult DoBatchDelArticle(string ids)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ids))
|
||||
{
|
||||
tip.Message = "请最少选择一篇文章!";
|
||||
return Json(tip);
|
||||
}
|
||||
List<int> listIds = new List<int>();
|
||||
try
|
||||
{
|
||||
listIds = JsonConvert.DeserializeObject<List<int>>(ids);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tip.Message = "转换出错:" + ex.Message;
|
||||
return Json(tip);
|
||||
}
|
||||
|
||||
if (listIds == null || listIds.Count < 1)
|
||||
{
|
||||
tip.Message = "请至少选择一篇文章!";
|
||||
return Json(tip);
|
||||
}
|
||||
|
||||
IList<Article> list = Article.FindAll(Article._.Id.In(listIds), null, null, 0, 0);
|
||||
if (list == null || list.Count < 1)
|
||||
{
|
||||
tip.Message = "请至少选择一篇文章!";
|
||||
return Json(tip);
|
||||
}
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
item.IsHide = 0;
|
||||
}
|
||||
list.Delete();
|
||||
Admin.WriteLogActions($"批量删除文章:{ids};");
|
||||
tip.Message = "批量删除文章成功!";
|
||||
tip.Status = JsonTip.SUCCESS;
|
||||
return Json(tip);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using COMCMS.Common;
|
||||
using COMCMS.Core;
|
||||
using XCode;
|
||||
using Newtonsoft.Json;
|
||||
using COMCMS.Web.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using COMCMS.Web.Models;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using COMCMS.Core.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.IO;
|
||||
|
||||
namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||
{
|
||||
public class AttachController : AdminBaseController
|
||||
{
|
||||
private readonly SystemSetting _attachsetting;
|
||||
private IWebHostEnvironment _env;
|
||||
private AttachConfigEntity attach;
|
||||
public AttachController(IWebHostEnvironment env, IOptions<SystemSetting> attachsetting)
|
||||
{
|
||||
attach = Config.GetSystemConfig().AttachConfigEntity;
|
||||
_env = env;
|
||||
_attachsetting = attachsetting.Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 附件管理
|
||||
[HttpGet]
|
||||
[MyAuthorize("viewlist", "attach")]
|
||||
public IActionResult AttachList()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取附件所有目录
|
||||
[HttpPost]
|
||||
[MyAuthorize("viewlist", "attach","JSON")]
|
||||
public IActionResult GetDirList(string subdir)
|
||||
{
|
||||
string attachPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}";
|
||||
|
||||
|
||||
|
||||
//Directory.GetDirectories()
|
||||
return Json(tip);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||
return Json(errorJson);
|
||||
}
|
||||
//判断是否是图片类型
|
||||
List<string> imgtypelist = new List<string> { "image/pjpeg", "image/png", "image/x-png", "image/gif", "image/bmp", "image/jpeg" };
|
||||
List<string> imgtypelist = new List<string> { "image/jpg", "image/png", "image/x-png", "image/gif", "image/bmp", "image/jpeg" };
|
||||
if (imgtypelist.FindIndex(x => x == upload.ContentType) == -1)
|
||||
{
|
||||
errorJson.error.message = "请选择一张图片!";
|
||||
@@ -244,7 +244,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||
//判断是否是图片,如果是图片,后面需要生成缩略图并可能的话,就加上水印
|
||||
bool isImage = false;
|
||||
//判断是否是图片类型
|
||||
List<string> imgtypelist = new List<string> { "image/pjpeg", "image/png", "image/x-png", "image/gif", "image/bmp" };
|
||||
List<string> imgtypelist = new List<string> { "image/jpg", "image/png", "image/x-png", "image/gif", "image/bmp", "image/jpeg" };
|
||||
if (imgtypelist.FindIndex(x => x == upload.ContentType) >= 0)
|
||||
{
|
||||
isImage = true;
|
||||
@@ -556,7 +556,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||
if (data != null)
|
||||
{
|
||||
//判断是否是图片类型
|
||||
List<string> imgtypelist = new List<string> { "image/pjpeg", "image/png", "image/x-png", "image/gif", "image/bmp", "image/jpeg" };
|
||||
List<string> imgtypelist = new List<string> { "image/jpg", "image/png", "image/x-png", "image/gif", "image/bmp", "image/jpeg" };
|
||||
if (imgtypelist.FindIndex(x => x == data.ContentType) == -1)
|
||||
{
|
||||
msg = "只能上传一张图片格式文件!";
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="ibox-content">
|
||||
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "addArticleForm", @class = "form-horizontal m-t" }))
|
||||
{
|
||||
<form asp-action="AddArticle" asp-controller="Article" asp-area="AdminCP" method="post" class="form-horizontal m-t" id="addArticleForm">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">文章栏目:</label>
|
||||
<div class="col-sm-8">
|
||||
@@ -156,7 +155,7 @@
|
||||
<button class="btn btn-default" type="button" onclick="closethisdialog();"><i class="fa fa-close"></i> 取消 </button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -42,20 +42,16 @@
|
||||
</button>
|
||||
}
|
||||
<button id="btn_edit" type="button" class="btn btn-outline btn-default" onclick="top.showDialog('addarticle','批量迁移文章','/AdminCP/Article/MoveArticle',0,0)">
|
||||
<span class="glyphicon glyphicon-move" aria-hidden="true"></span> 批量迁移
|
||||
<span class="glyphicon glyphicon-move" aria-hidden="true"></span> 文章迁移
|
||||
</button>
|
||||
<button id="btn_delete" type="button" class="btn btn-outline btn-default" onclick="doBatchHide()">
|
||||
<span class="glyphicon glyphicon-eye-close" aria-hidden="true"></span> 批量隐藏
|
||||
<button id="btn_delete" type="button" class="btn btn-outline btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
批量处理 <span class="caret"></span>
|
||||
</button>
|
||||
<button id="btn_delete" type="button" class="btn btn-outline btn-default" onclick="doBatchShow()">
|
||||
<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span> 批量显示
|
||||
</button>
|
||||
@*<button id="btn_edit" type="button" class="btn btn-outline btn-default">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
|
||||
</button>
|
||||
<button id="btn_delete" type="button" class="btn btn-outline btn-default">
|
||||
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
|
||||
</button>*@
|
||||
<ul class="dropdown-menu dropdown-menu-left">
|
||||
<li><a href="javascript:;" onclick="doBatchAction('/AdminCP/Article/DoBatchHideArticle','隐藏')"><i class="fa fa-eye-slash"></i> 批量隐藏</a></li>
|
||||
<li><a href="javascript:;" onclick="doBatchAction('/AdminCP/Article/DoBatchShowArticle','显示')"><i class="fa fa-eye"></i> 批量显示</a></li>
|
||||
<li><a href="javascript:;" onclick="doBatchAction('/AdminCP/Article/DoBatchDelArticle','删除')"><i class="fa fa-close"></i> 批量删除</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<table id="tb_departments"></table>
|
||||
|
||||
@@ -106,7 +102,7 @@
|
||||
pageNumber: 1, //初始化加载第一页,默认第一页
|
||||
pageSize: 25, //每页的记录行数(*)
|
||||
pageList: [10, 25, 50, 100], //可供选择的每页的行数(*)
|
||||
search: true, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
|
||||
search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
|
||||
strictSearch: true,
|
||||
showColumns: true, //是否显示所有的列
|
||||
showRefresh: true, //是否显示刷新按钮
|
||||
@@ -164,8 +160,9 @@
|
||||
var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的
|
||||
limit: params.limit, //页面大小
|
||||
page: (params.offset / params.limit)+1, //页码
|
||||
kid:$("#kid").val(),
|
||||
departmentname: $("#keyword").val()
|
||||
kid: $("#kid").val(),
|
||||
keyword: $("#keyword").val(),
|
||||
isshowsub: $("#isshowsub").prop("checked") ? 1 : 0
|
||||
};
|
||||
return temp;
|
||||
};
|
||||
@@ -213,92 +210,6 @@
|
||||
|
||||
return oInit;
|
||||
};
|
||||
function doBatchHide() {
|
||||
var list = $('#tb_departments').bootstrapTable('getAllSelections');
|
||||
var ids = [];
|
||||
if (!list || list.length <1) {
|
||||
layer.alert("请至少选择一篇文章!", { icon: 2 });
|
||||
return false;
|
||||
}
|
||||
list.map(function (item, index) {
|
||||
if (item.id) {
|
||||
ids.push(item.id);
|
||||
}
|
||||
})
|
||||
//alert(JSON.stringify(ids));
|
||||
//执行操作
|
||||
var loading = layer.load(0, {
|
||||
shade: [0.2, '#000'] //0.1透明度的背景
|
||||
});
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/AdminCP/Article/DoBatchHideArticle",
|
||||
data: { ids: JSON.stringify(ids)},
|
||||
dataType: "JSON",
|
||||
success: function (data) {
|
||||
if (data.status == "success") {
|
||||
layer.close(loading);
|
||||
layer.msg(data.message, {
|
||||
time: 1000 //2秒关闭(如果不配置,默认是3秒)
|
||||
}, function () {
|
||||
doSearch();
|
||||
});
|
||||
} else {
|
||||
layer.close(loading);
|
||||
layer.alert(data.message, { icon: 2 });
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
layer.close(loading);
|
||||
layer.alert('执行错误,请联系管理员!', { icon: 2 });
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function doBatchShow() {
|
||||
var list = $('#tb_departments').bootstrapTable('getAllSelections');
|
||||
var ids = [];
|
||||
if (!list || list.length <1) {
|
||||
//alert('请至少选择一行!');
|
||||
layer.alert("请至少选择一篇文章!", { icon: 2 });
|
||||
return false;
|
||||
}
|
||||
list.map(function (item, index) {
|
||||
if (item.id) {
|
||||
ids.push(item.id);
|
||||
}
|
||||
})
|
||||
//alert(JSON.stringify(ids));
|
||||
//执行操作
|
||||
var loading = layer.load(0, {
|
||||
shade: [0.2, '#000'] //0.1透明度的背景
|
||||
});
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/AdminCP/Article/DoBatchShowArticle",
|
||||
data: { ids: JSON.stringify(ids)},
|
||||
dataType: "JSON",
|
||||
success: function (data) {
|
||||
if (data.status == "success") {
|
||||
layer.close(loading);
|
||||
layer.msg(data.message, {
|
||||
time: 1000 //2秒关闭(如果不配置,默认是3秒)
|
||||
}, function () {
|
||||
doSearch();
|
||||
});
|
||||
} else {
|
||||
layer.close(loading);
|
||||
layer.alert(data.message, { icon: 2 });
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
layer.close(loading);
|
||||
layer.alert('执行错误,请联系管理员!', { icon: 2 });
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -26,12 +26,12 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- 全局js -->
|
||||
<script src="~/static/hplus/js/bootstrap.min.js"></script>
|
||||
<script src="~/static/js/jquery.form.min.js"></script>
|
||||
<script src="~/static/js/validate/jquery.validate.min.js"></script>
|
||||
<script src="~/static/js/validate/messages_zh.min.js"></script>
|
||||
<script src="~/static/js/jquery.metadata.js"></script>
|
||||
<script src="~/static/js/layer/layer.js"></script>
|
||||
<script src="~/static/js/rtpost.js"></script>
|
||||
<script src="~/hplus/js/bootstrap.min.js"></script>
|
||||
<script src="~/js/jquery.form.min.js"></script>
|
||||
<script src="~/js/validate/jquery.validate.min.js"></script>
|
||||
<script src="~/js/validate/messages_zh.min.js"></script>
|
||||
<script src="~/js/jquery.metadata.js"></script>
|
||||
<script src="~/js/layer/layer.js"></script>
|
||||
<script src="~/js/rtpost.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -22,7 +22,7 @@
|
||||
<script src="~/js/validation/messages_zh.js"></script>
|
||||
<script src="~/js/layer/layer.js"></script>
|
||||
<script src="~/js/jquery.form.js"></script>
|
||||
<script src="~/js/rtpost.js"></script>
|
||||
<script src="~/js/rtpost.js" asp-append-version="true"></script>
|
||||
<script src="~/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
|
||||
<script src="~/hplus/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
|
||||
<script src="~/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
|
||||
@@ -38,23 +38,13 @@
|
||||
<script src="~/js/bootstrap-colorpicker/js/bootstrap-colorpicker.js"></script>
|
||||
</environment>
|
||||
<environment names="Staging,Production">
|
||||
<script src="https://cdn.staticfile.org/jquery/2.2.4/jquery.min.js"
|
||||
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
|
||||
asp-fallback-test="window.jQuery"
|
||||
crossorigin="anonymous"
|
||||
integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk">
|
||||
</script>
|
||||
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"
|
||||
asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
|
||||
asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
|
||||
crossorigin="anonymous"
|
||||
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa">
|
||||
</script>
|
||||
<script src="~/lib/jquery/dist/jquery.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
|
||||
<script src="~/js/validation/jquery.validate.min.js"></script>
|
||||
<script src="~/js/validation/messages_zh.min.js"></script>
|
||||
<script src="~/js/layer/layer.js"></script>
|
||||
<script src="~/js/jquery.form.min.js"></script>
|
||||
<script src="~/js/rtpost.js"></script>
|
||||
<script src="~/js/rtpost.js" asp-append-version="true"></script>
|
||||
<script src="~/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
|
||||
<script src="~/hplus/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
|
||||
<script src="~/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace COMCMS.Web.Common
|
||||
/// <summary>
|
||||
/// 后台授权过滤器
|
||||
/// </summary>
|
||||
public class MyAuthorizeAttribute : ResultFilterAttribute
|
||||
public class MyAuthorizeAttribute : Attribute, IAuthorizationFilter
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜单key
|
||||
@@ -35,7 +35,7 @@ namespace COMCMS.Web.Common
|
||||
_returnType = !string.IsNullOrWhiteSpace(returnType) && returnType.ToLower() == "json" ? "JSON" : "HTML";
|
||||
}
|
||||
|
||||
public override void OnResultExecuting(ResultExecutingContext context)
|
||||
public void OnAuthorization(AuthorizationFilterContext context)
|
||||
{
|
||||
bool isOK = false;
|
||||
if (Admin.IsAdminLogin())
|
||||
@@ -89,7 +89,7 @@ namespace COMCMS.Web.Common
|
||||
}
|
||||
}
|
||||
}
|
||||
base.OnResultExecuting(context);
|
||||
//base.OnResultExecuting(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//所有异步提交 formId 不需要加上# last:2015-11-12 by Hogen Wang
|
||||
//所有异步提交 formId 不需要加上# last:2020-07-15 by Hogen Wang
|
||||
//依赖jquery jquery.form jquery.validate jquery.metadata
|
||||
function DoPost(formId, rules, messages) {
|
||||
//提交地址
|
||||
@@ -348,4 +348,60 @@ function DoAdminLogin(formId, rules, messages) {
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//后台列表执行批量操作
|
||||
function doBatchAction(url, title) {
|
||||
var list = $('#tb_departments').bootstrapTable('getAllSelections');
|
||||
var ids = [];
|
||||
if (!list || list.length < 1) {
|
||||
layer.alert("请至少选择一条记录!", { icon: 2 });
|
||||
return false;
|
||||
}
|
||||
list.map(function (item, index) {
|
||||
if (item.id) {
|
||||
ids.push(item.id);
|
||||
}
|
||||
})
|
||||
|
||||
layer.confirm('确认要执行批量' + title + '吗?', {
|
||||
icon: 3,
|
||||
title: '系统提示',
|
||||
btn: ['确定', '取消 '] //按钮
|
||||
}, function () {
|
||||
var loading = layer.load(0, {
|
||||
shade: [0.2, '#000'] //0.1透明度的背景
|
||||
});
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
data: { ids: JSON.stringify(ids) },
|
||||
dataType: "JSON",
|
||||
success: function (data) {
|
||||
if (data.status == "success") {
|
||||
layer.close(loading);
|
||||
layer.msg(data.message, {
|
||||
time: 1000 //2秒关闭(如果不配置,默认是3秒)
|
||||
}, function () {
|
||||
//执行重新载入
|
||||
if (doSearch) {
|
||||
doSearch();
|
||||
} else {
|
||||
refreshCurrentTab();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
layer.close(loading);
|
||||
layer.alert(data.message, { icon: 2 });
|
||||
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
layer.close(loading);
|
||||
layer.alert('执行错误,请联系管理员!', { icon: 2 });
|
||||
}
|
||||
});
|
||||
}, function () {
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user