mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-08-27 04:51:59 +08:00
v3.0.4,新增项目logo配置
This commit is contained in:
parent
6132863b02
commit
b8063b8d47
23
cfg.ts
23
cfg.ts
@ -10,15 +10,38 @@ export interface HTMLTitle {
|
|||||||
transformIndexHtml: (title: string) => string
|
transformIndexHtml: (title: string) => string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SideBarLogo {
|
||||||
|
icon?: string
|
||||||
|
title?: string
|
||||||
|
url?: string
|
||||||
|
jumpType?: 'station' | 'outsideStation'
|
||||||
|
}
|
||||||
|
|
||||||
export interface Config {
|
export interface Config {
|
||||||
server: ServerOptions
|
server: ServerOptions
|
||||||
buildOptions: (mode: string) => BuildOptions
|
buildOptions: (mode: string) => BuildOptions
|
||||||
alias: AliasOptions
|
alias: AliasOptions
|
||||||
title: HTMLTitle
|
title: HTMLTitle
|
||||||
copyright?: string | number | VNodeChild
|
copyright?: string | number | VNodeChild
|
||||||
|
sideBarLogo: SideBarLogo
|
||||||
}
|
}
|
||||||
|
|
||||||
const config: Config = {
|
const config: Config = {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* icon: LOGO 图标, 依赖 `RayIcon` 实现
|
||||||
|
* title: LOGO 标题
|
||||||
|
* url: 点击跳转地址, 如果不配置该属性, 则不会触发跳转
|
||||||
|
* jumpType: 跳转类型(station: 项目内跳转, outsideStation: 新页面打开)
|
||||||
|
*
|
||||||
|
* 如果不设置该属性或者为空, 则不会渲染 LOGO
|
||||||
|
*/
|
||||||
|
sideBarLogo: {
|
||||||
|
icon: 'ray',
|
||||||
|
title: 'Ray Template',
|
||||||
|
url: '/dashboard',
|
||||||
|
jumpType: 'station',
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 版权信息
|
* 版权信息
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ray-template",
|
"name": "ray-template",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "3.0.3",
|
"version": "3.0.4",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
27
src/layout/components/Menu/index.scss
Normal file
27
src/layout/components/Menu/index.scss
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
.ray-menu__logo {
|
||||||
|
height: 50px;
|
||||||
|
padding: 0 18px 0 24px;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
&.ray-menu__logo-url {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .ray-menu__logo-title {
|
||||||
|
opacity: 0;
|
||||||
|
display: none;
|
||||||
|
flex: 1;
|
||||||
|
white-space: nowrap;
|
||||||
|
|
||||||
|
&.ray-menu__logo-title--open {
|
||||||
|
opacity: 1;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,16 @@
|
|||||||
|
import './index.scss'
|
||||||
|
|
||||||
import { NMenu, NLayoutSider } from 'naive-ui'
|
import { NMenu, NLayoutSider } from 'naive-ui'
|
||||||
|
import RayIcon from '@/components/RayIcon/index'
|
||||||
|
|
||||||
import { useMenu } from '@/store'
|
import { useMenu } from '@/store'
|
||||||
|
|
||||||
const LayoutMenu = defineComponent({
|
const LayoutMenu = defineComponent({
|
||||||
name: 'LayoutMenu',
|
name: 'LayoutMenu',
|
||||||
setup() {
|
setup() {
|
||||||
const menuStore = useMenu()
|
const menuStore = useMenu()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
const { menuModelValueChange, setupAppRoutes, collapsedMenu } = menuStore
|
const { menuModelValueChange, setupAppRoutes, collapsedMenu } = menuStore
|
||||||
const modelMenuKey = computed({
|
const modelMenuKey = computed({
|
||||||
get: () => menuStore.menuKey,
|
get: () => menuStore.menuKey,
|
||||||
@ -13,6 +19,18 @@ const LayoutMenu = defineComponent({
|
|||||||
})
|
})
|
||||||
const modelMenuOptions = computed(() => menuStore.options)
|
const modelMenuOptions = computed(() => menuStore.options)
|
||||||
const modelCollapsed = computed(() => menuStore.collapsed)
|
const modelCollapsed = computed(() => menuStore.collapsed)
|
||||||
|
const collapsedWidth = 64
|
||||||
|
const {
|
||||||
|
layout: { sideBarLogo },
|
||||||
|
} = __APP_CFG__
|
||||||
|
|
||||||
|
const handleSideBarLogoClick = () => {
|
||||||
|
if (sideBarLogo && sideBarLogo.url) {
|
||||||
|
sideBarLogo.jumpType === 'station'
|
||||||
|
? router.push(sideBarLogo.url)
|
||||||
|
: window.open(sideBarLogo.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setupAppRoutes()
|
setupAppRoutes()
|
||||||
|
|
||||||
@ -22,6 +40,9 @@ const LayoutMenu = defineComponent({
|
|||||||
modelMenuOptions,
|
modelMenuOptions,
|
||||||
modelCollapsed,
|
modelCollapsed,
|
||||||
collapsedMenu,
|
collapsedMenu,
|
||||||
|
collapsedWidth,
|
||||||
|
sideBarLogo,
|
||||||
|
handleSideBarLogoClick,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
@ -30,16 +51,37 @@ const LayoutMenu = defineComponent({
|
|||||||
bordered
|
bordered
|
||||||
showTrigger
|
showTrigger
|
||||||
collapseMode="width"
|
collapseMode="width"
|
||||||
collapsedWidth={64}
|
collapsedWidth={this.collapsedWidth}
|
||||||
onUpdateCollapsed={this.collapsedMenu.bind(this)}
|
onUpdateCollapsed={this.collapsedMenu.bind(this)}
|
||||||
>
|
>
|
||||||
|
{this.sideBarLogo ? (
|
||||||
|
<div
|
||||||
|
class={[
|
||||||
|
'ray-menu__logo',
|
||||||
|
this.sideBarLogo.url ? 'ray-menu__logo-url' : '',
|
||||||
|
]}
|
||||||
|
onClick={this.handleSideBarLogoClick.bind(this)}
|
||||||
|
>
|
||||||
|
<RayIcon name={this.sideBarLogo.icon as string} size="30" />
|
||||||
|
<h1
|
||||||
|
class={[
|
||||||
|
!this.modelCollapsed ? 'ray-menu__logo-title--open' : '',
|
||||||
|
'ray-menu__logo-title',
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{this.sideBarLogo.title}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
''
|
||||||
|
)}
|
||||||
<NMenu
|
<NMenu
|
||||||
v-model:value={this.modelMenuKey}
|
v-model:value={this.modelMenuKey}
|
||||||
options={this.modelMenuOptions as NaiveMenuOptions[]}
|
options={this.modelMenuOptions as NaiveMenuOptions[]}
|
||||||
indent={24}
|
indent={24}
|
||||||
collapsed={this.modelCollapsed}
|
collapsed={this.modelCollapsed}
|
||||||
collapsedIconSize={22}
|
collapsedIconSize={22}
|
||||||
collapsedWidth={64}
|
collapsedWidth={this.collapsedWidth}
|
||||||
onUpdateValue={this.menuModelValueChange.bind(this)}
|
onUpdateValue={this.menuModelValueChange.bind(this)}
|
||||||
/>
|
/>
|
||||||
</NLayoutSider>
|
</NLayoutSider>
|
||||||
|
@ -98,7 +98,7 @@ const SiderBar = defineComponent({
|
|||||||
onPositiveClick: () => {
|
onPositiveClick: () => {
|
||||||
window.$message.info('账号退出中...')
|
window.$message.info('账号退出中...')
|
||||||
removeCache('all-sessionStorage')
|
removeCache('all-sessionStorage')
|
||||||
setTimeout(() => window.location.reload(), 2 * 1000)
|
setTimeout(() => window.location.reload(), 300)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -112,7 +112,7 @@ const SiderBar = defineComponent({
|
|||||||
reload: () => {
|
reload: () => {
|
||||||
changeSwitcher(false, 'reloadRouteSwitch')
|
changeSwitcher(false, 'reloadRouteSwitch')
|
||||||
|
|
||||||
setTimeout(() => changeSwitcher(true, 'reloadRouteSwitch'))
|
setTimeout(() => changeSwitcher(true, 'reloadRouteSwitch'), 1.5 * 1000)
|
||||||
},
|
},
|
||||||
setting: () => {
|
setting: () => {
|
||||||
showSettings.value = true
|
showSettings.value = true
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import './index.scss'
|
import './index.scss'
|
||||||
|
|
||||||
import { NLayout, NLayoutContent, NLayoutFooter } from 'naive-ui'
|
import { NLayout, NLayoutContent } from 'naive-ui'
|
||||||
import RayTransitionComponent from '@/components/RayTransitionComponent/index.vue'
|
import RayTransitionComponent from '@/components/RayTransitionComponent/index.vue'
|
||||||
import LayoutMenu from './components/Menu/index'
|
import LayoutMenu from './components/Menu/index'
|
||||||
import SiderBar from './components/SiderBar/index'
|
import SiderBar from './components/SiderBar/index'
|
||||||
@ -20,7 +20,7 @@ const Layout = defineComponent({
|
|||||||
|
|
||||||
if (menuStore.menuTagSwitch) {
|
if (menuStore.menuTagSwitch) {
|
||||||
cssVar = {
|
cssVar = {
|
||||||
'--layout-content-height': 'calc(100% - 110px)',
|
'--layout-content-height': 'calc(100% - 109px)',
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cssVar = {
|
cssVar = {
|
||||||
|
10
src/types/index.d.ts
vendored
10
src/types/index.d.ts
vendored
@ -16,6 +16,13 @@ import type { VNodeChild } from 'vue'
|
|||||||
export global {
|
export global {
|
||||||
declare type Recordable<T = unknown> = Record<string, T>
|
declare type Recordable<T = unknown> = Record<string, T>
|
||||||
|
|
||||||
|
export declare interface SideBarLogo {
|
||||||
|
icon?: string
|
||||||
|
title?: string
|
||||||
|
url?: string
|
||||||
|
jumpType?: 'station' | 'outsideStation'
|
||||||
|
}
|
||||||
|
|
||||||
declare const __APP_CFG__: {
|
declare const __APP_CFG__: {
|
||||||
pkg: {
|
pkg: {
|
||||||
name: string
|
name: string
|
||||||
@ -24,7 +31,8 @@ export global {
|
|||||||
devDependencies: Recordable<string>
|
devDependencies: Recordable<string>
|
||||||
}
|
}
|
||||||
layout: {
|
layout: {
|
||||||
copyright: string | number | VNodeChild
|
copyright?: string | number | VNodeChild
|
||||||
|
sideBarLogo?: SideBarLogo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ export const useVueI18nPlugin = () =>
|
|||||||
*
|
*
|
||||||
* @param title 浏览器 title 名称
|
* @param title 浏览器 title 名称
|
||||||
*/
|
*/
|
||||||
export const HTMLTitlePlugin = (title = 'ray template') => {
|
export const HTMLTitlePlugin = (title: string) => {
|
||||||
return {
|
return {
|
||||||
name: 'html-transform',
|
name: 'html-transform',
|
||||||
transformIndexHtml: (html: string) => {
|
transformIndexHtml: (html: string) => {
|
||||||
|
@ -4,12 +4,13 @@ import config from './cfg'
|
|||||||
const pkg = require('./package.json')
|
const pkg = require('./package.json')
|
||||||
|
|
||||||
const { dependencies, devDependencies, name, version } = pkg
|
const { dependencies, devDependencies, name, version } = pkg
|
||||||
const { server, buildOptions, alias, title, copyright } = config
|
const { server, buildOptions, alias, title, copyright, sideBarLogo } = config
|
||||||
|
|
||||||
const __APP_CFG__ = {
|
const __APP_CFG__ = {
|
||||||
pkg: { dependencies, devDependencies, name, version },
|
pkg: { dependencies, devDependencies, name, version },
|
||||||
layout: {
|
layout: {
|
||||||
copyright,
|
copyright,
|
||||||
|
sideBarLogo,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user