提交 e81138ec authored 作者: taojinlong's avatar taojinlong

feat: 支持精简模式

上级 0609d245
package io.dataease.controller.engine;
import io.dataease.base.domain.DeEngine;
import io.dataease.controller.ResultHolder;
import io.dataease.dto.DatasourceDTO;
import io.dataease.service.engine.EngineService;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
@ApiIgnore
@RequestMapping("engine")
@RestController
public class EngineController {
@Resource
private EngineService engineService;
@ApiIgnore
@GetMapping("/mode")
public String runMode() throws Exception{
return engineService.mode();
}
@ApiIgnore
@GetMapping("/info")
public DeEngine info() throws Exception{
return engineService.info();
}
@ApiIgnore
@PostMapping("/validate")
public ResultHolder validate(@RequestBody DatasourceDTO datasource) throws Exception {
return engineService.validate(datasource);
}
@ApiIgnore
@PostMapping("/save")
public ResultHolder save(@RequestBody DeEngine engine) throws Exception {
return engineService.save(engine);
}
}
......@@ -18,4 +18,6 @@ public abstract class DDLProvider {
public abstract String replaceTable(String name);
public abstract String createTableSql(String name, List<DatasetTableField> datasetTableFields);
public abstract String insertSql(String name, List<String[]> dataList, int page, int pageNumber);
}
package io.dataease.provider;
import io.dataease.base.domain.DatasetTableField;
import io.dataease.commons.utils.Md5Utils;
import java.util.Arrays;
import java.util.List;
public class DDLProviderImpl extends DDLProvider {
......@@ -30,5 +32,19 @@ public class DDLProviderImpl extends DDLProvider {
return null;
}
@Override
public String insertSql(String name, List<String[]> dataList, int page, int pageNumber) {
String insertSql = "INSERT INTO TABLE_NAME VALUES ".replace("TABLE_NAME", name);
StringBuffer values = new StringBuffer();
Integer realSize = page * pageNumber < dataList.size() ? page * pageNumber : dataList.size();
for (String[] strings : dataList.subList((page - 1) * pageNumber, realSize)) {
values.append("(").append(Md5Utils.md5(String.join(",", Arrays.asList(strings))))
.append("," ).append(String.join(",", Arrays.asList(strings)))
.append("),");
}
return insertSql + values.substring(0, values.length() - 1);
}
}
......@@ -71,7 +71,7 @@ public class DatasourceService {
return datasource;
}
private void handleConnectionPool(Datasource datasource, String type) {
public void handleConnectionPool(Datasource datasource, String type) {
commonThreadPool.addTask(() -> {
try {
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
......@@ -221,7 +221,6 @@ public class DatasourceService {
}catch (Exception e){
return ResultHolder.error("Datasource is invalid: " + e.getMessage());
}
}
public ResultHolder validate(String datasourceId) {
......
......@@ -6,20 +6,32 @@ import io.dataease.base.domain.DeEngine;
import io.dataease.base.domain.DeEngineExample;
import io.dataease.base.mapper.DeEngineMapper;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.controller.ResultHolder;
import io.dataease.controller.request.datasource.DatasourceRequest;
import io.dataease.dto.DatasourceDTO;
import io.dataease.provider.ProviderFactory;
import io.dataease.provider.datasource.DatasourceProvider;
import io.dataease.service.datasource.DatasourceService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;
@Service
@Transactional(rollbackFor = Exception.class)
public class EngineService {
@Resource
private Environment env;
@Resource
private DeEngineMapper deEngineMapper;
static private Datasource ds = null;
@Resource
private DatasourceService datasource;
static private Datasource ds = new Datasource();
public Boolean isLocalMode(){
......@@ -29,8 +41,50 @@ public class EngineService {
public Boolean isSimpleMode(){
return env.getProperty("engine_mode", "local").equalsIgnoreCase("simple");
}
public Datasource getDeEngine() throws Exception{
if (this.ds != null) {
public Boolean isClusterMode(){
return env.getProperty("engine_mode", "local").equalsIgnoreCase("cluster");
}
public String mode(){
return env.getProperty("engine_mode", "local");
}
public DeEngine info(){
List<DeEngine> deEngines = deEngineMapper.selectByExampleWithBLOBs(new DeEngineExample());
if(CollectionUtils.isEmpty(deEngines)){
return new DeEngine();
}
return deEngines.get(0);
}
public ResultHolder validate(DatasourceDTO datasource) throws Exception {
try {
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
DatasourceRequest datasourceRequest = new DatasourceRequest();
datasourceRequest.setDatasource(datasource);
datasourceProvider.checkStatus(datasourceRequest);
return ResultHolder.success(datasource);
}catch (Exception e){
return ResultHolder.error("Datasource is invalid: " + e.getMessage());
}
}
public ResultHolder save(DeEngine engine) throws Exception {
if(StringUtils.isEmpty(engine.getId())){
engine.setId(UUID.randomUUID().toString());
deEngineMapper.insert(engine);
}else {
deEngineMapper.updateByPrimaryKeyWithBLOBs(engine);
}
datasource.handleConnectionPool(this.ds, "delete");
BeanUtils.copyBean(this.ds, engine);
datasource.handleConnectionPool(this.ds, "add");
return ResultHolder.success(engine);
}
public Datasource getDeEngine() throws Exception{
if (this.ds != null || StringUtils.isNotEmpty(ds.getType())) {
return this.ds;
}
if(isLocalMode()){
......@@ -52,7 +106,7 @@ public class EngineService {
this.ds = datasource;
}
if(isSimpleMode()){
List<DeEngine> deEngines = deEngineMapper.selectByExample(new DeEngineExample());
List<DeEngine> deEngines = deEngineMapper.selectByExampleWithBLOBs(new DeEngineExample());
if(CollectionUtils.isEmpty(deEngines)){
throw new Exception("未设置数据引擎");
}
......
import request from '@/utils/request'
import {validateDs} from "@/api/system/datasource";
export function engineMode() {
return request({
url: '/engine/mode',
method: 'get',
loading: true
})
}
export function engineInfo() {
return request({
url: '/engine/info',
method: 'get',
loading: true
})
}
export function validate(data) {
return request({
url: '/engine/validate',
method: 'post',
loading: true,
data
})
}
export function save(data) {
return request({
url: '/engine/save',
method: 'post',
loading: true,
data
})
}
......@@ -647,7 +647,8 @@ export default {
port: 'Port number cannot be empty',
account: 'Account cannot be empty',
test_recipients: 'Test recipients',
tip: 'Tip: use as test mail recipient only'
tip: 'Tip: use as test mail recipient only',
engine_mode_setting: 'Engine Setting'
},
chart: {
save_snapshot: 'Save Snapshot',
......
......@@ -649,7 +649,8 @@ export default {
port: '端口號不能爲空',
account: '賬戶不能爲空',
test_recipients: '測試收件人',
tip: '提示:僅用來作爲測試郵件收件人'
tip: '提示:僅用來作爲測試郵件收件人',
engine_mode_setting: '引擎設置'
},
chart: {
save_snapshot: '保存縮略圖',
......
......@@ -651,7 +651,7 @@ export default {
account: '账户不能为空',
test_recipients: '测试收件人',
tip: '提示:仅用来作为测试邮件收件人',
simple_mode_datasource: '数据设置'
engine_mode_setting: '引擎设置'
},
chart: {
save_snapshot: '保存缩略图',
......
......@@ -28,7 +28,7 @@
</el-form-item>
<el-form-item class="form-item">
<el-select v-model="mode" filterable :placeholder="$t('dataset.connect_mode')" size="mini">
<el-option :label="$t('dataset.sync_data')" value="1" :disabled="!kettleRunning || selectedDatasource.type==='es' || selectedDatasource.type==='ck' || selectedDatasource.type==='mongo' || selectedDatasource.type==='redshift' || selectedDatasource.type==='hive'" />
<el-option :label="$t('dataset.sync_data')" value="1" :disabled="!kettleRunning && engineMode!=='simple'" />
</el-select>
</el-form-item>
......@@ -66,6 +66,7 @@
<script>
import { listApiDatasource, post, isKettleRunning } from '@/api/dataset/dataset'
import {engineMode} from "@/api/system/engine";
export default {
name: 'AddApi',
......@@ -86,6 +87,7 @@ export default {
syncType: 'sync_now',
tableData: [],
kettleRunning: false,
engineMode: 'local',
selectedDatasource: {}
}
},
......@@ -119,6 +121,9 @@ export default {
},
created() {
this.kettleState()
engineMode().then(res => {
this.engineMode = res.data
})
},
methods: {
initDataSource() {
......
......@@ -13,7 +13,7 @@
</el-button>
</el-row>
</el-row>
<el-divider />
<el-divider/>
<el-row>
<el-form :inline="true">
<el-form-item class="form-item">
......@@ -28,15 +28,16 @@
</el-form-item>
<el-form-item class="form-item">
<el-select v-model="mode" filterable :placeholder="$t('dataset.connect_mode')" size="mini">
<el-option :label="$t('dataset.direct_connect')" value="0" />
<el-option :label="$t('dataset.sync_data')" value="1" :disabled="!kettleRunning || selectedDatasource.type==='es' || selectedDatasource.type==='ck' || selectedDatasource.type==='mongo' || selectedDatasource.type==='redshift' || selectedDatasource.type==='hive'" />
<el-option :label="$t('dataset.direct_connect')" value="0"/>
<el-option :label="$t('dataset.sync_data')" value="1"
:disabled="disabledSync"/>
</el-select>
</el-form-item>
<el-form-item v-if="mode === '1'" class="form-item">
<el-select v-model="syncType" filterable :placeholder="$t('dataset.connect_mode')" size="mini">
<el-option :label="$t('dataset.sync_now')" value="sync_now" />
<el-option :label="$t('dataset.sync_latter')" value="sync_latter" />
<el-option :label="$t('dataset.sync_now')" value="sync_now"/>
<el-option :label="$t('dataset.sync_latter')" value="sync_latter"/>
</el-select>
</el-form-item>
......@@ -53,12 +54,14 @@
</el-row>
<el-col style="overflow-y: auto;">
<el-checkbox-group v-model="checkTableList" size="small">
<el-tooltip v-for="t in tableData" :key="t.name" :disabled="t.enableCheck" effect="dark" :content="$t('dataset.table_already_add_to')+': '+t.datasetPath" placement="bottom">
<el-tooltip v-for="t in tableData" :key="t.name" :disabled="t.enableCheck" effect="dark"
:content="$t('dataset.table_already_add_to')+': '+t.datasetPath" placement="bottom">
<el-checkbox
border
:label="t.name"
:disabled="!t.enableCheck"
>{{ showTableNameWithComment(t) }}</el-checkbox>
>{{ showTableNameWithComment(t) }}
</el-checkbox>
</el-tooltip>
</el-checkbox-group>
</el-col>
......@@ -66,7 +69,8 @@
</template>
<script>
import { listDatasource, post, isKettleRunning } from '@/api/dataset/dataset'
import {listDatasource, post, isKettleRunning} from '@/api/dataset/dataset'
import {engineMode} from "@/api/system/engine";
export default {
name: 'AddDB',
......@@ -87,13 +91,16 @@ export default {
syncType: 'sync_now',
tableData: [],
kettleRunning: false,
selectedDatasource: {}
selectedDatasource: {},
engineMode: 'local',
disabledSync: true,
disabledSyncDs: ['es', 'ck', 'mongo', 'redshift', 'hive']
}
},
watch: {
dataSource(val) {
if (val) {
post('/datasource/getTables', { id: val }).then(response => {
post('/datasource/getTables', {id: val}).then(response => {
this.tables = response.data
this.tableData = JSON.parse(JSON.stringify(this.tables))
})
......@@ -101,13 +108,20 @@ export default {
if (this.options[i].id === val) {
this.selectedDatasource = this.options[i]
this.mode = '0'
if (this.engineMode === 'simple' || (!this.kettleRunning || this.disabledSyncDs.indexOf(this.selectedDatasource.type) !== -1 )) {
this.disabledSync = true
} else {
this.disabledSync = false
}
}
}
}
},
searchTable(val) {
if (val && val !== '') {
this.tableData = JSON.parse(JSON.stringify(this.tables.filter(ele => { return ele.name.toLocaleLowerCase().includes(val.toLocaleLowerCase()) })))
this.tableData = JSON.parse(JSON.stringify(this.tables.filter(ele => {
return ele.name.toLocaleLowerCase().includes(val.toLocaleLowerCase())
})))
} else {
this.tableData = JSON.parse(JSON.stringify(this.tables))
}
......@@ -121,6 +135,9 @@ export default {
},
created() {
this.kettleState()
engineMode().then(res => {
this.engineMode = res.data
})
},
methods: {
initDataSource() {
......@@ -152,7 +169,7 @@ export default {
const tables = []
const mode = this.mode
const syncType = this.syncType
this.checkTableList.forEach(function(name) {
this.checkTableList.forEach(function (name) {
tables.push({
name: ds.name + '_' + name,
sceneId: sceneId,
......@@ -160,7 +177,7 @@ export default {
type: 'db',
syncType: syncType,
mode: parseInt(mode),
info: JSON.stringify({ table: name })
info: JSON.stringify({table: name})
})
})
post('/dataset/table/batchAdd', tables).then(response => {
......@@ -171,7 +188,7 @@ export default {
cancel() {
this.dataReset()
this.$emit('switchComponent', { name: '' })
this.$emit('switchComponent', {name: ''})
},
dataReset() {
......@@ -187,25 +204,25 @@ export default {
</script>
<style scoped>
.el-divider--horizontal {
margin: 12px 0;
}
.el-divider--horizontal {
margin: 12px 0;
}
.form-item {
margin-bottom: 6px;
}
.form-item {
margin-bottom: 6px;
}
.el-checkbox {
margin-bottom: 14px;
margin-left: 0;
margin-right: 14px;
}
.el-checkbox {
margin-bottom: 14px;
margin-left: 0;
margin-right: 14px;
}
.el-checkbox.is-bordered + .el-checkbox.is-bordered {
margin-left: 0;
}
.el-checkbox.is-bordered + .el-checkbox.is-bordered {
margin-left: 0;
}
span{
font-size: 14px;
}
span {
font-size: 14px;
}
</style>
......@@ -35,7 +35,7 @@
<el-select v-model="mode" filterable :placeholder="$t('dataset.connect_mode')" size="mini">
<el-option :label="$t('dataset.direct_connect')" value="0"/>
<el-option :label="$t('dataset.sync_data')" value="1"
:disabled="!kettleRunning || selectedDatasource.type==='es' || selectedDatasource.type==='ck'|| selectedDatasource.type==='mongo'|| selectedDatasource.type==='redshift' || selectedDatasource.type==='hive'"/>
:disabled="disabledSync"/>
</el-select>
</el-form-item>
......@@ -124,6 +124,7 @@ import 'codemirror/keymap/emacs.js'
import 'codemirror/addon/hint/show-hint.css'
import 'codemirror/addon/hint/sql-hint'
import 'codemirror/addon/hint/show-hint'
import {engineMode} from "@/api/system/engine";
export default {
name: 'AddSQL',
......@@ -157,7 +158,9 @@ export default {
syncType: 'sync_now',
height: 500,
kettleRunning: false,
selectedDatasource: {}
selectedDatasource: {},
engineMode: 'local',
disabledSync: true
}
},
computed: {
......@@ -187,6 +190,9 @@ export default {
},
created() {
this.kettleState()
engineMode().then(res => {
this.engineMode = res.data
})
},
methods: {
kettleState() {
......@@ -198,6 +204,11 @@ export default {
for (let i = 0; i < this.options.length; i++) {
if (this.options[i].id === this.dataSource) {
this.selectedDatasource = this.options[i]
if (this.engineMode === 'simple' || (!this.kettleRunning || this.disabledSyncDs.indexOf(this.selectedDatasource.type) !== -1 )) {
this.disabledSync = true
} else {
this.disabledSync = false
}
}
}
},
......
......@@ -79,7 +79,6 @@
</template>
<script>
import { isKettleRunning, post } from '@/api/dataset/dataset'
import { queryAuthModel } from '@/api/authModel/authModel'
export default {
name: 'DatasetGroupSelectorTree',
......@@ -144,7 +143,6 @@ export default {
all: this.$t('commons.all'),
folder: this.$t('commons.folder')
},
kettleRunning: false,
sceneMode: false,
search: '',
data: [],
......@@ -200,14 +198,8 @@ export default {
this.treeNode()
},
created() {
this.kettleState()
},
methods: {
kettleState() {
isKettleRunning(false).then(res => {
this.kettleRunning = res.data
})
},
close() {
this.editGroup = false
this.groupForm = {
......
......@@ -87,7 +87,7 @@
<svg-icon icon-class="ds-sql" class="ds-icon-sql" />
{{ $t('dataset.sql_data') }}
</el-dropdown-item>
<el-dropdown-item :command="beforeClickAddData('excel',data)" :disabled="!kettleRunning">
<el-dropdown-item :command="beforeClickAddData('excel',data)" :disabled="!kettleRunning && engineMode!=='simple'">
<svg-icon icon-class="ds-excel" class="ds-icon-excel" />
{{ $t('dataset.excel_data') }}
</el-dropdown-item>
......@@ -232,6 +232,7 @@ import { loadTable, getScene, addGroup, delGroup, delTable, post, isKettleRunnin
import GroupMoveSelector from './GroupMoveSelector'
import DsMoveSelector from './DsMoveSelector'
import { queryAuthModel } from '@/api/authModel/authModel'
import {engineMode} from "@/api/system/engine";
export default {
name: 'Group',
......@@ -304,6 +305,7 @@ export default {
},
isTreeSearch: false,
kettleRunning: false,
engineMode: 'local',
searchPids: [], // 查询命中的pid
filterText: '',
searchType: 'all',
......@@ -333,6 +335,9 @@ export default {
},
created() {
this.kettleState()
engineMode().then(res => {
this.engineMode = res.data
})
},
mounted() {
this.treeNode(true)
......
<template>
<div>
<!--邮件表单-->
<el-form ref="form" v-loading="loading"
:model="form"
:rules="rules"
class="demo-form-inline"
:disabled="show"
label-width="180px"
label-position="top"
size="small"
>
<el-row>
<el-col>
<el-form-item :label="$t('datasource.type')" prop="type">
<el-select
v-model="form.type"
:placeholder="$t('datasource.please_choose_type')"
@change="changeType()"
filterable
>
<el-option
v-for="item in allTypes"
:key="item.name"
:label="item.label"
:value="item.name"
/>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('datasource.host')" prop="configuration.host">
<el-input v-model="form.configuration.host"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('datasource.data_base')" prop="configuration.dataBase">
<el-input v-model="form.configuration.dataBase"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('datasource.user_name')">
<el-input v-model="form.configuration.username"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('datasource.password')">
<el-input v-model="form.configuration.password" show-password/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('datasource.port')" prop="configuration.port">
<el-input v-model="form.configuration.port" autocomplete="off" type="number" min="0"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('datasource.extra_params')">
<el-input v-model="form.configuration.extraParams"/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div>
<el-button type="primary" size="small" @click="validaDatasource">
{{ $t('commons.validate') }}
</el-button>
<el-button v-if="showEdit" size="small" @click="edit">
{{ $t('commons.edit') }}
</el-button>
<el-button v-if="showSave" type="success" size="small" @click="save">
{{ $t('commons.save') }}
</el-button>
<el-button v-if="showCancel" type="info" size="small" @click="cancel">
{{ $t('commons.cancel') }}
</el-button>
</div>
</div>
</template>
<script>
import {engineInfo, validate, save} from '@/api/system/engine'
import i18n from "@/lang";
export default {
name: 'SimpleMode',
data() {
return {
form:
{
type: 'mysql',
configuration: {
host: '',
dataBase: '',
username: '',
password: '',
port: '',
extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'
}
},
originConfiguration: {
host: '',
dataBase: '',
username: '',
password: '',
port: '',
extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'
},
input: '',
visible: true,
showEdit: true,
showSave: false,
showCancel: false,
show: true,
disabledConnection: false,
disabledSave: false,
loading: false,
rules: {
host: [
{
required: true,
message: this.$t('system_parameter_setting.host'),
trigger: ['change', 'blur']
}
],
port: [
{
required: true,
message: this.$t('system_parameter_setting.port'),
trigger: ['change', 'blur']
}
],
account: [
{
required: true,
message: this.$t('system_parameter_setting.account'),
trigger: ['change', 'blur']
}]
},
allTypes: [
{
name: 'mysql',
label: 'MySQL',
type: 'jdbc',
extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'
}
]
}
},
created() {
this.query()
},
methods: {
query() {
engineInfo().then(response => {
if (response.data.id) {
this.form = JSON.parse(JSON.stringify(response.data))
this.form.configuration = JSON.parse(this.form.configuration)
this.originConfiguration = JSON.parse(JSON.stringify(this.form.configuration))
}
this.$nextTick(() => {
this.$refs.form.clearValidate()
})
})
},
edit() {
this.showEdit = false
this.showSave = true
this.showCancel = true
this.show = false
},
save() {
if (this.form.configuration.dataSourceType === 'jdbc' && this.form.configuration.port <= 0) {
this.$message.error(i18n.t('datasource.port_no_less_then_0'))
return
}
if (this.form.configuration.initialPoolSize < 0 || this.form.configuration.minPoolSize < 0 || this.form.configuration.maxPoolSize < 0) {
this.$message.error(i18n.t('datasource.no_less_then_0'))
return
}
this.$refs.form.validate(valid => {
if (!valid) {
return false
}
const form = JSON.parse(JSON.stringify(this.form))
form.configuration = JSON.stringify(form.configuration)
save(form).then(res => {
this.showEdit = true
this.showCancel = false
this.showSave = false
this.show = true
this.originConfiguration = JSON.parse(JSON.stringify(this.form.configuration))
this.$success(i18n.t('commons.save_success'))
})
})
},
cancel() {
this.showEdit = true
this.showCancel = false
this.showSave = false
this.show = true
this.form.configuration = JSON.parse(JSON.stringify(this.originConfiguration))
},
changeType() {
for (let i = 0; i < this.allTypes.length; i++) {
if (this.allTypes[i].name === this.form.type) {
this.form.configuration.dataSourceType = this.allTypes[i].type
this.form.configuration.extraParams = this.allTypes[i].extraParams
}
}
},
validaDatasource() {
if (!this.form.configuration.schema && this.form.type === 'oracle') {
this.$message.error(i18n.t('datasource.please_choose_schema'))
return
}
if (this.form.configuration.dataSourceType === 'jdbc' && this.form.configuration.port <= 0) {
this.$message.error(i18n.t('datasource.port_no_less_then_0'))
return
}
this.$refs.form.validate(valid => {
if (valid) {
const data = JSON.parse(JSON.stringify(this.form))
data.configuration = JSON.stringify(data.configuration)
validate(data).then(res => {
if (res.success) {
this.$success(i18n.t('datasource.validate_success'))
} else {
if (res.message.length < 2500) {
this.$error(res.message)
} else {
this.$error(res.message.substring(0, 2500) + '......')
}
}
}).catch(res => {
this.$error(res.message)
})
} else {
return false
}
})
},
}
}
</script>
<style scoped>
</style>
<template>
<div>
<!--邮件表单-->
<el-form
ref="formInline"
v-loading="loading"
:model="formInline"
:rules="rules"
class="demo-form-inline"
:disabled="show"
size="small"
>
<el-row>
<el-col>
<el-form-item :label="$t('system_parameter_setting.SMTP_host')" prop="host">
<el-input
v-model="formInline.host"
:placeholder="$t('system_parameter_setting.SMTP_host')"
@input="change()"
/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('system_parameter_setting.SMTP_port')" prop="port">
<el-input
v-model="formInline.port"
:placeholder="$t('system_parameter_setting.SMTP_port')"
@input="change()"
/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('system_parameter_setting.SMTP_account')" prop="account">
<el-input
v-model="formInline.account"
:placeholder="$t('system_parameter_setting.SMTP_account')"
@input="change()"
/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('system_parameter_setting.SMTP_password')" prop="password">
<el-input
ref="input"
v-model="formInline.password"
:placeholder="$t('system_parameter_setting.SMTP_password')"
autocomplete="new-password"
show-password
type="text"
@focus="changeType"
/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('system_parameter_setting.test_recipients')">
<el-input
ref="input"
v-model="formInline.recipient"
:placeholder="$t('system_parameter_setting.test_recipients')"
autocomplete="new-password"
show-password
type="text"
/>
<p style="color: #8a8b8d">({{ $t('system_parameter_setting.tip') }})</p>
</el-form-item>
</el-col>
</el-row>
<!---->
<div style="border: 0px;margin-bottom: 20px">
<el-checkbox v-model="formInline.ssl" :label="$t('system_parameter_setting.SSL')" />
</div>
<div style="border: 0px;margin-bottom: 20px">
<el-checkbox v-model="formInline.tls" :label="$t('system_parameter_setting.TLS')" />
</div>
<template v-slot:footer />
</el-form>
<div>
<el-button type="primary" :disabled="disabledConnection" size="small" @click="testConnection('formInline')">
{{ $t('system_parameter_setting.test_connection') }}
</el-button>
<el-button v-if="showEdit" size="small" @click="edit">{{ $t('commons.edit') }}</el-button>
<el-button v-if="showSave" type="success" :disabled="disabledSave" size="small" @click="save('formInline')">
{{ $t('commons.save') }}
</el-button>
<el-button v-if="showCancel" type="info" size="small" @click="cancel">{{ $t('commons.cancel') }}</el-button>
</div>
</div>
</template>
<script>
import { emailInfo, updateInfo, validate } from '@/api/system/email'
export default {
name: 'EmailSetting',
data() {
return {
formInline: {},
input: '',
visible: true,
showEdit: true,
showSave: false,
showCancel: false,
show: true,
disabledConnection: false,
disabledSave: false,
loading: false,
rules: {
host: [
{
required: true,
message: this.$t('system_parameter_setting.host'),
trigger: ['change', 'blur']
}
],
port: [
{
required: true,
message: this.$t('system_parameter_setting.port'),
trigger: ['change', 'blur']
}
],
account: [
{
required: true,
message: this.$t('system_parameter_setting.account'),
trigger: ['change', 'blur']
}]
}
}
},
created() {
this.query()
},
methods: {
changeType() {
this.$refs.input = 'password'
},
query() {
emailInfo().then(response => {
this.formInline = response.data
this.formInline.ssl = this.formInline.ssl === 'true'
this.formInline.tls = this.formInline.tls === 'true'
this.$nextTick(() => {
this.$refs.formInline.clearValidate()
})
})
},
change() {
if (!this.formInline.host || !this.formInline.port || !this.formInline.account) {
this.disabledConnection = true
this.disabledSave = true
} else {
this.disabledConnection = false
this.disabledSave = false
}
},
testConnection(formInline) {
const param = {
'smtp.host': this.formInline.host,
'smtp.port': this.formInline.port,
'smtp.account': this.formInline.account,
'smtp.password': this.formInline.password,
'smtp.ssl': this.formInline.ssl,
'smtp.tls': this.formInline.tls,
'smtp.recipient': this.formInline.recipient
}
this.$refs[formInline].validate((valid) => {
if (valid) {
validate(param).then(response => {
this.$success(this.$t('commons.connection_successful'))
})
} else {
return false
}
})
},
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
const param = [
{ paramKey: 'smtp.host', paramValue: this.formInline.host, type: 'text', sort: 1 },
{ paramKey: 'smtp.port', paramValue: this.formInline.port, type: 'text', sort: 2 },
{ paramKey: 'smtp.account', paramValue: this.formInline.account, type: 'text', sort: 3 },
{ paramKey: 'smtp.password', paramValue: this.formInline.password, type: 'password', sort: 4 },
{ paramKey: 'smtp.ssl', paramValue: this.formInline.ssl, type: 'text', sort: 5 },
{ paramKey: 'smtp.tls', paramValue: this.formInline.tls, type: 'text', sort: 6 },
{ paramKey: 'smtp.recipient', paramValue: this.formInline.recipient, type: 'text', sort: 8 }
]
this.$refs[formInline].validate(valid => {
if (valid) {
updateInfo(param).then(response => {
const flag = response.success
if (flag) {
this.$success(this.$t('commons.save_success'))
} else {
this.$message.error(this.$t('commons.save_failed'))
}
})
} else {
// this.result = false
}
})
},
cancel() {
this.showEdit = true
this.showCancel = false
this.showSave = false
this.show = true
this.query()
}
}
}
</script>
<style scoped>
</style>
......@@ -6,10 +6,6 @@
<basic-setting />
</el-tab-pane>
<el-tab-pane :lazy="true" :label="$t('system_parameter_setting.simple_mode_datasource')" name="first">
<email-setting />
</el-tab-pane>
<el-tab-pane :lazy="true" :label="$t('system_parameter_setting.mailbox_service_settings')" name="first">
<email-setting />
</el-tab-pane>
......@@ -30,32 +26,42 @@
<plugin-com v-if="isPluginLoaded" ref="DisplaySetting" component-name="SsoSetting" />
</el-tab-pane>
<el-tab-pane v-if="engineMode==='simple'" :lazy="true" :label="$t('system_parameter_setting.engine_mode_setting')" name="six">
<simple-mode />
</el-tab-pane>
</el-tabs>
</layout-content>
</template>
<script>
import BasicSetting from './BasicSetting'
import EmailSetting from './EmailSetting'
import SimpleMode from './SimpleModeSetting'
import LayoutContent from '@/components/business/LayoutContent'
import PluginCom from '@/views/system/plugin/PluginCom'
import { pluginLoaded } from '@/api/user'
import { engineMode } from '@/api/system/engine'
export default {
components: { BasicSetting, EmailSetting, LayoutContent, PluginCom },
components: { BasicSetting, EmailSetting, LayoutContent, PluginCom, SimpleMode},
data() {
return {
activeName: 'zero',
isPluginLoaded: false
isPluginLoaded: false,
engineMode: 'local'
}
},
beforeCreate() {
pluginLoaded().then(res => {
this.isPluginLoaded = res.success && res.data
})
engineMode().then(res => {
this.engineMode = res.data
})
},
methods: {
handleClick(tab, event) {
console.log(tab, event)
// console.log(tab, event)
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论