前端数据字典增加条件过虑功能
This commit is contained in:
parent
003563a27f
commit
0d8599e94a
@ -25,11 +25,15 @@ public interface DictRepository extends R2dbcRepository<Dict, Long> {
|
||||
)
|
||||
Flux<Dict> findRootDicts(String organization, @Param("params") Map<String, Object> params, Pageable pageable);
|
||||
|
||||
@Query("SELECT * FROM jhi_dict WHERE parent_number = :parentNumber ORDER BY sort_no ASC")
|
||||
Flux<Dict> findByParentNumber(@Param("parentNumber") String parentNumber);
|
||||
@Query(
|
||||
"SELECT * FROM jhi_dict WHERE (:#{#organization} = '*' OR organization = :#{#organization}) AND parent_number = :parentNumber ORDER BY sort_no ASC"
|
||||
)
|
||||
Flux<Dict> findByParentNumber(String organization, @Param("parentNumber") String parentNumber);
|
||||
|
||||
@Query("SELECT COUNT(*) FROM jhi_dict WHERE parent_number = :parentNumber")
|
||||
Mono<Long> countChildren(@Param("parentNumber") String parentNumber);
|
||||
@Query(
|
||||
"SELECT COUNT(*) FROM jhi_dict WHERE (:#{#organization} = '*' OR organization = :#{#organization}) AND parent_number = :parentNumber"
|
||||
)
|
||||
Mono<Long> countChildren(String organization, @Param("parentNumber") String parentNumber);
|
||||
|
||||
@Query(
|
||||
"SELECT * FROM jhi_dict WHERE (:#{#organization} = '*' OR organization = :#{#organization}) " +
|
||||
|
||||
@ -48,7 +48,7 @@ public class DictService {
|
||||
.findById(id)
|
||||
.flatMap(dict ->
|
||||
dictRepository
|
||||
.countChildren(dict.getNumber())
|
||||
.countChildren(dict.getOrganization(), dict.getNumber())
|
||||
.flatMap(count -> {
|
||||
if (count > 0) {
|
||||
return Mono.error(new IllegalStateException("Cannot delete dict with children"));
|
||||
@ -63,7 +63,7 @@ public class DictService {
|
||||
.findById(id)
|
||||
.flatMap(dict ->
|
||||
Mono.just(dict)
|
||||
.zipWith(getChildren(dict.getNumber()).collectList())
|
||||
.zipWith(getChildren(dict.getOrganization(), dict.getNumber()).collectList())
|
||||
.map(tuple -> {
|
||||
dict.setChildren(tuple.getT2());
|
||||
return dict;
|
||||
@ -83,7 +83,7 @@ public class DictService {
|
||||
.flatMapMany(rootDicts ->
|
||||
rootDicts.flatMap(rootDict ->
|
||||
Mono.just(rootDict)
|
||||
.zipWith(getChildren(rootDict.getNumber()).collectList())
|
||||
.zipWith(getChildren(rootDict.getOrganization(), rootDict.getNumber()).collectList())
|
||||
.map(tuple -> {
|
||||
rootDict.setChildren(tuple.getT2());
|
||||
return rootDict;
|
||||
@ -92,12 +92,12 @@ public class DictService {
|
||||
);
|
||||
}
|
||||
|
||||
private Flux<Dict> getChildren(String number) {
|
||||
private Flux<Dict> getChildren(String organization, String number) {
|
||||
return dictRepository
|
||||
.findByParentNumber(number)
|
||||
.findByParentNumber(organization, number)
|
||||
.flatMap(dict ->
|
||||
Mono.just(dict)
|
||||
.zipWith(getChildren(dict.getNumber()).collectList())
|
||||
.zipWith(getChildren(dict.getOrganization(), dict.getNumber()).collectList())
|
||||
.map(tuple -> {
|
||||
dict.setChildren(tuple.getT2());
|
||||
return dict;
|
||||
|
||||
@ -25,6 +25,7 @@ export default defineComponent({
|
||||
property: '',
|
||||
remark: '',
|
||||
sortNo: 0,
|
||||
status: '',
|
||||
version: 0,
|
||||
});
|
||||
|
||||
|
||||
@ -57,10 +57,17 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="dict-value">{{ $t('jewpmsApp.dict.value') }}</label>
|
||||
<input type="text" class="form-control" id="dict-value" data-cy="value" name="value" v-model="dict.value" />
|
||||
<label class="form-control-label" for="dict-property">{{ $t('jewpmsApp.dict.property') }}</label>
|
||||
<input type="text" class="form-control" id="dict-property" data-cy="property" name="property" v-model="dict.property" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="dict-status">{{ $t('jewpmsApp.dict.status') }}</label>
|
||||
<input type="text" class="form-control" id="dict-status" data-cy="status" name="status" v-model="dict.status" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="dict-remark">{{ $t('jewpmsApp.dict.remark') }}</label>
|
||||
<input type="text" class="form-control" id="dict-remark" data-cy="remark" name="remark" v-model="dict.remark" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="dict-sort-no">{{ $t('jewpmsApp.dict.sortNo') }}</label>
|
||||
<input type="number" class="form-control" id="dict-sort-no" data-cy="sortNo" name="sortNo" v-model="dict.sortNo" />
|
||||
|
||||
@ -20,6 +20,14 @@ export default defineComponent({
|
||||
|
||||
const isFetching = ref(false);
|
||||
const dicts = ref([]);
|
||||
const showFilter = ref(false);
|
||||
const filterParams = ref({
|
||||
number: null,
|
||||
name: null,
|
||||
parentNumber: null,
|
||||
status: null,
|
||||
});
|
||||
|
||||
const dict = ref({
|
||||
id: null,
|
||||
number: '',
|
||||
@ -43,52 +51,59 @@ export default defineComponent({
|
||||
{
|
||||
label: t$('jewpmsApp.dict.number'),
|
||||
prop: 'number',
|
||||
width: '120px',
|
||||
minWidth: '100px',
|
||||
},
|
||||
{
|
||||
label: t$('jewpmsApp.dict.name'),
|
||||
prop: 'name',
|
||||
width: '150px',
|
||||
minWidth: '120px',
|
||||
},
|
||||
{
|
||||
label: t$('jewpmsApp.dict.property'),
|
||||
prop: 'property',
|
||||
width: '200px',
|
||||
minWidth: '150px',
|
||||
},
|
||||
{
|
||||
label: t$('jewpmsApp.dict.status'),
|
||||
prop: 'status',
|
||||
},
|
||||
{
|
||||
label: t$('jewpmsApp.dict.remark'),
|
||||
prop: 'remark',
|
||||
width: '200px',
|
||||
minWidth: '150px',
|
||||
},
|
||||
{
|
||||
label: t$('jewpmsApp.dict.sortNo'),
|
||||
prop: 'sortNo',
|
||||
width: '80px',
|
||||
minWidth: '60px',
|
||||
},
|
||||
{
|
||||
label: t$('entity.action.actions'),
|
||||
type: 'template',
|
||||
template: 'actions',
|
||||
width: '120px',
|
||||
fixed: 'right',
|
||||
},
|
||||
];
|
||||
|
||||
const handleFilter = () => {
|
||||
showFilter.value = !showFilter.value;
|
||||
page.value = 1; // 重置页码
|
||||
handleSyncList();
|
||||
};
|
||||
|
||||
const handleSyncList = async () => {
|
||||
isFetching.value = true;
|
||||
try {
|
||||
const processedParams = showFilter.value
|
||||
? Object.entries(filterParams.value).reduce((acc, [key, value]) => {
|
||||
acc[key] = value === '' ? null : value;
|
||||
return acc;
|
||||
}, {})
|
||||
: {};
|
||||
|
||||
// 获取分页数据
|
||||
const paginationQuery = {
|
||||
page: page.value - 1,
|
||||
size: itemsPerPage.value,
|
||||
sort: 'sortNo,asc',
|
||||
};
|
||||
const dictsRes = await axios.get(`api/dicts/tree?${buildPaginationQueryOpts(paginationQuery)}`);
|
||||
const dictsRes = await axios.get(`api/dicts/tree?${buildPaginationQueryOpts(paginationQuery)}`, {
|
||||
params: processedParams,
|
||||
});
|
||||
dicts.value = dictsRes.data;
|
||||
// 从响应头中获取总条数,如果响应头中没有,则使用数据长度作为总条数
|
||||
const headerCount = dictsRes.headers['x-total-count'];
|
||||
@ -127,14 +142,6 @@ export default defineComponent({
|
||||
}
|
||||
};
|
||||
|
||||
const goToCreate = () => {
|
||||
router.push({ name: 'DictCreate' });
|
||||
};
|
||||
|
||||
const goToEdit = (row: any) => {
|
||||
router.push({ name: 'DictEdit', params: { id: row.id } });
|
||||
};
|
||||
|
||||
handleSyncList();
|
||||
|
||||
return {
|
||||
@ -151,8 +158,9 @@ export default defineComponent({
|
||||
handlePageChange,
|
||||
prepareDelete,
|
||||
deleteDict,
|
||||
goToCreate,
|
||||
goToEdit,
|
||||
showFilter,
|
||||
filterParams,
|
||||
handleFilter,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@ -8,6 +8,10 @@
|
||||
</span>
|
||||
</h5>
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-warning btn-sm" v-on:click="handleFilter" data-cy="entityFilterButton">
|
||||
<font-awesome-icon icon="filter" />
|
||||
<span class="d-none d-md-inline" v-text="$t('entity.action.filter')"></span>
|
||||
</button>
|
||||
<button class="btn btn-info btn-sm" v-on:click="handleSyncList" data-cy="entitySyncListButton">
|
||||
<font-awesome-icon icon="sync" />
|
||||
<span class="d-none d-md-inline" v-text="$t('entity.action.refresh')"></span>
|
||||
@ -19,6 +23,28 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 过滤表单 -->
|
||||
<div class="form-container" v-show="showFilter">
|
||||
<div class="form-section">
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="filter-number">{{ $t('jewpmsApp.dict.number') }}</label>
|
||||
<input type="text" class="form-control" id="filter-number" v-model="filterParams.number" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="filter-name">{{ $t('jewpmsApp.dict.name') }}</label>
|
||||
<input type="text" class="form-control" id="filter-name" v-model="filterParams.name" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="filter-parentNumber">{{ $t('jewpmsApp.dict.parentNumber') }}</label>
|
||||
<input type="text" class="form-control" id="filter-parentNumber" v-model="filterParams.parentNumber" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="filter-status">{{ $t('jewpmsApp.dict.status') }}</label>
|
||||
<input type="text" class="form-control" id="filter-status" v-model="filterParams.status" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-warning" v-if="!isFetching && dicts && dicts.length === 0">
|
||||
<span v-text="$t('jewpmsApp.dict.home.notFound')"></span>
|
||||
</div>
|
||||
@ -85,4 +111,5 @@
|
||||
|
||||
<style>
|
||||
@import '@/shared/styles/mobile.css';
|
||||
@import '@/shared/styles/edit-form.css';
|
||||
</style>
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
"value": "键值",
|
||||
"company": "所属公司",
|
||||
"property": "属性",
|
||||
"status": "状态",
|
||||
"remark": "备注",
|
||||
"sortNo": "排序号",
|
||||
"createdBy": "创建人",
|
||||
|
||||
@ -118,7 +118,7 @@
|
||||
"delete": "删除",
|
||||
"search": "搜索",
|
||||
"refresh": "刷新",
|
||||
"filter": "过滤",
|
||||
"filter": "筛选",
|
||||
"edit": "编辑",
|
||||
"open": "打开",
|
||||
"save": "保存",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user