封装自element-ui的tree组件,用于更加简便化的使用tree结构。

    需要传入的参数:
    小写部分为element的原生属性,大写的为额外定义的属性。

    1. /**
    2. * 主键字段名称
    3. */
    4. PK?: string;
    5. /**
    6. * 父级字段
    7. */
    8. PPK?: string;
    9. /**
    10. * 标题字段
    11. */
    12. Title?: string | Function;
    13. /**
    14. * 最大层数
    15. */
    16. MaxLevel?: number;
    17. /**
    18. * 组件名称
    19. */
    20. Name?: string;

    示例代码:

    <template>
        <el-row>
            <el-col :span="24">
                <CtsyTree
                    PK="RGID"
                    PPK="PRGID"
                    Title="Title"
                    Name="权限组"
                    :editable="true"
                    :addable="true"
                    :MaxTree="3"
                    :more="search"
                    @add="add"
                    @node-click="nodeClick"
                    ref="tree"
                ></CtsyTree>
            </el-col>
        </el-row>
    </template>
    
    <script lang="ts">
    import { Component, Vue, Watch } from "vue-property-decorator";
    import UserApi from "@ctsy/api-sdk/dist/modules/User";
    import Ctsy from "@ctsy/template";
    @Component({})
    export default class RuleTree extends Vue {
        async search(data?: UserApi.RuleGroupClass) {
            let rs = await UserApi.RuleGroupApi.search({
                W: {},
                P: 1,
                N: 999,
            });
            console.log(rs);
            return rs.L;
        }
        async add(titles: string[], parent: UserApi.RuleGroupClass) {
            // console.log(titles);
            for (let x of titles) {
                if (x.length < 2) {
                    Ctsy.MessageBox.tip("名称长度不能小于2");
                    // throw new Error();
                    return;
                }
            }
            await UserApi.RuleGroupApi.adds(
                titles.map((o) => {
                    return Object.assign(new UserApi.RuleGroupClass(), {
                        PRGID: parent.RGID || 0,
                        Title: o,
                    });
                })
            );
            (<any>this.$refs.tree).refush(undefined, true);
        }
        nodeClick(data: any, node: any, el: any) {
            this.$emit("click", data);
            this.$emit("node-click", data, node, el);
            this.$emit("input", data.value);
        }
    }
    </script>
    
    <style lang="less" scoped>
    </style>