feat: 采集可以按字段名称查找对应的数据表
This commit is contained in:
@@ -59,6 +59,10 @@ const weekday = ref(1);
|
||||
const monthDay = ref(1);
|
||||
const clock = ref("08:00");
|
||||
const catalogLoading = ref(false);
|
||||
const fieldQuery = ref("");
|
||||
const fieldHits = ref<{ tablename: string; name: string; fields: { name: string; column: string; type: string }[] }[]>([]);
|
||||
const fieldSearched = ref(false);
|
||||
const fieldSearchLoading = ref(false);
|
||||
const runningId = ref<number | null>(null);
|
||||
const dialog = useDialog();
|
||||
const toast = useToast();
|
||||
@@ -235,6 +239,9 @@ function reset(source?: Source) {
|
||||
weekday.value = Number(schedule?.weekday || 1);
|
||||
monthDay.value = Number(schedule?.monthDay || 1);
|
||||
clock.value = schedule?.time || "08:00";
|
||||
fieldQuery.value = "";
|
||||
fieldHits.value = [];
|
||||
fieldSearched.value = false;
|
||||
show.value = true;
|
||||
if (!groups.value.length) void loadCatalog();
|
||||
}
|
||||
@@ -275,6 +282,46 @@ function removeTable(tablename: string) {
|
||||
chosen.value = chosen.value.filter((item) => item.tablename !== tablename);
|
||||
}
|
||||
|
||||
function matchedText(fields: { name: string }[]) {
|
||||
return fields.map((field) => field.name).filter(Boolean).join("、");
|
||||
}
|
||||
|
||||
function addFound(table: { tablename: string; name: string }) {
|
||||
if (chosen.value.some((item) => item.tablename === table.tablename)) return;
|
||||
const known = lookup(table.tablename);
|
||||
const item = known ?? {
|
||||
code: 0,
|
||||
category: "",
|
||||
tablename: table.tablename,
|
||||
name: table.name || table.tablename,
|
||||
};
|
||||
const wasEmpty = chosen.value.length === 0;
|
||||
chosen.value = [...chosen.value, item];
|
||||
if (wasEmpty && !name.value.trim()) name.value = item.name;
|
||||
}
|
||||
|
||||
async function searchTables() {
|
||||
const key = fieldQuery.value.trim();
|
||||
if (!key) {
|
||||
toast.error("请输入字段名称");
|
||||
return;
|
||||
}
|
||||
fieldSearchLoading.value = true;
|
||||
try {
|
||||
const result = await api<{ tables: { tablename: string; name: string; fields: { name: string; column: string; type: string }[] }[] }>(
|
||||
`/api/admin/nqi/search?key=${encodeURIComponent(key)}`,
|
||||
);
|
||||
fieldHits.value = result.tables;
|
||||
fieldSearched.value = true;
|
||||
} catch (error) {
|
||||
fieldHits.value = [];
|
||||
fieldSearched.value = false;
|
||||
toast.error(error instanceof Error ? error.message : "没有查到相关的表");
|
||||
} finally {
|
||||
fieldSearchLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!name.value.trim()) {
|
||||
toast.error("请填写名称");
|
||||
@@ -420,6 +467,27 @@ onMounted(load);
|
||||
<n-modal v-model:show="show" class="app-dialog app-dialog-collect" preset="card" :show-icon="false" title="采集">
|
||||
<div class="collect-form">
|
||||
<div class="form-row"><label>名称</label><n-input v-model:value="name" /></div>
|
||||
<div class="form-row form-row-find">
|
||||
<label>按字段找表</label>
|
||||
<div class="field-find">
|
||||
<div class="field-find-bar">
|
||||
<n-input v-model:value="fieldQuery" placeholder="输入字段名称" clearable @keydown.enter.prevent="searchTables" />
|
||||
<n-button type="primary" :loading="fieldSearchLoading" @click="searchTables">查找</n-button>
|
||||
</div>
|
||||
<p v-if="fieldSearched" class="time-hint">{{ fieldHits.length ? `找到 ${fieldHits.length} 张表` : "没有找到包含这个字段的表" }}</p>
|
||||
<div v-if="fieldHits.length" class="find-list">
|
||||
<div v-for="table in fieldHits" :key="table.tablename" class="find-row">
|
||||
<div class="find-copy">
|
||||
<strong>{{ table.name }}</strong>
|
||||
<span :title="matchedText(table.fields)">{{ matchedText(table.fields) }}</span>
|
||||
</div>
|
||||
<n-button size="small" :disabled="picked.includes(table.tablename)" @click="addFound(table)">
|
||||
{{ picked.includes(table.tablename) ? "已选" : "选用" }}
|
||||
</n-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>数据表</label>
|
||||
<div class="table-picker">
|
||||
@@ -507,6 +575,31 @@ onMounted(load);
|
||||
|
||||
<style scoped>
|
||||
.collect-form { display: grid; gap: 12px; min-width: 0; }
|
||||
.form-row-find { align-items: start; }
|
||||
.form-row-find > label { padding-top: 6px; }
|
||||
.field-find { display: grid; gap: 8px; min-width: 0; }
|
||||
.field-find-bar { display: flex; gap: 8px; min-width: 0; }
|
||||
.field-find-bar .n-button { flex: none; }
|
||||
.find-list {
|
||||
display: grid;
|
||||
gap: 0;
|
||||
max-height: 180px;
|
||||
overflow: auto;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
}
|
||||
.find-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 8px 12px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.find-row:last-child { border-bottom: 0; }
|
||||
.find-copy { min-width: 0; }
|
||||
.find-copy strong, .find-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.find-copy span { color: var(--muted); font-size: 12px; }
|
||||
.table-picker { display: flex; align-items: center; gap: 12px; min-width: 0; }
|
||||
.table-select { flex: 1; min-width: 0; }
|
||||
.picked-link { flex: none; }
|
||||
|
||||
Reference in New Issue
Block a user