feat: 为索引按钮添加动画
- 为索引按钮添加动画,在索引过程中使用动画表示进度
This commit is contained in:
@ -16,8 +16,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #actions>
|
<template #actions>
|
||||||
<v-button xSmall color="primary" @click="handleReindexAll">
|
<v-button :disabled="reindexingAll" xSmall color="primary" @click="handleReindexAll">
|
||||||
一键重建
|
<span>一键重建</span>
|
||||||
</v-button>
|
</v-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -29,7 +29,7 @@
|
|||||||
</template>"
|
</template>"
|
||||||
|
|
||||||
<template #item.actions="{ item }">
|
<template #item.actions="{ item }">
|
||||||
<v-button xSmall @click="handleReindex(item)">刷新索引</v-button>
|
<v-button :disabled="reindexing[item.id]" xSmall @click="handleReindex(item)">刷新索引</v-button>
|
||||||
</template>
|
</template>
|
||||||
</v-table>
|
</v-table>
|
||||||
</section>
|
</section>
|
||||||
@ -40,9 +40,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
import { useApi } from '@directus/extensions-sdk';
|
import { useApi } from '@directus/extensions-sdk';
|
||||||
|
import type { MeiliIndexConfig } from '../types/meilisearch';
|
||||||
|
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
const configs = ref([]);
|
const configs = ref<MeiliIndexConfig[]>([]);
|
||||||
const headers = [
|
const headers = [
|
||||||
{ text: '集合名称', value: 'collection_name' },
|
{ text: '集合名称', value: 'collection_name' },
|
||||||
{ text: '索引名称', value: 'index_name' },
|
{ text: '索引名称', value: 'index_name' },
|
||||||
@ -50,28 +51,40 @@ const headers = [
|
|||||||
{ text: '操作', value: 'actions', sortable: false },
|
{ text: '操作', value: 'actions', sortable: false },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const reindexingAll = ref(false);
|
||||||
|
const reindexing = ref<Record<string, boolean>>({});
|
||||||
|
|
||||||
const fetchConfigs = async () => {
|
const fetchConfigs = async () => {
|
||||||
const resp = await api.get('/items/meili_index_configs', { params: { limit: -1 } });
|
const resp = await api.get<{ data: MeiliIndexConfig[] }>('/items/meili_index_configs', { params: { limit: -1 } });
|
||||||
|
console.log(resp)
|
||||||
configs.value = resp.data.data;
|
configs.value = resp.data.data;
|
||||||
|
|
||||||
|
reindexing.value = Object.fromEntries(configs.value.map(c => [c.id, false]));
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleReindexAll = async () => {
|
const handleReindexAll = async () => {
|
||||||
try {
|
try {
|
||||||
|
reindexingAll.value = true;
|
||||||
await api.post('/meilisearch/reindex');
|
await api.post('/meilisearch/reindex');
|
||||||
console.log('Reindexing all started successfully');
|
console.log('Reindexing all started successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Reindexing all failed:', error);
|
console.error('Reindexing all failed:', error);
|
||||||
|
} finally {
|
||||||
|
reindexingAll.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleReindex = async (item: any) => {
|
const handleReindex = async (item: MeiliIndexConfig) => {
|
||||||
if (!item.enabled) return;
|
if (!item.enabled) return;
|
||||||
const configId = item.id;
|
const configId = item.id;
|
||||||
try {
|
try {
|
||||||
|
reindexing.value[configId] = true;
|
||||||
await api.post(`/meilisearch/reindex/${configId}`);
|
await api.post(`/meilisearch/reindex/${configId}`);
|
||||||
console.log('Reindexing started successfully');
|
console.log('Reindexing started successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Reindexing failed:', error);
|
console.error('Reindexing failed:', error);
|
||||||
|
} finally {
|
||||||
|
reindexing.value[configId] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user