UnisKB/ui/src/components/workspace-dropdown/index.vue

64 lines
1.8 KiB
Vue
Raw Normal View History

2025-06-13 09:38:37 +00:00
<template>
2025-06-20 09:02:42 +00:00
<el-dropdown placement="bottom-start" class="workspace-dropdown">
<el-button text style="font-size: 14px" class="workspace-dropdown__button">
2025-06-13 09:38:37 +00:00
<AppIcon iconName="app-wordspace" style="font-size: 18px"></AppIcon>
2025-06-20 09:02:42 +00:00
<span class="ellipsis" style="max-width: 155px">
2025-06-13 09:38:37 +00:00
{{ currentWorkspace?.name }}
</span>
<el-icon class="el-icon--right">
<CaretBottom />
</el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu v-loading="loading">
2025-06-17 10:38:00 +00:00
<el-dropdown-item
2025-06-19 13:43:57 +00:00
v-for="item in user.workspace_list"
2025-06-17 10:38:00 +00:00
:key="item.id"
:class="item.id === currentWorkspace?.id ? 'active' : ''"
@click="changeWorkspace(item)"
>
2025-06-13 09:38:37 +00:00
<AppIcon class="mr-8" iconName="app-wordspace" style="font-size: 16px"></AppIcon>
2025-06-20 09:02:42 +00:00
<span class="ellipsis" style="max-width: 230px">
2025-06-13 09:38:37 +00:00
{{ item.name }}
</span>
2025-06-17 10:38:00 +00:00
<el-icon
v-show="item.id === currentWorkspace?.id"
class="ml-8"
style="font-size: 16px; margin-right: 0"
>
2025-06-13 09:38:37 +00:00
<Check />
</el-icon>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</template>
<script setup lang="ts">
2025-06-19 13:43:57 +00:00
import { computed, ref } from 'vue'
2025-06-13 09:38:37 +00:00
import type { WorkspaceItem } from '@/api/type/workspace'
2025-06-17 10:38:00 +00:00
import useStore from '@/stores'
2025-06-19 13:43:57 +00:00
2025-06-17 10:38:00 +00:00
const { user } = useStore()
2025-06-13 09:38:37 +00:00
const loading = ref(false)
2025-06-19 13:43:57 +00:00
const currentWorkspace = computed(() => {
return user.workspace_list.find((w) => w.id == user.workspace_id)
2025-06-13 09:38:37 +00:00
})
function changeWorkspace(item: WorkspaceItem) {
2025-06-19 13:43:57 +00:00
if (item.id === user.workspace_id) return
2025-06-17 10:38:00 +00:00
user.setWorkspaceId(item.id || 'default')
2025-06-13 09:38:37 +00:00
window.location.reload()
}
</script>
<style lang="scss" scoped>
2025-06-20 09:02:42 +00:00
.workspace-dropdown {
&__button {
font-size: 14px;
padding: 0 12px !important;
max-height: 32px;
}
2025-06-13 09:38:37 +00:00
}
2025-06-13 10:31:22 +00:00
</style>