优化缓存策略.

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

@@ -173,11 +173,11 @@
const emits = defineEmits(['openAdd', 'openUpdate', 'openView']);
const cacheStore = useCacheStore();
const pagination = useTablePagination();
const rowSelection = useRowSelection();
const { loading, setLoading } = useLoading();
const { toOptions, getDictValue } = useDictStore();
const cacheStore = useCacheStore();
const selectedKeys = ref<number[]>([]);
const tableRenderData = ref<DictKeyQueryResponse[]>([]);
@@ -188,17 +188,14 @@
});
// 删除当前行
const deleteRow = async ({ id }: {
id: number
}) => {
const deleteRow = async (record: DictKeyQueryResponse) => {
try {
setLoading(true);
// 调用删除接口
await deleteDictKey(id);
await deleteDictKey(record.id);
Message.success('删除成功');
cacheStore.reset('dictKeys');
// 重新加载数据
fetchTableData();
// 重新加载
reload();
} catch (e) {
} finally {
setLoading(false);
@@ -213,9 +210,8 @@
await batchDeleteDictKey(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = [];
cacheStore.reset('dictKeys');
// 重新加载数据
fetchTableData();
// 重新加载
reload();
} catch (e) {
} finally {
setLoading(false);
@@ -224,7 +220,9 @@
// 重新加载
const reload = () => {
// 重新加载数据
fetchTableData();
// 清空缓存
cacheStore.reset('dictKeys');
};

View File

@@ -175,8 +175,8 @@
await batchDeleteDictValue(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = [];
// 重新加载数据
fetchTableData();
// 重新加载
reload();
} catch (e) {
} finally {
setLoading(false);
@@ -190,8 +190,8 @@
// 调用删除接口
await deleteDictValue(record.id);
Message.success('删除成功');
// 重新加载数据
fetchTableData();
// 重新加载
reload();
} catch (e) {
} finally {
setLoading(false);
@@ -200,6 +200,7 @@
// 重新加载
const reload = () => {
// 重新加载数据
fetchTableData();
};

View File

@@ -24,9 +24,8 @@
</script>
<script lang="ts" setup>
import { ref, onUnmounted } from 'vue';
import { ref } from 'vue';
import { historyType } from './types/const';
import { useCacheStore } from '@/store';
import { rollbackDictValue } from '@/api/system/dict-value';
import DictValueTable from './components/dict-value-table.vue';
import DictValueFormModal from './components/dict-value-form-modal.vue';
@@ -35,18 +34,12 @@
const table = ref();
const modal = ref();
const history = ref();
const cacheStore = useCacheStore();
// 回滚
const rollback = async (id: number, valueId: number) => {
await rollbackDictValue({ id, valueId });
};
// 卸载时清除 cache
onUnmounted(() => {
cacheStore.reset('dictKeys');
});
</script>
<style lang="less" scoped>

View File

@@ -18,11 +18,11 @@
</script>
<script lang="ts" setup>
import { ref, onBeforeMount } from 'vue';
import { useDictStore } from '@/store';
import { dictKeys } from './types/const';
import MenuTable from '@/views/system/menu/components/menu-table.vue';
import MenuFormModal from '@/views/system/menu/components/menu-form-modal.vue';
import { ref, onBeforeMount, onUnmounted } from 'vue';
import { useCacheStore, useDictStore } from '@/store';
import { dictKeys } from './types/const';
const table = ref();
const modal = ref();
@@ -35,10 +35,4 @@
render.value = true;
});
// 卸载时清除 cache
onUnmounted(() => {
const cacheStore = useCacheStore();
cacheStore.reset('menus');
});
</script>