Merge pull request #4107 from dataease/pr@dev@feat_filter_chinese_sort

feat(过滤器): 文本下拉组件选项可按照中文排序
This commit is contained in:
fit2cloud-chenyw 2022-12-15 21:20:44 +08:00 committed by GitHub
commit d2c3b07b81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 95 additions and 7 deletions

View File

@ -200,6 +200,7 @@ public class DataSetTableFieldController {
}
List<Object> list = results.stream().distinct().collect(Collectors.toList());
list = dataSetFieldService.chineseSort(list, multFieldValuesRequest.getSort());
return list;
}
@ -246,7 +247,7 @@ public class DataSetTableFieldController {
@DePermission(type = DePermissionType.DATASET)
@ApiOperation("时间格式")
@PostMapping("dateformats/{tableId}")
public List<Dateformat> dateformats(@PathVariable String tableId) throws Exception{
public List<Dateformat> dateformats(@PathVariable String tableId) throws Exception {
DatasetTable datasetTable = dataSetTableService.get(tableId);
Datasource ds = datasetTable.getMode() == 0 ? datasourceService.get(datasetTable.getDataSourceId()) : engineService.getDeEngine();
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());

View File

@ -1,8 +1,6 @@
package io.dataease.service.dataset;
import io.dataease.dto.dataset.DeSortDTO;
import java.util.List;
@ -14,4 +12,6 @@ public interface DataSetFieldService {
List<Object> fieldValues(String fieldId, DeSortDTO sortDTO, Long userId, Boolean userPermissions, Boolean rowAndColumnMgm) throws Exception;
List<Object> fieldValues(List<String> fieldIds, DeSortDTO sortDTO, Long userId, Boolean userPermissions, Boolean needMapping, Boolean rowAndColumnMgm) throws Exception;
List<Object> chineseSort(List<Object> list, DeSortDTO sortDTO) throws Exception;
}

View File

@ -1,5 +1,6 @@
package io.dataease.service.dataset.impl.direct;
import cn.hutool.core.collection.CollectionUtil;
import com.google.gson.Gson;
import io.dataease.commons.exception.DEException;
import io.dataease.commons.model.BaseTreeNode;
@ -32,6 +33,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.Collator;
import java.util.*;
import java.util.stream.Collectors;
@ -77,6 +79,26 @@ public class DirectFieldService implements DataSetFieldService {
}).collect(Collectors.toList());
}
@Override
public List<Object> chineseSort(List<Object> list, DeSortDTO sortDTO) throws Exception {
if (ObjectUtils.isEmpty(sortDTO) || CollectionUtil.isEmpty(list)) return list;
String sort = sortDTO.getSort();
if (!StringUtils.equals(sort, "chinese")) {
return list;
}
String id = sortDTO.getId();
String sortStr = StringUtils.equalsIgnoreCase("chineseDesc", id) ? "desc" : "asc";
List<Object> result = CollectionUtil.sort(list, (v1, v2) -> {
Collator instance = Collator.getInstance(Locale.CHINESE);
if (StringUtils.equals("desc", sortStr)) {
return instance.compare(v2, v1);
}
return instance.compare(v1, v2);
});
return result;
}
@Override
public List<Object> fieldValues(List<String> fieldIds, DeSortDTO sortDTO, Long userId, Boolean userPermissions, Boolean needMapping, Boolean rowAndColumnMgm) throws Exception {
String fieldId = fieldIds.get(0);
@ -146,7 +168,7 @@ public class DirectFieldService implements DataSetFieldService {
datasourceRequest.setQuery(qp.createQuerySQL(dataTableInfoDTO.getTable(), permissionFields, !needSort, ds, customFilter, rowPermissionsTree, deSortFields));
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), DatasetType.SQL.toString())) {
String sql = dataTableInfoDTO.getSql();
if(dataTableInfoDTO.isBase64Encryption()){
if (dataTableInfoDTO.isBase64Encryption()) {
sql = new String(java.util.Base64.getDecoder().decode(sql));
}
sql = dataSetTableService.removeVariables(sql, ds.getType());

View File

@ -99,6 +99,9 @@ class TextSelectGridServiceImpl extends WidgetService {
isCustomSortWidget() {
return true
}
isChinesSortWidget() {
return true
}
fillValueDerfault(element) {
const defaultV = element.options.value === null ? '' : element.options.value.toString()
if (element.options.attrs.multiple) {

View File

@ -105,7 +105,9 @@ class TextSelectServiceImpl extends WidgetService {
isParamWidget() {
return true
}
isChinesSortWidget() {
return true
}
fillValueDerfault(element) {
const defaultV = element.options.value === null ? '' : element.options.value.toString()
if (element.options.attrs.multiple) {

View File

@ -931,6 +931,7 @@ export default {
password_input_error: 'Original password input error'
},
chart: {
chinese: 'Chinese',
mark_field: 'Field',
mark_value: 'Value',
function_style: 'Function style',

View File

@ -930,6 +930,7 @@ export default {
password_input_error: '原始密碼輸入錯誤'
},
chart: {
chinese: '中文',
mark_field: '字段',
mark_value: '值',
function_style: '功能型樣式',

View File

@ -929,6 +929,7 @@ export default {
password_input_error: '原始密码输入错误'
},
chart: {
chinese: '中文',
mark_field: '字段',
mark_value: '值',
function_style: '功能型样式',

View File

@ -94,6 +94,43 @@
</el-popover>
</el-dropdown-item>
<el-dropdown-item
v-if="isChinesSortWidget"
:command="beforeClickItem('chinese')"
>
<span
v-popover:popoverchinese
class="el-dropdown-link inner-dropdown-menu de-sort-menu"
:class="sortNode.sort === 'chinese' ? 'de-active-li': ''"
>
<span>
<span>{{ $t('chart.chinese') }}</span>
</span>
<i class="el-icon-arrow-right el-icon--right" />
</span>
<el-popover
ref="popoverchinese"
v-model="chineseFieldsShow"
placement="right-start"
width="120"
:close-delay="500"
trigger="hover"
>
<ul class="de-ul">
<li
v-for="(node, i) in chineseFields"
:key="node.id"
:index="i"
class="de-sort-field-span"
:class="sortNode.sort === 'chinese' && sortNode.id === node.id ? 'de-active-li': ''"
@click="saveChineseField(node)"
>
<span>{{ node.name }}</span>
</li>
</ul>
</el-popover>
</el-dropdown-item>
<el-dropdown-item
v-if="isCustomSortWidget"
:command="beforeClickItem('custom')"
@ -166,13 +203,18 @@ export default {
return {
ascFieldsShow: false,
descFieldsShow: false,
chineseFieldsShow: false,
defaultSortProp: {
sort: 'none'
},
tableFields: [],
sortNode: null,
showCustomSort: false,
customSortList: []
customSortList: [],
chineseFields: [
{ id: 'chineseAsc', name: this.$t('chart.asc') },
{ id: 'chineseDesc', name: this.$t('chart.desc') }
]
}
},
computed: {
@ -192,6 +234,9 @@ export default {
return this.element.options.attrs.dragItems[0].tableId
}
return null
},
isChinesSortWidget() {
return this.widget?.isChinesSortWidget && this.widget.isChinesSortWidget()
}
},
watch: {
@ -260,6 +305,7 @@ export default {
this.tableFields = []
}
},
clickItem(param) {
if (!param) {
return
@ -277,7 +323,9 @@ export default {
case 'custom':
this.sortChange('custom')
break
case 'chinese':
this.sortChange('chinese')
break
default:
break
}
@ -301,6 +349,12 @@ export default {
this.sortNode = { id, name, sort }
this.$emit('sort-change', this.sortNode)
},
saveChineseField({ id, name }) {
this.chineseFieldsShow = false
const sort = 'chinese'
this.sortNode = { id, name, sort }
this.$emit('sort-change', this.sortNode)
},
sortChange(type) {
if (type === 'custom') {
this.showCustomSort = true
@ -310,6 +364,9 @@ export default {
if (type === 'none') {
this.sortNode = { sort: 'none' }
}
if (type === 'chinese') {
this.sortNode = { sort: 'chinese', id: 'chineseAsc' }
}
this.$emit('sort-change', this.sortNode)
}