fix(#I1BF4I): 网站设置增加前台标题与页脚设置

#Comment
comment #I1BF4I

#Issue
close https://gitee.com/LongbowEnterprise/dashboard/issues?id=I1BF4I
This commit is contained in:
Argo Zhang 2020-03-12 15:04:44 +08:00
parent 459a55f658
commit 9a407f2293
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
7 changed files with 239 additions and 32 deletions

View File

@ -1,4 +1,5 @@
using Bootstrap.DataAccess; using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Bootstrap.Security; using Bootstrap.Security;
using Longbow.Cache; using Longbow.Cache;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -34,16 +35,29 @@ namespace Bootstrap.Admin.Controllers.Api
public bool Post(string id, [FromBody]BootstrapDict dict) => id switch public bool Post(string id, [FromBody]BootstrapDict dict) => id switch
{ {
"Demo" => DictHelper.UpdateSystemModel(dict.Code == "1", dict.Name), "Demo" => DictHelper.UpdateSystemModel(dict.Code == "1", dict.Name),
"AppPath" => DictHelper.SaveAppSettings(dict),
_ => false _ => false
}; };
/// <summary>
/// 保存前台应用时调用
/// </summary>
/// <returns></returns>
[HttpPut()]
public bool Put([FromBody]QueryAppOption option) => option.Save();
/// <summary> /// <summary>
/// 获取网站缓存站点集合 /// 获取网站缓存站点集合
/// </summary> /// </summary>
[HttpGet] [HttpGet]
public IEnumerable<ICacheCorsItem> Get() => CacheManager.CorsSites; public IEnumerable<ICacheCorsItem> Get() => CacheManager.CorsSites;
/// <summary>
/// 通过指定 AppKey 获取前台应用配置信息
/// </summary>
/// <param name="key"></param>
[HttpGet("{key}")]
public QueryAppOption Get(string key) => QueryAppOption.RetrieveByKey(key);
/// <summary> /// <summary>
/// 删除指定键值的前台应用配置信息 /// 删除指定键值的前台应用配置信息
/// </summary> /// </summary>

View File

@ -0,0 +1,68 @@
using System.Linq;
using Bootstrap.DataAccess;
namespace Bootstrap.Admin.Query
{
/// <summary>
/// 前台应用查询类
/// </summary>
public class QueryAppOption
{
/// <summary>
/// 应用操作 new 为新建 edit 为保存
/// </summary>
/// <value></value>
public string AppId { get; set; } = "edit";
/// <summary>
/// 应用名称
/// </summary>
public string AppName { get; set; } = "";
/// <summary>
/// 应用编码
/// </summary>
public string AppCode { get; set; } = "";
/// <summary>
/// 前台应用路径
/// </summary>
public string AppUrl { get; set; } = "#";
/// <summary>
/// 前台应用标题
/// </summary>
public string AppTitle { get; set; } = "未设置";
/// <summary>
/// 前台应用页脚
/// </summary>
public string AppFooter { get; set; } = "未设置";
/// <summary>
/// 保存前台应用方法
/// </summary>
/// <returns></returns>
public bool Save()
{
var ret = DictHelper.SaveAppSettings(AppCode, AppName, AppUrl, AppTitle, AppFooter, AppId == "edit");
return true;
}
/// <summary>
/// 通过指定 AppKey 获取前台应用配置信息
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static QueryAppOption RetrieveByKey(string key)
{
var ret = new QueryAppOption() { AppCode = key };
var dicts = DictHelper.RetrieveDicts();
ret.AppName = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == key).Name ?? "";
ret.AppUrl = dicts.FirstOrDefault(d => d.Category == "应用首页" && d.Name == key).Code ?? "";
ret.AppTitle = dicts.FirstOrDefault(d => d.Category == ret.AppName && d.Name == "网站标题").Code ?? "";
ret.AppFooter = dicts.FirstOrDefault(d => d.Category == ret.AppName && d.Name == "网站页脚").Code ?? "";
return ret;
}
}
}

View File

@ -83,13 +83,13 @@
<div class="row" id="appList"> <div class="row" id="appList">
@foreach (var app in Model.Apps) @foreach (var app in Model.Apps)
{ {
<div class="form-group col-12" data-toggle="LgbValidate" data-valid-button="[data-method='saveApp']"> <div class="form-group col-12 app" data-key="@app.Key">
<label class="control-label" for="@app.Key">@app.Name</label> <label class="control-label" for="@app.Key">@app.Name</label>
<div class="input-group flex-fill"> <div class="input-group flex-fill">
<input id="@app.Key" class="form-control" placeholder="请输入应用首页2000字以内" value="@app.Url" maxlength="2000" data-valid="true" /> <input id="@app.Key" class="form-control" value="@app.Url" readonly />
<div class="input-group-append" asp-condition="@(!Model.IsDemo)"> <div class="input-group-append" asp-condition="@(!Model.IsDemo)">
<button class="btn btn-danger" type="button" data-key="@app.Key" data-method="delApp"><i class="fa fa-trash-o"></i><span>删除</span></button> <button class="btn btn-danger" type="button" data-key="@app.Key" data-method="delApp"><i class="fa fa-trash-o"></i><span>删除</span></button>
<button class="btn btn-secondary" type="button" data-key="@app.Key" data-method="saveApp"><i class="fa fa-save"></i><span>保存</span></button> <button class="btn btn-primary" type="button" data-key="@app.Key" data-method="editApp"><i class="fa fa fa-pencil"></i><span>编辑</span></button>
</div> </div>
</div> </div>
</div> </div>
@ -331,6 +331,7 @@
<form class="form-inline"> <form class="form-inline">
<div class="row"> <div class="row">
<div class="form-group col-sm-6"> <div class="form-group col-sm-6">
<input hidden id="appId" value />
<label class="control-label" for="appKey">应用ID</label> <label class="control-label" for="appKey">应用ID</label>
<input type="text" class="form-control" id="appKey" placeholder="不可为空50字以内" maxlength="50" data-valid="true" /> <input type="text" class="form-control" id="appKey" placeholder="不可为空50字以内" maxlength="50" data-valid="true" />
</div> </div>
@ -343,6 +344,14 @@
<label class="control-label" for="appUrl">应用首页</label> <label class="control-label" for="appUrl">应用首页</label>
<input type="text" class="form-control flex-fill" id="appUrl" placeholder="不可为空2000字以内" maxlength="2000" data-valid="true" /> <input type="text" class="form-control flex-fill" id="appUrl" placeholder="不可为空2000字以内" maxlength="2000" data-valid="true" />
</div> </div>
<div class="form-group col-sm-12">
<label class="control-label" for="appTitle">网站标题</label>
<input type="text" class="form-control flex-fill" id="appTitle" placeholder="不可为空50字以内" maxlength="50" data-valid="true" />
</div>
<div class="form-group col-sm-12">
<label class="control-label" for="appFooter">网站页脚</label>
<input type="text" class="form-control flex-fill" id="appFooter" placeholder="不可为空50字以内" maxlength="50" data-valid="true" />
</div>
</div> </div>
</form> </form>
</div> </div>

View File

@ -161,34 +161,57 @@ $(function () {
}); });
break; break;
case 'addApp': case 'addApp':
$('#appKey').val(''); $('#appKey').val('').removeAttr('readonly');
$('#appName').val(''); $('#appName').val('').removeAttr('readonly');
$('#appUrl').val(''); $('#appUrl').val('');
$('#appTitle').val('');
$('#appFooter').val('');
$('#appId').val('new');
$dialog.modal('show'); $dialog.modal('show');
break; break;
case 'saveApp':
var appPath = $(this).parents('.input-group').find(':text').val();
var appKey = $(this).attr('data-key');
var appName = $(this).parents('.input-group').prev().text();
$.bc({
url: Settings.url + '/AppPath', data: { category: appName, name: appKey, code: appPath, define: 0 }, title: "保存" + appName, method: "post"
});
break;
case 'saveNewApp': case 'saveNewApp':
var appPath = $('#appUrl').val(); var appPath = $('#appUrl').val();
var appKey = $('#appKey').val(); var appKey = $('#appKey').val();
var appName = $('#appName').val(); var appName = $('#appName').val();
var appTitle = $('#appTitle').val();
var appFooter = $('#appFooter').val();
var appId = $('#appId').val();
$.bc({ $.bc({
url: Settings.url + '/AppPath', data: { category: appName, name: appKey, code: appPath }, title: "保存" + appName, method: "post", url: Settings.url, data: { AppName: appName, AppCode: appKey, AppUrl: appPath, AppTitle: appTitle, AppFooter: appFooter, AppId: appId }, title: "保存" + appName, method: "put",
callback: function (result) { callback: function (result) {
if (result) { if (result) {
$dialog.modal('hide'); $dialog.modal('hide');
// 保存成功创建新 dom if (appId === 'new') {
var segment = $.format('<div class="form-group col-12" data-toggle="LgbValidate" data-valid-button="[data-method=\'saveApp\']"><label class="control-label" for="{0}">{1}</label> <div class="input-group flex-fill"><input id="{0}" class="form-control" placeholder="请输入应用首页2000字以内" value="{2}" maxlength="2000" data-valid="true" /><div class="input-group-append"> <button class="btn btn-danger" type="button" data-key="{0}" data-method="delApp"><i class="fa fa-trash-o"></i><span>删除</span></button><button class="btn btn-secondary" type="button" data-key="{0}" data-method="saveApp"><i class="fa fa-save"></i><span>保存</span></button></div></div></div>', appKey, appName, appPath); // 保存成功创建新 dom
var segment = $.format('<div class="form-group col-12 app" data-key="{0}"><label class="control-label" for="{0}">{1}</label><div class="input-group flex-fill"><input id="{0}" class="form-control" placeholder="请输入应用首页2000字以内" value="{2}" maxlength="2000" data-valid="true" /><div class="input-group-append"><button class="btn btn-danger" type="button" data-key="{0}" data-method="delApp"><i class="fa fa-trash-o"></i><span>删除</span></button><button class="btn btn-primary" type="button" data-key="{0}" data-method="editApp"><i class="fa fa fa-pencil"></i><span>编辑</span></button></div></div></div>', appKey, appName, appPath);
// append dom // append dom
$('#appList').append($(segment)); $('#appList').append($(segment));
}
else {
// update
$('#' + appKey).val(appPath);
}
}
}
});
break;
case 'editApp':
$('#appId').val('edit');
$('#appKey').attr('readonly', true);
$('#appName').attr('readonly', true);
var appKey = $(this).parents('.app').attr('data-key');
$.bc({
url: Settings.url, id: appKey, method: 'get',
callback: function (result) {
if (result) {
$('#appUrl').val(result.AppUrl);
$('#appKey').val(result.AppCode);
$('#appName').val(result.AppName);
$('#appTitle').val(result.AppTitle);
$('#appFooter').val(result.AppFooter);
$dialog.modal('show');
} }
} }
}); });

View File

@ -53,7 +53,7 @@ namespace Bootstrap.DataAccess
public virtual bool SaveSettings(IEnumerable<BootstrapDict> dicts) public virtual bool SaveSettings(IEnumerable<BootstrapDict> dicts)
{ {
using var db = DbManager.Create(); using var db = DbManager.Create();
dicts.ToList().ForEach(dict => db.Update<BootstrapDict>("set Code = @Code where Category = @Category and Name = @Name", dict)); dicts.ToList().ForEach(dict => db.Update<Dict>("set Code = @Code where Category = @Category and Name = @Name", dict));
return true; return true;
} }

View File

@ -394,24 +394,43 @@ namespace Bootstrap.DataAccess
/// <summary> /// <summary>
/// 保存前台应用配置信息 /// 保存前台应用配置信息
/// </summary> /// </summary>
/// <param name="dict"></param> /// <param name="appKey"></param>
/// <param name="appName"></param>
/// <param name="appUrl"></param>
/// <param name="appTitle"></param>
/// <param name="appFooter"></param>
/// <param name="update"></param>
/// <returns></returns> /// <returns></returns>
public static bool SaveAppSettings(BootstrapDict dict) public static bool SaveAppSettings(string appKey, string appName, string appUrl, string appTitle, string appFooter, bool update)
{ {
// dict define == 1 时为新建前台应用 // dict define == 1 时为新建前台应用
bool ret; bool ret;
// 前台网站配置地址 不允许以 / 结尾 // 前台网站配置地址 不允许以 / 结尾
dict.Code = dict.Code.TrimEnd('/'); appUrl = appUrl.TrimEnd('/');
if (dict.Define == 0) if (update)
{ {
// Update // Update
ret = SaveSettings(new BootstrapDict[] { ret = SaveSettings(new BootstrapDict[] {
new BootstrapDict()
{
Category = appName,
Name = "网站标题",
Code = appTitle,
Define = 1
},
new BootstrapDict()
{
Category = appName,
Name = "网站页脚",
Code = appFooter,
Define = 1
},
new BootstrapDict() new BootstrapDict()
{ {
Category = "应用首页", Category = "应用首页",
Name = dict.Name, Name = appKey,
Code = dict.Code, Code = appUrl,
Define = 0 Define = 0
} }
}); });
@ -421,17 +440,52 @@ namespace Bootstrap.DataAccess
ret = Save(new BootstrapDict() ret = Save(new BootstrapDict()
{ {
Category = "应用程序", Category = "应用程序",
Name = dict.Category, Name = appName,
Code = dict.Name, Code = appKey,
Define = 0 Define = 0
}); });
if (ret) ret = Save(new BootstrapDict() if (ret) ret = Save(new BootstrapDict()
{ {
Category = "应用首页", Category = "应用首页",
Name = dict.Name, Name = appKey,
Code = dict.Code, Code = appUrl,
Define = 0 Define = 0
}); });
if (ret) ret = Save(new BootstrapDict()
{
Category = appName,
Name = "网站标题",
Code = appTitle,
Define = 1
});
if (ret) ret = Save(new BootstrapDict()
{
Category = appName,
Name = "网站页脚",
Code = appFooter,
Define = 1
});
if (ret) ret = Save(new BootstrapDict()
{
Category = appName,
Name = "个人中心地址",
Code = "/Admin/Profiles",
Define = 1
});
if (ret) ret = Save(new BootstrapDict()
{
Category = appName,
Name = "系统设置地址",
Code = "/Admin/Index",
Define = 1
});
if (ret) ret = Save(new BootstrapDict()
{
Category = appName,
Name = "系统通知地址",
Code = "/Admin/Notifications",
Define = 1
});
} }
return ret; return ret;
} }
@ -446,6 +500,7 @@ namespace Bootstrap.DataAccess
var ids = new List<string>(); var ids = new List<string>();
ids.AddRange(RetrieveDicts().Where(d => d.Category == "应用程序" && d.Name == dict.Name && d.Code == dict.Code).Select(d => d.Id ?? "")); ids.AddRange(RetrieveDicts().Where(d => d.Category == "应用程序" && d.Name == dict.Name && d.Code == dict.Code).Select(d => d.Id ?? ""));
ids.AddRange(RetrieveDicts().Where(d => d.Category == "应用首页" && d.Name == dict.Code).Select(d => d.Id ?? "")); ids.AddRange(RetrieveDicts().Where(d => d.Category == "应用首页" && d.Name == dict.Code).Select(d => d.Id ?? ""));
ids.AddRange(RetrieveDicts().Where(d => d.Category == dict.Name).Select(d => d.Id ?? ""));
return Delete(ids); return Delete(ids);
} }

View File

@ -1,4 +1,5 @@
using Bootstrap.DataAccess; using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Bootstrap.Security; using Bootstrap.Security;
using Longbow.Cache; using Longbow.Cache;
using System.Collections.Generic; using System.Collections.Generic;
@ -19,6 +20,43 @@ namespace Bootstrap.Admin.Api
Assert.NotNull(resp); Assert.NotNull(resp);
} }
[Fact]
public async void GetByKey_Ok()
{
var resp = await Client.GetAsJsonAsync<QueryAppOption>("Demo");
Assert.NotNull(resp);
}
[Fact]
public async void Put_Ok()
{
var data = new QueryAppOption()
{
AppId = "new",
AppName = "UnitTest",
AppCode = "UnitTest",
AppUrl = "http://localhost",
AppTitle = "网站标题",
AppFooter = "网站页脚"
};
var resp = await Client.PutAsJsonAsync<QueryAppOption, bool>("", data);
Assert.True(resp);
// Check
var op = await Client.GetAsJsonAsync<QueryAppOption>("UnitTest");
Assert.Equal(data.AppTitle, op.AppTitle);
// 删除
resp = await Client.DeleteAsJsonAsync<BootstrapDict, bool>("AppPath", new BootstrapDict()
{
Category = "UnitTest",
Name = "UnitTest",
Code = "UnitTest"
});
Assert.True(resp);
}
[Fact] [Fact]
public async void Post_Ok() public async void Post_Ok()
{ {