wangzhibo
7 天以前 1c3ae7bcad167c9a593f4634968a6e142d9b08f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<template>
    <component v-for="item in list" :key="item.name" :is="item.component" />
</template>
 
<script setup lang="ts">
import { isFunction, orderBy } from "lodash-es";
import { markRaw, onMounted, shallowRef } from "vue";
import { module } from "/@/cool";
 
const list = shallowRef<any[]>([]);
 
async function refresh() {
    const arr = orderBy(
        module.list.filter((e) => e.enable !== false && !!e.global).map((e) => e.global),
        "order"
    );
 
    list.value = await Promise.all(
        arr
            .filter((e) => e?.component)
            .map(async (e) => {
                if (e) {
                    const c = await (isFunction(e.component) ? e.component() : e.component);
 
                    return {
                        ...e,
                        component: markRaw(c.default || c)
                    };
                }
            })
    );
}
 
onMounted(() => {
    refresh();
});
</script>