优化缓存策略.

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

@@ -170,8 +170,8 @@
// 调用删除接口 // 调用删除接口
await delete${vue.featureEntity}(id); await delete${vue.featureEntity}(id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchCardData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -182,6 +182,7 @@
// 重新加载 // 重新加载
const reload = () => { const reload = () => {
// 重新加载数据
fetchCardData(); fetchCardData();
}; };

View File

@@ -189,8 +189,8 @@
await batchDelete${vue.featureEntity}(selectedKeys.value); await batchDelete${vue.featureEntity}(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -207,8 +207,8 @@
// 调用删除接口 // 调用删除接口
await delete${vue.featureEntity}(id); await delete${vue.featureEntity}(id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -217,6 +217,7 @@
// 重新加载 // 重新加载
const reload = () => { const reload = () => {
// 重新加载数据
fetchTableData(); fetchTableData();
}; };

View File

@@ -16,7 +16,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { TreeNodeData } from '@arco-design/web-vue'; import type { TreeNodeData } from '@arco-design/web-vue';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onActivated, onMounted, ref } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
@@ -44,7 +44,7 @@
const treeData = ref<Array<TreeNodeData>>([]); const treeData = ref<Array<TreeNodeData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(async () => { const initOptions = async () => {
setLoading(true); setLoading(true);
try { try {
treeData.value = await cacheStore.loadHostGroups(); treeData.value = await cacheStore.loadHostGroups();
@@ -52,7 +52,11 @@
} finally { } finally {
setLoading(false); setLoading(false);
} }
}); };
// 初始化选项
onMounted(initOptions);
onActivated(initOptions);
</script> </script>

View File

@@ -29,7 +29,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { SelectOptionData } from '@arco-design/web-vue'; import type { SelectOptionData } from '@arco-design/web-vue';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onActivated, onMounted, ref } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
@@ -60,7 +60,7 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(async () => { const initOptions = async () => {
setLoading(true); setLoading(true);
try { try {
const hostIdentities = props.authorized const hostIdentities = props.authorized
@@ -77,7 +77,11 @@
} finally { } finally {
setLoading(false); setLoading(false);
} }
}); };
// 初始化选项
onMounted(initOptions);
onActivated(initOptions);
</script> </script>

View File

@@ -14,7 +14,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { SelectOptionData } from '@arco-design/web-vue'; import type { SelectOptionData } from '@arco-design/web-vue';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onActivated, onMounted, ref } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
@@ -45,7 +45,7 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(async () => { const initOptions = async () => {
setLoading(true); setLoading(true);
try { try {
const hostKeys = props.authorized const hostKeys = props.authorized
@@ -61,7 +61,12 @@
} finally { } finally {
setLoading(false); setLoading(false);
} }
}); };
// 初始化选项
onMounted(initOptions);
onActivated(initOptions);
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@@ -16,7 +16,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { SelectOptionData } from '@arco-design/web-vue'; import type { SelectOptionData } from '@arco-design/web-vue';
import type { HostType } from '@/api/asset/host'; import type { HostType } from '@/api/asset/host';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onActivated, onMounted, ref } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
@@ -51,7 +51,7 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(async () => { const initOptions = async () => {
setLoading(true); setLoading(true);
try { try {
const hosts = await cacheStore.loadHosts(props.type); const hosts = await cacheStore.loadHosts(props.type);
@@ -66,7 +66,11 @@
} finally { } finally {
setLoading(false); setLoading(false);
} }
}); };
// 初始化选项
onMounted(initOptions);
onActivated(initOptions);
</script> </script>

View File

@@ -17,7 +17,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { SelectOptionData } from '@arco-design/web-vue'; import type { SelectOptionData } from '@arco-design/web-vue';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onActivated, onMounted, ref } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import { labelFilter } from '@/types/form'; import { labelFilter } from '@/types/form';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
@@ -57,7 +57,7 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(async () => { const initOptions = async () => {
setLoading(true); setLoading(true);
try { try {
const dictKeys = await cacheStore.loadExecJobs(); const dictKeys = await cacheStore.loadExecJobs();
@@ -71,7 +71,11 @@
} finally { } finally {
setLoading(false); setLoading(false);
} }
}); };
// 初始化选项
onMounted(initOptions);
onActivated(initOptions);
</script> </script>

View File

@@ -26,7 +26,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { SelectOptionData } from '@arco-design/web-vue'; import type { SelectOptionData } from '@arco-design/web-vue';
import type { TagCreateRequest } from '@/api/meta/tag'; import type { TagCreateRequest } from '@/api/meta/tag';
import { ref, computed, onBeforeMount } from 'vue'; import { ref, computed, onMounted, onActivated } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import { dataColor } from '@/utils'; import { dataColor } from '@/utils';
import { createTag } from '@/api/meta/tag'; import { createTag } from '@/api/meta/tag';
@@ -113,7 +113,7 @@
}; };
// 初始化选项 // 初始化选项
onBeforeMount(async () => { const initOptions = async () => {
setLoading(true); setLoading(true);
try { try {
const tags = await cacheStore.loadTags(props.type as string); const tags = await cacheStore.loadTags(props.type as string);
@@ -130,7 +130,11 @@
} finally { } finally {
setLoading(false); setLoading(false);
} }
}); };
// 初始化选项
onMounted(initOptions);
onActivated(initOptions);
</script> </script>

View File

@@ -17,7 +17,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { SelectOptionData } from '@arco-design/web-vue'; import type { SelectOptionData } from '@arco-design/web-vue';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onActivated, onMounted, ref } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import { labelFilter } from '@/types/form'; import { labelFilter } from '@/types/form';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
@@ -59,7 +59,7 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(async () => { const initOptions = async () => {
setLoading(true); setLoading(true);
try { try {
const dictKeys = await cacheStore.loadDictKeys(); const dictKeys = await cacheStore.loadDictKeys();
@@ -74,7 +74,11 @@
} finally { } finally {
setLoading(false); setLoading(false);
} }
}); };
// 初始化选项
onMounted(initOptions);
onActivated(initOptions);
</script> </script>

View File

@@ -17,7 +17,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { TreeNodeData } from '@arco-design/web-vue'; import type { TreeNodeData } from '@arco-design/web-vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onActivated, onMounted, ref } from 'vue';
import { MenuType } from '@/views/system/menu/types/const'; import { MenuType } from '@/views/system/menu/types/const';
import { titleFilter } from '@/types/form'; import { titleFilter } from '@/types/form';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
@@ -47,7 +47,8 @@
} }
}); });
onBeforeMount(async () => { // 初始化选项
const initOptions = async () => {
let render = (arr: any[]): TreeNodeData[] => { let render = (arr: any[]): TreeNodeData[] => {
return arr.map((s) => { return arr.map((s) => {
// 为 function 返回空 // 为 function 返回空
@@ -81,7 +82,11 @@
} finally { } finally {
setLoading(false); setLoading(false);
} }
}); };
// 初始化选项
onMounted(initOptions);
onActivated(initOptions);
</script> </script>

View File

@@ -17,7 +17,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { SelectOptionData } from '@arco-design/web-vue'; import type { SelectOptionData } from '@arco-design/web-vue';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onActivated, onMounted, ref } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import { RoleStatus } from '@/views/user/role/types/const'; import { RoleStatus } from '@/views/user/role/types/const';
import { labelFilter } from '@/types/form'; import { labelFilter } from '@/types/form';
@@ -54,7 +54,7 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(async () => { const initOptions = async () => {
setLoading(true); setLoading(true);
try { try {
const roles = await cacheStore.loadRoles(); const roles = await cacheStore.loadRoles();
@@ -69,7 +69,11 @@
} finally { } finally {
setLoading(false); setLoading(false);
} }
}); };
// 初始化选项
onMounted(initOptions);
onActivated(initOptions);
</script> </script>

View File

@@ -17,7 +17,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { SelectOptionData } from '@arco-design/web-vue'; import type { SelectOptionData } from '@arco-design/web-vue';
import { computed, ref, onMounted } from 'vue'; import { computed, ref, onMounted, onActivated } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import { labelFilter } from '@/types/form'; import { labelFilter } from '@/types/form';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
@@ -53,7 +53,7 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onMounted(async () => { const initOptions = async () => {
setLoading(true); setLoading(true);
try { try {
// 加载用户列表 // 加载用户列表
@@ -68,7 +68,11 @@
} finally { } finally {
setLoading(false); setLoading(false);
} }
}); };
// 初始化选项
onMounted(initOptions);
onActivated(initOptions);
</script> </script>

View File

@@ -1,11 +1,12 @@
// 缓存类型 // 缓存类型
export type CacheType = 'users' | 'menus' | 'roles' export type CacheType = 'users' | 'menus' | 'roles'
| 'hostGroups' | 'hostKeys' | 'hostIdentities' | 'hostGroups' | 'hostKeys' | 'hostIdentities' | 'host_*'
| 'dictKeys' | 'dictKeys'
| 'execJob'
| 'authorizedHostKeys' | 'authorizedHostIdentities' | 'authorizedHostKeys' | 'authorizedHostIdentities'
| 'commandSnippetGroups' | 'pathBookmarkGroups' | 'commandSnippetGroups' | 'pathBookmarkGroups'
| 'commandSnippets' | 'pathBookmarks' | 'commandSnippets' | 'pathBookmarks'
| 'execJob' | '*_Tags' | 'preference_*' | 'system_setting_*' | 'footer_setting'
| string | string
export interface CacheState { export interface CacheState {

View File

@@ -264,8 +264,6 @@
doFetchTableData({ page, limit, ...form }); doFetchTableData({ page, limit, ...form });
}; };
defineExpose({ fetchTableData });
// 打开清空 // 打开清空
const openClear = () => { const openClear = () => {
emits('openClear', { ...formModel, id: undefined }); emits('openClear', { ...formModel, id: undefined });
@@ -293,8 +291,8 @@
await deleteTerminalConnectLog(selectedKeys.value); await deleteTerminalConnectLog(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -309,14 +307,22 @@
await deleteTerminalConnectLog([record.id]); await deleteTerminalConnectLog([record.id]);
Message.success('删除成功'); Message.success('删除成功');
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
} }
}; };
// 重新加载
const reload = () => {
// 重新加载数据
fetchTableData();
};
defineExpose({ reload });
onMounted(() => { onMounted(() => {
// 当前用户 // 当前用户
const action = route.query.action as string; const action = route.query.action as string;

View File

@@ -6,7 +6,7 @@
@open-detail="(s) => detailModal.open(s)" /> @open-detail="(s) => detailModal.open(s)" />
<!-- 清空模态框 --> <!-- 清空模态框 -->
<connect-log-clear-modal ref="clearModal" <connect-log-clear-modal ref="clearModal"
@clear="() => table.fetchTableData()" /> @clear="() => table.reload()" />
<!-- 详情模态框 --> <!-- 详情模态框 -->
<connect-log-detail-drawer ref="detailModal" /> <connect-log-detail-drawer ref="detailModal" />
</div> </div>
@@ -19,8 +19,8 @@
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, onBeforeMount, onUnmounted } from 'vue'; import { ref, onBeforeMount } from 'vue';
import { useCacheStore, useDictStore } from '@/store'; import { useDictStore } from '@/store';
import { dictKeys } from './types/const'; import { dictKeys } from './types/const';
import ConnectLogTable from './components/connect-log-table.vue'; import ConnectLogTable from './components/connect-log-table.vue';
import ConnectLogClearModal from './components/connect-log-clear-modal.vue'; import ConnectLogClearModal from './components/connect-log-clear-modal.vue';
@@ -38,12 +38,6 @@
render.value = true; render.value = true;
}); });
// 重置缓存
onUnmounted(() => {
const cacheStore = useCacheStore();
cacheStore.reset('users');
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@@ -12,8 +12,8 @@
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, onBeforeMount, onUnmounted } from 'vue'; import { ref, onBeforeMount } from 'vue';
import { useCacheStore, useDictStore } from '@/store'; import { useDictStore } from '@/store';
import { dictKeys } from './types/const'; import { dictKeys } from './types/const';
import ConnectSessionTable from './components/connect-session-table.vue'; import ConnectSessionTable from './components/connect-session-table.vue';
@@ -26,12 +26,6 @@
render.value = true; render.value = true;
}); });
// 重置缓存
onUnmounted(() => {
const cacheStore = useCacheStore();
cacheStore.reset('users');
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@@ -247,8 +247,8 @@
await deleteTerminalSftpLog(selectedKeys.value); await deleteTerminalSftpLog(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -263,14 +263,20 @@
await deleteTerminalSftpLog([record.id]); await deleteTerminalSftpLog([record.id]);
Message.success('删除成功'); Message.success('删除成功');
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
} }
}; };
// 重新加载
const reload = () => {
// 重新加载数据
fetchTableData();
};
onMounted(() => { onMounted(() => {
fetchTableData(); fetchTableData();
}); });

View File

@@ -12,8 +12,8 @@
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, onBeforeMount, onUnmounted } from 'vue'; import { ref, onBeforeMount } from 'vue';
import { useCacheStore, useDictStore } from '@/store'; import { useDictStore } from '@/store';
import { dictKeys } from './types/const'; import { dictKeys } from './types/const';
import SftpLogTable from './components/sftp-log-table.vue'; import SftpLogTable from './components/sftp-log-table.vue';
@@ -26,12 +26,6 @@
render.value = true; render.value = true;
}); });
// 重置缓存
onUnmounted(() => {
const cacheStore = useCacheStore();
cacheStore.reset('users');
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@@ -25,13 +25,12 @@
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
import { onBeforeMount, onUnmounted, ref } from 'vue'; import { onBeforeMount, ref } from 'vue';
import { useCacheStore, useDictStore } from '@/store'; import { useDictStore } from '@/store';
import { GrantTabs, dictKeys } from './types/const'; import { GrantTabs, dictKeys } from './types/const';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
const route = useRoute(); const route = useRoute();
const cacheStore = useCacheStore();
const activeKey = ref(); const activeKey = ref();
@@ -49,11 +48,6 @@
} }
}); });
// 卸载时清除 cache
onUnmounted(() => {
cacheStore.reset('users', 'roles', 'hostGroups', 'hostKeys', 'hostIdentities');
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

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

View File

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

View File

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

View File

@@ -84,6 +84,7 @@
import type { HostKeyQueryRequest, HostKeyQueryResponse } from '@/api/asset/host-key'; import type { HostKeyQueryRequest, HostKeyQueryResponse } from '@/api/asset/host-key';
import { useCardPagination, useCardColLayout } from '@/hooks/card'; import { useCardPagination, useCardColLayout } from '@/hooks/card';
import { reactive, ref, onMounted } from 'vue'; import { reactive, ref, onMounted } from 'vue';
import { useCacheStore } from '@/store';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
import { resetObject } from '@/utils'; import { resetObject } from '@/utils';
import fieldConfig from '../types/card.fields'; import fieldConfig from '../types/card.fields';
@@ -95,6 +96,7 @@
const list = ref<HostKeyQueryResponse[]>([]); const list = ref<HostKeyQueryResponse[]>([]);
const cacheStore = useCacheStore();
const cardColLayout = useCardColLayout(); const cardColLayout = useCardColLayout();
const pagination = useCardPagination(); const pagination = useCardPagination();
const { loading, setLoading } = useLoading(); const { loading, setLoading } = useLoading();
@@ -116,8 +118,8 @@
// 调用删除接口 // 调用删除接口
await deleteHostKey(id); await deleteHostKey(id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchCardData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -128,7 +130,10 @@
// 重新加载 // 重新加载
const reload = () => { const reload = () => {
// 重新加载数据
fetchCardData(); fetchCardData();
// 清空缓存
cacheStore.reset('hostKeys', 'authorizedHostKeys');
}; };
defineExpose({ reload }); defineExpose({ reload });

View File

@@ -135,6 +135,7 @@
import { reactive, ref, onMounted } from 'vue'; import { reactive, ref, onMounted } from 'vue';
import { deleteHostKey, batchDeleteHostKey, getHostKeyPage } from '@/api/asset/host-key'; import { deleteHostKey, batchDeleteHostKey, getHostKeyPage } from '@/api/asset/host-key';
import { Message } from '@arco-design/web-vue'; import { Message } from '@arco-design/web-vue';
import { useCacheStore } from '@/store';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
import columns from '../types/table.columns'; import columns from '../types/table.columns';
import { useTablePagination, useRowSelection } from '@/hooks/table'; import { useTablePagination, useRowSelection } from '@/hooks/table';
@@ -142,6 +143,7 @@
const emits = defineEmits(['openAdd', 'openUpdate', 'openView']); const emits = defineEmits(['openAdd', 'openUpdate', 'openView']);
const cacheStore = useCacheStore();
const pagination = useTablePagination(); const pagination = useTablePagination();
const rowSelection = useRowSelection(); const rowSelection = useRowSelection();
const { loading, setLoading } = useLoading(); const { loading, setLoading } = useLoading();
@@ -156,16 +158,14 @@
}); });
// 删除当前行 // 删除当前行
const deleteRow = async ({ id }: { const deleteRow = async (record: HostKeyQueryResponse) => {
id: number
}) => {
try { try {
setLoading(true); setLoading(true);
// 调用删除接口 // 调用删除接口
await deleteHostKey(id); await deleteHostKey(record.id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -180,8 +180,8 @@
await batchDeleteHostKey(selectedKeys.value); await batchDeleteHostKey(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -190,7 +190,10 @@
// 重新加载 // 重新加载
const reload = () => { const reload = () => {
// 重新加载数据
fetchTableData(); fetchTableData();
// 清空缓存
cacheStore.reset('hostKeys', 'authorizedHostKeys');
}; };
defineExpose({ reload }); defineExpose({ reload });

View File

@@ -234,7 +234,7 @@
import { Message, Modal } from '@arco-design/web-vue'; import { Message, Modal } from '@arco-design/web-vue';
import { HostOsType, hostOsTypeKey, hostStatusKey, HostType, hostTypeKey, tagColor } from '../types/const'; import { HostOsType, hostOsTypeKey, hostStatusKey, HostType, hostTypeKey, tagColor } from '../types/const';
import { copy } from '@/hooks/copy'; import { copy } from '@/hooks/copy';
import { useDictStore } from '@/store'; import { useCacheStore, useDictStore } from '@/store';
import { GrantKey, GrantRouteName } from '@/views/asset/grant/types/const'; import { GrantKey, GrantRouteName } from '@/views/asset/grant/types/const';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
import fieldConfig from '../types/card.fields'; import fieldConfig from '../types/card.fields';
@@ -243,6 +243,7 @@
const emits = defineEmits(['openAdd', 'openUpdate', 'openUpdateConfig', 'openHostGroup', 'openCopy']); const emits = defineEmits(['openAdd', 'openUpdate', 'openUpdateConfig', 'openHostGroup', 'openCopy']);
const cacheStore = useCacheStore();
const cardColLayout = useCardColLayout(); const cardColLayout = useCardColLayout();
const pagination = useCardPagination(); const pagination = useCardPagination();
const { loading, setLoading } = useLoading(); const { loading, setLoading } = useLoading();
@@ -308,8 +309,8 @@
// 调用删除接口 // 调用删除接口
await deleteHost(id); await deleteHost(id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchCardData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -320,7 +321,10 @@
// 重新加载 // 重新加载
const reload = () => { const reload = () => {
// 重新加载数据
fetchCardData(); fetchCardData();
// 清空缓存
cacheStore.reset('host_SSH');
}; };
defineExpose({ reload }); defineExpose({ reload });

View File

@@ -269,7 +269,7 @@
import { Message, Modal } from '@arco-design/web-vue'; import { Message, Modal } from '@arco-design/web-vue';
import { tagColor, hostTypeKey, hostStatusKey, HostType, HostOsType, hostOsTypeKey } from '../types/const'; import { tagColor, hostTypeKey, hostStatusKey, HostType, HostOsType, hostOsTypeKey } from '../types/const';
import { useTablePagination, useRowSelection } from '@/hooks/table'; import { useTablePagination, useRowSelection } from '@/hooks/table';
import { useDictStore } from '@/store'; import { useCacheStore, useDictStore } from '@/store';
import { copy } from '@/hooks/copy'; import { copy } from '@/hooks/copy';
import { dataColor } from '@/utils'; import { dataColor } from '@/utils';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
@@ -280,6 +280,7 @@
const emits = defineEmits(['openCopy', 'openAdd', 'openUpdate', 'openUpdateConfig', 'openHostGroup']); const emits = defineEmits(['openCopy', 'openAdd', 'openUpdate', 'openUpdateConfig', 'openHostGroup']);
const cacheStore = useCacheStore();
const pagination = useTablePagination(); const pagination = useTablePagination();
const rowSelection = useRowSelection(); const rowSelection = useRowSelection();
const { loading, setLoading } = useLoading(); const { loading, setLoading } = useLoading();
@@ -334,8 +335,8 @@
// 调用删除接口 // 调用删除接口
await deleteHost(record.id); await deleteHost(record.id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -350,8 +351,8 @@
await batchDeleteHost(selectedKeys.value); await batchDeleteHost(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -360,11 +361,16 @@
// 重新加载 // 重新加载
const reload = () => { const reload = () => {
// 重新加载数据
fetchTableData(); fetchTableData();
// 清空缓存
cacheStore.reset('host_SSH');
}; };
defineExpose({ reload }); defineExpose({ reload });
defineExpose({ reload });
// 加载数据 // 加载数据
const doFetchTableData = async (request: HostQueryRequest) => { const doFetchTableData = async (request: HostQueryRequest) => {
try { try {

View File

@@ -34,8 +34,8 @@
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref, onUnmounted, onBeforeMount } from 'vue'; import { computed, ref, onBeforeMount } from 'vue';
import { useAppStore, useCacheStore, useDictStore } from '@/store'; import { useAppStore, useDictStore } from '@/store';
import { dictKeys } from './types/const'; import { dictKeys } from './types/const';
import HostTable from './components/host-table.vue'; import HostTable from './components/host-table.vue';
import HostCardList from './components/host-card-list.vue'; import HostCardList from './components/host-card-list.vue';
@@ -50,7 +50,6 @@
const hostGroup = ref(); const hostGroup = ref();
const appStore = useAppStore(); const appStore = useAppStore();
const cacheStore = useCacheStore();
const renderTable = computed(() => appStore.hostView === 'table'); const renderTable = computed(() => appStore.hostView === 'table');
@@ -69,11 +68,6 @@
await dictStore.loadKeys(dictKeys); await dictStore.loadKeys(dictKeys);
}); });
// 卸载时清除 cache
onUnmounted(() => {
cacheStore.reset('hostKeys', 'hostIdentities', 'hostGroups', 'HOST_Tags');
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@@ -264,8 +264,8 @@
await batchDeleteExecCommandLog(selectedKeys.value); await batchDeleteExecCommandLog(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -273,16 +273,14 @@
}; };
// 删除当前行 // 删除当前行
const deleteRow = async ({ id }: { const deleteRow = async (record: ExecLogQueryResponse) => {
id: number
}) => {
try { try {
setLoading(true); setLoading(true);
// 调用删除接口 // 调用删除接口
await deleteExecCommandLog(id); await deleteExecCommandLog(record.id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -381,6 +379,14 @@
}); });
}; };
// 重新加载
const reload = () => {
// 重新加载数据
fetchTableData();
};
defineExpose({ reload });
// 加载数据 // 加载数据
const doFetchTableData = async (request: ExecLogQueryRequest) => { const doFetchTableData = async (request: ExecLogQueryRequest) => {
try { try {
@@ -403,10 +409,6 @@
doFetchTableData({ page, limit, ...form }); doFetchTableData({ page, limit, ...form });
}; };
defineExpose({
fetchTableData
});
onMounted(() => { onMounted(() => {
// 当前用户 // 当前用户
const action = route.query.action as string; const action = route.query.action as string;

View File

@@ -8,7 +8,7 @@
@open-clear="openClearModal" /> @open-clear="openClearModal" />
<!-- 清理模态框 --> <!-- 清理模态框 -->
<exec-command-log-clear-modal ref="clearModal" <exec-command-log-clear-modal ref="clearModal"
@clear="clearCallback" /> @clear="() => tableRef.reload()" />
<!-- 执行日志模态框 --> <!-- 执行日志模态框 -->
<exec-log-panel-modal ref="logModal" <exec-log-panel-modal ref="logModal"
type="BATCH" /> type="BATCH" />
@@ -67,20 +67,13 @@
// 跳转新页面 // 跳转新页面
openNewRoute({ openNewRoute({
name: 'execCommand', name: 'execCommand',
query: { query: { id },
id
}
}); });
} else { } else {
logModal.value.open(id); logModal.value.open(id);
} }
}; };
// 清理回调
const clearCallback = () => {
tableRef.value.fetchTableData();
};
onBeforeMount(async () => { onBeforeMount(async () => {
const dictStore = useDictStore(); const dictStore = useDictStore();
await dictStore.loadKeys(dictKeys); await dictStore.loadKeys(dictKeys);

View File

@@ -264,6 +264,21 @@
emits('openClear', { ...formModel, id: undefined, description: undefined }); emits('openClear', { ...formModel, id: undefined, description: undefined });
}; };
// 删除当前行
const deleteRow = async (record: ExecLogQueryResponse) => {
try {
setLoading(true);
// 调用删除接口
await deleteExecJobLog(record.id);
Message.success('删除成功');
// 重新加载
reload();
} catch (e) {
} finally {
setLoading(false);
}
};
// 删除选中行 // 删除选中行
const deleteSelectedRows = async () => { const deleteSelectedRows = async () => {
try { try {
@@ -272,31 +287,22 @@
await batchDeleteExecJobLog(selectedKeys.value); await batchDeleteExecJobLog(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
} }
}; };
// 删除当前行 // 重新加载
const deleteRow = async ({ id }: { const reload = () => {
id: number // 重新加载数据
}) => { fetchTableData();
try {
setLoading(true);
// 调用删除接口
await deleteExecJobLog(id);
Message.success('删除成功');
// 重新加载数据
fetchTableData();
} catch (e) {
} finally {
setLoading(false);
}
}; };
defineExpose({ reload });
// 中断执行 // 中断执行
const doInterruptExecJob = async (record: ExecLogQueryResponse) => { const doInterruptExecJob = async (record: ExecLogQueryResponse) => {
try { try {
@@ -395,10 +401,6 @@
doFetchTableData({ page, limit, ...form }); doFetchTableData({ page, limit, ...form });
}; };
defineExpose({
fetchTableData
});
onMounted(() => { onMounted(() => {
// 加载数据 // 加载数据
fetchTableData(); fetchTableData();

View File

@@ -8,7 +8,7 @@
@open-clear="openClearModal" /> @open-clear="openClearModal" />
<!-- 清理模态框 --> <!-- 清理模态框 -->
<exec-job-log-clear-modal ref="clearModal" <exec-job-log-clear-modal ref="clearModal"
@clear="clearCallback" /> @clear="() => tableRef.reload()" />
<!-- 执行日志模态框 --> <!-- 执行日志模态框 -->
<exec-log-panel-modal ref="logModal" <exec-log-panel-modal ref="logModal"
type="JOB" /> type="JOB" />
@@ -70,20 +70,13 @@
// 跳转新页面 // 跳转新页面
openNewRoute({ openNewRoute({
name: 'execJobLogView', name: 'execJobLogView',
query: { query: { id },
id
}
}); });
} else { } else {
logModal.value.open(id); logModal.value.open(id);
} }
}; };
// 清理回调
const clearCallback = () => {
tableRef.value.fetchTableData();
};
onBeforeMount(async () => { onBeforeMount(async () => {
const dictStore = useDictStore(); const dictStore = useDictStore();
await dictStore.loadKeys(dictKeys); await dictStore.loadKeys(dictKeys);

View File

@@ -215,7 +215,7 @@
import columns from '../types/table.columns'; import columns from '../types/table.columns';
import { ExecJobStatus, execJobStatusKey, execStatusKey } from '../types/const'; import { ExecJobStatus, execJobStatusKey, execStatusKey } from '../types/const';
import { useTablePagination, useRowSelection } from '@/hooks/table'; import { useTablePagination, useRowSelection } from '@/hooks/table';
import { useDictStore, useUserStore } from '@/store'; import { useCacheStore, useDictStore, useUserStore } from '@/store';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { copy } from '@/hooks/copy'; import { copy } from '@/hooks/copy';
import { dateFormat } from '@/utils'; import { dateFormat } from '@/utils';
@@ -224,6 +224,7 @@
const emits = defineEmits(['openAdd', 'openUpdate', 'openDetail', 'updateExecUser', 'testCron']); const emits = defineEmits(['openAdd', 'openUpdate', 'openDetail', 'updateExecUser', 'testCron']);
const route = useRoute(); const route = useRoute();
const cacheStore = useCacheStore();
const pagination = useTablePagination(); const pagination = useTablePagination();
const rowSelection = useRowSelection(); const rowSelection = useRowSelection();
const { loading, setLoading } = useLoading(); const { loading, setLoading } = useLoading();
@@ -242,16 +243,14 @@
}); });
// 删除当前行 // 删除当前行
const deleteRow = async ({ id }: { const deleteRow = async (record: ExecJobQueryResponse) => {
id: number
}) => {
try { try {
setLoading(true); setLoading(true);
// 调用删除接口 // 调用删除接口
await deleteExecJob(id); await deleteExecJob(record.id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -266,8 +265,8 @@
await batchDeleteExecJob(selectedKeys.value); await batchDeleteExecJob(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -276,7 +275,10 @@
// 重新加载 // 重新加载
const reload = () => { const reload = () => {
// 重新加载数据
fetchTableData(); fetchTableData();
// 清空缓存
cacheStore.reset('execJob');
}; };
defineExpose({ reload }); defineExpose({ reload });

View File

@@ -153,16 +153,14 @@
}); });
// 删除当前行 // 删除当前行
const deleteRow = async ({ id }: { const deleteRow = async (record: ExecTemplateQueryResponse) => {
id: number
}) => {
try { try {
setLoading(true); setLoading(true);
// 调用删除接口 // 调用删除接口
await deleteExecTemplate(id); await deleteExecTemplate(record.id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -177,8 +175,8 @@
await batchDeleteExecTemplate(selectedKeys.value); await batchDeleteExecTemplate(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -187,6 +185,7 @@
// 重新加载 // 重新加载
const reload = () => { const reload = () => {
// 重新加载数据
fetchTableData(); fetchTableData();
}; };

View File

@@ -238,8 +238,8 @@
await batchDeleteUploadTask(selectedKeys.value); await batchDeleteUploadTask(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -247,22 +247,26 @@
}; };
// 删除当前行 // 删除当前行
const deleteRow = async ({ id }: { const deleteRow = async (record: UploadTaskQueryResponse) => {
id: number
}) => {
try { try {
setLoading(true); setLoading(true);
// 调用删除接口 // 调用删除接口
await deleteUploadTask(id); await deleteUploadTask(record.id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
} }
}; };
// 重新加载
const reload = () => {
// 重新加载数据
fetchTableData();
};
// 加载状态 // 加载状态
const pullTaskStatus = async () => { const pullTaskStatus = async () => {
const unCompleteIdList = tableRenderData.value const unCompleteIdList = tableRenderData.value
@@ -303,10 +307,6 @@
doFetchTableData({ page, limit, ...form }); doFetchTableData({ page, limit, ...form });
}; };
defineExpose({
fetchTableData
});
onMounted(() => { onMounted(() => {
// 加载数据 // 加载数据
fetchTableData(); fetchTableData();

View File

@@ -5,7 +5,7 @@
@open-clear="(e) => clear.open(e)" /> @open-clear="(e) => clear.open(e)" />
<!-- 清理模态框 --> <!-- 清理模态框 -->
<upload-task-clear-modal ref="clear" <upload-task-clear-modal ref="clear"
@clear="clearCallback" /> @clear="() => table.reload()" />
</div> </div>
</template> </template>
@@ -26,11 +26,6 @@
const table = ref(); const table = ref();
const clear = ref(); const clear = ref();
// 清理回调
const clearCallback = () => {
table.value.fetchTableData();
};
// 加载字典值 // 加载字典值
onBeforeMount(async () => { onBeforeMount(async () => {
const dictStore = useDictStore(); const dictStore = useDictStore();

View File

@@ -197,8 +197,6 @@
// 卸载处理 // 卸载处理
onUnmounted(() => { onUnmounted(() => {
// 卸载时清除 cache
useCacheStore().reset('authorizedHostKeys', 'authorizedHostIdentities', 'commandSnippetGroups', 'pathBookmarkGroups');
// 去除 body style // 去除 body style
document.body.removeAttribute('terminal-theme'); document.body.removeAttribute('terminal-theme');
// 重置 title // 重置 title

View File

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

View File

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

View File

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

View File

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

View File

@@ -120,6 +120,14 @@
jsonView.value.open(getLogDetail(record)); jsonView.value.open(getLogDetail(record));
}; };
// 重新加载
const reload = () => {
// 重新加载数据
fetchTableData();
};
defineExpose({ reload });
// 加载数据 // 加载数据
const doFetchTableData = async (request: OperatorLogQueryRequest) => { const doFetchTableData = async (request: OperatorLogQueryRequest) => {
try { try {
@@ -151,10 +159,6 @@
doFetchTableData({ page, limit, ...form }); doFetchTableData({ page, limit, ...form });
}; };
defineExpose({
fetchTableData
});
// 初始化 // 初始化
onMounted(async () => { onMounted(async () => {
// 加载字典值 // 加载字典值

View File

@@ -181,8 +181,8 @@
await deleteOperatorLog(selectedKeys.value); await deleteOperatorLog(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -197,14 +197,20 @@
await deleteOperatorLog([record.id]); await deleteOperatorLog([record.id]);
Message.success('删除成功'); Message.success('删除成功');
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
} }
}; };
// 重新加载
const reload = () => {
// 重新加载数据
fetchTableData();
};
// 加载数据 // 加载数据
const doFetchTableData = async (request: OperatorLogQueryRequest) => { const doFetchTableData = async (request: OperatorLogQueryRequest) => {
try { try {
@@ -228,8 +234,6 @@
doFetchTableData({ page, limit, ...form }); doFetchTableData({ page, limit, ...form });
}; };
defineExpose({ fetchTableData });
// 初始化 // 初始化
onMounted(() => { onMounted(() => {
fetchTableData(); fetchTableData();

View File

@@ -6,7 +6,7 @@
@open-clear="(s) => clearModal.open(s)" /> @open-clear="(s) => clearModal.open(s)" />
<!-- 清理模态框 --> <!-- 清理模态框 -->
<operator-log-clear-modal ref="clearModal" <operator-log-clear-modal ref="clearModal"
@clear="() => table.fetchTableData()" /> @clear="() => table.reload()" />
<!-- json 查看器模态框 --> <!-- json 查看器模态框 -->
<json-editor-modal ref="jsonView" /> <json-editor-modal ref="jsonView" />
</div> </div>
@@ -20,15 +20,13 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { OperatorLogQueryResponse } from '@/api/user/operator-log'; import type { OperatorLogQueryResponse } from '@/api/user/operator-log';
import { ref, onUnmounted, onBeforeMount } from 'vue'; import { ref, onBeforeMount } from 'vue';
import { useCacheStore, useDictStore } from '@/store'; import { useDictStore } from '@/store';
import { dictKeys, getLogDetail } from './types/const'; import { dictKeys, getLogDetail } from './types/const';
import OperatorLogTable from './components/operator-log-table.vue'; import OperatorLogTable from './components/operator-log-table.vue';
import OperatorLogClearModal from './components/operator-log-clear-modal.vue'; import OperatorLogClearModal from './components/operator-log-clear-modal.vue';
import JsonEditorModal from '@/components/view/json-editor/modal/index.vue'; import JsonEditorModal from '@/components/view/json-editor/modal/index.vue';
const cacheStore = useCacheStore();
const render = ref(false); const render = ref(false);
const table = ref(); const table = ref();
const clearModal = ref(); const clearModal = ref();
@@ -46,11 +44,6 @@
render.value = true; render.value = true;
}); });
// 卸载时清除 cache
onUnmounted(() => {
cacheStore.reset('users');
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@@ -139,11 +139,12 @@
import { RoleStatus, roleStatusKey } from '../types/const'; import { RoleStatus, roleStatusKey } from '../types/const';
import { useTablePagination } from '@/hooks/table'; import { useTablePagination } from '@/hooks/table';
import usePermission from '@/hooks/permission'; import usePermission from '@/hooks/permission';
import { useDictStore } from '@/store'; import { useCacheStore, useDictStore } from '@/store';
import { AdminRoleCode } from '@/types/const'; import { AdminRoleCode } from '@/types/const';
const emits = defineEmits(['openAdd', 'openUpdate', 'openGrant']); const emits = defineEmits(['openAdd', 'openUpdate', 'openGrant']);
const cacheStore = useCacheStore();
const pagination = useTablePagination(); const pagination = useTablePagination();
const { hasPermission } = usePermission(); const { hasPermission } = usePermission();
const { loading, setLoading } = useLoading(); const { loading, setLoading } = useLoading();
@@ -173,8 +174,8 @@
// 调用删除接口 // 调用删除接口
await deleteRole(record.id); await deleteRole(record.id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -183,7 +184,10 @@
// 重新加载 // 重新加载
const reload = () => { const reload = () => {
// 加载数据
fetchTableData(); fetchTableData();
// 清空缓存
cacheStore.reset('roles');
}; };
defineExpose({ reload }); defineExpose({ reload });

View File

@@ -21,8 +21,8 @@
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, onBeforeMount, onUnmounted } from 'vue'; import { ref, onBeforeMount } from 'vue';
import { useCacheStore, useDictStore } from '@/store'; import { useDictStore } from '@/store';
import { dictKeys } from './types/const'; import { dictKeys } from './types/const';
import RoleTable from './components/role-table.vue'; import RoleTable from './components/role-table.vue';
import RoleFormModal from './components/role-form-modal.vue'; import RoleFormModal from './components/role-form-modal.vue';
@@ -39,12 +39,6 @@
render.value = true; render.value = true;
}); });
// 卸载时清除 cache
onUnmounted(() => {
const cacheStore = useCacheStore();
cacheStore.reset('menus');
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@@ -183,11 +183,12 @@
import { useTablePagination, useRowSelection } from '@/hooks/table'; import { useTablePagination, useRowSelection } from '@/hooks/table';
import usePermission from '@/hooks/permission'; import usePermission from '@/hooks/permission';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { useDictStore, useUserStore } from '@/store'; import { useCacheStore, useDictStore, useUserStore } from '@/store';
import { copy } from '@/hooks/copy'; import { copy } from '@/hooks/copy';
const emits = defineEmits(['openAdd', 'openUpdate', 'openResetPassword', 'openGrantRole']); const emits = defineEmits(['openAdd', 'openUpdate', 'openResetPassword', 'openGrantRole']);
const cacheStore = useCacheStore();
const pagination = useTablePagination(); const pagination = useTablePagination();
const rowSelection = useRowSelection(); const rowSelection = useRowSelection();
const { hasPermission } = usePermission(); const { hasPermission } = usePermission();
@@ -217,8 +218,8 @@
// 调用删除接口 // 调用删除接口
await deleteUser(record.id); await deleteUser(record.id);
Message.success('删除成功'); Message.success('删除成功');
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -233,8 +234,8 @@
await batchDeleteUser(selectedKeys.value); await batchDeleteUser(selectedKeys.value);
Message.success(`成功删除 ${selectedKeys.value.length} 条数据`); Message.success(`成功删除 ${selectedKeys.value.length} 条数据`);
selectedKeys.value = []; selectedKeys.value = [];
// 重新加载数据 // 重新加载
fetchTableData(); reload();
} catch (e) { } catch (e) {
} finally { } finally {
setLoading(false); setLoading(false);
@@ -260,7 +261,10 @@
// 重新加载 // 重新加载
const reload = () => { const reload = () => {
// 加载数据
fetchTableData(); fetchTableData();
// 清空缓存
cacheStore.reset('users');
}; };
defineExpose({ reload }); defineExpose({ reload });

View File

@@ -24,13 +24,13 @@
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, onBeforeMount } from 'vue';
import { useDictStore } from '@/store';
import { dictKeys } from './types/const';
import UserTable from './components/user-table.vue'; import UserTable from './components/user-table.vue';
import UserFormModal from './components/user-form-modal.vue'; import UserFormModal from './components/user-form-modal.vue';
import UserResetPasswordFormModal from './components/user-reset-password-form-modal.vue'; import UserResetPasswordFormModal from './components/user-reset-password-form-modal.vue';
import UserGrantRolesFormModal from './components/user-grant-roles-form-modal.vue'; import UserGrantRolesFormModal from './components/user-grant-roles-form-modal.vue';
import { ref, onBeforeMount, onUnmounted } from 'vue';
import { useCacheStore, useDictStore } from '@/store';
import { dictKeys } from './types/const';
const render = ref(false); const render = ref(false);
const table = ref(); const table = ref();
@@ -45,12 +45,6 @@
render.value = true; render.value = true;
}); });
// 卸载时清除 cache
onUnmounted(() => {
const cacheStore = useCacheStore();
cacheStore.reset('roles');
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>