index.vue 1.06 KB
Newer Older
水落(YangLei)'s avatar
水落(YangLei) committed
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 38 39 40 41 42 43 44 45 46 47 48 49
<template>
    <a-tree
        :checkedKeys="value"
        :selectable="false"
        checkable
        :replaceFields="replaceFields"
        :tree-data="treeData"
        style="max-height:400px"
        class="tw-overflow-y-auto"
        v-bind="$attrs"
        v-on="$listeners"
    />
</template>

<script>
import { getMenuDataApi } from '@/api';
import { convertListToTree } from '@/utils';

export default {
    model: {
        prop: 'value',
        event: 'check',
    },
    props: {
        value: [Object, Array],
        showMenu: Boolean,
    },
    data() {
        return {
            treeData: [],
            replaceFields: {
                title: 'menuName',
                key: 'menuId',
            },
        };
    },
    async mounted() {
        this.rawData = await getMenuDataApi();
        this.treeData = convertListToTree(this.rawData, !this.showMenu);
    },

    methods: {
        get() {
            if (Array.isArray(this.value)) return this.rawData.filter(m => this.value.includes(m.menuId));
            return [];
        },
    },
};
</script>