重构代码:重新设计网站皮肤逻辑,移除客户端请求api/css接口
This commit is contained in:
parent
9f7e0ab0ba
commit
00e0b0b5e8
|
@ -89,7 +89,7 @@ namespace Bootstrap.Admin.Controllers
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public ActionResult Settings()
|
public ActionResult Settings()
|
||||||
{
|
{
|
||||||
return View(new NavigatorBarModel(this));
|
return View(new ThemeModel(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
using Bootstrap.DataAccess;
|
|
||||||
using Bootstrap.Security;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Bootstrap.Admin.Controllers.Api
|
|
||||||
{
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
public class CssController : Controller
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 获得当前样式接口
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet]
|
|
||||||
[AllowAnonymous]
|
|
||||||
public JsonResult Get()
|
|
||||||
{
|
|
||||||
return new JsonResult(DictHelper.RetrieveActiveCss().FirstOrDefault().Code);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 获得网站所有样式表
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost]
|
|
||||||
public IEnumerable<BootstrapDict> Post()
|
|
||||||
{
|
|
||||||
return DictHelper.RetrieveWebCss();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -14,6 +14,7 @@ namespace Bootstrap.Admin.Models
|
||||||
{
|
{
|
||||||
Title = DictHelper.RetrieveWebTitle();
|
Title = DictHelper.RetrieveWebTitle();
|
||||||
Footer = DictHelper.RetrieveWebFooter();
|
Footer = DictHelper.RetrieveWebFooter();
|
||||||
|
Theme = DictHelper.RetrieveActiveTheme();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
@ -23,5 +24,9 @@ namespace Bootstrap.Admin.Models
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Footer { get; private set; }
|
public string Footer { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string Theme { get; private set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,17 +10,13 @@ namespace Bootstrap.Admin.Models
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProfilesModel : NavigatorBarModel
|
public class ProfilesModel : ThemeModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得/设置 头像文件大小
|
/// 获得/设置 头像文件大小
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long Size { get; }
|
public long Size { get; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得 系统配置的所有样式表
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerable<BootstrapDict> Csss { get; }
|
|
||||||
/// <summary>
|
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="controller"></param>
|
/// <param name="controller"></param>
|
||||||
|
@ -32,8 +28,6 @@ namespace Bootstrap.Admin.Models
|
||||||
{
|
{
|
||||||
Size = new FileInfo(fileName).Length;
|
Size = new FileInfo(fileName).Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
Csss = DictHelper.RetrieveWebCss();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
using Bootstrap.DataAccess;
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.Admin.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class ThemeModel : NavigatorBarModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="controller"></param>
|
||||||
|
public ThemeModel(ControllerBase controller) : base(controller)
|
||||||
|
{
|
||||||
|
Themes = DictHelper.RetrieveThemes();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获得 系统配置的所有样式表
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<BootstrapDict> Themes { get; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -84,7 +84,7 @@
|
||||||
<label class="control-label" for="userName">样式</label>
|
<label class="control-label" for="userName">样式</label>
|
||||||
<select id="css" class="select form-control">
|
<select id="css" class="select form-control">
|
||||||
<option value="">默认样式</option>
|
<option value="">默认样式</option>
|
||||||
@foreach (var css in Model.Csss)
|
@foreach (var css in Model.Themes)
|
||||||
{
|
{
|
||||||
if (css.Code == Model.Css)
|
if (css.Code == Model.Css)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
@model Bootstrap.Admin.Models.NavigatorBarModel
|
@model Bootstrap.Admin.Models.ThemeModel
|
||||||
@{
|
@{
|
||||||
ViewBag.Title = "网站设置";
|
ViewBag.Title = "网站设置";
|
||||||
Layout = "~/Views/Shared/_Admin.cshtml";
|
Layout = "~/Views/Shared/_Admin.cshtml";
|
||||||
|
@ -48,9 +48,21 @@
|
||||||
<form id="CssDataForm" class="form-inline">
|
<form id="CssDataForm" class="form-inline">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button id="dictCssDefine" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="">默认样式</button>
|
<button id="dictCssDefine" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="" value="@Model.Theme">默认样式</button>
|
||||||
<ul class="dropdown-menu" role="menu" id="cssContainer">
|
<ul class="dropdown-menu" role="menu" id="cssContainer">
|
||||||
<li><a href="#" data-val="">默认样式</a></li>
|
<li><a href="#" data-val="">默认样式</a></li>
|
||||||
|
@foreach (var css in Model.Themes)
|
||||||
|
{
|
||||||
|
if (css.Code == Model.Css)
|
||||||
|
{
|
||||||
|
<li><a href="#" data-val="@css.Code">@css.Name</a></li>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<li><a href="#" data-val="@css.Code">@css.Name</a></li>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-secondary" type="button" data-method="css">保存</button>
|
<button class="btn btn-secondary" type="button" data-method="css">保存</button>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
@model Bootstrap.Admin.Models.HeaderBarModel
|
@model ModelBase
|
||||||
<footer class="site-footer">
|
<footer class="site-footer">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<span id="websiteFooter">@Model.Footer</span>
|
<span id="websiteFooter">@Model.Footer</span>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
@model Bootstrap.Admin.Models.HeaderBarModel
|
@model HeaderBarModel
|
||||||
<header class="header">
|
<header class="header">
|
||||||
<div class="bg"></div>
|
<div class="bg"></div>
|
||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
@{
|
@model ModelBase
|
||||||
|
@{
|
||||||
Layout = "~/Views/Shared/_Root.cshtml";
|
Layout = "~/Views/Shared/_Root.cshtml";
|
||||||
}
|
}
|
||||||
@section css {
|
@section css {
|
||||||
|
@ -16,6 +17,10 @@
|
||||||
<link href="~/css/theme-responsive.css" rel="stylesheet" />
|
<link href="~/css/theme-responsive.css" rel="stylesheet" />
|
||||||
<link href="~/css/site.css" rel="stylesheet" />
|
<link href="~/css/site.css" rel="stylesheet" />
|
||||||
<link href="~/css/site-responsive.css" rel="stylesheet" />
|
<link href="~/css/site-responsive.css" rel="stylesheet" />
|
||||||
|
@if (!string.IsNullOrEmpty(Model.Theme))
|
||||||
|
{
|
||||||
|
<link href="~/css/@Model.Theme" rel="stylesheet" />
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@section javascript {
|
@section javascript {
|
||||||
<environment include="Development">
|
<environment include="Development">
|
||||||
|
|
|
@ -257,8 +257,7 @@
|
||||||
|
|
||||||
// Dicts
|
// Dicts
|
||||||
Dicts = {
|
Dicts = {
|
||||||
url: 'api/Dicts/',
|
url: 'api/Dicts/'
|
||||||
css: 'api/Css/',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Profiles
|
// Profiles
|
||||||
|
@ -373,14 +372,3 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
|
||||||
$(function () {
|
|
||||||
// loading customer css
|
|
||||||
$.bc({
|
|
||||||
url: Dicts.css, swal: false, method: 'get',
|
|
||||||
callback: function (result) {
|
|
||||||
if (result.length > 0)
|
|
||||||
$('head').append($.format('<link href="{0}css/{1}" rel="stylesheet" type="text/css" />', $('#pathBase').attr('href'), result));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -117,19 +117,5 @@
|
||||||
listCacheUrl();
|
listCacheUrl();
|
||||||
});
|
});
|
||||||
|
|
||||||
var $css = $('#dictCssDefine');
|
var $css = $('#dictCssDefine').dropdown('val');
|
||||||
$.bc({
|
|
||||||
url: Dicts.css, swal: false,
|
|
||||||
callback: function (result) {
|
|
||||||
var html = result.map(function (ele, index) { return $.format('<li><a href="#" data-val="{1}">{0}</a></li>', ele.Name, ele.Code); }).join('');
|
|
||||||
$('#cssContainer').append(html);
|
|
||||||
$.bc({
|
|
||||||
url: Dicts.css, swal: false, method: 'get',
|
|
||||||
callback: function (result) {
|
|
||||||
if (result.length > 0)
|
|
||||||
$css.val(result).dropdown('val');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
})
|
|
@ -163,7 +163,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获得系统中配置的可以使用的网站样式
|
/// 获得系统中配置的可以使用的网站样式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<BootstrapDict> RetrieveWebCss()
|
public static IEnumerable<BootstrapDict> RetrieveThemes()
|
||||||
{
|
{
|
||||||
var data = RetrieveDicts();
|
var data = RetrieveDicts();
|
||||||
return data.Where(d => d.Category == "网站样式");
|
return data.Where(d => d.Category == "网站样式");
|
||||||
|
@ -172,10 +172,11 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获得网站设置中的当前样式
|
/// 获得网站设置中的当前样式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<BootstrapDict> RetrieveActiveCss()
|
public static string RetrieveActiveTheme()
|
||||||
{
|
{
|
||||||
var data = RetrieveDicts();
|
var data = RetrieveDicts();
|
||||||
return data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0 && !d.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase));
|
var theme = data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0).FirstOrDefault();
|
||||||
|
return theme == null ? string.Empty : (theme.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase) ? string.Empty : theme.Code);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取头像路径
|
/// 获取头像路径
|
||||||
|
|
Loading…
Reference in New Issue