Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
546d95c926 | ||
|
|
6b0a6118e0 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "shrimp-admin",
|
||||
"version": "0.7.6",
|
||||
"version": "0.7.9",
|
||||
"private": true,
|
||||
"description": "Shrimp 框架前端 — 消费 ShrimpServer + ShrimpTable 契约的经典 Vue3 + Element Plus 实现",
|
||||
"main": "src/index.ts",
|
||||
|
||||
@@ -4,11 +4,18 @@
|
||||
<el-form :model="localFilterData">
|
||||
<template v-for="field in filterableFields" :key="field.key">
|
||||
<el-form-item :label="vueAdmin.t(field.label)">
|
||||
<div class="filter-field-row">
|
||||
<div class="filter-field-control">
|
||||
<slot :name="`filter-${field.key}`" :field="field" :data="localFilterData">
|
||||
<component :is="vueAdmin.getFieldComponent(moduleKey, field.type, field.key)" :field="field"
|
||||
:model-value="localFilterData[field.key]"
|
||||
<component :is="vueAdmin.getFieldComponent(moduleKey, field.type, field.key)"
|
||||
:field="field" :model-value="localFilterData[field.key]"
|
||||
@update:model-value="onFieldChange(field.key, $event)" mode="filter" />
|
||||
</slot>
|
||||
</div>
|
||||
<!-- 单独清空该字段:常驻、无值时禁用(不 v-if,避免按钮显隐导致布局闪动) -->
|
||||
<el-button link :icon="CircleClose" class="filter-clear"
|
||||
:disabled="!hasValue(field.key)" @click="clearField(field.key)" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-form>
|
||||
@@ -21,6 +28,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, watch } from 'vue'
|
||||
import { CircleClose } from '@element-plus/icons-vue'
|
||||
import { IFieldConfig } from '../IShrimpType'
|
||||
import { vueAdmin } from '../VueAdmin'
|
||||
|
||||
@@ -68,6 +76,21 @@ function onFieldChange(key: string, value: any) {
|
||||
localFilterData.value = { ...localFilterData.value, [key]: value }
|
||||
}
|
||||
|
||||
// 该字段当前是否有筛选值(决定单独清空按钮是否出现);范围 {gte,lte}/数组按内容判空
|
||||
function hasValue(key: string): boolean {
|
||||
const v = localFilterData.value[key]
|
||||
if (v == null || v === '') return false
|
||||
if (Array.isArray(v)) return v.length > 0
|
||||
if (typeof v === 'object') return Object.keys(v).length > 0
|
||||
return true
|
||||
}
|
||||
|
||||
// 单独清空某个字段:只摘掉这一个 key,其余筛选条件不动
|
||||
function clearField(key: string) {
|
||||
const { [key]: _, ...rest } = localFilterData.value
|
||||
localFilterData.value = rest
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
closedByReset.value = true
|
||||
localFilterData.value = {}
|
||||
@@ -101,4 +124,23 @@ function handleConfirm() {
|
||||
.shrimp-drawer .el-drawer__body .el-form-item {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.filter-field-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.filter-field-control {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.filter-clear {
|
||||
flex: none;
|
||||
padding: 0;
|
||||
font-size: 16px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user