/** * * @author Ray * * @date 2023-01-04 * * @workspace ray-template * * @remark 今天也是元气满满撸代码的一天 */ import './index.scss' import { NLayoutHeader, NSpace, NTooltip, NDropdown, NTag } from 'naive-ui' import RayIcon from '@/components/RayIcon/index' import RayTooltipIcon from '@/components/RayTooltipIcon/index' import SettingDrawer from './components/SettingDrawer/index' import { useSetting } from '@/store' import { useLanguageOptions } from '@/language/index' import { useAvatarOptions } from './hook' import { getCache } from '@/utils/cache' import screenfull from 'screenfull' import { logout } from '@/utils/user' import type { IconEventMapOptions, IconEventMap } from './type' /** * * 本来想通过写数据配置化的方式实现顶部的功能小按钮, 结果事实发现... * * 但是我又不想改, 就这样吧 */ const SiderBar = defineComponent({ name: 'SiderBar', setup() { const settingStore = useSetting() const { t } = useI18n() const { updateLocale, changeSwitcher } = settingStore const modelDrawerPlacement = ref(settingStore.drawerPlacement) const showSettings = ref(false) const person = getCache('person') /** * * 顶部左边操作栏 */ const leftIconOptions = [ { name: 'reload', size: 18, tooltip: 'LayoutHeaderTooltipOptions.Reload', }, ] /** * * 顶部右边提示框操作栏 */ const rightTooltipIconOptions = [ { name: 'fullscreen', size: 18, tooltip: 'LayoutHeaderTooltipOptions.FullScreen', eventKey: 'screen', }, { name: 'github', size: 18, tooltip: 'LayoutHeaderTooltipOptions.Github', eventKey: 'github', }, { name: 'setting', size: 18, tooltip: 'LayoutHeaderTooltipOptions.Setting', eventKey: 'setting', }, ] const iconEventMap: IconEventMapOptions = { reload: () => { changeSwitcher(false, 'reloadRouteSwitch') setTimeout(() => changeSwitcher(true, 'reloadRouteSwitch'), 1.5 * 1000) }, setting: () => { showSettings.value = true }, github: () => { window.open('https://github.com/XiaoDaiGua-Ray/ray-template') }, fullscreen: () => { if (screenfull.isEnabled) { screenfull.toggle() } else { window.$message.warning('您的浏览器不支持全屏~') } }, } const handleIconClick = (key: IconEventMap) => { iconEventMap[key]?.() } const handlePersonSelect = (key: string | number) => { if (key === 'logout') { window.$dialog.warning({ title: '提示', content: '您确定要退出登录吗', positiveText: '确定', negativeText: '不确定', onPositiveClick: () => { logout() }, }) } else { window.$message.info('这个人很懒, 没做这个功能~') } } return { leftIconOptions, rightTooltipIconOptions, t, handleIconClick, modelDrawerPlacement, showSettings, updateLocale, handlePersonSelect, person, } }, render() { return ( {this.leftIconOptions.map((curr) => ( {{ trigger: () => ( ), default: () => this.t(curr.tooltip), }} ))} {this.rightTooltipIconOptions.map((curr) => ( ))} this.updateLocale(String(key)) } trigger="click" > {{ icon: () => ( ), default: () => this.person.name, }} ) }, }) export default SiderBar