feat(系统设置): 增加当前站点配置

This commit is contained in:
chenjianxing 2020-09-24 18:42:05 +08:00
parent 366265db36
commit 4093f39b58
10 changed files with 209 additions and 5 deletions

View File

@ -29,6 +29,7 @@ public interface ParamConstants {
enum Classify implements ParamConstants {
MAIL("smtp"),
BASE("base"),
LDAP("ldap"),
REGISTRY("registry");
@ -114,6 +115,21 @@ public interface ParamConstants {
}
}
enum BASE implements ParamConstants {
URL("base.url");
private String value;
private BASE(String value) {
this.value = value;
}
@Override
public String getValue() {
return value;
}
}
enum LDAP implements ParamConstants {
URL("ldap.url"),
DN("ldap.dn"),

View File

@ -3,6 +3,7 @@ package io.metersphere.controller;
import io.metersphere.base.domain.SystemParameter;
import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.dto.BaseSystemConfigDTO;
import io.metersphere.ldap.domain.LdapInfo;
import io.metersphere.service.SystemParameterService;
import org.apache.shiro.authz.annotation.RequiresRoles;
@ -41,6 +42,18 @@ public class SystemParameterController {
return SystemParameterService.mailInfo(ParamConstants.Classify.MAIL.getValue());
}
@GetMapping("/base/info")
@RequiresRoles(value = {RoleConstants.ADMIN})
public BaseSystemConfigDTO getBaseInfo () {
return SystemParameterService.getBaseInfo();
}
@PostMapping("/save/base")
@RequiresRoles(value = {RoleConstants.ADMIN})
public void saveBaseInfo (@RequestBody List<SystemParameter> systemParameter) {
SystemParameterService.saveBaseInfo(systemParameter);
}
@PostMapping("/save/ldap")
@RequiresRoles(value = {RoleConstants.ADMIN})
public void saveLdap(@RequestBody List<SystemParameter> systemParameter) {

View File

@ -0,0 +1,10 @@
package io.metersphere.dto;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class BaseSystemConfigDTO {
private String url;
}

View File

@ -7,6 +7,7 @@ import io.metersphere.base.mapper.ext.ExtSystemParameterMapper;
import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.EncryptUtils;
import io.metersphere.dto.BaseSystemConfigDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.ldap.domain.LdapInfo;
import org.apache.commons.collections.CollectionUtils;
@ -182,4 +183,30 @@ public class SystemParameterService {
}
return param.getParamValue();
}
public BaseSystemConfigDTO getBaseInfo() {
BaseSystemConfigDTO baseSystemConfigDTO = new BaseSystemConfigDTO();
List<SystemParameter> paramList = this.getParamList(ParamConstants.Classify.BASE.getValue());
if (!CollectionUtils.isEmpty(paramList)) {
for (SystemParameter param : paramList) {
if (StringUtils.equals(param.getParamKey(), ParamConstants.BASE.URL.getValue())) {
baseSystemConfigDTO.setUrl(param.getParamValue());
}
}
}
return baseSystemConfigDTO;
}
public void saveBaseInfo(List<SystemParameter> parameters) {
SystemParameterExample example = new SystemParameterExample();
parameters.forEach(param -> {
example.createCriteria().andParamKeyEqualTo(param.getParamKey());
if (systemParameterMapper.countByExample(example) > 0) {
systemParameterMapper.updateByPrimaryKey(param);
} else {
systemParameterMapper.insert(param);
}
example.clear();
});
}
}

View File

@ -0,0 +1 @@
INSERT into system_parameter values('base.url', 'http://localhost:8081', 'text', 1);

View File

@ -0,0 +1,110 @@
<template>
<div v-loading="result.loading">
<el-form :model="formInline" :rules="rules" ref="formInline" class="demo-form-inline"
:disabled="show" v-loading="loading" size="small">
<el-row>
<el-col>
<el-form-item :label="$t('system_config.base.url')" prop="url">
<el-input v-model="formInline.url" :placeholder="$t('system_config.base.url_tip')"/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div>
<el-button @click="edit" v-if="showEdit" size="small">{{ $t('commons.edit') }}</el-button>
<el-button type="success" @click="save('formInline')" v-if="showSave" :disabled="disabledSave" size="small">
{{ $t('commons.save') }}
</el-button>
<el-button @click="cancel" type="info" v-if="showCancel" size="small">{{ $t('commons.cancel') }}</el-button>
</div>
</div>
</template>
<script>
export default {
name: "BaseSetting",
data() {
return {
formInline: {},
input: '',
visible: true,
result: {},
showEdit: true,
showSave: false,
showCancel: false,
show: true,
disabledConnection: false,
disabledSave: false,
loading: false,
rules: {
url: [
{
required: true,
message: this.$t('system_par'),
trigger: ['change', 'blur']
},
],
}
}
},
created() {
this.query()
},
methods: {
query() {
this.result = this.$get("/system/base/info", response => {
this.formInline = response.data;
this.$nextTick(() => {
this.$refs.formInline.clearValidate();
})
})
},
edit() {
this.showEdit = false;
this.showSave = true;
this.showCancel = true;
this.show = false;
},
save(formInline) {
this.showEdit = true;
this.showCancel = false;
this.showSave = false;
this.show = true;
let param = [
{paramKey: "base.url", paramValue: this.formInline.url, type: "text", sort: 1},
];
this.$refs[formInline].validate(valid => {
if (valid) {
this.result = this.$post("/system/save/base", param, response => {
if (response.success) {
this.$success(this.$t('commons.save_success'));
} else {
this.$message.error(this.$t('commons.save_failed'));
}
});
} else {
return false;
}
})
},
cancel() {
this.showEdit = true;
this.showCancel = false;
this.showSave = false;
this.show = true;
this.query();
}
}
}
</script>
<style scoped>
.el-form {
min-height: 300px;
}
</style>

View File

@ -1,6 +1,10 @@
<template>
<el-card>
<el-tabs class="system-setting" v-model="activeName">
<el-tab-pane :label="$t('system_config.base_config')" name="base">
<base-setting/>
</el-tab-pane>
<el-tab-pane :label="$t('system_parameter_setting.mailbox_service_settings')" name="email">
<email-setting/>
</el-tab-pane>
@ -14,15 +18,17 @@
<script>
import EmailSetting from "./EmailSetting";
import LdapSetting from "./LdapSetting";
import BaseSetting from "./BaseSetting";
export default {
name: "SystemParameterSetting",
components: {
BaseSetting,
EmailSetting, LdapSetting
},
data() {
return {
activeName: 'email'
activeName: 'base'
}
}
}

View File

@ -175,6 +175,13 @@ export default {
invalid: 'invalid',
expired: 'expired',
},
system_config: {
base_config: 'Base Config',
base: {
url: 'Website URL',
url_tip: 'examplehttp://localhost:8081'
}
},
workspace: {
create: 'Create Workspace',
update: 'Update Workspace',

View File

@ -175,6 +175,13 @@ export default {
invalid: '无效',
expired: '已过期',
},
system_config: {
base_config: '基本配置',
base: {
url: '当前站点URL',
url_tip: '例如http://localhost:8081'
}
},
workspace: {
create: '创建工作空间',
update: '修改工作空间',

View File

@ -152,14 +152,14 @@ export default {
ge: "大於等於",
lt: "小於",
le: "小於等於",
not_equals: "不等於",
equals: "等於",
not_equals: "不等於",
between: "之間",
current_user: "是當前用戶"
}
}
},
license:{
license: {
title: '授權管理',
corporation: '客戶名稱',
time: '授權時間',
@ -175,6 +175,13 @@ export default {
invalid: '無效',
expired: '已過期',
},
system_config: {
base_config: '基本配置',
base: {
url: '當前站點URL',
url_tip: '例如http://localhost:8081'
}
},
workspace: {
create: '創建工作空間',
update: '修改工作空間',
@ -281,7 +288,7 @@ export default {
email_format_is_incorrect: '郵箱格式不正確',
delete_confirm: '這個用戶確定要刪除嗎?',
apikey_delete_confirm: '這個 API Key 確定要刪除嗎?',
input_id_placeholder: '請輸入ID (不支持中文字符)',
input_id_placeholder: '請輸入ID (不支持中文)',
source: '用戶來源'
},
role: {
@ -632,7 +639,7 @@ export default {
cancel_relevance_success: "取消關聯成功",
switch_project: "切換項目",
case: {
export_all_cases: '確定要匯出全部用例嗎?',
export_all_cases: '確定要導出全部用例嗎?',
input_test_case: '請輸入關聯用例名稱',
test_name: '測試名稱',
other: "--其他--",