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

feat: 支持数据源插件

上级 8f9b355b
...@@ -486,45 +486,45 @@ ...@@ -486,45 +486,45 @@
<build> <build>
<plugins> <plugins>
<!-- <plugin>--> <plugin>
<!-- <groupId>org.apache.maven.plugins</groupId>--> <groupId>org.apache.maven.plugins</groupId>
<!-- <artifactId>maven-antrun-plugin</artifactId>--> <artifactId>maven-antrun-plugin</artifactId>
<!-- <executions>--> <executions>
<!-- <execution>--> <execution>
<!-- <?m2e execute onConfiguration?>--> <?m2e execute onConfiguration?>
<!-- <id>main-class-placement</id>--> <id>main-class-placement</id>
<!-- <phase>generate-resources</phase>--> <phase>generate-resources</phase>
<!-- <configuration>--> <configuration>
<!-- <target>--> <target>
<!-- <move todir="src/main/resources/static">--> <move todir="src/main/resources/static">
<!-- <fileset dir="../frontend/dist">--> <fileset dir="../frontend/dist">
<!-- <exclude name="*.html"/>--> <exclude name="*.html"/>
<!-- </fileset>--> </fileset>
<!-- </move>--> </move>
<!-- <move todir="src/main/resources/templates">--> <move todir="src/main/resources/templates">
<!-- <fileset dir="../frontend/dist">--> <fileset dir="../frontend/dist">
<!-- <include name="*.html"/>--> <include name="*.html"/>
<!-- </fileset>--> </fileset>
<!-- </move>--> </move>
<!-- <copy todir="src/main/resources/static/de-app">--> <copy todir="src/main/resources/static/de-app">
<!-- <fileset dir="../mobile/dist">--> <fileset dir="../mobile/dist">
<!-- <exclude name="*.html"/>--> <exclude name="*.html"/>
<!-- </fileset>--> </fileset>
<!-- </copy>--> </copy>
<!-- <copy file="../mobile/dist/index.html" tofile="src/main/resources/templates/app.html" />--> <copy file="../mobile/dist/index.html" tofile="src/main/resources/templates/app.html" />
<!-- </target>--> </target>
<!-- </configuration>--> </configuration>
<!-- <goals>--> <goals>
<!-- <goal>run</goal>--> <goal>run</goal>
<!-- </goals>--> </goals>
<!-- </execution>--> </execution>
<!-- </executions>--> </executions>
<!-- </plugin>--> </plugin>
</plugins> </plugins>
</build> </build>
</profile> </profile>
......
...@@ -65,6 +65,52 @@ public class DeFileUtils { ...@@ -65,6 +65,52 @@ public class DeFileUtils {
} }
return null; return null;
} }
public static void copyFolder(String sourcePath,String targetPath) throws Exception{
//源文件夹路径
File sourceFile = new File(sourcePath);
//目标文件夹路径
File targetFile = new File(targetPath);
if(!sourceFile.exists()){
throw new Exception("文件夹不存在");
}
if(!sourceFile.isDirectory()){
throw new Exception("源文件夹不是目录");
}
if(!targetFile.exists()){
targetFile.mkdirs();
}
if(!targetFile.isDirectory()){
throw new Exception("目标文件夹不是目录");
}
File[] files = sourceFile.listFiles();
if(files == null || files.length == 0){
return;
}
for(File file : files){
//文件要移动的路径
String movePath = targetFile+File.separator+file.getName();
if(file.isDirectory()){
//如果是目录则递归调用
copyFolder(file.getAbsolutePath(),movePath);
}else {
//如果是文件则复制文件
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(movePath));
byte[] b = new byte[1024];
int temp = 0;
while((temp = in.read(b)) != -1){
out.write(b,0,temp);
}
out.close();
in.close();
}
}
}
public static String copy(File source, String targetDir) throws IOException{ public static String copy(File source, String targetDir) throws IOException{
String name = source.getName(); String name = source.getName();
......
...@@ -56,12 +56,9 @@ public class ZipUtils { ...@@ -56,12 +56,9 @@ public class ZipUtils {
} }
public static void unzip(File source, String out) throws IOException { public static void unzip(File source, String out) throws IOException {
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(source))) { ZipInputStream zis = new ZipInputStream(new FileInputStream(source));
ZipEntry entry = zis.getNextEntry(); ZipEntry entry = zis.getNextEntry();
while (entry != null) { while (entry != null) {
File file = protectZipSlip(entry.getName(), out); File file = protectZipSlip(entry.getName(), out);
if (entry.isDirectory()) { if (entry.isDirectory()) {
...@@ -89,7 +86,6 @@ public class ZipUtils { ...@@ -89,7 +86,6 @@ public class ZipUtils {
entry = zis.getNextEntry(); entry = zis.getNextEntry();
} }
} }
}
/** /**
* 把所有文件都直接解压到指定目录(忽略子文件夹) * 把所有文件都直接解压到指定目录(忽略子文件夹)
......
...@@ -2,6 +2,7 @@ package io.dataease.dto; ...@@ -2,6 +2,7 @@ package io.dataease.dto;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import io.dataease.plugins.common.base.domain.Datasource; import io.dataease.plugins.common.base.domain.Datasource;
import io.dataease.plugins.common.constants.DatasourceCalculationMode;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -17,4 +18,5 @@ public class DatasourceDTO extends Datasource { ...@@ -17,4 +18,5 @@ public class DatasourceDTO extends Datasource {
private String privileges; private String privileges;
private JSONArray apiConfiguration; private JSONArray apiConfiguration;
private String typeDesc; private String typeDesc;
private DatasourceCalculationMode calculationMode;
} }
package io.dataease.dto;
import io.dataease.plugins.common.base.domain.MyPlugin;
import lombok.Data;
@Data
public class MyPluginDTO extends MyPlugin {
private String require = "1.9.0";
}
...@@ -24,27 +24,17 @@ public class ProviderFactory implements ApplicationContextAware { ...@@ -24,27 +24,17 @@ public class ProviderFactory implements ApplicationContextAware {
this.context = ctx; this.context = ctx;
for(final DatasourceTypes d: DatasourceTypes.values()) { for(final DatasourceTypes d: DatasourceTypes.values()) {
final ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) context).getBeanFactory(); final ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) context).getBeanFactory();
DataSourceType dataSourceType = new DataSourceType(); if(d.isDatasource()){
dataSourceType.setType(d.getType()); DataSourceType dataSourceType = new DataSourceType(d.getType(), d.getName(), false, d.getExtraParams(), d.getCalculationMode());
dataSourceType.setName(d.getName());
dataSourceType.setAliasPrefix(d.getAliasPrefix());
dataSourceType.setAliasSuffix(d.getAliasSuffix());
dataSourceType.setKeywordPrefix(d.getKeywordPrefix());
dataSourceType.setKeywordSuffix(d.getKeywordSuffix());
dataSourceType.setPlugin(false);
dataSourceType.setExtraParams(d.getExtraParams());
System.out.println(new Gson().toJson(dataSourceType));
beanFactory.registerSingleton(d.getType(), dataSourceType); beanFactory.registerSingleton(d.getType(), dataSourceType);
} }
} }
}
public static Provider getProvider(String type) { public static Provider getProvider(String type) {
Map<String, DataSourceType> dataSourceTypeMap = SpringContextUtil.getApplicationContext().getBeansOfType((DataSourceType.class)); Map<String, DataSourceType> dataSourceTypeMap = SpringContextUtil.getApplicationContext().getBeansOfType((DataSourceType.class));
if(dataSourceTypeMap.get(type).isPlugin()){ if(dataSourceTypeMap.keySet().contains(type)){
return context.getBean(type, Provider.class);
}
DatasourceTypes datasourceType = DatasourceTypes.valueOf(type); DatasourceTypes datasourceType = DatasourceTypes.valueOf(type);
switch (datasourceType) { switch (datasourceType) {
case es: case es:
...@@ -56,11 +46,13 @@ public class ProviderFactory implements ApplicationContextAware { ...@@ -56,11 +46,13 @@ public class ProviderFactory implements ApplicationContextAware {
} }
} }
return SpringContextUtil.getApplicationContext().getBean(type + "DsProvider", Provider.class);
}
public static QueryProvider getQueryProvider(String type) { public static QueryProvider getQueryProvider(String type) {
Map<String, DataSourceType> dataSourceTypeMap = SpringContextUtil.getApplicationContext().getBeansOfType((DataSourceType.class)); Map<String, DataSourceType> dataSourceTypeMap = SpringContextUtil.getApplicationContext().getBeansOfType((DataSourceType.class));
if(dataSourceTypeMap.get(type).isPlugin()){ if(dataSourceTypeMap.keySet().contains(type)){
return context.getBean(type, QueryProvider.class);
}
DatasourceTypes datasourceType = DatasourceTypes.valueOf(type); DatasourceTypes datasourceType = DatasourceTypes.valueOf(type);
switch (datasourceType) { switch (datasourceType) {
case mysql: case mysql:
...@@ -100,6 +92,9 @@ public class ProviderFactory implements ApplicationContextAware { ...@@ -100,6 +92,9 @@ public class ProviderFactory implements ApplicationContextAware {
} }
} }
return SpringContextUtil.getApplicationContext().getBean(type + "QueryProvider", QueryProvider.class);
}
public static DDLProvider getDDLProvider(String type) { public static DDLProvider getDDLProvider(String type) {
DatasourceTypes datasourceType = DatasourceTypes.valueOf(type); DatasourceTypes datasourceType = DatasourceTypes.valueOf(type);
switch (datasourceType) { switch (datasourceType) {
......
...@@ -34,7 +34,7 @@ public class JdbcProvider extends DefaultJdbcProvider { ...@@ -34,7 +34,7 @@ public class JdbcProvider extends DefaultJdbcProvider {
return false; return false;
} }
@Override @Override
public String getName(){ public String getType(){
return "built-in"; return "built-in";
} }
/** /**
......
package io.dataease.provider.datasource;
import com.alibaba.druid.pool.DruidDataSource;
import com.google.gson.Gson;
import io.dataease.plugins.common.constants.DatasourceTypes;
import io.dataease.plugins.common.dto.datasource.TableDesc;
import io.dataease.plugins.common.dto.datasource.TableField;
import io.dataease.plugins.common.exception.DataEaseException;
import io.dataease.plugins.common.request.datasource.DatasourceRequest;
import io.dataease.plugins.datasource.entity.JdbcConfiguration;
import io.dataease.plugins.datasource.provider.DefaultJdbcProvider;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.sql.*;
import java.util.*;
@Component("maxcompute")
public class MaxCompute extends DefaultJdbcProvider {
@Override
public String getName(){
return "maxcompute";
}
@Override
public boolean isUseDatasourcePool(){
return false;
}
@Override
public Connection getConnection(DatasourceRequest datasourceRequest) throws Exception {
Properties props = new Properties();
MaxcomputeConfig maxcomputeConfig = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), MaxcomputeConfig.class);
String username = maxcomputeConfig.getUsername();
String password = maxcomputeConfig.getPassword();
String driver = maxcomputeConfig.getDriver();
String url = maxcomputeConfig.getUrl();
Driver driverClass = (Driver) extendedJdbcClassLoader.loadClass(driver).newInstance();
if (StringUtils.isNotBlank(username)) {
props.setProperty("user", username);
if (StringUtils.isNotBlank(password)) {
props.setProperty("password", password);
}
}
Connection conn = driverClass.connect(url, props);
return conn;
}
@Override
public List<TableDesc> getTables(DatasourceRequest datasourceRequest) throws Exception {
List<TableDesc> tables = new ArrayList<>();
String queryStr = getTablesSql(datasourceRequest);
try (Connection con = getConnectionFromPool(datasourceRequest); Statement statement = con.createStatement(); ResultSet resultSet = statement.executeQuery(queryStr)) {
while (resultSet.next()) {
tables.add(getTableDesc(datasourceRequest, resultSet));
}
} catch (Exception e) {
DataEaseException.throwException(e);
}
return tables;
}
private TableDesc getTableDesc(DatasourceRequest datasourceRequest, ResultSet resultSet) throws SQLException {
TableDesc tableDesc = new TableDesc();
tableDesc.setName(resultSet.getString(1));
return tableDesc;
}
@Override
public List<TableField> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
datasourceRequest.setQuery("select * from " + datasourceRequest.getTable() + " limit 0");
return fetchResultField(datasourceRequest);
}
}
package io.dataease.provider.datasource;
import io.dataease.plugins.datasource.entity.JdbcConfiguration;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
@Getter
@Setter
public class MaxcomputeConfig extends JdbcConfiguration {
private String driver = "com.aliyun.odps.jdbc.OdpsDriver";
private String url;
}
...@@ -45,6 +45,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -45,6 +45,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
...@@ -62,15 +63,19 @@ public class DatasourceService { ...@@ -62,15 +63,19 @@ public class DatasourceService {
private CommonThreadPool commonThreadPool; private CommonThreadPool commonThreadPool;
@Resource @Resource
private SysAuthService sysAuthService; private SysAuthService sysAuthService;
// private static List<String> dsTypes = Arrays.asList("TiDB", "StarRocks", "excel", "mysql", "hive", "impala", "mariadb", "ds_doris", "pg", "sqlServer", "oracle", "mongo", "ck", "db2", "es", "redshift", "api");
public Collection<DataSourceType>types(){ public Collection<DataSourceType>types(){
return SpringContextUtil.getApplicationContext().getBeansOfType((DataSourceType.class)).values(); Collection<DataSourceType> types = new ArrayList<>();
types.addAll(SpringContextUtil.getApplicationContext().getBeansOfType(DataSourceType.class).values());
SpringContextUtil.getApplicationContext().getBeansOfType(io.dataease.plugins.datasource.service.DatasourceService.class).values().forEach(datasourceService -> {
types.add(datasourceService.getDataSourceType());
});
return types;
} }
@DeCleaner(DePermissionType.DATASOURCE) @DeCleaner(DePermissionType.DATASOURCE)
public Datasource addDatasource(Datasource datasource) throws Exception{ public Datasource addDatasource(Datasource datasource) throws Exception{
if(!SpringContextUtil.getApplicationContext().getBeansOfType(DataSourceType.class).keySet().contains(datasource.getType())){ if(!types().stream().map(DataSourceType::getType).collect(Collectors.toList()).contains(datasource.getType())){
throw new Exception("Datasource type not supported."); throw new Exception("Datasource type not supported.");
} }
checkName(datasource.getName(),datasource.getType(), datasource.getId()); checkName(datasource.getName(),datasource.getType(), datasource.getId());
...@@ -104,7 +109,12 @@ public class DatasourceService { ...@@ -104,7 +109,12 @@ public class DatasourceService {
request.setSort("update_time desc"); request.setSort("update_time desc");
List<DatasourceDTO> datasourceDTOS = extDataSourceMapper.queryUnion(request); List<DatasourceDTO> datasourceDTOS = extDataSourceMapper.queryUnion(request);
datasourceDTOS.forEach(datasourceDTO -> { datasourceDTOS.forEach(datasourceDTO -> {
datasourceDTO.setTypeDesc(SpringContextUtil.getApplicationContext().getBean(datasourceDTO.getType(), DataSourceType.class).getName()); types().forEach(dataSourceType -> {
if(dataSourceType.getType().equalsIgnoreCase(datasourceDTO.getType())){
datasourceDTO.setTypeDesc(dataSourceType.getName());
datasourceDTO.setCalculationMode(dataSourceType.getCalculationMode());
}
});
if(datasourceDTO.getType().equalsIgnoreCase(DatasourceTypes.api.toString())){ if(datasourceDTO.getType().equalsIgnoreCase(DatasourceTypes.api.toString())){
JSONArray apiDefinitionList = JSONObject.parseArray(datasourceDTO.getConfiguration()); JSONArray apiDefinitionList = JSONObject.parseArray(datasourceDTO.getConfiguration());
JSONArray apiDefinitionListWithStatus = new JSONArray(); JSONArray apiDefinitionListWithStatus = new JSONArray();
...@@ -165,7 +175,7 @@ public class DatasourceService { ...@@ -165,7 +175,7 @@ public class DatasourceService {
} }
public void updateDatasource(UpdataDsRequest updataDsRequest)throws Exception{ public void updateDatasource(UpdataDsRequest updataDsRequest)throws Exception{
if(!SpringContextUtil.getApplicationContext().getBeansOfType(DataSourceType.class).keySet().contains(updataDsRequest.getType())){ if(!types().stream().map(DataSourceType::getType).collect(Collectors.toList()).contains(updataDsRequest.getType())){
throw new Exception("Datasource type not supported."); throw new Exception("Datasource type not supported.");
} }
checkName(updataDsRequest.getName(),updataDsRequest.getType(),updataDsRequest.getId()); checkName(updataDsRequest.getName(),updataDsRequest.getType(),updataDsRequest.getId());
......
...@@ -2,6 +2,7 @@ package io.dataease.service.sys; ...@@ -2,6 +2,7 @@ package io.dataease.service.sys;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.dataease.dto.MyPluginDTO;
import io.dataease.ext.ExtSysPluginMapper; import io.dataease.ext.ExtSysPluginMapper;
import io.dataease.ext.query.GridExample; import io.dataease.ext.query.GridExample;
import io.dataease.commons.constants.AuthConstants; import io.dataease.commons.constants.AuthConstants;
...@@ -65,13 +66,13 @@ public class PluginService { ...@@ -65,13 +66,13 @@ public class PluginService {
* @param file * @param file
* @return * @return
*/ */
public Map<String, Object> localInstall(MultipartFile file) { public Map<String, Object> localInstall(MultipartFile file) throws Exception{
//1.上传文件到服务器pluginDir目录下 //1.上传文件到服务器pluginDir目录下
File dest = DeFileUtils.upload(file, pluginDir + "temp/"); File dest = DeFileUtils.upload(file, pluginDir + "temp/");
//2.解压目标文件dest 得到plugin.json和jar //2.解压目标文件dest 得到plugin.json和jar
String folder = pluginDir + "folder/"; String folder = pluginDir + "folder/";
try { try {
ZipUtils.upZipFile(dest, folder); ZipUtils.unzip(dest, folder);
} catch (IOException e) { } catch (IOException e) {
DeFileUtils.deleteFile(pluginDir + "temp/"); DeFileUtils.deleteFile(pluginDir + "temp/");
DeFileUtils.deleteFile(folder); DeFileUtils.deleteFile(folder);
...@@ -90,7 +91,7 @@ public class PluginService { ...@@ -90,7 +91,7 @@ public class PluginService {
LogUtil.error(msg); LogUtil.error(msg);
DEException.throwException(new RuntimeException(msg)); DEException.throwException(new RuntimeException(msg));
} }
MyPlugin myPlugin = formatJsonFile(jsonFiles[0]); MyPluginDTO myPlugin = formatJsonFile(jsonFiles[0]);
if (!versionMatch(myPlugin.getRequire())) { if (!versionMatch(myPlugin.getRequire())) {
String msg = "当前插件要求系统版本最低为:" + myPlugin.getRequire(); String msg = "当前插件要求系统版本最低为:" + myPlugin.getRequire();
...@@ -118,6 +119,9 @@ public class PluginService { ...@@ -118,6 +119,9 @@ public class PluginService {
targetDir = makeTargetDir(myPlugin); targetDir = makeTargetDir(myPlugin);
String jarPath; String jarPath;
jarPath = DeFileUtils.copy(jarFile, targetDir); jarPath = DeFileUtils.copy(jarFile, targetDir);
if(myPlugin.getCategory().equalsIgnoreCase("datasource")){
DeFileUtils.copyFolder(folder + "/" + myPlugin.getDsType() + "Driver", targetDir + myPlugin.getDsType() + "Driver");
}
loadJar(jarPath, myPlugin); loadJar(jarPath, myPlugin);
myPluginMapper.insert(myPlugin); myPluginMapper.insert(myPlugin);
...@@ -192,6 +196,11 @@ public class PluginService { ...@@ -192,6 +196,11 @@ public class PluginService {
String path = pluginDir + plugin.getStore() + "/" + fileName; String path = pluginDir + plugin.getStore() + "/" + fileName;
File jarFile = new File(path); File jarFile = new File(path);
FileUtil.del(jarFile); FileUtil.del(jarFile);
if(plugin.getCategory().equalsIgnoreCase("datasource")){
File driverFile = new File(pluginDir + plugin.getStore() + "/" + plugin.getDsType() + "Driver");
FileUtil.del(driverFile);
}
} }
/** /**
...@@ -224,13 +233,13 @@ public class PluginService { ...@@ -224,13 +233,13 @@ public class PluginService {
* *
* @return * @return
*/ */
private MyPlugin formatJsonFile(File file) { private MyPluginDTO formatJsonFile(File file) {
String str = DeFileUtils.readJson(file); String str = DeFileUtils.readJson(file);
Gson gson = new Gson(); Gson gson = new Gson();
Map<String, Object> myPlugin = gson.fromJson(str, Map.class); Map<String, Object> myPlugin = gson.fromJson(str, Map.class);
myPlugin.put("free", (Double) myPlugin.get("free") > 0.0); myPlugin.put("free", (Double) myPlugin.get("free") > 0.0);
myPlugin.put("loadMybatis", (Double) myPlugin.get("loadMybatis") > 0.0); myPlugin.put("loadMybatis", myPlugin.get("loadMybatis") == null ? false : (Double) myPlugin.get("loadMybatis") > 0.0);
MyPlugin result = new MyPlugin(); MyPluginDTO result = new MyPluginDTO();
try { try {
org.apache.commons.beanutils.BeanUtils.populate(result, myPlugin); org.apache.commons.beanutils.BeanUtils.populate(result, myPlugin);
result.setInstallTime(System.currentTimeMillis()); result.setInstallTime(System.currentTimeMillis());
...@@ -240,6 +249,10 @@ public class PluginService { ...@@ -240,6 +249,10 @@ public class PluginService {
e.printStackTrace(); e.printStackTrace();
} }
//BeanUtils.copyBean(result, myPlugin); //BeanUtils.copyBean(result, myPlugin);
if(result.getCategory().equalsIgnoreCase("datasource")){
result.setStore("thirdpart");
}
return result; return result;
} }
......
...@@ -213,5 +213,4 @@ export function checkCustomDs() { ...@@ -213,5 +213,4 @@ export function checkCustomDs() {
loading: true loading: true
}) })
} }
export const disabledSyncDs= ['es', 'ck', 'mongo', 'redshift', 'hive', 'impala']
export default { loadTable, getScene, addGroup, delGroup, addTable, delTable, groupTree, checkCustomDs } export default { loadTable, getScene, addGroup, delGroup, addTable, delTable, groupTree, checkCustomDs }
...@@ -70,7 +70,7 @@ export default { ...@@ -70,7 +70,7 @@ export default {
}, */ }, */
callPluginInner(param) { callPluginInner(param) {
const { methodName, methodParam } = param const { methodName, methodParam } = param
this.$refs[this.refId] && this.$refs[this.refId][methodName] && this.$refs[this.refId][methodName](methodParam) return this.$refs[this.refId] && this.$refs[this.refId][methodName] && this.$refs[this.refId][methodName](methodParam)
} }
} }
} }
......
...@@ -2,7 +2,7 @@ export default { ...@@ -2,7 +2,7 @@ export default {
fu: { fu: {
search_bar: { search_bar: {
search: 'Search', search: 'Search',
adv_search: 'Advanced search', adv_search: 'Advarequirednced search',
ok: 'Confirm', ok: 'Confirm',
cancel: 'Cancel', cancel: 'Cancel',
please_select: 'Please select', please_select: 'Please select',
...@@ -278,7 +278,7 @@ export default { ...@@ -278,7 +278,7 @@ export default {
id: 'ID', id: 'ID',
millisecond: 'Millisecond', millisecond: 'Millisecond',
cannot_be_null: 'Cannot be null', cannot_be_null: 'Cannot be null',
required: '{0} is required', required: 'Required',
already_exists: 'Already Exists', already_exists: 'Already Exists',
modifier: 'Modifier', modifier: 'Modifier',
validate: 'Validate', validate: 'Validate',
......
...@@ -278,7 +278,7 @@ export default { ...@@ -278,7 +278,7 @@ export default {
id: 'ID', id: 'ID',
millisecond: '毫秒', millisecond: '毫秒',
cannot_be_null: '不能爲空', cannot_be_null: '不能爲空',
required: '{0}是必填的', required: '必填',
already_exists: '名稱不能重複', already_exists: '名稱不能重複',
modifier: '修改人', modifier: '修改人',
validate: '校驗', validate: '校驗',
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
</template> </template>
<script> <script>
import {listDatasource, post, isKettleRunning, disabledSyncDs} from '@/api/dataset/dataset' import {listDatasource, post, isKettleRunning} from '@/api/dataset/dataset'
import {engineMode} from "@/api/system/engine"; import {engineMode} from "@/api/system/engine";
export default { export default {
...@@ -93,8 +93,7 @@ export default { ...@@ -93,8 +93,7 @@ export default {
kettleRunning: false, kettleRunning: false,
selectedDatasource: {}, selectedDatasource: {},
engineMode: 'local', engineMode: 'local',
disabledSync: true, disabledSync: true
disabledSyncDs: disabledSyncDs
} }
}, },
watch: { watch: {
...@@ -108,7 +107,7 @@ export default { ...@@ -108,7 +107,7 @@ export default {
if (this.options[i].id === val) { if (this.options[i].id === val) {
this.selectedDatasource = this.options[i] this.selectedDatasource = this.options[i]
this.mode = '0' this.mode = '0'
if (this.engineMode === 'simple' || (!this.kettleRunning || this.disabledSyncDs.indexOf(this.selectedDatasource.type) !== -1 )) { if (this.engineMode === 'simple' || (!this.kettleRunning || this.selectedDatasource.calculationMode === 'DIRECT')) {
this.disabledSync = true this.disabledSync = true
} else { } else {
this.disabledSync = false this.disabledSync = false
......
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
</template> </template>
<script> <script>
import {post, listDatasource, isKettleRunning, disabledSyncDs} from '@/api/dataset/dataset' import {post, listDatasource, isKettleRunning} from '@/api/dataset/dataset'
import {codemirror} from 'vue-codemirror' import {codemirror} from 'vue-codemirror'
import {getTable} from '@/api/dataset/dataset' import {getTable} from '@/api/dataset/dataset'
// 核心样式 // 核心样式
...@@ -206,7 +206,7 @@ export default { ...@@ -206,7 +206,7 @@ export default {
if (this.options[i].id === this.dataSource) { if (this.options[i].id === this.dataSource) {
this.selectedDatasource = this.options[i] this.selectedDatasource = this.options[i]
this.mode = '0' this.mode = '0'
if (this.engineMode === 'simple' || (!this.kettleRunning || this.disabledSyncDs.indexOf(this.selectedDatasource.type) !== -1 )) { if (this.engineMode === 'simple' || (!this.kettleRunning || this.selectedDatasource.calculationMode === 'DIRECT' )) {
this.disabledSync = true this.disabledSync = true
} else { } else {
this.disabledSync = false this.disabledSync = false
......
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
<div> <div>
<el-row> <el-row>
<el-col> <el-col>
<el-form <el-form
ref="DsForm" ref="DsConfig"
:model="form" :model="form"
:rules="rule" :rules="rule"
size="small" size="small"
...@@ -214,7 +213,7 @@ export default { ...@@ -214,7 +213,7 @@ export default {
disabled: { disabled: {
type: Boolean, type: Boolean,
default() { default() {
return true; return false;
} }
}, },
method: String, method: String,
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
:model="form" :model="form"
:rules="rule" :rules="rule"
size="small" size="small"
:disabled="disabled" :disabled="params && params.id && params.showModel && params.showModel === 'show' && !canEdit"
label-width="180px" label-width="180px"
label-position="right" label-position="right"
> >
...@@ -41,7 +41,10 @@ ...@@ -41,7 +41,10 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<ds-configuration :form="form" :disabled="disabled" :edit-api-item="edit_api_item"></ds-configuration> <ds-configuration ref="dsConfig" v-if="!datasourceType.isPlugin" :form="form" :disabled="params && params.id && params.showModel && params.showModel === 'show' && !canEdit" :edit-api-item="edit_api_item"></ds-configuration>
<plugin-com ref="pluginDsConfig" v-if="datasourceType.isPlugin" :component-name="datasourceType.type" :obj="{form, disabled }" />
</el-form> </el-form>
...@@ -72,13 +75,15 @@ import {$confirm} from '@/utils/message' ...@@ -72,13 +75,15 @@ import {$confirm} from '@/utils/message'
import i18n from '@/lang/index' import i18n from '@/lang/index'
import ApiHttpRequestForm from '@/views/system/datasource/ApiHttpRequestForm' import ApiHttpRequestForm from '@/views/system/datasource/ApiHttpRequestForm'
import DsConfiguration from "@/views/system/datasource/DsConfiguration"; import DsConfiguration from "@/views/system/datasource/DsConfiguration";
import PluginCom from '@/views/system/plugin/PluginCom'
export default { export default {
name: 'DsForm', name: 'DsForm',
components: { components: {
DsConfiguration, DsConfiguration,
LayoutContent, LayoutContent,
ApiHttpRequestForm ApiHttpRequestForm,
PluginCom
}, },
props: { props: {
params: { params: {
...@@ -96,7 +101,7 @@ export default { ...@@ -96,7 +101,7 @@ export default {
}, },
data() { data() {
return { return {
disabled: true, disabled: false,
form: { form: {
configuration: { configuration: {
initialPoolSize: 5, initialPoolSize: 5,
...@@ -110,6 +115,7 @@ export default { ...@@ -110,6 +115,7 @@ export default {
}, },
apiConfiguration: [] apiConfiguration: []
}, },
datasourceType: {},
rule: { rule: {
name: [{required: true, message: i18n.t('datasource.input_name'), trigger: 'blur'}, name: [{required: true, message: i18n.t('datasource.input_name'), trigger: 'blur'},
{min: 2, max: 25, message: i18n.t('datasource.input_limit_2_25', [2, 25]), trigger: 'blur'}], {min: 2, max: 25, message: i18n.t('datasource.input_limit_2_25', [2, 25]), trigger: 'blur'}],
...@@ -229,10 +235,11 @@ export default { ...@@ -229,10 +235,11 @@ export default {
if (this.params && this.params.id) { if (this.params && this.params.id) {
const row = this.params const row = this.params
this.edit(row) this.edit(row)
this.changeType()
} else { } else {
this.create() this.create()
if (this.params && this.params.type) { if (this.params && this.params.type) {
this.setType() this.changeType()
} }
} }
this.disabled = this.params && this.params.id && this.params.showModel && this.params.showModel === 'show' && !this.canEdit this.disabled = this.params && this.params.id && this.params.showModel && this.params.showModel === 'show' && !this.canEdit
...@@ -252,13 +259,12 @@ export default { ...@@ -252,13 +259,12 @@ export default {
idleConnectionTestPeriod: 5, idleConnectionTestPeriod: 5,
connectTimeout: 5 connectTimeout: 5
} }
this.changeType()
}, },
changeEdit() { changeEdit() {
this.canEdit = true this.canEdit = true
this.formType = 'modify' this.formType = 'modify'
this.disabled = this.params && this.params.id && this.params.showModel && this.params.showModel === 'show' && !this.canEdit this.disabled = this.params && this.params.id && this.params.showModel && this.params.showModel === 'show' && !this.canEdit
console.log(this.disabled)
}, },
create() { create() {
this.formType = 'add' this.formType = 'add'
...@@ -413,6 +419,15 @@ export default { ...@@ -413,6 +419,15 @@ export default {
this.$message.error(i18n.t('datasource.port_no_less_then_0')) this.$message.error(i18n.t('datasource.port_no_less_then_0'))
return return
} }
let status = null;
if(this.datasourceType.isPlugin){
status = this.$refs['pluginDsConfig'].callPluginInner({methodName: 'validate'})
}else {
status = this.$refs['dsConfig'].$refs['DsConfig'].validate
}
if(!status){
return;
}
this.$refs.dsForm.validate(valid => { this.$refs.dsForm.validate(valid => {
if (valid) { if (valid) {
const data = JSON.parse(JSON.stringify(this.form)) const data = JSON.parse(JSON.stringify(this.form))
...@@ -461,6 +476,7 @@ export default { ...@@ -461,6 +476,7 @@ export default {
for (let i = 0; i < this.dsTypes.length; i++) { for (let i = 0; i < this.dsTypes.length; i++) {
if (this.dsTypes[i].type === this.form.type) { if (this.dsTypes[i].type === this.form.type) {
this.form.configuration.extraParams = this.dsTypes[i].extraParams this.form.configuration.extraParams = this.dsTypes[i].extraParams
this.datasourceType = this.dsTypes[i]
} }
} }
}, },
......
...@@ -83,7 +83,7 @@ export default { ...@@ -83,7 +83,7 @@ export default {
this.$refs[this.refId] && this.$refs[this.refId].chartResize && this.$refs[this.refId].chartResize() this.$refs[this.refId] && this.$refs[this.refId].chartResize && this.$refs[this.refId].chartResize()
}, */ }, */
callPluginInner(param) { callPluginInner(param) {
this.$refs[this.refId] && this.$refs[this.refId].callPluginInner && this.$refs[this.refId].callPluginInner(param) return this.$refs[this.refId] && this.$refs[this.refId].callPluginInner && this.$refs[this.refId].callPluginInner(param)
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论