UnisKB/ui/src/layout/components/top-bar/avatar/index.vue

141 lines
4.3 KiB
Vue
Raw Normal View History

2023-10-13 08:11:54 +00:00
<template>
<el-dropdown trigger="click" type="primary">
2023-11-02 10:25:09 +00:00
<div class="flex-center cursor">
<AppAvatar>
2025-01-20 11:39:46 +00:00
<img src="@/assets/user-icon.svg" style="width: 54%" alt="" />
2023-11-02 10:25:09 +00:00
</AppAvatar>
<span class="ml-8">{{ user.userInfo?.username }}</span>
<el-icon class="el-icon--right">
2025-01-20 11:39:46 +00:00
<CaretBottom />
2023-11-02 10:25:09 +00:00
</el-icon>
</div>
2023-10-13 08:11:54 +00:00
<template #dropdown>
2023-12-08 10:19:31 +00:00
<el-dropdown-menu class="avatar-dropdown">
<div class="userInfo">
2023-12-12 08:00:54 +00:00
<p class="bold mb-4" style="font-size: 14px">{{ user.userInfo?.username }}</p>
2023-12-08 10:19:31 +00:00
<p>
<el-text type="info">
{{ user.userInfo?.email }}
</el-text>
</p>
</div>
<el-dropdown-item class="border-t p-8" @click="openResetPassword">
2025-01-21 07:25:21 +00:00
{{ $t('views.login.resetPassword') }}
</el-dropdown-item>
2024-07-11 11:51:28 +00:00
<div v-hasPermission="new ComplexPermission([], ['x-pack'], 'OR')">
2024-07-10 07:25:06 +00:00
<el-dropdown-item class="border-t p-8" @click="openAPIKeyDialog">
2025-01-21 12:27:10 +00:00
{{ $t('layout.apiKey') }}
2024-07-10 07:25:06 +00:00
</el-dropdown-item>
</div>
2025-01-20 11:39:46 +00:00
<el-dropdown-item class="border-t" style="padding: 0" @click.stop>
<el-dropdown class="w-full" trigger="hover" placement="left-start">
<div class="flex-between w-full" style="line-height: 22px; padding: 12px 11px">
<span> {{ $t('layout.language') }}</span>
<el-icon><ArrowRight /></el-icon>
</div>
<template #dropdown>
<el-dropdown-menu style="width: 180px">
<el-dropdown-item
v-for="(lang, index) in langList"
:key="index"
:value="lang.value"
@click="changeLang(lang.value)"
class="flex-between"
>
<span :class="lang.value === user.userInfo?.language ? 'primary' : ''">{{
lang.label
}}</span>
<el-icon
:class="lang.value === user.userInfo?.language ? 'primary' : ''"
v-if="lang.value === user.userInfo?.language"
>
<Check />
</el-icon>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</el-dropdown-item>
2024-07-10 07:25:06 +00:00
<el-dropdown-item class="border-t" @click="openAbout">
2025-01-21 12:27:10 +00:00
{{ $t('layout.about.label') }}
2024-07-10 07:25:06 +00:00
</el-dropdown-item>
2025-01-20 11:39:46 +00:00
2024-07-10 07:25:06 +00:00
<el-dropdown-item class="border-t" @click="logout">
2025-01-21 12:27:10 +00:00
{{ $t('layout.logout') }}
2023-10-13 08:11:54 +00:00
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<ResetPassword ref="resetPasswordRef"></ResetPassword>
2023-12-18 03:11:13 +00:00
<AboutDialog ref="AboutDialogRef"></AboutDialog>
2025-01-20 11:39:46 +00:00
<APIKeyDialog :user-id="user.userInfo?.id" ref="APIKeyDialogRef" />
<UserPwdDialog ref="UserPwdDialogRef" />
2023-09-15 09:40:35 +00:00
</template>
<script setup lang="ts">
2025-01-20 11:39:46 +00:00
import { ref, onMounted } from 'vue'
2023-10-25 10:35:28 +00:00
import useStore from '@/stores'
2025-01-20 11:39:46 +00:00
import { useRouter } from 'vue-router'
2024-04-15 07:40:15 +00:00
import ResetPassword from './ResetPassword.vue'
2023-12-18 03:11:13 +00:00
import AboutDialog from './AboutDialog.vue'
import UserPwdDialog from '@/views/user-manage/component/UserPwdDialog.vue'
2024-07-10 07:25:06 +00:00
import APIKeyDialog from './APIKeyDialog.vue'
2025-01-20 11:39:46 +00:00
import { ComplexPermission } from '@/utils/permission/type'
import { langList } from '@/locales/index'
import { useLocale } from '@/locales/useLocale'
const { user } = useStore()
2023-09-15 09:40:35 +00:00
const router = useRouter()
2023-10-25 10:35:28 +00:00
const UserPwdDialogRef = ref()
2023-12-18 03:11:13 +00:00
const AboutDialogRef = ref()
const APIKeyDialogRef = ref()
2023-10-13 08:11:54 +00:00
const resetPasswordRef = ref<InstanceType<typeof ResetPassword>>()
2023-09-15 09:40:35 +00:00
2025-01-20 11:39:46 +00:00
// const { changeLocale } = useLocale()
const changeLang = (lang: string) => {
user.postUserLanguage(lang)
// changeLocale(lang)
}
2023-12-18 03:11:13 +00:00
const openAbout = () => {
AboutDialogRef.value?.open()
}
2024-07-11 11:51:28 +00:00
function openAPIKeyDialog() {
APIKeyDialogRef.value.open()
}
2023-12-18 03:11:13 +00:00
2023-09-15 09:40:35 +00:00
const openResetPassword = () => {
2023-10-13 08:11:54 +00:00
resetPasswordRef.value?.open()
2023-09-15 09:40:35 +00:00
}
const logout = () => {
2023-10-19 10:18:45 +00:00
user.logout().then(() => {
2025-01-20 11:39:46 +00:00
router.push({ name: 'login' })
2023-10-13 08:11:54 +00:00
})
2023-09-15 09:40:35 +00:00
}
onMounted(() => {
if (user.userInfo?.is_edit_password) {
UserPwdDialogRef.value.open(user.userInfo)
}
})
2023-09-15 09:40:35 +00:00
</script>
2023-12-08 10:19:31 +00:00
<style lang="scss" scoped>
.avatar-dropdown {
2023-12-12 08:00:54 +00:00
min-width: 210px;
2024-07-11 11:51:28 +00:00
2023-12-08 10:19:31 +00:00
.userInfo {
padding: 12px 11px;
}
2024-07-11 11:51:28 +00:00
2023-12-08 10:19:31 +00:00
:deep(.el-dropdown-menu__item) {
padding: 12px 11px;
2025-01-20 11:39:46 +00:00
&:hover {
background: var(--app-text-color-light-1);
}
2023-12-08 10:19:31 +00:00
}
}
</style>