refactor: 修改缓存加载逻辑.

This commit is contained in:
lijiahang
2023-12-04 16:08:14 +08:00
parent f4b5ba168a
commit 4cfc22753b
16 changed files with 119 additions and 76 deletions

View File

@@ -69,6 +69,10 @@ body {
} }
// -- arco // -- arco
.arco-menu-inner::-webkit-scrollbar {
display: none;
}
.arco-table-td-content { .arco-table-td-content {
color: rgba(var(--gray-9), .95); color: rgba(var(--gray-9), .95);
font-size: 13px; font-size: 13px;
@@ -119,7 +123,8 @@ body {
margin: 0; margin: 0;
} }
} }
.arco-scrollbar-track-direction-horizontal{
.arco-scrollbar-track-direction-horizontal {
height: 9px; height: 9px;
.arco-scrollbar-thumb-bar { .arco-scrollbar-thumb-bar {

View File

@@ -2,6 +2,7 @@
<a-tree-select v-model="value" <a-tree-select v-model="value"
:multiple="true" :multiple="true"
:data="treeData" :data="treeData"
:loading="loading"
placeholder="请选择主机分组" placeholder="请选择主机分组"
:allow-clear="true" :allow-clear="true"
:allow-search="true"> :allow-search="true">
@@ -19,7 +20,7 @@
import type { PropType } from 'vue'; import type { PropType } from 'vue';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onBeforeMount, ref } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import { getHostGroupTree } from '@/api/asset/host-group'; import useLoading from '@/hooks/loading';
const props = defineProps({ const props = defineProps({
modelValue: Array as PropType<Array<Number>>, modelValue: Array as PropType<Array<Number>>,
@@ -27,6 +28,7 @@
const emits = defineEmits(['update:modelValue']); const emits = defineEmits(['update:modelValue']);
const { loading, setLoading } = useLoading();
const cacheStore = useCacheStore(); const cacheStore = useCacheStore();
const value = computed<Array<number>>({ const value = computed<Array<number>>({
@@ -44,10 +46,14 @@
const treeData = ref<Array<TreeNodeData>>([]); const treeData = ref<Array<TreeNodeData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(() => { onBeforeMount(async () => {
cacheStore.loadHostGroups().then(s => { setLoading(true);
treeData.value = s; try {
}); treeData.value = await cacheStore.loadHostGroups();
} catch (e) {
} finally {
setLoading(false);
}
}); });
</script> </script>

View File

@@ -92,7 +92,7 @@
import { computed, nextTick, onMounted, ref } from 'vue'; import { computed, nextTick, onMounted, ref } from 'vue';
import { createGroupGroupPrefix, rootId } from './types/const'; import { createGroupGroupPrefix, rootId } from './types/const';
import { findNode, findParentNode, moveNode } from '@/utils/tree'; import { findNode, findParentNode, moveNode } from '@/utils/tree';
import { createHostGroup, deleteHostGroup, getHostGroupTree, updateHostGroupName, moveHostGroup } from '@/api/asset/host-group'; import { createHostGroup, deleteHostGroup, updateHostGroupName, moveHostGroup } from '@/api/asset/host-group';
import { isString } from '@/utils/is'; import { isString } from '@/utils/is';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';

View File

@@ -1,6 +1,7 @@
<template> <template>
<a-select v-model:model-value="value" <a-select v-model:model-value="value"
:options="optionData" :options="optionData"
:loading="loading"
placeholder="请选择主机身份" placeholder="请选择主机身份"
allow-clear /> allow-clear />
</template> </template>
@@ -15,6 +16,7 @@
import type { SelectOptionData } from '@arco-design/web-vue'; import type { SelectOptionData } from '@arco-design/web-vue';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onBeforeMount, ref } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import useLoading from '@/hooks/loading';
const props = defineProps({ const props = defineProps({
modelValue: Number, modelValue: Number,
@@ -22,6 +24,7 @@
const emits = defineEmits(['update:modelValue']); const emits = defineEmits(['update:modelValue']);
const { loading, setLoading } = useLoading();
const cacheStore = useCacheStore(); const cacheStore = useCacheStore();
const value = computed<number>({ const value = computed<number>({
@@ -39,15 +42,20 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(() => { onBeforeMount(async () => {
cacheStore.loadHostIdentities().then(hostIdentities => { setLoading(true);
try {
const hostIdentities = await cacheStore.loadHostIdentities();
optionData.value = hostIdentities.map(s => { optionData.value = hostIdentities.map(s => {
return { return {
label: `${s.name} (${s.username})`, label: `${s.name} (${s.username})`,
value: s.id, value: s.id,
}; };
}); });
}); } catch (e) {
} finally {
setLoading(false);
}
}); });
</script> </script>

View File

@@ -1,6 +1,7 @@
<template> <template>
<a-select v-model:model-value="value" <a-select v-model:model-value="value"
:options="optionData" :options="optionData"
:loading="loading"
placeholder="请选择主机秘钥" placeholder="请选择主机秘钥"
allow-clear /> allow-clear />
</template> </template>
@@ -15,6 +16,7 @@
import type { SelectOptionData } from '@arco-design/web-vue'; import type { SelectOptionData } from '@arco-design/web-vue';
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onBeforeMount, ref } from 'vue';
import { useCacheStore } from '@/store'; import { useCacheStore } from '@/store';
import useLoading from '@/hooks/loading';
const props = defineProps({ const props = defineProps({
modelValue: Number, modelValue: Number,
@@ -22,6 +24,7 @@
const emits = defineEmits(['update:modelValue']); const emits = defineEmits(['update:modelValue']);
const { loading, setLoading } = useLoading();
const cacheStore = useCacheStore(); const cacheStore = useCacheStore();
const value = computed<number>({ const value = computed<number>({
@@ -39,15 +42,20 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(() => { onBeforeMount(async () => {
cacheStore.loadHostKeys().then(hostKeys => { setLoading(true);
try {
const hostKeys = await cacheStore.loadHostKeys();
optionData.value = hostKeys.map(s => { optionData.value = hostKeys.map(s => {
return { return {
label: s.name, label: s.name,
value: s.id, value: s.id,
}; };
}); });
}); } catch (e) {
} finally {
setLoading(false);
}
}); });
</script> </script>

View File

@@ -51,18 +51,6 @@
}); });
const optionData = ref<SelectOptionData[]>([]); const optionData = ref<SelectOptionData[]>([]);
// 初始化选项
onBeforeMount(() => {
cacheStore.loadTags(props.type as string).then((tags) => {
optionData.value = tags.map(s => {
return {
label: s.name,
value: s.id,
};
});
});
});
// 检查是否可以创建tag // 检查是否可以创建tag
const checkCreateTag = async (tags: Array<any>) => { const checkCreateTag = async (tags: Array<any>) => {
if (!tags.length) { if (!tags.length) {
@@ -112,6 +100,23 @@
return id; return id;
}; };
// 初始化选项
onBeforeMount(async () => {
setLoading(true);
try {
const tags = await cacheStore.loadTags(props.type as string);
optionData.value = tags.map(s => {
return {
label: s.name,
value: s.id,
};
});
} catch (e) {
} finally {
setLoading(false);
}
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@@ -20,10 +20,10 @@
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onBeforeMount, 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';
const props = defineProps({ const props = defineProps({
modelValue: Number, modelValue: Number,
loading: Boolean,
allowCreate: { allowCreate: {
type: Boolean, type: Boolean,
default: false default: false
@@ -32,7 +32,7 @@
const emits = defineEmits(['update:modelValue', 'change']); const emits = defineEmits(['update:modelValue', 'change']);
// 选项数据 const { loading, setLoading } = useLoading();
const cacheStore = useCacheStore(); const cacheStore = useCacheStore();
const value = computed({ const value = computed({
@@ -60,8 +60,10 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(() => { onBeforeMount(async () => {
cacheStore.loadDictKeys().then(dictKeys => { setLoading(true);
try {
const dictKeys = await cacheStore.loadDictKeys();
optionData.value = dictKeys.map(s => { optionData.value = dictKeys.map(s => {
return { return {
label: `${s.keyName} - ${s.description || ''}`, label: `${s.keyName} - ${s.description || ''}`,
@@ -69,7 +71,10 @@
origin: s origin: s
}; };
}); });
}); } catch (e) {
} finally {
setLoading(false);
}
}); });
</script> </script>

View File

@@ -2,6 +2,7 @@
<a-tree-select v-model:model-value="value" <a-tree-select v-model:model-value="value"
:data="treeData" :data="treeData"
:disabled="disabled" :disabled="disabled"
:loading="loading"
:allow-search="true" :allow-search="true"
:filter-tree-node="titleFilter" :filter-tree-node="titleFilter"
placeholder="请选择菜单" /> placeholder="请选择菜单" />
@@ -19,6 +20,7 @@
import { computed, onBeforeMount, ref } from 'vue'; import { computed, onBeforeMount, 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';
const props = defineProps({ const props = defineProps({
modelValue: Number, modelValue: Number,
@@ -27,6 +29,7 @@
const emits = defineEmits(['update:modelValue']); const emits = defineEmits(['update:modelValue']);
const { loading, setLoading } = useLoading();
const cacheStore = useCacheStore(); const cacheStore = useCacheStore();
const treeData = ref<Array<TreeNodeData>>([]); const treeData = ref<Array<TreeNodeData>>([]);
@@ -40,7 +43,7 @@
} }
}); });
onBeforeMount(() => { onBeforeMount(async () => {
let render = (arr: any[]): TreeNodeData[] => { let render = (arr: any[]): TreeNodeData[] => {
return arr.map((s) => { return arr.map((s) => {
// 为 function 返回空 // 为 function 返回空
@@ -60,13 +63,20 @@
return node; return node;
}).filter(Boolean); }).filter(Boolean);
}; };
cacheStore.loadMenus().then(menus => {
// 加载数据
try {
setLoading(true);
const menus = await cacheStore.loadMenus();
treeData.value = [{ treeData.value = [{
key: 0, key: 0,
title: '根目录', title: '根目录',
children: render([...menus]) children: render([...menus])
}]; }];
}); } catch (e) {
} finally {
setLoading(false);
}
}); });
</script> </script>

View File

@@ -22,15 +22,16 @@
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';
import useLoading from '@/hooks/loading';
const props = defineProps({ const props = defineProps({
modelValue: [Number, Array] as PropType<number | Array<number>>, modelValue: [Number, Array] as PropType<number | Array<number>>,
loading: Boolean,
multiple: Boolean, multiple: Boolean,
}); });
const emits = defineEmits(['update:modelValue']); const emits = defineEmits(['update:modelValue']);
const { loading, setLoading } = useLoading();
const cacheStore = useCacheStore(); const cacheStore = useCacheStore();
const value = computed({ const value = computed({
@@ -44,8 +45,10 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onBeforeMount(() => { onBeforeMount(async () => {
cacheStore.loadRoles().then(roles => { setLoading(true);
try {
const roles = await cacheStore.loadRoles();
optionData.value = roles.map(s => { optionData.value = roles.map(s => {
return { return {
label: `${s.name} (${s.code})`, label: `${s.name} (${s.code})`,
@@ -53,7 +56,10 @@
value: s.id, value: s.id,
}; };
}); });
}); } catch (e) {
} finally {
setLoading(false);
}
}); });
</script> </script>

View File

@@ -21,15 +21,16 @@
import { computed, ref, onMounted } from 'vue'; import { computed, ref, onMounted } 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';
const props = defineProps({ const props = defineProps({
modelValue: [Number, Array] as PropType<number | Array<number>>, modelValue: [Number, Array] as PropType<number | Array<number>>,
loading: Boolean,
multiple: Boolean, multiple: Boolean,
}); });
const emits = defineEmits(['update:modelValue']); const emits = defineEmits(['update:modelValue']);
const { loading, setLoading } = useLoading();
const cacheStore = useCacheStore(); const cacheStore = useCacheStore();
const value = computed({ const value = computed({
@@ -43,16 +44,21 @@
const optionData = ref<Array<SelectOptionData>>([]); const optionData = ref<Array<SelectOptionData>>([]);
// 初始化选项 // 初始化选项
onMounted(() => { onMounted(async () => {
// 加载用户列表 setLoading(true);
cacheStore.loadUsers().then(users => { try {
// 加载用户列表
const users = await cacheStore.loadUsers();
optionData.value = users.map(s => { optionData.value = users.map(s => {
return { return {
label: `${s.nickname} (${s.username})`, label: `${s.nickname} (${s.username})`,
value: s.id, value: s.id,
}; };
}); });
}); } catch (e) {
} finally {
setLoading(false);
}
}); });
</script> </script>

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="layout-container" v-if="render"> <div class="layout-container">
<!-- 列表-表格 --> <!-- 列表-表格 -->
<host-key-table v-if="renderTable" <host-key-table v-if="renderTable"
ref="table" ref="table"
@@ -26,14 +26,12 @@
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref } from 'vue';
import { useAppStore } from '@/store';
import HostKeyCardList from './components/host-key-card-list.vue'; import HostKeyCardList from './components/host-key-card-list.vue';
import HostKeyTable from './components/host-key-table.vue'; import HostKeyTable from './components/host-key-table.vue';
import HostKeyFormDrawer from './components/host-key-form-drawer.vue'; import HostKeyFormDrawer from './components/host-key-form-drawer.vue';
import { computed, ref, onBeforeMount } from 'vue';
import { useAppStore } from '@/store';
const render = ref(false);
const table = ref(); const table = ref();
const card = ref(); const card = ref();
const drawer = ref(); const drawer = ref();
@@ -59,10 +57,6 @@
} }
}; };
onBeforeMount(async () => {
render.value = true;
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@@ -30,7 +30,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { HostConfigWrapper } from '../../types/const'; import type { HostConfigWrapper } from '../../types/const';
import { ref, onBeforeMount } from 'vue'; import { ref } from 'vue';
import useVisible from '@/hooks/visible'; import useVisible from '@/hooks/visible';
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
import { Message } from '@arco-design/web-vue'; import { Message } from '@arco-design/web-vue';
@@ -54,6 +54,9 @@
try { try {
setLoading(true); setLoading(true);
setVisible(true); setVisible(true);
// 加载字典值
const dictStore = useDictStore();
await dictStore.loadKeys([...sshDictKeys]);
// 加载配置 // 加载配置
const { data } = await getHostConfigAll({ hostId: record.value.id }); const { data } = await getHostConfigAll({ hostId: record.value.id });
data.forEach(s => { data.forEach(s => {
@@ -75,12 +78,6 @@
defineExpose({ open }); defineExpose({ open });
onBeforeMount(async () => {
// 加载字典值
const dictStore = useDictStore();
await dictStore.loadKeys([...sshDictKeys]);
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@@ -46,7 +46,7 @@
:hide-asterisk="true" :hide-asterisk="true"
label-col-flex="60px"> label-col-flex="60px">
<a-radio-group type="button" <a-radio-group type="button"
class="auth-type-group" class="auth-type-group usn"
v-model="formModel.authType" v-model="formModel.authType"
:options="toOptions(authTypeKey)" /> :options="toOptions(authTypeKey)" />
</a-form-item> </a-form-item>

View File

@@ -40,7 +40,6 @@
import HostConfigDrawer from './components/config/host-config-drawer.vue'; import HostConfigDrawer from './components/config/host-config-drawer.vue';
import HostGroupDrawer from './components/group/host-group-drawer.vue'; import HostGroupDrawer from './components/group/host-group-drawer.vue';
const render = ref(false);
const table = ref(); const table = ref();
const card = ref(); const card = ref();
const modal = ref(); const modal = ref();

View File

@@ -14,7 +14,7 @@
:cancel-button-props="{ disabled: loading }" :cancel-button-props="{ disabled: loading }"
:on-before-ok="handlerOk" :on-before-ok="handlerOk"
@close="handleClose"> @close="handleClose">
<div class="role-menu-wrapper"> <a-spin :loading="loading" class="role-menu-wrapper">
<a-alert class="usn mb8"> <a-alert class="usn mb8">
<span>{{ roleRecord.name }} {{ roleRecord.code }}</span> <span>{{ roleRecord.name }} {{ roleRecord.code }}</span>
<span class="mx8">-</span> <span class="mx8">-</span>
@@ -40,7 +40,7 @@
</div> </div>
<!-- 菜单 --> <!-- 菜单 -->
<menu-grant-table ref="table" /> <menu-grant-table ref="table" />
</div> </a-spin>
</a-modal> </a-modal>
</template> </template>

View File

@@ -8,11 +8,11 @@
:draggable="true" :draggable="true"
:mask-closable="false" :mask-closable="false"
:unmount-on-close="true" :unmount-on-close="true"
:ok-button-props="{ disabled: saveLoading }" :ok-button-props="{ disabled: loading }"
:cancel-button-props="{ disabled: saveLoading }" :cancel-button-props="{ disabled: loading }"
:on-before-ok="handlerOk" :on-before-ok="handlerOk"
@close="handleClose"> @close="handleClose">
<a-spin :loading="saveLoading"> <a-spin :loading="loading">
<a-form :model="formModel" <a-form :model="formModel"
ref="formRef" ref="formRef"
label-align="right" label-align="right"
@@ -30,8 +30,7 @@
<!-- 角色 --> <!-- 角色 -->
<a-form-item field="roles" label="角色"> <a-form-item field="roles" label="角色">
<role-selector v-model="formModel.roleIdList" <role-selector v-model="formModel.roleIdList"
:loading="roleLoading" :multiple="true" />
:multiple="true" />
</a-form-item> </a-form-item>
</a-form> </a-form>
</a-spin> </a-spin>
@@ -55,8 +54,7 @@
import { getUserRoleIdList, grantUserRole } from '@/api/user/user'; import { getUserRoleIdList, grantUserRole } from '@/api/user/user';
const { visible, setVisible } = useVisible(); const { visible, setVisible } = useVisible();
const { loading: saveLoading, setLoading: setSaveLoading } = useLoading(); const { loading, setLoading } = useLoading();
const { loading: roleLoading, setLoading: setRoleLoading } = useLoading();
const formRef = ref(); const formRef = ref();
const formModel = ref<UserUpdateRequest>({}); const formModel = ref<UserUpdateRequest>({});
@@ -82,13 +80,10 @@
// 加载角色 // 加载角色
const loadRoles = async () => { const loadRoles = async () => {
try { try {
setRoleLoading(true);
// 加载用户角色 // 加载用户角色
const { data: roleIdList } = await getUserRoleIdList(formModel.value.id as number); const { data: roleIdList } = await getUserRoleIdList(formModel.value.id as number);
formModel.value.roleIdList = roleIdList; formModel.value.roleIdList = roleIdList;
} catch (e) { } catch (e) {
} finally {
setRoleLoading(false);
} }
}; };
@@ -96,7 +91,7 @@
// 确定 // 确定
const handlerOk = async () => { const handlerOk = async () => {
setSaveLoading(true); setLoading(true);
try { try {
await grantUserRole(formModel.value); await grantUserRole(formModel.value);
Message.success('修改成功'); Message.success('修改成功');
@@ -105,7 +100,7 @@
} catch (e) { } catch (e) {
return false; return false;
} finally { } finally {
setSaveLoading(false); setLoading(false);
} }
}; };
@@ -116,8 +111,7 @@
// 清空 // 清空
const handlerClear = () => { const handlerClear = () => {
setSaveLoading(false); setLoading(false);
setRoleLoading(false);
setVisible(false); setVisible(false);
}; };