feat: 添加索引重建功能

This commit is contained in:
2025-10-23 08:45:21 +00:00
parent 539e9b23ca
commit 2f1754ff0b

View File

@ -15,12 +15,22 @@
</v-list>
</template>
<template #actions>
<v-button xSmall color="primary" @click="handleReindexAll">
一键重建
</v-button>
</template>
<section>
<v-notice type="info">请选择希望被 MeiliSearch 索引的集合</v-notice>
<v-table :headers="headers" :items="collections" :items-per-page="10" class="mt-4">
<v-table :headers="headers" :items="configs" :items-per-page="10" class="mt-4">
<template #item.enabled="{ item }">
<v-checkbox v-model="item.enabled" :label="item.enabled ? '已启用' : '未启用'" />
</template>"
<template #item.actions="{ item }">
<v-button xSmall @click="handleReindex(item)">刷新索引</v-button>
</template>
</v-table>
</section>
@ -32,31 +42,44 @@ import { ref, onMounted } from 'vue';
import { useApi } from '@directus/extensions-sdk';
const api = useApi();
const collections = ref([]);
const configs = ref([]);
const headers = [
{ text: '集合名称', value: 'collection' },
{ text: '说明', value: 'note' },
{ text: '集合名称', value: 'collection_name' },
{ text: '索引名称', value: 'index_name' },
{ text: '启用索引', value: 'enabled' },
{ text: '操作', value: 'actions', sortable: false },
];
// const fetchConfigs = async () => {
// const resp = await api.get('/items/meili_index_configs', { params: { limit: -1 } });
// configs.value = resp.data.data;
// }
const fetchConfigs = async () => {
const resp = await api.get('/items/meili_index_configs', { params: { limit: -1 } });
configs.value = resp.data.data;
}
const handleReindexAll = async () => {
try {
await api.post('/meilisearch/reindex');
console.log('Reindexing all started successfully');
} catch (error) {
console.error('Reindexing all failed:', error);
}
}
const handleReindex = async (item: any) => {
if (!item.enabled) return;
const configId = item.id;
try {
await api.post(`/meilisearch/reindex/${configId}`);
console.log('Reindexing started successfully');
} catch (error) {
console.error('Reindexing failed:', error);
}
const fetchCollections = async () => {
const resp = await api.get('/meilisearch/collections');
collections.value = resp.data.map((col: any) => ({
...col,
enabled: false,
}));
};
const selected = ref(null);
onMounted(() => {
fetchCollections();
// fetchConfigs();
fetchConfigs();
})
</script>