按 UI 评审闭环 UI-02~UI-07(查询降权、对象/处理人可读化、筛选分层、数据源名映射、焦点外环);概览与登录壳按约定暂缓。 Co-authored-by: Cursor <cursoragent@cursor.com>
424 lines
13 KiB
Vue
424 lines
13 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* Query list. Filters are drafts until 查询; sort and page hit the server.
|
|
* Row actions: 打开 / 切换版本 / 预览 (D26). Disabled rows stay visible; 预览 is disabled
|
|
* with a title. 预览 opens the detail scrolled to the trial-run panel.
|
|
*/
|
|
import { computed, onMounted, reactive, ref } from "vue";
|
|
import { useI18n } from "vue-i18n";
|
|
import { useRouter } from "vue-router";
|
|
import {
|
|
ElAlert,
|
|
ElButton,
|
|
ElDialog,
|
|
ElInput,
|
|
ElOption,
|
|
ElPagination,
|
|
ElSelect,
|
|
ElTable,
|
|
ElTableColumn,
|
|
ElTag,
|
|
vLoading,
|
|
} from "element-plus";
|
|
import { listDatasources } from "../datasources/client";
|
|
import type { Datasource } from "../datasources/types";
|
|
import ListPageShell from "../shared/components/ListPageShell.vue";
|
|
import { LIST_DEFAULT_PAGE_SIZE, LIST_PAGE_SIZES, actionsColumnWidth } from "../tableLayout";
|
|
import { listQueries, listVersions } from "./client";
|
|
import { describeError } from "./errors";
|
|
import { formatDateTime, versionLabel } from "./format";
|
|
import type { QuerySummary, VersionSummary } from "./types";
|
|
import VersionsTable from "./VersionsTable.vue";
|
|
|
|
const { t, te } = useI18n();
|
|
const router = useRouter();
|
|
|
|
const items = ref<QuerySummary[]>([]);
|
|
const total = ref(0);
|
|
const datasources = ref<Datasource[]>([]);
|
|
const loading = ref(true);
|
|
const loadError = ref("");
|
|
|
|
/** Draft filters edited in the toolbar; applied only on 查询 / 重置. */
|
|
const draft = reactive({ name: "", datasourceId: "", status: "" });
|
|
const applied = reactive({ name: "", datasourceId: "", status: "" });
|
|
|
|
const page = ref(1);
|
|
const pageSize = ref(LIST_DEFAULT_PAGE_SIZE);
|
|
const sortBy = ref("updated_at");
|
|
const sortOrder = ref<"asc" | "desc">("desc");
|
|
|
|
const datasourceNames = computed(() => new Map(datasources.value.map((item) => [item.id, item.name])));
|
|
const hasAppliedFilters = computed(
|
|
() =>
|
|
applied.name.trim() !== "" || applied.datasourceId !== "" || applied.status !== "",
|
|
);
|
|
const actionsWidth = actionsColumnWidth(3);
|
|
const switchOpen = ref(false);
|
|
const switchRow = ref<QuerySummary | null>(null);
|
|
const switchVersions = ref<VersionSummary[]>([]);
|
|
const switchLoading = ref(false);
|
|
const switchError = ref("");
|
|
|
|
async function loadOptions(): Promise<void> {
|
|
try {
|
|
// Name map + filter options: page through the datasource API (max 100/page).
|
|
const all: Datasource[] = [];
|
|
let pageNo = 1;
|
|
for (;;) {
|
|
const sources = await listDatasources({
|
|
page: pageNo,
|
|
page_size: 100,
|
|
sort_by: "name",
|
|
sort_order: "asc",
|
|
});
|
|
all.push(...sources.items);
|
|
if (all.length >= sources.total || sources.items.length === 0 || pageNo > 50) {
|
|
break;
|
|
}
|
|
pageNo += 1;
|
|
}
|
|
datasources.value = all;
|
|
} catch {
|
|
datasources.value = [];
|
|
}
|
|
}
|
|
|
|
async function load(): Promise<void> {
|
|
loading.value = true;
|
|
loadError.value = "";
|
|
try {
|
|
const enabled =
|
|
applied.status === "enabled" ? true : applied.status === "disabled" ? false : undefined;
|
|
const result = await listQueries({
|
|
name: applied.name.trim() || undefined,
|
|
datasource_id: applied.datasourceId || undefined,
|
|
enabled,
|
|
sort_by: sortBy.value,
|
|
sort_order: sortOrder.value,
|
|
page: page.value,
|
|
page_size: pageSize.value,
|
|
});
|
|
items.value = result.items;
|
|
total.value = result.total;
|
|
} catch (error) {
|
|
loadError.value = describeError(error, t, te, "query.list.loadFailed");
|
|
items.value = [];
|
|
total.value = 0;
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
function applyFilters(): void {
|
|
applied.name = draft.name;
|
|
applied.datasourceId = draft.datasourceId;
|
|
applied.status = draft.status;
|
|
page.value = 1;
|
|
void load();
|
|
}
|
|
|
|
function resetFilters(): void {
|
|
draft.name = "";
|
|
draft.datasourceId = "";
|
|
draft.status = "";
|
|
applied.name = "";
|
|
applied.datasourceId = "";
|
|
applied.status = "";
|
|
page.value = 1;
|
|
void load();
|
|
}
|
|
|
|
function onSortChange(payload: { prop: string | null; order: string | null }): void {
|
|
const propMap: Record<string, string> = {
|
|
name: "name",
|
|
datasource: "datasource_name",
|
|
status: "enabled",
|
|
currentVersion: "current_version_no",
|
|
updated_at: "updated_at",
|
|
};
|
|
const next = payload.prop ? propMap[payload.prop] : undefined;
|
|
if (!next || !payload.order) {
|
|
sortBy.value = "updated_at";
|
|
sortOrder.value = "desc";
|
|
} else {
|
|
sortBy.value = next;
|
|
sortOrder.value = payload.order === "ascending" ? "asc" : "desc";
|
|
}
|
|
page.value = 1;
|
|
void load();
|
|
}
|
|
|
|
function onPageChange(next: number): void {
|
|
page.value = next;
|
|
void load();
|
|
}
|
|
|
|
function onSizeChange(next: number): void {
|
|
pageSize.value = next;
|
|
page.value = 1;
|
|
void load();
|
|
}
|
|
|
|
function asRow(source: unknown): QuerySummary {
|
|
return source as QuerySummary;
|
|
}
|
|
|
|
function rowClass({ row }: { row: unknown }): string {
|
|
return asRow(row).enabled ? "" : "query-row-off";
|
|
}
|
|
|
|
function sourceName(source: unknown): string {
|
|
const row = asRow(source);
|
|
return datasourceNames.value.get(row.datasource_id) ?? row.datasource_id;
|
|
}
|
|
|
|
function currentVersion(source: unknown): string {
|
|
return versionLabel(asRow(source).current_version_no) ?? t("query.versions.none");
|
|
}
|
|
|
|
function openCreate(): void {
|
|
void router.push({ name: "query-create" });
|
|
}
|
|
|
|
function openDetail(source: unknown): void {
|
|
void router.push({ name: "query-detail", params: { id: asRow(source).id } });
|
|
}
|
|
|
|
function openPreview(source: unknown): void {
|
|
void router.push({ name: "query-detail", params: { id: asRow(source).id }, query: { preview: "1" } });
|
|
}
|
|
|
|
async function openSwitch(source: unknown): Promise<void> {
|
|
const row = asRow(source);
|
|
switchRow.value = row;
|
|
switchOpen.value = true;
|
|
switchLoading.value = true;
|
|
switchError.value = "";
|
|
switchVersions.value = [];
|
|
try {
|
|
switchVersions.value = (await listVersions(row.id)).items;
|
|
} catch (error) {
|
|
switchError.value = describeError(error, t, te, "query.versions.loadFailed");
|
|
} finally {
|
|
switchLoading.value = false;
|
|
}
|
|
}
|
|
|
|
async function onSwitchActivated(): Promise<void> {
|
|
switchOpen.value = false;
|
|
await load();
|
|
}
|
|
|
|
onMounted(async () => {
|
|
await loadOptions();
|
|
await load();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<ListPageShell test-id="query-list">
|
|
<template #filters>
|
|
<div data-testid="query-list-toolbar" class="contents">
|
|
<div class="w-[16rem]" data-testid="query-filter-name">
|
|
<ElInput v-model="draft.name" clearable :placeholder="t('query.list.filterName')" />
|
|
</div>
|
|
<div class="w-[16rem]" data-testid="query-filter-datasource">
|
|
<ElSelect
|
|
v-model="draft.datasourceId"
|
|
clearable
|
|
class="w-full"
|
|
:placeholder="t('query.list.filterDatasource')"
|
|
>
|
|
<ElOption
|
|
v-for="source in datasources"
|
|
:key="source.id"
|
|
:label="source.name"
|
|
:value="source.id"
|
|
/>
|
|
</ElSelect>
|
|
</div>
|
|
<div class="w-[9rem]" data-testid="query-filter-status">
|
|
<ElSelect
|
|
v-model="draft.status"
|
|
clearable
|
|
class="w-full"
|
|
:placeholder="t('query.list.filterStatus')"
|
|
>
|
|
<ElOption :label="t('query.status.enabled')" value="enabled" />
|
|
<ElOption :label="t('query.status.disabled')" value="disabled" />
|
|
</ElSelect>
|
|
</div>
|
|
<ElButton data-testid="query-filter-search" @click="applyFilters">
|
|
{{ t("query.list.filterSearch") }}
|
|
</ElButton>
|
|
<ElButton data-testid="query-filter-reset" @click="resetFilters">
|
|
{{ t("query.list.filterReset") }}
|
|
</ElButton>
|
|
<div class="ml-auto">
|
|
<ElButton type="primary" data-testid="query-create" @click="openCreate">
|
|
{{ t("query.list.create") }}
|
|
</ElButton>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<ElAlert
|
|
v-if="loadError"
|
|
class="m-4 mx-8"
|
|
type="error"
|
|
data-testid="query-load-error"
|
|
:title="loadError"
|
|
show-icon
|
|
:closable="false"
|
|
/>
|
|
<div v-else-if="!loading && total === 0 && !hasAppliedFilters" data-testid="query-empty" class="wm-list-empty">
|
|
<div>
|
|
<h3 class="wm-list-empty__title">{{ t("query.list.empty") }}</h3>
|
|
<p class="wm-list-empty__hint">{{ t("query.list.emptyHint") }}</p>
|
|
</div>
|
|
</div>
|
|
<div
|
|
v-else-if="!loading && total === 0 && hasAppliedFilters"
|
|
data-testid="query-filter-empty"
|
|
class="wm-list-empty"
|
|
>
|
|
<div>
|
|
<h3 class="wm-list-empty__title">{{ t("query.list.filterEmpty") }}</h3>
|
|
<p class="wm-list-empty__hint">{{ t("query.list.filterEmptyHint") }}</p>
|
|
</div>
|
|
</div>
|
|
<div v-else class="min-h-0 flex-1" data-testid="query-table-wrap">
|
|
<ElTable
|
|
v-loading="loading"
|
|
class="wm-admin-table"
|
|
height="100%"
|
|
:data="items"
|
|
row-key="id"
|
|
data-testid="query-table"
|
|
:default-sort="{ prop: 'updated_at', order: 'descending' }"
|
|
:row-class-name="rowClass"
|
|
@sort-change="onSortChange"
|
|
>
|
|
<ElTableColumn
|
|
prop="name"
|
|
:label="t('query.columns.name')"
|
|
min-width="180"
|
|
sortable="custom"
|
|
/>
|
|
<ElTableColumn
|
|
prop="datasource"
|
|
:label="t('query.columns.datasource')"
|
|
min-width="160"
|
|
sortable="custom"
|
|
>
|
|
<template #default="{ row }">{{ sourceName(row) }}</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn
|
|
prop="status"
|
|
:label="t('query.columns.status')"
|
|
min-width="110"
|
|
sortable="custom"
|
|
>
|
|
<template #default="{ row }">
|
|
<ElTag :type="row.enabled ? 'success' : 'info'" effect="light" data-testid="row-status">
|
|
{{ row.enabled ? t("query.status.enabled") : t("query.status.disabled") }}
|
|
</ElTag>
|
|
</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn
|
|
prop="currentVersion"
|
|
:label="t('query.columns.currentVersion')"
|
|
min-width="120"
|
|
sortable="custom"
|
|
>
|
|
<template #default="{ row }">{{ currentVersion(row) }}</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn
|
|
prop="updated_at"
|
|
:label="t('query.columns.updatedAt')"
|
|
min-width="150"
|
|
sortable="custom"
|
|
>
|
|
<template #default="{ row }">{{ formatDateTime(row.updated_at) }}</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn
|
|
:label="t('query.columns.actions')"
|
|
:width="actionsWidth"
|
|
align="right"
|
|
fixed="right"
|
|
>
|
|
<template #default="{ row }">
|
|
<div class="whitespace-nowrap" :data-testid="`query-row-${row.id}`">
|
|
<ElButton link type="primary" data-testid="row-open" @click="openDetail(row)">
|
|
{{ t("query.actions.open") }}
|
|
</ElButton>
|
|
<ElButton link type="primary" data-testid="row-switch-version" @click="openSwitch(row)">
|
|
{{ t("query.actions.switchVersion") }}
|
|
</ElButton>
|
|
<ElButton
|
|
link
|
|
type="primary"
|
|
data-testid="row-preview"
|
|
:disabled="!row.enabled"
|
|
:title="row.enabled ? undefined : t('query.actions.previewDisabledWhy')"
|
|
@click="openPreview(row)"
|
|
>
|
|
{{ t("query.actions.preview") }}
|
|
</ElButton>
|
|
</div>
|
|
</template>
|
|
</ElTableColumn>
|
|
</ElTable>
|
|
</div>
|
|
|
|
<template v-if="!loadError && (loading || total > 0)" #pagination>
|
|
<div data-testid="query-pagination">
|
|
<ElPagination
|
|
background
|
|
layout="total, sizes, prev, pager, next"
|
|
:total="total"
|
|
:page-size="pageSize"
|
|
:page-sizes="[...LIST_PAGE_SIZES]"
|
|
:current-page="page"
|
|
@current-change="onPageChange"
|
|
@size-change="onSizeChange"
|
|
/>
|
|
</div>
|
|
</template>
|
|
</ListPageShell>
|
|
|
|
<ElDialog
|
|
v-model="switchOpen"
|
|
align-center
|
|
append-to-body
|
|
:close-on-click-modal="false"
|
|
:title="t('query.versions.switchTitle', { name: switchRow?.name ?? '' })"
|
|
width="680px"
|
|
data-testid="query-switch-dialog"
|
|
>
|
|
<ElAlert
|
|
v-if="switchError"
|
|
type="error"
|
|
:title="switchError"
|
|
show-icon
|
|
:closable="false"
|
|
/>
|
|
<div v-else v-loading="switchLoading">
|
|
<VersionsTable
|
|
v-if="switchRow"
|
|
:definition-id="switchRow.id"
|
|
:versions="switchVersions"
|
|
:active-no="switchRow.current_version_no ?? undefined"
|
|
@activated="onSwitchActivated"
|
|
/>
|
|
</div>
|
|
</ElDialog>
|
|
</template>
|
|
|
|
<style scoped>
|
|
:deep(.query-row-off td) {
|
|
color: var(--text-muted);
|
|
}
|
|
</style>
|