mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-12-03 18:46:25 +08:00
Enforce live session grants for runtime routes and support profile and credential updates in both the backend and demo modes. Add the account settings workspace and document fullstack setup and PC acceptance.
225 lines
6.5 KiB
TypeScript
225 lines
6.5 KiB
TypeScript
import { useRuntimeActions, useRuntimeGetters } from '@/store'
|
|
import './index.scss'
|
|
import AppAvatar from '@/app-components/app/AppAvatar'
|
|
import { LOCAL_OPTIONS } from '@/app-config'
|
|
import { RIcon } from '@/components'
|
|
import { useDevice, useI18n } from '@/hooks'
|
|
import { useSettingActions, useSettingGetters } from '@/store'
|
|
import { NButton, NDropdown, NFlex, NLayoutHeader, NScrollbar } from 'naive-ui'
|
|
import type { VNode } from 'vue'
|
|
import { useFullscreen } from 'vue-hooks-plus'
|
|
import {
|
|
Breadcrumb,
|
|
GlobalSearch,
|
|
GlobalSearchButton,
|
|
SettingDrawer,
|
|
TooltipIcon,
|
|
} from './components'
|
|
import {
|
|
avatarDropdownClick,
|
|
createAvatarOptions,
|
|
createLeftIconOptions,
|
|
createRightIconOptions,
|
|
} from './shared'
|
|
import type { IconEventMapOptions } from './type'
|
|
|
|
export default defineComponent({
|
|
name: 'AppSiderBar',
|
|
setup() {
|
|
// 获取 setting 相关值
|
|
const { updateLocale, updateSettingState } = useSettingActions()
|
|
const { t } = useI18n()
|
|
// 获取全屏相关方法
|
|
const [isFullscreen, { toggleFullscreen, isEnabled }] = useFullscreen(
|
|
document.getElementsByTagName('html')[0],
|
|
)
|
|
// 获取设置相关方法
|
|
const { getDrawerPlacement, getBreadcrumbSwitch } = useSettingGetters()
|
|
// 是否显示设置抽屉
|
|
const showSettings = ref(false)
|
|
// 是否展示全局搜索
|
|
const globalSearchShown = ref(false)
|
|
// 当前是否为平板或者更小的设备
|
|
const { isTabletOrSmaller } = useDevice()
|
|
// 获取全局 drawer 的值
|
|
const globalDrawerValue = useRuntimeGetters().globalDrawerValue
|
|
|
|
/**
|
|
*
|
|
* @description
|
|
* 顶部左边操作栏。
|
|
*/
|
|
const leftIconOptions = computed(() =>
|
|
createLeftIconOptions({
|
|
isFullscreen,
|
|
isTabletOrSmaller,
|
|
}),
|
|
)
|
|
/**
|
|
*
|
|
* @description
|
|
* 顶部右边提示框操作栏。
|
|
*/
|
|
const rightTooltipIconOptions = computed(() =>
|
|
createRightIconOptions({
|
|
isFullscreen,
|
|
isTabletOrSmaller,
|
|
}),
|
|
)
|
|
const iconEventMap: IconEventMapOptions = {
|
|
search: () => {
|
|
globalSearchShown.value = true
|
|
},
|
|
setting: () => {
|
|
showSettings.value = true
|
|
},
|
|
github: () => {
|
|
window.open('https://github.com/XiaoDaiGua-Ray/r-template')
|
|
},
|
|
fullscreen: () => {
|
|
if (!isEnabled) {
|
|
window.$message.warning(t('globalMessage.isEnabledFullscreen'))
|
|
}
|
|
|
|
toggleFullscreen()
|
|
},
|
|
lock: () => {
|
|
updateSettingState('lockScreenSwitch', true)
|
|
},
|
|
menu: () => {
|
|
useRuntimeActions().setRuntimeState(
|
|
'globalDrawerValue',
|
|
!globalDrawerValue.value,
|
|
)
|
|
},
|
|
}
|
|
|
|
const toolIconClick = (key: keyof typeof iconEventMap) => {
|
|
iconEventMap[key]?.()
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param vnode 需要渲染的节点
|
|
* @returns 如果是平板或者更小的设备, 就返回 null, 否则返回 vnode
|
|
*/
|
|
const isRenderVNode = (vnode: VNode) => {
|
|
return isTabletOrSmaller.value ? null : vnode
|
|
}
|
|
|
|
return {
|
|
t,
|
|
isFullscreen,
|
|
leftIconOptions,
|
|
rightTooltipIconOptions,
|
|
toolIconClick,
|
|
showSettings,
|
|
updateLocale,
|
|
getDrawerPlacement,
|
|
getBreadcrumbSwitch,
|
|
globalSearchShown,
|
|
isRenderVNode,
|
|
}
|
|
},
|
|
render() {
|
|
const {
|
|
rightTooltipIconOptions,
|
|
leftIconOptions,
|
|
getDrawerPlacement,
|
|
getBreadcrumbSwitch,
|
|
} = this
|
|
const { toolIconClick, updateLocale, isRenderVNode } = this
|
|
|
|
return (
|
|
<NLayoutHeader class="layout-header">
|
|
<GlobalSearch v-model:show={this.globalSearchShown} />
|
|
<NFlex
|
|
class="layout-header__method"
|
|
align="center"
|
|
justify="space-between"
|
|
wrap={false}
|
|
>
|
|
<NFlex align="center" wrap={false}>
|
|
{leftIconOptions.map((curr) => (
|
|
<NButton
|
|
quaternary
|
|
key={curr.name}
|
|
aria-label={this.t<string>('layout.toggleMenu')}
|
|
onClick={toolIconClick.bind(this, curr.eventKey ?? curr.name)}
|
|
>
|
|
<TooltipIcon
|
|
iconName={curr.name}
|
|
tooltipText={
|
|
isRef(curr.tooltip) ? curr.tooltip.value : curr.tooltip
|
|
}
|
|
customClassName={curr.iconClass}
|
|
/>
|
|
</NButton>
|
|
))}
|
|
{getBreadcrumbSwitch ? <Breadcrumb /> : null}
|
|
</NFlex>
|
|
<NFlex justify="end" align="center" size={[0, 0]} wrap={false}>
|
|
{isRenderVNode(
|
|
<GlobalSearchButton
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
|
|
this.globalSearchShown = true
|
|
}}
|
|
/>,
|
|
)}
|
|
{rightTooltipIconOptions.map((curr) => (
|
|
<NButton
|
|
class="override-button__layout"
|
|
quaternary
|
|
size="medium"
|
|
key={curr.eventKey ?? curr.name}
|
|
aria-label={this.t<string>(
|
|
curr.eventKey === 'setting'
|
|
? 'headerTooltip.Setting'
|
|
: curr.eventKey === 'github'
|
|
? 'headerTooltip.Github'
|
|
: this.isFullscreen
|
|
? 'headerTooltip.CancelFullScreen'
|
|
: 'headerTooltip.FullScreen',
|
|
)}
|
|
onClick={toolIconClick.bind(this, curr.eventKey ?? curr.name)}
|
|
>
|
|
<RIcon name={curr.name} />
|
|
</NButton>
|
|
))}
|
|
<NDropdown
|
|
options={LOCAL_OPTIONS}
|
|
onSelect={(key: string | number) => updateLocale(String(key))}
|
|
trigger="click"
|
|
>
|
|
<NButton
|
|
quaternary
|
|
aria-label={this.t<string>('layout.language')}
|
|
class="override-button__layout"
|
|
>
|
|
<RIcon name="system/language" />
|
|
</NButton>
|
|
</NDropdown>
|
|
<NDropdown
|
|
options={createAvatarOptions(this.t)}
|
|
onSelect={(key) => void avatarDropdownClick(key)}
|
|
trigger="click"
|
|
>
|
|
<AppAvatar
|
|
avatarSize={24}
|
|
spaceSize={[8, 0]}
|
|
class="override-button__layout"
|
|
/>
|
|
</NDropdown>
|
|
</NFlex>
|
|
</NFlex>
|
|
<SettingDrawer
|
|
v-model:show={this.showSettings}
|
|
placement={getDrawerPlacement}
|
|
/>
|
|
</NLayoutHeader>
|
|
)
|
|
},
|
|
})
|