perf: 下拉过滤器使用后台模糊搜索

This commit is contained in:
fit2cloud-chenyw 2023-11-14 16:03:49 +08:00
parent 3ed4c133ba
commit a014b5200f
3 changed files with 42 additions and 29 deletions

View File

@ -119,7 +119,7 @@ public class DirectFieldService implements DataSetFieldService {
List<DeSortField> deSortFields = buildSorts(fields, sortDTO);
Boolean needSort = CollectionUtils.isNotEmpty(deSortFields);
boolean needSort = CollectionUtils.isNotEmpty(deSortFields);
final List<String> allTableFieldIds = fields.stream().map(DatasetTableField::getId).collect(Collectors.toList());
boolean multi = fieldIds.stream().anyMatch(item -> !allTableFieldIds.contains(item));
@ -180,15 +180,24 @@ public class DirectFieldService implements DataSetFieldService {
sql = new String(java.util.Base64.getDecoder().decode(sql));
}
sql = dataSetTableService.handleVariableDefaultValue(sql, null, ds.getType(), false);
if (StringUtils.isNotBlank(keyword)) {
sql = formatTableByKeyword(keyword, " (" + sql + ") " + "inner_like_temp ", permissionFields);
}
createSQL = qp.createQuerySQLAsTmp(sql, permissionFields, !needSort, customFilter, rowPermissionsTree, deSortFields);
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), DatasetType.CUSTOM.toString())) {
DataTableInfoDTO dt = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class);
List<DataSetTableUnionDTO> listUnion = dataSetTableUnionService.listByTableId(dt.getList().get(0).getTableId());
String sql = dataSetTableService.getCustomSQLDatasource(dt, listUnion, ds);
if (StringUtils.isNotBlank(keyword)) {
sql = formatTableByKeyword(keyword, " (" + sql + ") " + "inner_like_temp ", permissionFields);
}
createSQL = qp.createQuerySQLAsTmp(sql, permissionFields, !needSort, customFilter, rowPermissionsTree, deSortFields);
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), DatasetType.UNION.toString())) {
DataTableInfoDTO dt = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class);
String sql = (String) dataSetTableService.getUnionSQLDatasource(dt, ds).get("sql");
if (StringUtils.isNotBlank(keyword)) {
sql = formatTableByKeyword(keyword, " (" + sql + ") " + "inner_like_temp ", permissionFields);
}
createSQL = qp.createQuerySQLAsTmp(sql, permissionFields, !needSort, customFilter, rowPermissionsTree, deSortFields);
}
datasourceRequest.setQuery(qp.createSQLPreview(createSQL, null));
@ -201,15 +210,16 @@ public class DirectFieldService implements DataSetFieldService {
String tableName = "ds_" + datasetTable.getId().replaceAll("-", "_");
datasourceRequest.setTable(tableName);
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
createSQL = qp.createQuerySQL(tableName, permissionFields, !needSort, null, customFilter, rowPermissionsTree, deSortFields);
String formatSql = formatTableByKeyword(keyword, tableName, permissionFields);
createSQL = qp.createQuerySQL(formatSql, permissionFields, !needSort, null, customFilter, rowPermissionsTree, deSortFields);
datasourceRequest.setQuery(qp.createSQLPreview(createSQL, null));
}
LogUtil.info(datasourceRequest.getQuery());
datasourceRequest.setPermissionFields(permissionFields);
assert datasourceProvider != null;
List<String[]> rows = datasourceProvider.getData(datasourceRequest);
if (!needMapping) {
List<Object> results = rows.stream().map(row -> row[0]).distinct().collect(Collectors.toList());
return results;
return rows.stream().map(row -> row[0]).distinct().collect(Collectors.toList());
}
Set<String> pkSet = new HashSet<>();

View File

@ -85,6 +85,10 @@ export default {
clearable: {
type: Boolean,
default: true
},
flag: {
type: String,
require: true
}
},
data() {
@ -124,14 +128,14 @@ export default {
},
list() {
this.resetList()
// this.show = false
this.$nextTick(() => {
// this.show = true
this.$nextTick(() => {
this.init()
})
})
},
}
/*
模糊搜索改为后端检索暂注释前端
keyWord(val, old) {
if (val === old) return
const results = val ? this.vagueFilter(val, this.list) : null
@ -141,6 +145,7 @@ export default {
this.callback()
})
}
*/
},
mounted() {
this.resetList()
@ -174,8 +179,10 @@ export default {
this.$emit('handleShowNumber')
},
addScrollDiv(selectDom) {
const baseClass = `${this.classId}-creator`
this.maxHeightDom = document.createElement('div')
this.maxHeightDom.className = 'el-select-height'
this.maxHeightDom.classList.add(baseClass)
selectDom.insertBefore(this.maxHeightDom, this.domList)
},
reCacularHeight() {
@ -206,26 +213,26 @@ export default {
this.customInputStyle()
return
}
const baseClass = `.${this.classId}-creator`
if (document.querySelector(baseClass)) {
this.customInputStyle()
this.reCacularHeight()
return
}
const selectDom = document.querySelector(
`.${this.classId} .el-select-dropdown .el-select-dropdown__wrap`
)
this.scrollbar = document.querySelector(`.${this.classId} .el-select-dropdown .el-scrollbar`)
this.selectBoxDom = document.querySelector(`.${this.classId} .el-select-dropdown__wrap`)
if (this.selectBoxDom) {
this.selectBoxDom.style.display = 'flex'
this.selectBoxDom.style.flexDirection = 'row'
}
if (selectDom) {
this.domList = selectDom.querySelector(
`.${this.classId} .el-select-dropdown__wrap .el-select-dropdown__list`
)
}
if (this.selectBoxDom) {
this.addScrollDiv(this.selectBoxDom)
}
this.selectBoxDom.style.display = 'flex'
this.selectBoxDom.style.flexDirection = 'row'
this.domList = selectDom.querySelector(
`.${this.classId} .el-select-dropdown__wrap .el-select-dropdown__list`
)
this.addScrollDiv(this.selectBoxDom)
this.scrollbar && this.scrollFn()
this.scrollFn()
this.customInputStyle()
},

View File

@ -18,6 +18,7 @@
popper-class="coustom-de-select"
:class="{'disabled-close': !inDraw && selectFirst && element.options.attrs.multiple}"
:list="data"
:flag="flag"
:is-config="isConfig"
:custom-style="customStyle"
@resetKeyWords="filterMethod"
@ -52,7 +53,7 @@ import { isSameVueObj, mergeCustomSortOption } from '@/utils'
import { getLinkToken, getToken } from '@/utils/auth'
import customInput from '@/components/widget/deWidget/customInput'
import { textSelectWidget } from '@/components/widget/deWidget/serviceNameFn.js'
import { uuid } from 'vue-uuid'
export default {
components: { ElVisualSelect },
mixins: [customInput],
@ -96,7 +97,8 @@ export default {
keyWord: '',
separator: ',',
timeMachine: null,
changeIndex: 0
changeIndex: 0,
flag: uuid.v1()
}
},
computed: {
@ -334,14 +336,8 @@ export default {
this.element.options.attrs.fieldId &&
this.element.options.attrs.fieldId.length > 0 &&
method(param).then(res => {
// console.log(res.data)
this.data = this.optionData(res.data)
/* this.$nextTick(() => {
this.handleCoustomStyle()
}) */
// bus.$emit('valid-values-change', true)
}).catch(e => {
// bus.$emit('valid-values-change', false)
this.flag = uuid.v1()
})
},
onScroll() {