feat: 网站设置增加前台站点配置功能
This commit is contained in:
parent
e547a84f5a
commit
712455ebe2
|
@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bootstrap.Admin.Controllers.Api
|
||||
{
|
||||
|
@ -29,13 +30,31 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
/// 保存网站是否为演示系统时调用
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{id}")]
|
||||
public bool Put(string id, [FromBody]BootstrapDict dict) => DictHelper.UpdateSystemModel(dict.Code == "1", dict.Name);
|
||||
[HttpPost("{id}")]
|
||||
public bool Post(string id, [FromBody]BootstrapDict dict) => id switch
|
||||
{
|
||||
"Demo" => DictHelper.UpdateSystemModel(dict.Code == "1", dict.Name),
|
||||
"AppPath" => DictHelper.SaveAppSettings(dict),
|
||||
_ => false
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 获取网站缓存站点集合
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public IEnumerable<ICacheCorsItem> Get() => CacheManager.CorsSites;
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定键值的前台应用配置信息
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="dict"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id}")]
|
||||
public bool Delete(string id, [FromBody]BootstrapDict dict) => id switch
|
||||
{
|
||||
"AppPath" => DictHelper.DeleteApp(dict),
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using Bootstrap.DataAccess;
|
||||
using Bootstrap.Security;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bootstrap.Admin.Models
|
||||
{
|
||||
|
@ -29,6 +31,13 @@ namespace Bootstrap.Admin.Models
|
|||
IPCachePeriod = DictHelper.RetrieveLocaleIPSvrCachePeriod();
|
||||
EnableDemo = DictHelper.RetrieveSystemModel();
|
||||
AdminPathBase = DictHelper.RetrievePathBase();
|
||||
|
||||
var dicts = DictHelper.RetrieveDicts();
|
||||
Apps = DictHelper.RetrieveApps().Where(d => !d.Key.Equals("BA", StringComparison.OrdinalIgnoreCase)).Select(k =>
|
||||
{
|
||||
var url = dicts.FirstOrDefault(d => d.Category == "应用首页" && d.Name == k.Key && d.Define == 0)?.Code ?? "未设置";
|
||||
return (k.Key, k.Value, url);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -94,6 +103,11 @@ namespace Bootstrap.Admin.Models
|
|||
/// <summary>
|
||||
/// 获得/设置 后台管理网站地址
|
||||
/// </summary>
|
||||
public string AdminPathBase { get; set; } = "";
|
||||
public string AdminPathBase { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 系统应用程序集合
|
||||
/// </summary>
|
||||
public IEnumerable<(string Key, string Name, string Url)> Apps { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,47 @@
|
|||
<script src="~/lib/longbow/longbow.validate.js"></script>
|
||||
<script src="~/js/settings.js" asp-append-version="true"></script>
|
||||
}
|
||||
@section modal {
|
||||
<div class="modal fade" id="dialogNew" tabindex="-1" role="dialog" data-backdrop="static" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
|
||||
<div class="modal-content" data-toggle="LgbValidate" data-valid-button="[data-method='saveNewApp']" data-valid-modal="#dialogNew">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="myModalLabel">前台应用设置</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-inline">
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-6">
|
||||
<label class="control-label" for="appKey">应用ID</label>
|
||||
<input type="text" class="form-control" id="appKey" placeholder="不可为空,50字以内" maxlength="50" data-valid="true" />
|
||||
</div>
|
||||
<div class="form-group col-sm-6">
|
||||
<input type="hidden" id="roleID" />
|
||||
<label class="control-label" for="appName">应用名称</label>
|
||||
<input type="text" class="form-control" id="appName" placeholder="不可为空,50字以内" maxlength="50" data-valid="true" />
|
||||
</div>
|
||||
<div class="form-group col-sm-12">
|
||||
<label class="control-label" for="appUrl">应用首页</label>
|
||||
<input type="text" class="form-control flex-fill" id="appUrl" placeholder="不可为空,2000字以内" maxlength="2000" data-valid="true" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">
|
||||
<i class="fa fa-times"></i>
|
||||
<span>关闭</span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary" data-method="saveNewApp">
|
||||
<i class="fa fa-save"></i>
|
||||
<span>保存</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div class="card" asp-auth="saveTitle">
|
||||
<div class="card-header">网站名称设置</div>
|
||||
<div class="card-body" data-toggle="LgbValidate" data-valid-button="[data-method='title']">
|
||||
|
@ -58,7 +99,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-header">后台管理地址设置</div>
|
||||
<div class="card-header"><label class="control-label" data-toggle="lgbinfo" data-content="此功能给前台网站拼接后台功能菜单时使用">后台管理地址设置</label></div>
|
||||
<div class="card-body" data-toggle="LgbValidate" data-valid-button="[data-method='appPath']">
|
||||
<div class="alert alert-danger" role="alert" asp-condition="@Model.IsDemo">
|
||||
<span>演示系统禁止更改后台管理地址</span>
|
||||
|
@ -168,7 +209,7 @@
|
|||
<div class="card-body">
|
||||
<div class="form-inline">
|
||||
<div class="row">
|
||||
<div class="form-group col-6">
|
||||
<div class="form-group col-12">
|
||||
<label class="control-label" data-toggle="lgbinfo" data-content="开启此功能后登录时默认导航到第一个已授权的前台应用" for="defaultApp">默认应用</label>
|
||||
<input id="defaultApp" hidden type="checkbox" data-default-val="@Model.DefaultApp" data-toggle="toggle" data-width="120" data-onstyle="success" data-on="开启" data-off="关闭" />
|
||||
</div>
|
||||
|
@ -179,6 +220,34 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card" asp-auth="app">
|
||||
<div class="card-header">前台应用设置</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-danger" role="alert" asp-condition="@Model.IsDemo">
|
||||
<span>演示系统禁止更改前台应用设置</span>
|
||||
</div>
|
||||
<div class="form-inline">
|
||||
<div class="row" id="appList">
|
||||
@foreach (var app in Model.Apps)
|
||||
{
|
||||
<div class="form-group col-12" data-toggle="LgbValidate" data-valid-button="[data-method='saveApp']">
|
||||
<label class="control-label" for="@app.Key">@app.Name</label>
|
||||
<div class="input-group flex-fill">
|
||||
<input id="@app.Key" class="form-control" placeholder="请输入应用首页,2000字以内" value="@app.Url" maxlength="2000" data-valid="true" />
|
||||
<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-secondary" type="button" data-key="@app.Key" data-method="saveApp"><i class="fa fa-save"></i><span>保存</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer text-right" asp-condition="@(!Model.IsDemo)">
|
||||
<button class="btn btn-secondary" type="button" data-method="addApp"><i class="fa fa-plus"></i><span>新增</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card" asp-auth="blazor">
|
||||
<div class="card-header">网站设置</div>
|
||||
<div class="card-body">
|
||||
|
|
|
@ -76,6 +76,10 @@ body.trans-mute * {
|
|||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.card-header label.control-label {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.modal-body .dd {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
|
|
@ -564,7 +564,7 @@ input.pending {
|
|||
padding: 0.5rem 1rem;
|
||||
}
|
||||
|
||||
.card .card-header a {
|
||||
.card .card-header a:not([data-toggle="popover"]) {
|
||||
color: #797979;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
$(function () {
|
||||
var swalDeleteOptions = {
|
||||
title: "删除前台站点配置",
|
||||
type: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#dc3545',
|
||||
cancelButtonColor: '#6c757d',
|
||||
confirmButtonText: "我要删除",
|
||||
cancelButtonText: "取消"
|
||||
};
|
||||
|
||||
var dataBinder = new DataEntity({
|
||||
Title: "#sysName",
|
||||
Footer: "#sysFoot"
|
||||
});
|
||||
|
||||
$('button[data-method]').on('click', function (e) {
|
||||
var $dialog = $('#dialogNew');
|
||||
|
||||
$(document).on('click', 'button[data-method]', function (e) {
|
||||
var $this = $(this);
|
||||
var data = {};
|
||||
switch ($this.attr('data-method')) {
|
||||
|
@ -132,7 +144,7 @@ $(function () {
|
|||
var demo = $('#demo').prop('checked') ? "1" : "0";
|
||||
var authKey = $('#authKey').val();
|
||||
$.bc({
|
||||
url: Settings.url + '/Demo', data: { name: authKey, code: demo }, title: '演示系统设置', method: "put",
|
||||
url: Settings.url + '/Demo', data: { name: authKey, code: demo }, title: '演示系统设置', method: "post",
|
||||
callback: function (result) {
|
||||
if (result) {
|
||||
window.setTimeout(function () { window.location.reload(true); }, 1000);
|
||||
|
@ -146,6 +158,55 @@ $(function () {
|
|||
url: Settings.url, data: [{ name: 'AppPath', code: appPath }], title: '后台管理地址设置', method: "post"
|
||||
});
|
||||
break;
|
||||
case 'addApp':
|
||||
$('#appKey').val('');
|
||||
$('#appName').val('');
|
||||
$('#appUrl').val('');
|
||||
$dialog.modal('show');
|
||||
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':
|
||||
var appPath = $('#appUrl').val();
|
||||
var appKey = $('#appKey').val();
|
||||
var appName = $('#appName').val();
|
||||
$.bc({
|
||||
url: Settings.url + '/AppPath', data: { category: appName, name: appKey, code: appPath }, title: "保存" + appName, method: "post",
|
||||
callback: function (result) {
|
||||
if (result) {
|
||||
$dialog.modal('hide');
|
||||
|
||||
// 保存成功创建新 dom
|
||||
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);
|
||||
|
||||
// append dom
|
||||
$('#appList').append($(segment));
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'delApp':
|
||||
var appKey = $(this).attr('data-key');
|
||||
var appName = $(this).parents('.input-group').prev().text();
|
||||
var $this = $(this);
|
||||
swal($.extend({}, swalDeleteOptions, { html: "您确定要删除" + appName + "前台站点配置吗" })).then(function (result) {
|
||||
if (result.value) {
|
||||
$.bc({
|
||||
url: Settings.url + '/AppPath', data: { name: appName, code: appKey }, title: "删除" + appName, method: "delete",
|
||||
callback: function (result) {
|
||||
// remove dom
|
||||
$this.parents('.form-group').remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -347,5 +347,61 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string RetrievePathBase() => DbContextManager.Create<Dict>()?.RetrievePathBase() ?? "";
|
||||
|
||||
/// <summary>
|
||||
/// 保存前台应用配置信息
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SaveAppSettings(BootstrapDict dict)
|
||||
{
|
||||
// dict define == 1 时为新建前台应用
|
||||
bool ret;
|
||||
if (dict.Define == 0)
|
||||
{
|
||||
// Update
|
||||
ret = SaveSettings(new BootstrapDict[] {
|
||||
new BootstrapDict()
|
||||
{
|
||||
Category = "应用首页",
|
||||
Name = dict.Name,
|
||||
Code = dict.Code,
|
||||
Define = 0
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = Save(new BootstrapDict()
|
||||
{
|
||||
Category = "应用程序",
|
||||
Name = dict.Category,
|
||||
Code = dict.Name,
|
||||
Define = 0
|
||||
});
|
||||
if (ret) ret = Save(new BootstrapDict()
|
||||
{
|
||||
Category = "应用首页",
|
||||
Name = dict.Name,
|
||||
Code = dict.Code,
|
||||
Define = 0
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定前台应用
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
/// <returns></returns>
|
||||
public static bool DeleteApp(BootstrapDict dict)
|
||||
{
|
||||
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.Code).Select(d => d.Id ?? ""));
|
||||
|
||||
return Delete(ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue