diff --git a/login-base/src/main/resources/templates/config/update.html b/login-base/src/main/resources/templates/config/update.html index aebe2b9b..37127456 100644 --- a/login-base/src/main/resources/templates/config/update.html +++ b/login-base/src/main/resources/templates/config/update.html @@ -254,7 +254,7 @@
- 系统参数配置 + 系统参数配置(参数名唯一且只能是字母、数字与下划线的组合)
- + + + + + + + + + + + + + + +
参数名参数值操作
@@ -500,19 +517,20 @@ }); // 系统参数事件 - (function() { - var systemParamsArray = []; + function paramsConfigInit(idPrefix, classPrefix, initObj) { + var paramsArray = []; + var keyupSetTimeout; function getTr(index, key, value) { return '' + ' ' + - ' ' + + ' ' + ' ' + ' ' + - ' ' + + ' ' + ' ' + ' ' + - ' ' + ' ' + @@ -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() {