DesktopRightSider.vue
3.96 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<template>
<el-main id="glsxRightSide"
class="glsx-right-side"
:style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: '280px' }">
<el-breadcrumb>
<el-breadcrumb-item class="breadcrumb-item"
:class="{active: index === breadCrumbList.length - 1, pointer: item.path}"
v-for="(item, index) in breadCrumbList"
:key="index"
@click="routerGo(item, item.path || '/noData')">
{{item.name}}
</el-breadcrumb-item>
</el-breadcrumb>
<div v-show="showEmpty">
<el-empty description="暂无数据"
:image-size="imgSize"></el-empty>
</div>
<div v-show="!showEmpty"
id="sub-system-frame"
ref="elmSubMicro"></div>
</el-main>
</template>
<script>
import { useStore } from 'vuex';
import { reactive, toRefs, computed, onMounted, ref } from 'vue';
export default {
name: 'DesktopRightSider',
setup(props, context) {
const elmSubMicro = ref(null);
const state = reactive({
imgSize: 100,
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 observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'childList') {
const tarInner = subMircroEle.innerHTML;
if (state.el_sub_innerH !== tarInner) {
state.el_sub_innerH = tarInner;
}
}
});
});
observer.observe(subMircroEle, { childList: true, subtree: true });
})
const showEmpty = computed(() => {
return store.getters.commonData.showEmpty || !state.el_sub_innerH;
})
const breadCrumbList = computed(() => {
return store.getters.curBreadCrumb;
})
const routerGo = (item, path) => {
let saveBreadCrumb = {};
const thisName = item.name.replace(' / ', '');
const curBreadCrumb = store.getters.curBreadCrumb,
curParent = curBreadCrumb['parent'],
curChildren = curBreadCrumb['children'];
if (thisName === curParent.menuName) {
saveBreadCrumb.parent = curParent;
saveBreadCrumb.children = {};
return false;
}
if (curChildren) {
const nextChildren = curChildren.children;
if (thisName === curChildren.menuName) {
saveBreadCrumb.parent = curParent;
if (nextChildren) {
delete curChildren.children;
}
saveBreadCrumb.children = curChildren;
} else {
if (thisName === nextChildren.menuName) {
saveBreadCrumb = curBreadCrumb;
}
}
}
store.dispatch('menu/setBreadCrumb', saveBreadCrumb);
history.pushState(null, path, path);
}
return {
...toRefs(state),
breadCrumbList,
elmSubMicro,
showEmpty,
routerGo
}
}
}
</script>
<style scoped>
.glsx-right-side >>> .breadcrumb-item span {
color: rgba(0, 0, 0, 0.45);
}
.glsx-right-side >>> .breadcrumb-item.active span {
color: #2196f3;
}
</style>
<style lang="less" scoped>
@import 'styles/variables.less';
.glsx-right-side {
position: relative;
}
.el-breadcrumb {
margin-bottom: 20px;
}
.empty-text {
text-align: center;
}
.breadcrumb-item {
cursor: context-menu;
.pointer:hover {
color: @defaultTextColor;
}
}
#sub-system-frame {
// min-width: 1190px;
min-width: calc(100% - 400px);
}
.pointer {
// cursor: pointer;
}
.active {
color: @defaultTextColor;
}
</style>