UnisKB/ui/src/layout/components/breadcrumb/index.vue

278 lines
7.6 KiB
Vue
Raw Normal View History

2025-04-28 07:23:25 +00:00
<template>
<div class="breadcrumb ml-4 mt-4 mb-12 flex">
<back-button :to="activeMenu" class="mt-4"></back-button>
2025-06-19 10:54:02 +00:00
<div class="flex align-center">
<el-avatar
v-if="isApplication && isAppIcon(current?.icon)"
shape="square"
:size="24"
style="background: none"
class="mr-8"
>
<img :src="current?.icon" alt="" />
</el-avatar>
<LogoIcon
v-else-if="isApplication"
height="28px"
style="width: 28px; height: 28px; display: block"
class="mr-8"
/>
<KnowledgeIcon v-else-if="isKnowledge" :type="current?.type" class="mr-8" />
<div class="ellipsis" :title="current?.name">{{ current?.name }}</div>
</div>
<!-- <el-dropdown
2025-04-28 07:23:25 +00:00
placement="bottom"
trigger="click"
@command="changeMenu"
class="w-full"
style="display: block"
>
<div class="breadcrumb-hover flex-between cursor">
<div class="flex align-center">
2025-05-27 11:06:47 +00:00
<el-avatar
2025-04-28 07:23:25 +00:00
v-if="isApplication && isAppIcon(current?.icon)"
shape="square"
:size="24"
style="background: none"
class="mr-8"
>
<img :src="current?.icon" alt="" />
2025-05-27 11:06:47 +00:00
</el-avatar>
2025-06-19 10:54:02 +00:00
<LogoIcon
2025-04-28 07:23:25 +00:00
v-else-if="isApplication"
2025-06-19 10:54:02 +00:00
height="28px"
style="width: 28px; height: 28px; display: block"
2025-04-28 07:23:25 +00:00
/>
2025-06-13 09:17:01 +00:00
<KnowledgeIcon v-else-if="isKnowledge" :type="current?.type" />
2025-04-28 07:23:25 +00:00
<div class="ellipsis" :title="current?.name">{{ current?.name }}</div>
</div>
<el-button text>
<el-icon><CaretBottom /></el-icon>
</el-button>
</div>
<template #dropdown>
<el-scrollbar>
<div style="max-height: 400px">
<el-dropdown-menu>
<template v-for="(item, index) in list" :key="index">
<div :class="item.id === id ? 'dropdown-active' : ''">
<el-dropdown-item :command="item.id">
<div class="flex align-center">
2025-05-27 11:06:47 +00:00
<el-avatar
2025-04-28 07:23:25 +00:00
v-if="isApplication && isAppIcon(item?.icon)"
shape="square"
:size="24"
style="background: none"
class="mr-8"
>
<img :src="item?.icon" alt="" />
2025-05-27 11:06:47 +00:00
</el-avatar>
2025-04-28 07:23:25 +00:00
2025-05-27 11:06:47 +00:00
<el-avatar
2025-04-28 07:23:25 +00:00
v-else-if="isApplication"
:name="item.name"
pinyinColor
class="mr-12"
shape="square"
:size="24"
/>
2025-06-11 11:15:17 +00:00
2025-06-13 09:17:01 +00:00
<KnowledgeIcon v-if="isKnowledge" :type="item.type" />
2025-06-11 11:15:17 +00:00
2025-04-28 07:23:25 +00:00
<span class="ellipsis" :title="item?.name"> {{ item?.name }}</span>
</div>
</el-dropdown-item>
</div>
</template>
</el-dropdown-menu>
</div>
</el-scrollbar>
<div class="breadcrumb__footer border-t" style="padding: 8px 11px; min-width: 200px">
<template v-if="isApplication">
<div class="w-full text-left cursor" @click="openCreateDialog">
<el-button link>
<el-icon class="mr-4"><Plus /></el-icon>
{{ $t('views.application.createApplication') }}
</el-button>
</div>
</template>
2025-06-13 09:17:01 +00:00
<template v-else-if="isKnowledge">
2025-04-28 07:23:25 +00:00
<div class="w-full text-left cursor" @click="openCreateDialog">
<el-button link>
2025-06-13 09:17:01 +00:00
<el-icon class="mr-4"><Plus /></el-icon> {{ $t('views.knowledge.createKnowledge') }}
2025-04-28 07:23:25 +00:00
</el-button>
</div>
</template>
</div>
</template>
2025-06-19 10:54:02 +00:00
</el-dropdown> -->
2025-04-28 07:23:25 +00:00
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, computed } from 'vue'
import { onBeforeRouteLeave, useRouter, useRoute } from 'vue-router'
2025-05-26 10:10:18 +00:00
import { isWorkFlow } from '@/utils/application'
import { isAppIcon } from '@/utils/common'
2025-04-28 07:23:25 +00:00
import useStore from '@/stores'
2025-06-09 10:54:13 +00:00
const { common, knowledge, application } = useStore()
2025-04-28 07:23:25 +00:00
const route = useRoute()
const router = useRouter()
const {
meta: { activeMenu },
2025-05-26 10:10:18 +00:00
params: { id },
2025-04-28 07:23:25 +00:00
} = route as any
onBeforeRouteLeave((to, from) => {
common.saveBreadcrumb(null)
})
2025-06-13 09:17:01 +00:00
const CreateKnowledgeDialogRef = ref()
2025-04-28 07:23:25 +00:00
const CreateApplicationDialogRef = ref()
const list = ref<any[]>([])
const loading = ref(false)
const breadcrumbData = computed(() => common.breadcrumb)
2025-06-19 10:54:02 +00:00
const current = ref<any>(null)
// const current = computed(() => {
// return list.value?.filter((v) => v.id === id)?.[0]
// })
2025-04-28 07:23:25 +00:00
const isApplication = computed(() => {
return activeMenu.includes('application')
})
2025-06-13 09:17:01 +00:00
const isKnowledge = computed(() => {
2025-06-09 10:54:13 +00:00
return activeMenu.includes('knowledge')
2025-04-28 07:23:25 +00:00
})
2025-06-19 10:54:02 +00:00
function getKnowledgeDetail() {
loading.value = true
knowledge
.asyncGetKnowledgeDetail(id)
.then((res: any) => {
current.value = res.data
loading.value = false
})
.catch(() => {
loading.value = false
})
}
function getApplicationDetail() {
loading.value = true
application
.asyncGetApplicationDetail(id)
.then((res: any) => {
current.value = res.data
loading.value = false
})
.catch(() => {
loading.value = false
})
}
2025-04-28 07:23:25 +00:00
function openCreateDialog() {
2025-06-13 09:17:01 +00:00
if (isKnowledge.value) {
CreateKnowledgeDialogRef.value.open()
2025-04-28 07:23:25 +00:00
} else if (isApplication.value) {
CreateApplicationDialogRef.value.open()
}
}
function changeMenu(id: string) {
const lastMatched = route.matched[route.matched.length - 1]
if (lastMatched) {
2025-06-13 09:17:01 +00:00
if (isKnowledge.value) {
2025-04-28 07:23:25 +00:00
router.push({ name: lastMatched.name, params: { id: id } })
} else if (isApplication.value) {
const type = list.value?.filter((v) => v.id === id)?.[0]?.type
if (
isWorkFlow(type) &&
(lastMatched.name === 'AppSetting' || lastMatched.name === 'AppHitTest')
) {
router.push({ path: `/application/${id}/${type}/overview` })
} else {
router.push({
name: lastMatched.name,
2025-05-26 10:10:18 +00:00
params: { id: id, type: type },
2025-04-28 07:23:25 +00:00
})
}
}
}
}
2025-06-13 09:17:01 +00:00
function getKnowledge() {
2025-04-28 07:23:25 +00:00
loading.value = true
2025-06-09 10:54:13 +00:00
knowledge
2025-06-19 10:39:52 +00:00
.asyncGetFolderKnowledge()
2025-04-28 07:23:25 +00:00
.then((res: any) => {
list.value = res.data
common.saveBreadcrumb(list.value)
loading.value = false
})
.catch(() => {
loading.value = false
})
}
function getApplication() {
loading.value = true
application
.asyncGetAllApplication()
.then((res: any) => {
list.value = res.data
common.saveBreadcrumb(list.value)
loading.value = false
})
.catch(() => {
loading.value = false
})
}
function refresh() {
common.saveBreadcrumb(null)
}
onMounted(() => {
2025-06-19 10:54:02 +00:00
if (isKnowledge.value) {
getKnowledgeDetail()
} else if (isApplication.value) {
getApplicationDetail()
2025-04-28 07:23:25 +00:00
}
2025-06-19 10:54:02 +00:00
// if (!breadcrumbData.value) {
// if (isKnowledge.value) {
// getKnowledge()
// } else if (isApplication.value) {
// getApplication()
// }
// } else {
// list.value = breadcrumbData.value
// }
2025-04-28 07:23:25 +00:00
})
</script>
<style scoped lang="scss">
:deep(.dropdown-active) {
background-color: var(--el-dropdown-menuItem-hover-fill);
.el-dropdown-menu__item {
color: var(--el-dropdown-menuItem-hover-color);
}
}
.breadcrumb {
.breadcrumb-hover {
padding: 4px;
border-radius: 4px;
&:hover {
background: var(--el-color-primary-light-9);
color: var(--el-color-primary);
}
}
&__footer {
&:hover {
background-color: var(--app-text-color-light-1);
}
}
}
</style>