完善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-header">
<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>
<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>
@ -283,12 +283,29 @@
<div class="layui-card" th:if="${appLogin eq 'appLogin'}">
<div class="layui-card-header">
<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>
<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 class="layui-card-body" style="padding: 15px;">
<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>
@ -500,19 +517,20 @@
});
// 系统参数事件
(function() {
var systemParamsArray = [];
function paramsConfigInit(idPrefix, classPrefix, initObj) {
var paramsArray = [];
var keyupSetTimeout;
function getTr(index, key, value) {
return '<tr>' +
' <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>' +
' <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 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>' +
' </button>' +
' </td>' +
@ -521,67 +539,83 @@
function refreshTr() {
var trs = '';
for(var i = 0; i < systemParamsArray.length; i++) {
var item = systemParamsArray[i];
for(var i = 0; i < paramsArray.length; i++) {
var item = paramsArray[i];
trs += getTr(i, item.key, item.value);
}
$('#systemParamsBody').empty();
$('#systemParamsBody').append(trs);
$('#'+ idPrefix +'Body').empty();
$('#'+ idPrefix +'Body').append(trs);
}
function isKeyExist(key) {
function isKeyExist(index, key) {
if(!key) {
return false;
}
for(var i = 0, item; item = systemParamsArray[i++];) {
if(key == item.key) {
for(var i = 0, item; item = paramsArray[i++];) {
if(key == item.key && index != (i - 1)) {
return true;
}
}
return false;
}
function isKeyEffective(key) {
if((/^[a-zA-Z0-9\_]+$/g.test(key))) {
return true;
}
return false;
}
function init() {
}
init();
$(document).on('keyup', '.system-params-key', function() {
$(document).on('keyup', '.'+ classPrefix +'-key', function() {
var self = this;
var index = this.dataset.index;
this.value = this.value.replace(/\s/g, '');
var value = this.value;
setTimeout(function() {
if(isKeyExist(value)) {
systemParamsArray[index].key = '';
top.dialog.msg('参数名重复');
self.value = '';
if(keyupSetTimeout) {
clearTimeout(keyupSetTimeout);
}
keyupSetTimeout = setTimeout(function() {
if(!isKeyEffective(value)) {
top.dialog.msg('参数名只能是字母、数字与下划线组合');
self.focus();
self.value = '';
return;
}
if(isKeyExist(index, value)) {
top.dialog.msg('参数名重复');
self.focus();
self.value = '';
return;
} 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;
systemParamsArray[index].value = this.value;
paramsArray[index].value = this.value;
});
$(document).on('click', '#systemParamsPlusBtn', function() {
systemParamsArray.push({
$(document).on('click', '#'+ idPrefix +'PlusBtn', function() {
paramsArray.push({
key: '',
value: ''
});
refreshTr();
})
$(document).on('click', '.system-params-remove-btn', function() {
$(document).on('click', '.'+ classPrefix +'-remove-btn', function() {
var index = this.dataset.index;
systemParamsArray.splice(index, 1);
paramsArray.splice(index, 1);
refreshTr();
})
})();
};
// 初始化
function initData() {
@ -621,6 +655,8 @@
photos = data.loginBackgroundImages.split(',');
}
setBackgroundTemple();
paramsConfigInit('systemParams', 'system-params', {});
paramsConfigInit('appParams', 'app-params', {});
}, function(code, data) {
top.dialog.msg(data.msg);
}, function() {