2020-09-28 20:19:10 +08:00
|
|
|
// components
|
|
|
|
|
import { Dropdown, Menu, Divider } from 'ant-design-vue';
|
|
|
|
|
|
|
|
|
|
import { defineComponent, computed, unref } from 'vue';
|
|
|
|
|
|
|
|
|
|
// res
|
|
|
|
|
import headerImg from '/@/assets/images/header.jpg';
|
|
|
|
|
|
|
|
|
|
import Icon from '/@/components/Icon/index';
|
|
|
|
|
|
|
|
|
|
import { userStore } from '/@/store/modules/user';
|
|
|
|
|
|
|
|
|
|
import { DOC_URL } from '/@/settings/siteSetting';
|
|
|
|
|
import { appStore } from '/@/store/modules/app';
|
|
|
|
|
|
|
|
|
|
const prefixCls = 'user-dropdown';
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'UserDropdown',
|
|
|
|
|
setup() {
|
|
|
|
|
const getProjectConfigRef = computed(() => {
|
|
|
|
|
return appStore.getProjectConfig;
|
|
|
|
|
});
|
|
|
|
|
|
2020-10-31 19:51:24 +08:00
|
|
|
const getUserInfo = computed(() => {
|
|
|
|
|
const { realName = '', desc } = userStore.getUserInfoState || {};
|
|
|
|
|
return { realName, desc };
|
|
|
|
|
});
|
|
|
|
|
|
2020-11-02 23:04:25 +08:00
|
|
|
// login out
|
2020-09-28 20:19:10 +08:00
|
|
|
function handleLoginOut() {
|
|
|
|
|
userStore.confirmLoginOut();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-02 23:04:25 +08:00
|
|
|
// open doc
|
2020-09-28 20:19:10 +08:00
|
|
|
function openDoc() {
|
|
|
|
|
window.open(DOC_URL, '__blank');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleMenuClick(e: any) {
|
|
|
|
|
if (e.key === 'loginOut') {
|
|
|
|
|
handleLoginOut();
|
2020-11-10 23:50:47 +08:00
|
|
|
} else if (e.key === 'doc') {
|
2020-09-28 20:19:10 +08:00
|
|
|
openDoc();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-31 19:51:24 +08:00
|
|
|
|
|
|
|
|
function renderItem({ icon, text, key }: { icon: string; text: string; key: string }) {
|
|
|
|
|
return (
|
|
|
|
|
<Menu.Item key={key}>
|
|
|
|
|
{() => (
|
|
|
|
|
<span class="flex items-center">
|
|
|
|
|
<Icon icon={icon} class="mr-1" />
|
|
|
|
|
<span>{text}</span>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</Menu.Item>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:19:10 +08:00
|
|
|
return () => {
|
|
|
|
|
const { realName } = unref(getUserInfo);
|
|
|
|
|
const {
|
|
|
|
|
headerSetting: { showDoc },
|
|
|
|
|
} = unref(getProjectConfigRef);
|
|
|
|
|
return (
|
|
|
|
|
<Dropdown placement="bottomLeft">
|
|
|
|
|
{{
|
|
|
|
|
default: () => (
|
2020-10-14 21:22:08 +08:00
|
|
|
<section class={prefixCls}>
|
|
|
|
|
<img class={`${prefixCls}__header`} src={headerImg} />
|
|
|
|
|
<section class={`${prefixCls}__info`}>
|
|
|
|
|
<section class={`${prefixCls}__name`}>{realName}</section>
|
2020-09-28 20:19:10 +08:00
|
|
|
</section>
|
2020-10-14 21:22:08 +08:00
|
|
|
</section>
|
2020-09-28 20:19:10 +08:00
|
|
|
),
|
|
|
|
|
overlay: () => (
|
|
|
|
|
<Menu slot="overlay" onClick={handleMenuClick}>
|
|
|
|
|
{() => (
|
|
|
|
|
<>
|
2020-10-31 19:51:24 +08:00
|
|
|
{showDoc && renderItem({ key: 'doc', text: '文档', icon: 'gg:loadbar-doc' })}
|
2020-09-28 20:19:10 +08:00
|
|
|
{showDoc && <Divider />}
|
2020-10-31 19:51:24 +08:00
|
|
|
{renderItem({
|
|
|
|
|
key: 'loginOut',
|
|
|
|
|
text: '退出系统',
|
|
|
|
|
icon: 'ant-design:poweroff-outlined',
|
|
|
|
|
})}
|
2020-09-28 20:19:10 +08:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Menu>
|
|
|
|
|
),
|
|
|
|
|
}}
|
|
|
|
|
</Dropdown>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
});
|