index.vue
6.05 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<script lang="ts" setup name="SidebarItem">
// import SidebarItem from './index.vue'
import { resolveRoutePath } from '@/utils'
import useSettingsStore from '@/store/modules/settings'
import type { Menu } from '#/global'
import { getDownloadUrl, download } from "@/utils/common";
import { getImageContent } from "@/api/modules/queryService";
import {createSVG } from "@/utils/common"
import { onBeforeMount } from "vue"
import { resolve } from 'path-browserify';
const props = defineProps({
item: {
type: Object as () => Menu.recordRaw,
required: true,
},
basePath: {
type: String,
default: '',
},
})
const settingsStore = useSettingsStore()
const item1:any = ref()
const hasChildren = computed(() => {
let flag = true
if (props.item.children) {
if (props.item.children.every(item => item.meta?.sidebar === false)) {
flag = false
}
}
else {
flag = false
}
return flag
})
onBeforeMount( async ()=>{
await getSvgElement(props.item)
})
const getSvgElement = async (item:any)=>{
item1.value = item
//// return new Promise( async (reslove,inject)=>{
if(item1.value.meta.icon && item1.value.meta.icon.indexOf("https")>-1) {
const res1:any = await getImageContent(item1.value.meta?.icon)
let ele:any
if (res1 && !res1.msg) {
let name = item1.value.meta?.icon;
var fileSuffix = name ? name.substring(name.lastIndexOf('.') + 1) : '';
if (fileSuffix === 'svg') { //浏览器可以支持图片和pdf预览
let blob= getDownloadUrl(res1, name, fileSuffix,false) as Blob
ele = await createSVG(blob)
item1.value.meta.isEle = false
item1.value.meta.icon = ele
// reslove({})
}
}
}
// reslove(122)
// })
}
</script>
<template>
<div class="sidebar-item">
<router-link v-if="!hasChildren" v-slot="{ href, navigate, isActive, isExactActive }" custom :to="resolveRoutePath(basePath, item1.path)">
<a :href="item1.meta?.link ? item1.meta.link : href" :class="[isActive && 'router-link-active', isExactActive && 'router-link-exact-active']" :target="item.meta?.link ? '_blank' : '_self'" @click="navigate" v-preReClick>
<el-menu-item :title="item1.meta?.title ?? '[ 无标题 ]'" :index="resolveRoutePath(basePath, item1.path || '')">
<el-icon v-if="item1.meta?.icon" class="title-icon" >
<!-- <img :src="item.meta.icon" v-if="item.meta.icon.indexOf('http')>-1" alt=""> -->
<!-- {{ item.meta.icon }} -->
<template v-if="item1.meta.icon.indexOf('svg')>-1">
<i v-html="item1.meta.icon" :key="item1.meta.icon" v-if="!item1.meta.isEle"></i>
</template>
<template v-else>
<svg-icon :name="item1.meta.icon"/>
</template>
</el-icon>
<span class="title">{{ item1.meta?.title ?? '[ 无标题 ]' }}</span>
</el-menu-item>
</a>
</router-link>
<el-sub-menu v-else :title="item1.meta?.title ?? '[ 无标题 ]'" :index="settingsStore.settings.app.routeBaseOn !== 'filesystem' ? resolveRoutePath(basePath, item1.path) : JSON.stringify(item1)">
<template #title>
<el-icon v-if="item1.meta?.icon" class="title-icon" >
<!-- <img :src="item.meta.icon" v-if="item.meta.icon.indexOf('http')>-1" alt="">
<svg-icon :name="item.meta.icon" v-else /> -->
<template v-if="item1.meta.icon.indexOf('svg')>-1">
<i v-html="item1.meta.icon" :key="item1.meta.icon" v-if="!item1.meta.isEle"></i>
</template>
<template v-else>
<svg-icon :name="item1.meta.icon"/>
</template>
</el-icon>
<span class="title">{{ item.meta?.title ?? '[ 无标题 ]' }}</span>
</template>
<template v-for="route in (item1.children as Menu.recordRaw[])">
<SidebarItem v-if="route.meta?.sidebar !== false" :key="route.path" :item="route" :base-path="resolveRoutePath(basePath, item1.path)" />
</template>
</el-sub-menu>
</div>
</template>
<style lang="scss" scoped>
:deep(.el-menu-item),
:deep(.el-menu-item span.title),
:deep(.el-sub-menu__title),
:deep(.el-sub-menu__title span.title) {
flex: 1;
vertical-align: inherit;
@include text-overflow;
}
:deep(.el-menu-item) {
display: flex;
align-items: center;
justify-content: center;
}
:deep(.el-sub-menu),
:deep(.el-menu-item) {
.title-icon {
width: 20px;
font-size: 20px;
vertical-align: -0.25em;
transition: transform 0.3s;
color: #B2B2B2;
}
.title-icon + .title {
margin-left: 10px;
}
}
a {
cursor: pointer;
color: inherit;
text-decoration: none;
}
:deep(.el-sub-menu) {
.el-sub-menu__icon-arrow {
color: #666;
transform: rotateZ(270deg) !important;
}
&.is-opened {
.el-sub-menu__icon-arrow {
transform: rotateZ(360deg) !important;
}
}
}
.el-sub-menu__title {
> .badge {
&-dot {
right: 40px;
}
&-text {
right: 40px;
}
}
}
</style>
<style lang="scss">
.el-menu--inline {
background-color: var(--g-sub-sidebar-menu-bg) !important;
.el-menu-item,
.el-sub-menu > .el-sub-menu__title {
color: var(--g-sub-sidebar-menu-color);
background-color: var(--g-sub-sidebar-menu-bg) !important;
&:hover {
color: var(--g-sub-sidebar-menu-hover-color) !important;
background-color: var(--g-sub-sidebar-menu-hover-bg) !important;
}
}
}
.el-menu-item,
.el-sub-menu__title {
color: var(--g-sub-sidebar-menu-color) !important;
background: transparent !important;
&:hover {
color: var(--g-sub-sidebar-menu-hover-color) !important;
background-color: var(--g-sub-sidebar-menu-hover-bg) !important;
}
}
.el-menu-item.is-active,
.el-menu--collapse .el-sub-menu.is-active > .el-sub-menu__title,
.el-sub-menu .el-menu--inline .el-menu-item.is-active {
color: var(--g-sub-sidebar-menu-active-color) !important;
background-color: var(--g-sub-sidebar-menu-active-bg) !important;
.icon,
.el-sub-menu__icon-arrow {
color: unset;
}
.title-icon {
color: var(--g-sub-sidebar-menu-active-color);
}
}
svg {
g {
fill: inherit !important;
}
}
</style>