feat: 更新数据源,左侧树状结构保持不变

This commit is contained in:
taojinlong 2021-11-02 15:42:52 +08:00
parent 0d8df94bcb
commit 76141c85dc
7 changed files with 51 additions and 15 deletions

View File

@ -331,7 +331,10 @@ public class ExcelXlsReader implements HSSFListener {
totalSheets.add(excelSheetData); totalSheets.add(excelSheetData);
}else { }else {
List<String> tmp = new ArrayList<>(cellList); List<String> tmp = new ArrayList<>(cellList);
if(totalSheets.stream().filter(s->s.getExcelLable().equalsIgnoreCase(sheetName)).collect(Collectors.toList()).get(0).getData().size() < 100){
totalSheets.stream().filter(s->s.getExcelLable().equalsIgnoreCase(sheetName)).collect(Collectors.toList()).get(0).getData().add(tmp); totalSheets.stream().filter(s->s.getExcelLable().equalsIgnoreCase(sheetName)).collect(Collectors.toList()).get(0).getData().add(tmp);
}
totalRows++; totalRows++;
} }
} }

View File

@ -20,6 +20,7 @@ import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Api(tags = "数据源:数据源管理") @Api(tags = "数据源:数据源管理")
@ApiSupport(order = 30) @ApiSupport(order = 30)
@ -32,7 +33,7 @@ public class DatasourceController {
@ApiOperation("新增数据源") @ApiOperation("新增数据源")
@PostMapping("/add") @PostMapping("/add")
public Datasource addDatasource(@RequestBody Datasource datasource) { public Datasource addDatasource(@RequestBody Datasource datasource) throws Exception{
return datasourceService.addDatasource(datasource); return datasourceService.addDatasource(datasource);
} }
@ -57,6 +58,12 @@ public class DatasourceController {
return datasourceService.getDatasourceList(request); return datasourceService.getDatasourceList(request);
} }
@ApiOperation("查询当前用户数据源")
@GetMapping("/list/{type}")
public List<DatasourceDTO> getDatasourceListByType(@PathVariable String type) throws Exception {
return getDatasourceList().stream().filter(datasourceDTO -> datasourceDTO.getType().equalsIgnoreCase(type)).collect(Collectors.toList());
}
@ApiIgnore @ApiIgnore
@PostMapping("/list/{goPage}/{pageSize}") @PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<DatasourceDTO>> getDatasourceList(@RequestBody BaseGridRequest request, @PathVariable int goPage, @PathVariable int pageSize) throws Exception { public Pager<List<DatasourceDTO>> getDatasourceList(@RequestBody BaseGridRequest request, @PathVariable int goPage, @PathVariable int pageSize) throws Exception {

View File

@ -57,7 +57,7 @@ public class DatasourceService {
@Resource @Resource
private CommonThreadPool commonThreadPool; private CommonThreadPool commonThreadPool;
public Datasource addDatasource(Datasource datasource) { public Datasource addDatasource(Datasource datasource) throws Exception{
checkName(datasource); checkName(datasource);
long currentTimeMillis = System.currentTimeMillis(); long currentTimeMillis = System.currentTimeMillis();
datasource.setId(UUID.randomUUID().toString()); datasource.setId(UUID.randomUUID().toString());

View File

@ -15,6 +15,13 @@ export function listDatasource() {
method: 'get' method: 'get'
}) })
} }
export function listDatasourceByType(type) {
return request({
url: '/datasource/list/' + type,
loading: true,
method: 'get'
})
}
export function addDs(data) { export function addDs(data) {
return request({ return request({
url: 'datasource/add/', url: 'datasource/add/',

View File

@ -1,10 +1,10 @@
<template> <template>
<de-container v-loading="$store.getters.loadingMap[$store.getters.currentPath]"> <de-container v-loading="$store.getters.loadingMap[$store.getters.currentPath]">
<de-aside-container style="padding: 0 0;"> <de-aside-container style="padding: 0 0;">
<ds-tree ref="dsTree" @switch-main="switchMain" /> <ds-tree ref="dsTree" :datasource="datasource" @switch-main="switchMain" />
</de-aside-container> </de-aside-container>
<de-main-container> <de-main-container>
<component :is="component" v-if="!!component" :params="param" @refresh-left-tree="refreshTree" @switch-component="switchMain" /> <component :is="component" v-if="!!component" :params="param" @refresh-type="refreshType" @switch-component="switchMain" />
</de-main-container> </de-main-container>
</de-container> </de-container>
</template> </template>
@ -22,6 +22,7 @@ export default {
data() { data() {
return { return {
component: DataHome, component: DataHome,
datasource: {},
param: null param: null
} }
}, },
@ -53,8 +54,9 @@ export default {
} }
}) })
}, },
refreshTree() { refreshType(datasource) {
this.$refs.dsTree && this.$refs.dsTree.queryTreeDatas() this.datasource = datasource;
this.$refs.dsTree && this.$refs.dsTree.refreshType(datasource)
}, },
msg2Current(sourceParam) { msg2Current(sourceParam) {
this.$refs.dsTree && this.$refs.dsTree.markInvalid(sourceParam) this.$refs.dsTree && this.$refs.dsTree.markInvalid(sourceParam)

View File

@ -87,10 +87,16 @@
</el-col> </el-col>
</template> </template>
<script> <script>
import { listDatasource, delDs } from '@/api/system/datasource' import { listDatasource, listDatasourceByType, delDs } from '@/api/system/datasource'
export default { export default {
name: 'DsTree', name: 'DsTree',
props: {
datasource: {
type: Object,
default: null
}
},
data() { data() {
return { return {
expandedArray: [], expandedArray: [],
@ -106,7 +112,6 @@ export default {
}, },
mounted() { mounted() {
this.queryTreeDatas() this.queryTreeDatas()
// console.log('permis:' + JSON.stringify(this.$store.getters.permissions))
}, },
methods: { methods: {
filterNode(value, data) { filterNode(value, data) {
@ -124,6 +129,19 @@ export default {
listDatasource().then(res => { listDatasource().then(res => {
this.tData = this.buildTree(res.data) this.tData = this.buildTree(res.data)
}) })
},
refreshType(datasource) {
let typeData = []
listDatasourceByType(datasource.type).then(res => {
typeData = this.buildTree(res.data)
for (let index = 0; index < this.tData.length; index++) {
if(typeData[0].id === this.tData[index].id){
this.tData[index].children = typeData[0].children
}
}
})
}, },
buildTree(array) { buildTree(array) {
const types = {} const types = {}
@ -212,7 +230,7 @@ export default {
}).then(() => { }).then(() => {
delDs(datasource.id).then(res => { delDs(datasource.id).then(res => {
this.$success(this.$t('commons.delete_success')) this.$success(this.$t('commons.delete_success'))
this.queryTreeDatas() this.refreshType(datasource)
}) })
}).catch(() => { }).catch(() => {
this.$message({ this.$message({

View File

@ -235,14 +235,14 @@ export default {
$confirm(this.$t('datasource.edit_datasource_msg'), () => { $confirm(this.$t('datasource.edit_datasource_msg'), () => {
method(form).then(res => { method(form).then(res => {
this.$success(this.$t('commons.save_success')) this.$success(this.$t('commons.save_success'))
this.refreshTree() this.refreshType(form)
this.backToList() this.backToList()
}) })
}) })
} else { } else {
method(form).then(res => { method(form).then(res => {
this.$success(this.$t('commons.save_success')) this.$success(this.$t('commons.save_success'))
this.refreshTree() this.refreshType(form)
this.backToList() this.backToList()
}) })
} }
@ -315,10 +315,9 @@ export default {
}, },
backToList() { backToList() {
this.$emit('switch-component', { }) this.$emit('switch-component', { })
// this.$router.push({ name: 'datasource' })
}, },
refreshTree() { refreshType(form) {
this.$emit('refresh-left-tree') this.$emit('refresh-type', form)
} }
} }
} }