mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-04-06 03:57:54 +08:00
refactor(components): 头部的按钮包装层封装,统一样式
This commit is contained in:
parent
04cea2907d
commit
54bf56a0c3
@ -32,7 +32,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useApp } from '@/store';
|
import { useAppStore } from '@/store';
|
||||||
import {
|
import {
|
||||||
Breadcrumb,
|
Breadcrumb,
|
||||||
CollapaseButton,
|
CollapaseButton,
|
||||||
@ -46,7 +46,7 @@ import {
|
|||||||
UserCenter,
|
UserCenter,
|
||||||
} from '../components';
|
} from '../components';
|
||||||
|
|
||||||
const appStore = useApp();
|
const appStore = useAppStore();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
9
src/layouts/components/common/HeaderButton.vue
Normal file
9
src/layouts/components/common/HeaderButton.vue
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<template>
|
||||||
|
<n-space align="center" class="hover:bg-hex-F3F4F6 hover:shadow-inner h-full px-3 cursor-pointer">
|
||||||
|
<slot />
|
||||||
|
</n-space>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts"></script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
@ -1,16 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<HeaderButton @click="appStore.toggleCollapse()">
|
||||||
class="hover:bg-hex-F3F4F6 hover:shadow-inner h-full px-4 flex-center cursor-pointer"
|
<e-icon v-if="appStore.collapsed" icon="icon-park-outline:menu-unfold" />
|
||||||
@click="appStore.toggleCollapse()"
|
<e-icon v-else icon="icon-park-outline:menu-fold" />
|
||||||
>
|
</HeaderButton>
|
||||||
<e-icon v-show="appStore.collapsed" icon="icon-park-outline:menu-unfold" />
|
|
||||||
<e-icon v-show="!appStore.collapsed" icon="icon-park-outline:menu-fold" />
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useApp } from '@/store';
|
import { useAppStore } from '@/store';
|
||||||
const appStore = useApp();
|
import HeaderButton from '../common/HeaderButton.vue';
|
||||||
|
|
||||||
|
const appStore = useAppStore();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<n-tooltip placement="bottom" trigger="hover">
|
<n-tooltip placement="bottom" trigger="hover">
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<div
|
<HeaderButton @click="appStore.toggleDarkMode()">
|
||||||
class="hover:bg-hex-F3F4F6 hover:shadow-inner h-full px-4 flex-center cursor-pointer"
|
<e-icon v-if="appStore.darkMode" icon="icon-park-outline:moon" />
|
||||||
@click="appStore.toggleDarkMode()"
|
<e-icon v-else icon="icon-park-outline:sun" />
|
||||||
>
|
</HeaderButton>
|
||||||
<e-icon v-show="appStore.darkMode" icon="icon-park-outline:moon" />
|
|
||||||
<e-icon v-show="!appStore.darkMode" icon="icon-park-outline:sun" />
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
<span>切换主题模式</span>
|
<span>切换主题模式</span>
|
||||||
</n-tooltip>
|
</n-tooltip>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useApp } from '@/store';
|
import { useAppStore } from '@/store';
|
||||||
const appStore = useApp();
|
import HeaderButton from '../common/HeaderButton.vue';
|
||||||
|
|
||||||
|
const appStore = useAppStore();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
@ -1,21 +1,19 @@
|
|||||||
<template>
|
<template>
|
||||||
<n-tooltip placement="bottom" trigger="hover">
|
<n-tooltip placement="bottom" trigger="hover">
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<div
|
<HeaderButton @click="appStore.toggleFullScreen()">
|
||||||
class="hover:bg-hex-F3F4F6 hover:shadow-inner h-full px-4 flex-center cursor-pointer"
|
<e-icon v-if="appStore.fullScreen" icon="icon-park-outline:off-screen-two" />
|
||||||
@click="appStore.toggleFullScreen()"
|
<e-icon v-else icon="icon-park-outline:full-screen-two" />
|
||||||
>
|
</HeaderButton>
|
||||||
<e-icon v-show="appStore.fullScreen" icon="icon-park-outline:off-screen-two" />
|
|
||||||
<e-icon v-show="!appStore.fullScreen" icon="icon-park-outline:full-screen-two" />
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
<span>全屏</span>
|
<span>全屏</span>
|
||||||
</n-tooltip>
|
</n-tooltip>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useApp } from '@/store';
|
import HeaderButton from '../common/HeaderButton.vue';
|
||||||
const appStore = useApp();
|
import { useAppStore } from '@/store';
|
||||||
|
const appStore = useAppStore();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<n-tooltip placement="bottom" trigger="hover">
|
<n-tooltip placement="bottom" trigger="hover">
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<div class="hover:bg-hex-F3F4F6 hover:shadow-inner h-full px-4 flex-center cursor-pointer" @click="toMyGithub">
|
<HeaderButton @click="toMyGithub"><e-icon icon="icon-park-outline:github" /></HeaderButton>
|
||||||
<e-icon icon="icon-park-outline:github" />
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
<span>Github</span>
|
<span>Github</span>
|
||||||
</n-tooltip>
|
</n-tooltip>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import HeaderButton from '../common/HeaderButton.vue';
|
||||||
const toMyGithub = () => {
|
const toMyGithub = () => {
|
||||||
window.open('https://github.com/chen-see');
|
window.open('https://github.com/chen-see');
|
||||||
};
|
};
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<n-tooltip placement="bottom" trigger="hover">
|
<n-tooltip placement="bottom" trigger="hover">
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<div class="hover:bg-hex-F3F4F6 hover:shadow-inner h-full px-4 flex-center cursor-pointer" @click="openNotice">
|
<HeaderButton @click="openNotice"><e-icon icon="icon-park-outline:remind" /></HeaderButton>
|
||||||
<e-icon icon="icon-park-outline:remind" />
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
<span>消息通知</span>
|
<span>消息通知</span>
|
||||||
</n-tooltip>
|
</n-tooltip>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import HeaderButton from '../common/HeaderButton.vue';
|
||||||
const openNotice = () => {
|
const openNotice = () => {
|
||||||
console.log('消息通知');
|
console.log('消息通知');
|
||||||
};
|
};
|
||||||
|
@ -1,21 +1,24 @@
|
|||||||
<template>
|
<template>
|
||||||
<n-tooltip placement="bottom" trigger="hover">
|
<n-tooltip placement="bottom" trigger="hover">
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<div class="hover:bg-hex-F3F4F6 hover:shadow-inner h-full px-4 flex-center cursor-pointer" @click="openSetting">
|
<HeaderButton @click="openSetting">
|
||||||
<e-icon icon="icon-park-outline:setting-two" />
|
<div>
|
||||||
<n-drawer v-model:show="drawerActive" :width="400">
|
<e-icon icon="icon-park-outline:setting-two" />
|
||||||
<n-drawer-content title="系统设置">这是系统设置,但是暂时还没有内容</n-drawer-content>
|
<n-drawer v-model:show="drawerActive" :width="300">
|
||||||
</n-drawer>
|
<n-drawer-content title="系统设置">这是系统设置,但是暂时还没有内容</n-drawer-content>
|
||||||
</div>
|
</n-drawer>
|
||||||
|
</div>
|
||||||
|
</HeaderButton>
|
||||||
</template>
|
</template>
|
||||||
<span>设置</span>
|
<span>设置</span>
|
||||||
</n-tooltip>
|
</n-tooltip>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// import { useApp } from '@/store';
|
import HeaderButton from '../common/HeaderButton.vue';
|
||||||
|
// import { useAppStore } from '@/store';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
// const appStore = useApp();
|
// const appStore = useAppStore();
|
||||||
|
|
||||||
const drawerActive = ref(false);
|
const drawerActive = ref(false);
|
||||||
const openSetting = () => {
|
const openSetting = () => {
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
<template>
|
<template>
|
||||||
<n-dropdown trigger="hover" :options="options" @select="handleSelect">
|
<n-dropdown trigger="hover" :options="options" @select="handleSelect">
|
||||||
<div class="hover:bg-hex-F3F4F6 hover:shadow-inner h-full px-4 flex-center cursor-pointer">Admin chen</div>
|
<HeaderButton>
|
||||||
|
<n-avatar size="large" src="https://z3.ax1x.com/2021/10/29/5jnWgf.jpg" />
|
||||||
|
{{ authStore.name }}
|
||||||
|
</HeaderButton>
|
||||||
</n-dropdown>
|
</n-dropdown>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Icon } from '@iconify/vue';
|
import HeaderButton from '../common/HeaderButton.vue';
|
||||||
import { h } from 'vue';
|
import { renderIcon } from '@/utils/icon';
|
||||||
|
import { useAuthStore } from '@/store';
|
||||||
|
|
||||||
function renderIcon(icon: string) {
|
const authStore = useAuthStore();
|
||||||
return () => h(Icon, { icon });
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = [
|
const options = [
|
||||||
{
|
{
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useApp } from '@/store';
|
import { useAppStore } from '@/store';
|
||||||
const appStore = useApp();
|
const appStore = useAppStore();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
@ -10,19 +10,14 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useApp } from '@/store';
|
import { useAppStore } from '@/store';
|
||||||
import { Icon } from '@iconify/vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { h } from 'vue';
|
|
||||||
import type { MenuOption } from 'naive-ui';
|
import type { MenuOption } from 'naive-ui';
|
||||||
|
import { renderIcon } from '@/utils/icon';
|
||||||
|
|
||||||
const appStore = useApp();
|
const appStore = useAppStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
function renderIcon(icon: string) {
|
|
||||||
return () => h(Icon, { icon });
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleClickMenu = (key: string) => {
|
const handleClickMenu = (key: string) => {
|
||||||
router.push(key);
|
router.push(key);
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
export const useApp = defineStore('app-store', {
|
export const useAppStore = defineStore('app-store', {
|
||||||
state: () => {
|
state: () => {
|
||||||
return {
|
return {
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
export const useAuth = defineStore('auth-store', {
|
export const useAuthStore = defineStore('auth-store', {
|
||||||
state: () => {
|
state: () => {
|
||||||
return {
|
return {
|
||||||
name: '张三',
|
name: '张三',
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export * from './user';
|
export * from './user';
|
||||||
export * from './app';
|
export * from './app';
|
||||||
|
export * from './auth';
|
||||||
|
7
src/utils/icon.ts
Normal file
7
src/utils/icon.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { h } from 'vue';
|
||||||
|
import { Icon } from '@iconify/vue';
|
||||||
|
import { NIcon } from 'naive-ui';
|
||||||
|
|
||||||
|
export function renderIcon(icon: string) {
|
||||||
|
return () => h(NIcon, null, { default: () => h(Icon, { icon }) });
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user