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';
|
2020-11-23 23:24:13 +08:00
|
|
|
|
|
|
|
|
import { openWindow } from '/@/utils';
|
|
|
|
|
|
|
|
|
|
import { useHeaderSetting } from '/@/hooks/setting/useHeaderSetting';
|
|
|
|
|
|
|
|
|
|
interface RenderItemParams {
|
|
|
|
|
icon: string;
|
|
|
|
|
text: string;
|
|
|
|
|
key: string;
|
|
|
|
|
}
|
2020-09-28 20:19:10 +08:00
|
|
|
|
|
|
|
|
const prefixCls = 'user-dropdown';
|
2020-11-23 23:24:13 +08:00
|
|
|
|
2020-09-28 20:19:10 +08:00
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'UserDropdown',
|
|
|
|
|
setup() {
|
2020-11-23 23:24:13 +08:00
|
|
|
const { getShowDoc } = useHeaderSetting();
|
2020-09-28 20:19:10 +08:00
|
|
|
|
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() {
|
2020-11-23 23:24:13 +08:00
|
|
|
openWindow(DOC_URL);
|
2020-09-28 20:19:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-11-23 23:24:13 +08:00
|
|
|
function renderItem({ icon, text, key }: RenderItemParams) {
|
2020-10-31 19:51:24 +08:00
|
|
|
return (
|
|
|
|
|
<Menu.Item key={key}>
|
|
|
|
|
{() => (
|
|
|
|
|
<span class="flex items-center">
|
|
|
|
|
<Icon icon={icon} class="mr-1" />
|
|
|
|
|
<span>{text}</span>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</Menu.Item>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 23:24:13 +08:00
|
|
|
function renderSlotsDefault() {
|
2020-09-28 20:19:10 +08:00
|
|
|
const { realName } = unref(getUserInfo);
|
2020-11-23 23:24:13 +08:00
|
|
|
return (
|
|
|
|
|
<section class={prefixCls}>
|
|
|
|
|
<img class={`${prefixCls}__header`} src={headerImg} />
|
|
|
|
|
<section class={`${prefixCls}__info`}>
|
|
|
|
|
<section class={`${prefixCls}__name`}>{realName}</section>
|
|
|
|
|
</section>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderSlotOverlay() {
|
|
|
|
|
const showDoc = unref(getShowDoc);
|
|
|
|
|
return (
|
|
|
|
|
<Menu onClick={handleMenuClick}>
|
|
|
|
|
{() => (
|
|
|
|
|
<>
|
|
|
|
|
{showDoc && renderItem({ key: 'doc', text: '文档', icon: 'gg:loadbar-doc' })}
|
|
|
|
|
{showDoc && <Divider />}
|
|
|
|
|
{renderItem({
|
|
|
|
|
key: 'loginOut',
|
|
|
|
|
text: '退出系统',
|
|
|
|
|
icon: 'ant-design:poweroff-outlined',
|
|
|
|
|
})}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Menu>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return () => {
|
2020-09-28 20:19:10 +08:00
|
|
|
return (
|
|
|
|
|
<Dropdown placement="bottomLeft">
|
|
|
|
|
{{
|
2020-11-23 23:24:13 +08:00
|
|
|
default: () => renderSlotsDefault(),
|
|
|
|
|
overlay: () => renderSlotOverlay(),
|
2020-09-28 20:19:10 +08:00
|
|
|
}}
|
|
|
|
|
</Dropdown>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
});
|