feat: 添加索引重建功能
This commit is contained in:
@ -15,12 +15,22 @@
|
|||||||
</v-list>
|
</v-list>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template #actions>
|
||||||
|
<v-button xSmall color="primary" @click="handleReindexAll">
|
||||||
|
一键重建
|
||||||
|
</v-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<v-notice type="info">请选择希望被 MeiliSearch 索引的集合。</v-notice>
|
<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 }">
|
<template #item.enabled="{ item }">
|
||||||
<v-checkbox v-model="item.enabled" :label="item.enabled ? '已启用' : '未启用'" />
|
<v-checkbox v-model="item.enabled" :label="item.enabled ? '已启用' : '未启用'" />
|
||||||
</template>"
|
</template>"
|
||||||
|
|
||||||
|
<template #item.actions="{ item }">
|
||||||
|
<v-button xSmall @click="handleReindex(item)">刷新索引</v-button>
|
||||||
|
</template>
|
||||||
</v-table>
|
</v-table>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@ -32,31 +42,44 @@ import { ref, onMounted } from 'vue';
|
|||||||
import { useApi } from '@directus/extensions-sdk';
|
import { useApi } from '@directus/extensions-sdk';
|
||||||
|
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
const collections = ref([]);
|
const configs = ref([]);
|
||||||
const headers = [
|
const headers = [
|
||||||
{ text: '集合名称', value: 'collection' },
|
{ text: '集合名称', value: 'collection_name' },
|
||||||
{ text: '说明', value: 'note' },
|
{ text: '索引名称', value: 'index_name' },
|
||||||
{ text: '启用索引', value: 'enabled' },
|
{ text: '启用索引', value: 'enabled' },
|
||||||
|
{ text: '操作', value: 'actions', sortable: false },
|
||||||
];
|
];
|
||||||
|
|
||||||
// const fetchConfigs = async () => {
|
const fetchConfigs = async () => {
|
||||||
// const resp = await api.get('/items/meili_index_configs', { params: { limit: -1 } });
|
const resp = await api.get('/items/meili_index_configs', { params: { limit: -1 } });
|
||||||
// configs.value = resp.data.data;
|
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);
|
const selected = ref(null);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchCollections();
|
fetchConfigs();
|
||||||
// fetchConfigs();
|
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user