完善APP与系统参数配置功能

This commit is contained in:
WenG 2022-03-22 13:50:05 +08:00
parent 83923d8384
commit a3681f65b3

View File

@ -254,7 +254,7 @@
<div class="layui-card"> <div class="layui-card">
<div class="layui-card-header"> <div class="layui-card-header">
<span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;"> <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
<a href="javascript:void(0);"><cite>系统参数配置</cite></a> <a href="javascript:void(0);"><cite>系统参数配置(参数名唯一且只能是字母、数字与下划线的组合)</cite></a>
</span> </span>
<button id="systemParamsPlusBtn" type="button" class="layui-btn layui-btn-xs" style="float: right; margin-top: 12px;"> <button id="systemParamsPlusBtn" type="button" class="layui-btn layui-btn-xs" style="float: right; margin-top: 12px;">
<i class="fa fa-plus" aria-hidden="true"></i> <i class="fa fa-plus" aria-hidden="true"></i>
@ -283,12 +283,29 @@
<div class="layui-card" th:if="${appLogin eq 'appLogin'}"> <div class="layui-card" th:if="${appLogin eq 'appLogin'}">
<div class="layui-card-header"> <div class="layui-card-header">
<span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;"> <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
<a href="javascript:void(0);"><cite>APP参数配置</cite></a> <a href="javascript:void(0);"><cite>APP参数配置(参数名唯一且只能是字母、数字与下划线的组合)</cite></a>
</span> </span>
<button id="appParamsPlusBtn" type="button" class="layui-btn layui-btn-xs" style="float: right; margin-top: 12px;">
<i class="fa fa-plus" aria-hidden="true"></i>
</button>
</div> </div>
<div class="layui-card-body" style="padding: 15px;"> <div class="layui-card-body" style="padding: 15px;">
<div class="layui-form-item"> <div class="layui-form-item">
<table class="layui-table">
<colgroup>
<col width="150">
<col>
<col width="60">
</colgroup>
<thead>
<tr>
<th>参数名</th>
<th>参数值</th>
<th style="text-align: center;">操作</th>
</tr>
</thead>
<tbody id="appParamsBody"></tbody>
</table>
</div> </div>
</div> </div>
</div> </div>
@ -500,19 +517,20 @@
}); });
// 系统参数事件 // 系统参数事件
(function() { function paramsConfigInit(idPrefix, classPrefix, initObj) {
var systemParamsArray = []; var paramsArray = [];
var keyupSetTimeout;
function getTr(index, key, value) { function getTr(index, key, value) {
return '<tr>' + return '<tr>' +
' <td>' + ' <td>' +
' <input type="text" id="systemParamsKey'+ index +'" placeholder="输入参数名" class="layui-input system-params-key" value="'+ (key ? key : '') +'" data-index="'+ index +'">' + ' <input type="text" id="'+ idPrefix +'Key'+ index +'" placeholder="输入参数名" class="layui-input '+ classPrefix +'-key" value="'+ (key ? key : '') +'" data-index="'+ index +'">' +
' </td>' + ' </td>' +
' <td>' + ' <td>' +
' <input type="text" id="systemParamsValue'+ index +'" placeholder="输入参数值" class="layui-input system-params-value" value="'+ (value ? value : '') +'" data-index="'+ index +'">' + ' <input type="text" id="'+ idPrefix +'Value'+ index +'" placeholder="输入参数值" class="layui-input '+ classPrefix +'-value" value="'+ (value ? value : '') +'" data-index="'+ index +'">' +
' </td>' + ' </td>' +
' <td style="text-align: center;">' + ' <td style="text-align: center;">' +
' <button type="button" class="layui-btn layui-btn-xs layui-btn-danger system-params-remove-btn" data-index="'+ index +'">' + ' <button type="button" class="layui-btn layui-btn-xs layui-btn-danger '+ classPrefix +'-remove-btn" data-index="'+ index +'">' +
' <i class="fa fa-times" aria-hidden="true"></i>' + ' <i class="fa fa-times" aria-hidden="true"></i>' +
' </button>' + ' </button>' +
' </td>' + ' </td>' +
@ -521,67 +539,83 @@
function refreshTr() { function refreshTr() {
var trs = ''; var trs = '';
for(var i = 0; i < systemParamsArray.length; i++) { for(var i = 0; i < paramsArray.length; i++) {
var item = systemParamsArray[i]; var item = paramsArray[i];
trs += getTr(i, item.key, item.value); trs += getTr(i, item.key, item.value);
} }
$('#systemParamsBody').empty(); $('#'+ idPrefix +'Body').empty();
$('#systemParamsBody').append(trs); $('#'+ idPrefix +'Body').append(trs);
} }
function isKeyExist(key) { function isKeyExist(index, key) {
if(!key) { if(!key) {
return false; return false;
} }
for(var i = 0, item; item = systemParamsArray[i++];) { for(var i = 0, item; item = paramsArray[i++];) {
if(key == item.key) { if(key == item.key && index != (i - 1)) {
return true; return true;
} }
} }
return false; return false;
} }
function isKeyEffective(key) {
if((/^[a-zA-Z0-9\_]+$/g.test(key))) {
return true;
}
return false;
}
function init() { function init() {
} }
init(); init();
$(document).on('keyup', '.system-params-key', function() { $(document).on('keyup', '.'+ classPrefix +'-key', function() {
var self = this; var self = this;
var index = this.dataset.index; var index = this.dataset.index;
this.value = this.value.replace(/\s/g, '');
var value = this.value; var value = this.value;
setTimeout(function() { if(keyupSetTimeout) {
if(isKeyExist(value)) { clearTimeout(keyupSetTimeout);
systemParamsArray[index].key = ''; }
top.dialog.msg('参数名重复'); keyupSetTimeout = setTimeout(function() {
self.value = ''; if(!isKeyEffective(value)) {
top.dialog.msg('参数名只能是字母、数字与下划线组合');
self.focus(); self.focus();
self.value = '';
return;
}
if(isKeyExist(index, value)) {
top.dialog.msg('参数名重复');
self.focus();
self.value = '';
return; return;
} else { } else {
systemParamsArray[index].key = value; paramsArray[index].key = value;
} }
}, 50) }, 500);
}); });
$(document).on('keyup', '.system-params-value', function() { $(document).on('keyup', '.'+ classPrefix +'-value', function() {
var index = this.dataset.index; var index = this.dataset.index;
systemParamsArray[index].value = this.value; paramsArray[index].value = this.value;
}); });
$(document).on('click', '#systemParamsPlusBtn', function() { $(document).on('click', '#'+ idPrefix +'PlusBtn', function() {
systemParamsArray.push({ paramsArray.push({
key: '', key: '',
value: '' value: ''
}); });
refreshTr(); refreshTr();
}) })
$(document).on('click', '.system-params-remove-btn', function() { $(document).on('click', '.'+ classPrefix +'-remove-btn', function() {
var index = this.dataset.index; var index = this.dataset.index;
systemParamsArray.splice(index, 1); paramsArray.splice(index, 1);
refreshTr(); refreshTr();
}) })
})(); };
// 初始化 // 初始化
function initData() { function initData() {
@ -621,6 +655,8 @@
photos = data.loginBackgroundImages.split(','); photos = data.loginBackgroundImages.split(',');
} }
setBackgroundTemple(); setBackgroundTemple();
paramsConfigInit('systemParams', 'system-params', {});
paramsConfigInit('appParams', 'app-params', {});
}, function(code, data) { }, function(code, data) {
top.dialog.msg(data.msg); top.dialog.msg(data.msg);
}, function() { }, function() {