重构代码:根据最新的Longbow.Cache组件更新CacheList.axd?clear=clear,移动跨域缓存中间件移动到角色授权中间件后

This commit is contained in:
Argo-MacBookPro 2018-06-09 17:04:59 +08:00
parent 0d3218dca8
commit 8883e48b61
6 changed files with 32 additions and 20 deletions

View File

@ -62,11 +62,11 @@ namespace Bootstrap.Admin
{
app.UseExceptionHandler("/Home/Error");
}
app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials());
app.UseCors(builder => builder.WithOrigins(Configuration["AllowOrigins"].Split(',', StringSplitOptions.RemoveEmptyEntries)).AllowAnyHeader().AllowAnyMethod().AllowCredentials());
app.UseStaticFiles();
app.UseAuthentication();
app.UseCacheManagerCorsHandler();
app.UseBootstrapRoleAuthorization();
app.UseCacheManagerCorsHandler();
app.UseMvc(routes =>
{
routes.MapRoute(

View File

@ -58,7 +58,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">网站缓存<a id="refreshCache" href="#" class="pull-right fa fa-refresh" title="点击刷新" data-placement="left" role="tooltip"></a></div>
<div class="panel-heading">网站缓存<a data-method="clear" href="#" class="clearcache fa fa-times-circle-o" data-admin="@User.IsInRole("Administrators")" title="全部清除" role="tooltip" data-placement="left"></a><a data-method="refresh" href="#" class="pull-right fa fa-refresh" title="点击刷新" role="tooltip"></a></div>
<div class="panel-body">
<div class="tasks-widget">
<ul id="sortable" class="task-list ui-sortable"></ul>

View File

@ -18,5 +18,6 @@
"DbProviderFactories": {
"sql": "SQLServer"
},
"KeyPath": "C:\\keys"
"KeyPath": "C:\\keys",
"AllowOrigins": "http://localhost:49823"
}

View File

@ -5,15 +5,15 @@
{
"Enabled": true,
"Name": "ba",
"Url": "http://localhost:50852/CacheList.axd?cacheKey={0}",
"Url": "http://localhost:50852/CacheList.axd",
"Desc": "后台管理数据缓存接口",
"Self": true
},
{
"Enabled": true,
"Name": "ba",
"Url": "http://localhost:49823/CacheList.axd?cacheKey={0}",
"Desc": "托盘组垛系统数据缓存接口",
"Name": "Pallet",
"Url": "http://localhost:49823/CacheList.axd",
"Desc": "托盘组垛系统",
"Self": false
}
],

View File

@ -129,8 +129,7 @@
callback: null,
$element: null,
async: true,
toastr: false,
crossDomain: null
toastr: false
}, options);
if (!options.url || options.url === "") {
@ -156,7 +155,6 @@
contentType: options.contentType,
dataType: options.dataType,
async: options.async,
crossDomain: options.crossDomain,
xhrFields: options.xhrFields,
success: function (result) {
success(result);

View File

@ -51,7 +51,7 @@
var $sortable = $('#sortable');
var listCacheUrl = function (options) {
options = $.extend({ key: '' }, options);
options = $.extend({ clear: false }, options);
$sortable.html('');
$.bc({
url: Settings.url,
@ -60,16 +60,17 @@
callback: function (result) {
if (result && $.isArray(result)) {
$.each(result, function (index, item) {
if (options.clear) options.url = item.Url + "?clear=clear";
else options.url = item.Url;
$.bc({
url: $.format(item.Url, options.key),
crossDomain: !item.Self,
url: options.url,
xhrFields: {
withCredentials: !item.Self
withCredentials: true
},
swal: false,
callback: function (result) {
if ($.isArray(result)) {
var html = '<li class="{4}"><i class="fa fa-ellipsis-v"></i><div class="task-title"><span class="task-title-sp" role="tooltip" title="{1}">{2}</span><span class="badge badge-sm label-success">{0}</span><span class="task-value" title="{3}">{3}</span><div class="pull-right hidden-phone"><span>{7}</span><button class="btn btn-danger btn-xs fa fa-trash-o" title="{1}" data-url="{5}" role="tooltip" data-self="{6}" data-placement="left"></button></div></div></li>';
var html = '<li class="{4}"><i class="fa fa-ellipsis-v"></i><div class="task-title"><span class="task-title-sp" role="tooltip" title="{1}">{2}</span><span class="badge badge-sm label-success">{0}</span><span class="task-value" title="{3}">{3}</span><div class="pull-right hidden-phone"><span>{7}</span><button class="btn btn-danger btn-xs fa fa-trash-o" title="{1}" data-url="{5}?cacheKey={1}" role="tooltip" data-self="{6}" data-placement="left"></button></div></div></li>';
var content = result.sort(function (x, y) {
return x.Key > y.Key ? 1 : -1;
}).map(function (ele) {
@ -126,17 +127,29 @@
var listCache = function (options) {
$.bc({
url: options.url,
crossDomain: !options.self,
xhrFields: {
withCredentials: !options.self
withCredentials: true
},
swal: false
});
}
$('#refreshCache').click(function () { listCacheUrl(); }).trigger('click');
$('a[data-method]').on('click', function (e) {
e.preventDefault();
e.stopPropagation();
var $this = $(this);
var options = {};
switch ($this.attr('data-method')) {
case 'clear':
options.clear = true;
break;
case 'refresh':
break;
}
listCacheUrl(options);
}).last().trigger('click');
$sortable.on('click', '.btn', function () {
$(this).lgbTooltip('destroy');
listCache({ self: $(this).attr('data-self') === "true", url: $(this).attr('data-url') });
listCache({ url: $(this).attr('data-url') });
listCacheUrl();
});