DesktopRightSider.vue 3.67 KB
<template>
    <a-layout-content
        :style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: '280px' }"
        >
        <a-breadcrumb>
            <a-breadcrumb-item class="breadcrumb-item" 
                               :class="{active: item.active, pointer: item.path}" 
                               v-for="(item, index) in breadCrumbList" 
                               :key="index" 
                               @click="routerGo(item.path || '')">
                {{item.name}}
            </a-breadcrumb-item>
        </a-breadcrumb>
        <div v-show="showEmpty">
            <a-empty :description="false" />
            <h1 class="empty-text">暂无数据</h1>
        </div>
        <div v-show="!showEmpty" id="sub-system-frame" ref="elmSubMicro"></div>
    </a-layout-content>
</template>

<script>
import { useStore } from 'vuex';
import { reactive, toRefs, computed, watch, onMounted, ref } from 'vue';


export default {
    name: 'DesktopRightSider',
    components: {
    },
    setup(props, context) {
        const elmSubMicro = ref(null);
        const state = reactive({
            el_sub_innerH: ''
        });
        const store = useStore();

        onMounted(() => {
            state.el_sub_innerH = elmSubMicro._value.innerHTML;

            // 监听子系统挂载的元素内容变化
            const subMircroEle = document.getElementById('sub-system-frame');
            subMircroEle.addEventListener('DOMNodeInserted', function(e) {
                const target = e.currentTarget,
                      tarInner = target.innerHTML;
                if(!state.el_sub_innerH !== !tarInner) {
                    state.el_sub_innerH = target.innerHTML;
                }
            })
        })

        const showEmpty = computed(() => {
            return !state.el_sub_innerH || store.getters.commonData.showEmpty;
        })

        const breadCrumbList = computed(() => {
            const curBreadCrumb = store.getters.curBreadCrumb,
                  curParent = curBreadCrumb['parent'],
                  curChildren = curBreadCrumb['children'];
            let breadCrumbList = [];
            if(curParent) {
                breadCrumbList.push({ 
                    name: curParent.menuName + ' / '
                });
            }
            if(curChildren && curChildren.length > 0) {
                curChildren.forEach((item, index, arr) => {
                    if(index === arr.length - 1) {
                        breadCrumbList.push({
                            name: item.menuName,
                            path: item.path,
                            active: item.active
                        });
                    }  else {
                        breadCrumbList.push({
                            name: item.menuName + ' / ',
                            path: item.path,
                            active: item.active
                        });
                    }
                    
                });
            }
            return breadCrumbList;
        })

        const routerGo = (path) => {
            // history.pushState(null, path, path);
        }

        return {
            breadCrumbList,
            elmSubMicro,
            showEmpty
            // routerGo
        }
    }
}
</script>
<style lang="less" scoped>
@import 'styles/variables.less';
.ant-layout-content {
    min-height: unset !important;
}
.ant-empty {
    margin-top: 200px;
}

.empty-text {
    text-align: center;
}

.breadcrumb-item {
    cursor: context-menu;
    .pointer:hover {
        color: @defaultTextColor;
    }
}

#sub-system-frame {
    min-width: 1190px;
}

.pointer {
    // cursor: pointer;
}

.active {
    color: @defaultTextColor;
}
</style>