123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <template>
- <div class="cus-tree-item">
- <template v-for="item in data">
- <template v-if="item._count > 0">
- <div
- class="cus-tree-item-slot"
- :style="`padding-left: ${options.left * level}px;`"
- >
- <div class="expend-img" @click="item._expend = !item._expend, $forceUpdate()">
- <template v-if="item?.[options.children]?.length > 0">
- <img v-if="item._expend" :src="options.expendTrueImg"/>
- <img v-else :src="options.expendFalseImg"/>
- </template>
- </div>
- <slot :data="item">
- <div
- class="cus-tree-item-label"
- >
- {{item[options.label]}}
- </div>
- </slot>
- </div>
- <CusTreeItem
- v-if="item?.[options.children]?.length > 0"
- v-show="item._expend"
- :data="item[options.children]"
- :options="options"
- :level="level + 1"
- >
- <template #default="{data}">
- <slot :data="data"/>
- </template>
- </CusTreeItem>
- </template>
- </template>
- </div>
- </template>
- <script lang="ts">
- import {
- defineComponent,
- onMounted,
- ref,
- toRefs,
- reactive,
- watch,
- getCurrentInstance,
- ComponentInternalInstance,
- computed, nextTick,
- } from "vue";
- import { useStore } from "vuex";
- import { useRouter } from "vue-router";
- import { ElMessage, ElMessageBox } from "element-plus";
- export default defineComponent({
- name: "CusTreeItem",
- components: {
- },
- props: {
- data: {
- required: true
- },
- options: {
- required: true
- },
- level: {
- default: 0
- }
- },
- setup(props) {
- const store = useStore();
- const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties;
- const state = reactive({
- });
- onMounted(() => {
- })
- return {
- ...toRefs(state),
- }
- },
- });
- </script>
- <style scoped lang="scss">
- .cus-tree {
- width: 100%;
- height: calc(100vh);
- .cus-tree-item-slot {
- display: flex;
- align-items: center;
- .cus-tree-item-label {
- width: 100%;
- cursor: pointer;
- &:hover {
- background-color: #F5F7FA;
- }
- }
- .expend-img {
- width: 16px;
- height: 16px;
- margin-right: 5px;
- >img {
- cursor: pointer;
- width: 100%;
- height: 100%;
- }
- }
- }
- }
- </style>
|