refactor: 修改缓存加载逻辑.
This commit is contained in:
@@ -20,10 +20,10 @@
|
||||
import { computed, onBeforeMount, ref } from 'vue';
|
||||
import { useCacheStore } from '@/store';
|
||||
import { labelFilter } from '@/types/form';
|
||||
import useLoading from '@/hooks/loading';
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: Number,
|
||||
loading: Boolean,
|
||||
allowCreate: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
const emits = defineEmits(['update:modelValue', 'change']);
|
||||
|
||||
// 选项数据
|
||||
const { loading, setLoading } = useLoading();
|
||||
const cacheStore = useCacheStore();
|
||||
|
||||
const value = computed({
|
||||
@@ -60,8 +60,10 @@
|
||||
const optionData = ref<Array<SelectOptionData>>([]);
|
||||
|
||||
// 初始化选项
|
||||
onBeforeMount(() => {
|
||||
cacheStore.loadDictKeys().then(dictKeys => {
|
||||
onBeforeMount(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const dictKeys = await cacheStore.loadDictKeys();
|
||||
optionData.value = dictKeys.map(s => {
|
||||
return {
|
||||
label: `${s.keyName} - ${s.description || ''}`,
|
||||
@@ -69,7 +71,10 @@
|
||||
origin: s
|
||||
};
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<a-tree-select v-model:model-value="value"
|
||||
:data="treeData"
|
||||
:disabled="disabled"
|
||||
:loading="loading"
|
||||
:allow-search="true"
|
||||
:filter-tree-node="titleFilter"
|
||||
placeholder="请选择菜单" />
|
||||
@@ -19,6 +20,7 @@
|
||||
import { computed, onBeforeMount, ref } from 'vue';
|
||||
import { MenuType } from '@/views/system/menu/types/const';
|
||||
import { titleFilter } from '@/types/form';
|
||||
import useLoading from '@/hooks/loading';
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: Number,
|
||||
@@ -27,6 +29,7 @@
|
||||
|
||||
const emits = defineEmits(['update:modelValue']);
|
||||
|
||||
const { loading, setLoading } = useLoading();
|
||||
const cacheStore = useCacheStore();
|
||||
|
||||
const treeData = ref<Array<TreeNodeData>>([]);
|
||||
@@ -40,7 +43,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeMount(() => {
|
||||
onBeforeMount(async () => {
|
||||
let render = (arr: any[]): TreeNodeData[] => {
|
||||
return arr.map((s) => {
|
||||
// 为 function 返回空
|
||||
@@ -60,13 +63,20 @@
|
||||
return node;
|
||||
}).filter(Boolean);
|
||||
};
|
||||
cacheStore.loadMenus().then(menus => {
|
||||
|
||||
// 加载数据
|
||||
try {
|
||||
setLoading(true);
|
||||
const menus = await cacheStore.loadMenus();
|
||||
treeData.value = [{
|
||||
key: 0,
|
||||
title: '根目录',
|
||||
children: render([...menus])
|
||||
}];
|
||||
});
|
||||
} catch (e) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user