add: 在结果集中增加数据过滤的功能 (#163)
* add: 在结果集中增加数据过滤的功能
* 1. 提取 isResultsContext — 新增具名计算属性,替代魔法字符串 results,模板和逻辑中统一使用。
2. wherePredicate 在 results 场景下短路 — 加了 canUseWhereSearch.value ? ... : undefined 守卫,避免在结果集界面无意义地调用 normalizeWhereInput()。在 results 上下文下:
- wherePredicate → undefined
- isWhereSearch → false(因为 canUseWhereSearch 为 false)
- activeWhereInput → undefined
- 搜索框 placeholder 切换为纯 search(由 canUseWhereSearch 控制,已存在)
- 应用按钮隐藏(v-if=isWhereSearch,已存在)
逻辑链现在是一致的:canUseWhereSearch === false 时,所有 where 相关功能(解析、建议、按钮、回车提交)全部失效
This commit is contained in:
parent
3b4b6c1ff7
commit
8a249a2194
|
|
@ -424,9 +424,10 @@ watch(() => props.result.columns.length, initColumnWidths);
|
|||
const pageSize = ref(100);
|
||||
const currentPage = ref(1);
|
||||
const isFullPage = computed(() => props.result.rows.length >= pageSize.value);
|
||||
const canUseWhereSearch = computed(() => !!props.tableMeta && !!props.onExecuteSql);
|
||||
const isResultsContext = computed(() => props.context === "results");
|
||||
const canUseWhereSearch = computed(() => !!props.tableMeta && !!props.onExecuteSql && !isResultsContext.value);
|
||||
const isWhereSearch = computed(() => canUseWhereSearch.value && /^\s*where\b/i.test(searchText.value));
|
||||
const wherePredicate = computed(() => normalizeWhereInput(searchText.value));
|
||||
const wherePredicate = computed(() => (canUseWhereSearch.value ? normalizeWhereInput(searchText.value) : undefined));
|
||||
const activeWhereInput = computed(() => (isWhereSearch.value && wherePredicate.value ? searchText.value : undefined));
|
||||
const clientSearchText = computed(() => (isWhereSearch.value ? "" : searchText.value));
|
||||
|
||||
|
|
@ -1285,14 +1286,8 @@ defineExpose({
|
|||
<ContextMenuTrigger as-child>
|
||||
<div v-if="hasData" class="flex-1 flex flex-col overflow-hidden">
|
||||
<!-- Search bar -->
|
||||
<div
|
||||
v-if="useTransaction || props.context === 'table-data'"
|
||||
class="flex items-center gap-1 px-2 py-1 border-b shrink-0 bg-muted/20 relative"
|
||||
>
|
||||
<Search
|
||||
class="w-3.5 h-3.5 text-muted-foreground shrink-0"
|
||||
:style="props.context === 'table-data' ? '' : 'visibility: hidden'"
|
||||
/>
|
||||
<div class="flex items-center gap-1 px-2 py-1 border-b shrink-0 bg-muted/20 relative">
|
||||
<Search class="w-3.5 h-3.5 text-muted-foreground shrink-0" />
|
||||
<input
|
||||
ref="searchInputRef"
|
||||
v-model="searchText"
|
||||
|
|
@ -1303,7 +1298,6 @@ defineExpose({
|
|||
:placeholder="canUseWhereSearch ? t('grid.searchOrWhere') : t('grid.search')"
|
||||
@keydown="onSearchKeydown"
|
||||
@click="updateSuggestionPosition"
|
||||
:style="props.context === 'table-data' ? '' : 'visibility: hidden'"
|
||||
/>
|
||||
<span
|
||||
ref="measureRef"
|
||||
|
|
@ -1360,7 +1354,7 @@ defineExpose({
|
|||
{{ t("grid.refresh") }}
|
||||
</Button>
|
||||
<Select
|
||||
v-if="editable && tableMeta"
|
||||
v-if="useTransaction && editable && tableMeta"
|
||||
:model-value="rowStatusFilter"
|
||||
@update:model-value="(value: any) => setRowStatusFilter(String(value))"
|
||||
>
|
||||
|
|
@ -1376,7 +1370,7 @@ defineExpose({
|
|||
</SelectContent>
|
||||
</Select>
|
||||
<Button
|
||||
v-if="editable && tableMeta"
|
||||
v-if="useTransaction && editable && tableMeta"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="h-5 text-xs px-1.5 shrink-0"
|
||||
|
|
@ -1385,6 +1379,7 @@ defineExpose({
|
|||
<Plus class="w-3 h-3 mr-1" /> {{ t("grid.addRow") }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="useTransaction"
|
||||
:variant="transactionActive ? 'default' : 'secondary'"
|
||||
size="sm"
|
||||
class="h-5 text-xs px-1.5"
|
||||
|
|
@ -1396,6 +1391,7 @@ defineExpose({
|
|||
{{ t("grid.commit") }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="useTransaction"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="h-5 text-xs px-1.5"
|
||||
|
|
|
|||
Loading…
Reference in New Issue