优化缓存策略.

This commit is contained in:
lijiahangmax
2024-12-29 23:58:44 +08:00
parent 3b89e9bf29
commit c2311f0682
47 changed files with 302 additions and 289 deletions

View File

@@ -155,7 +155,7 @@
import { deleteHostIdentity, getHostIdentityPage } from '@/api/asset/host-identity';
import { Message, Modal } from '@arco-design/web-vue';
import usePermission from '@/hooks/permission';
import { useDictStore } from '@/store';
import { useCacheStore, useDictStore } from '@/store';
import { copy } from '@/hooks/copy';
import { GrantKey, GrantRouteName } from '@/views/asset/grant/types/const';
import { IdentityType, identityTypeKey } from '../types/const';
@@ -165,6 +165,7 @@
const list = ref<HostIdentityQueryResponse[]>([]);
const cacheStore = useCacheStore();
const cardColLayout = useCardColLayout();
const pagination = useCardPagination();
const { toOptions, getDictValue } = useDictStore();
@@ -199,8 +200,8 @@
// 调用删除接口
await deleteHostIdentity(id);
Message.success('删除成功');
// 重新加载数据
fetchCardData();
// 重新加载
reload();
} catch (e) {
} finally {
setLoading(false);
@@ -211,7 +212,10 @@
// 重新加载
const reload = () => {
// 重新加载数据
fetchCardData();
// 清空缓存
cacheStore.reset('hostIdentities', 'authorizedHostIdentities');
};
defineExpose({ reload });

View File

@@ -182,7 +182,7 @@
import useLoading from '@/hooks/loading';
import usePermission from '@/hooks/permission';
import { copy } from '@/hooks/copy';
import { useDictStore } from '@/store';
import { useCacheStore, useDictStore } from '@/store';
import { useTablePagination, useRowSelection } from '@/hooks/table';
import { GrantKey, GrantRouteName } from '@/views/asset/grant/types/const';
import { IdentityType, identityTypeKey } from '../types/const';
@@ -190,6 +190,7 @@
const emits = defineEmits(['openAdd', 'openUpdate', 'openKeyView']);
const cacheStore = useCacheStore();
const pagination = useTablePagination();
const rowSelection = useRowSelection();
const { toOptions, getDictValue } = useDictStore();
@@ -215,8 +216,8 @@
// 调用删除接口
await deleteHostIdentity(id);
Message.success('删除成功');
// 重新加载数据
fetchTableData();
// 重新加载
reload();
} catch (e) {
} finally {
setLoading(false);
@@ -231,8 +232,8 @@
await batchDeleteHostIdentity(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = [];
// 重新加载数据
fetchTableData();
// 重新加载
reload();
} catch (e) {
} finally {
setLoading(false);
@@ -241,7 +242,10 @@
// 重新加载
const reload = () => {
// 重新加载数据
fetchTableData();
// 清空缓存
cacheStore.reset('hostIdentities', 'authorizedHostIdentities');
};
defineExpose({ reload });

View File

@@ -28,8 +28,8 @@
</script>
<script lang="ts" setup>
import { ref, computed, onUnmounted, onBeforeMount } from 'vue';
import { useAppStore, useCacheStore, useDictStore } from '@/store';
import { ref, computed, onBeforeMount } from 'vue';
import { useAppStore, useDictStore } from '@/store';
import { dictKeys } from './types/const';
import HostIdentityCardList from './components/host-identity-card-list.vue';
import HostIdentityTable from './components/host-identity-table.vue';
@@ -41,7 +41,6 @@
const modal = ref();
const keyDrawer = ref();
const appStore = useAppStore();
const cacheStore = useCacheStore();
const renderTable = computed(() => appStore.hostIdentityView === 'table');
@@ -60,12 +59,6 @@
await dictStore.loadKeys(dictKeys);
});
// 卸载时清除 cache
onUnmounted(() => {
const cacheStore = useCacheStore();
cacheStore.reset('hostKeys');
});
</script>
<style lang="less" scoped>