Skip to content

Commit

Permalink
feat: add BaseLayoutItem component to switch layout mode
Browse files Browse the repository at this point in the history
  • Loading branch information
flingyp committed Jun 12, 2023
1 parent 14a74fe commit 082d53b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 30 deletions.
54 changes: 54 additions & 0 deletions src/layout/components/layout/BaseLayoutItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script setup lang="ts">
import { LayoutMode } from '~/vadmire.config'
interface BaseLayoutItemProps {
mode: LayoutMode
}
defineProps<BaseLayoutItemProps>()
defineEmits(['updateLayoutMode'])
const { layoutMode } = storeToRefs(useVAdmireConfigStore())
</script>

<template>
<div
class="
p-1 h-16 border rounded transition duration-500
hover:border-primaryHover dark:hover:border-primaryHover
"
:class="{
'border-primarySuppl dark:border-primarySuppl': mode === layoutMode,
'border-vBorderLight dark:border-vBorderDark': mode !== layoutMode
}"
>
<div
v-if="mode === 'SIDER_MENU'"
class="relative h-full cursor-pointer"
@click="$emit('updateLayoutMode', mode)"
>
<div class="absolute w-2.5 h-full left-0 bg-primary rounded-sm opacity-80" />
<div class="absolute w-5/6 right-0 h-2 bg-primary rounded-sm opacity-60" />
<div class="absolute w-5/6 h-[calc(100%-8px)] top-2.5 right-0 bg-primary rounded-sm opacity-30" />
</div>

<div
v-if="mode === 'TOP_MENU'"
class="relative h-full cursor-pointer"
@click="$emit('updateLayoutMode', mode)"
>
<div class="absolute w-full h-2 bg-primary rounded-sm opacity-60" />
<div class="absolute w-full h-[calc(100%-8px)] top-2.5 right-0 bg-primary rounded-sm opacity-30" />
</div>

<div
v-if="mode === 'SIDER_MIX_MENU'"
class="relative h-full cursor-pointer"
@click="$emit('updateLayoutMode', mode)"
>
<div class="absolute w-2.5 h-[calc(100%-8px)] top-2.5 left-0 bg-primary rounded-sm opacity-80" />
<div class="absolute w-full h-2 bg-primary rounded-sm opacity-60" />
<div class="absolute w-[calc(100%-12px)] h-[calc(100%-8px)] top-2.5 left-3 bg-primary rounded-sm opacity-30" />
</div>
</div>
</template>
47 changes: 17 additions & 30 deletions src/layout/components/setting/BaseLayoutMode.vue
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
<script setup lang="ts">import { LayoutMode } from '~/vadmire.config'
<script setup lang="ts">
import { LayoutMode } from '~/vadmire.config'
import BaseLayoutItem from '../layout/BaseLayoutItem.vue'
const vadmireConfigStore = useVAdmireConfigStore()
interface LayoutItem {
key: LayoutMode,
value: string
}
// layout list
const systemLayoutOption: LayoutItem[] = [
{
key: 'SIDER_MENU',
value: '左侧菜单',
},
{
key: 'TOP_MENU',
value: '顶部菜单',
},
{
key: 'SIDER_MIX_MENU',
value: '顶部混合菜单',
},
]
const changeLayoutMode = (mode: LayoutMode) => {
const updateLayoutMode = (mode: LayoutMode) => {
vadmireConfigStore.layoutMode = mode
}
</script>

<template>
<div class="w-full grid grid-cols-1 space-y-2">
<NButton
v-for="item in systemLayoutOption"
:key="item.key"
:type="vadmireConfigStore.layoutMode === item.key ? 'primary' : 'default'"
@click="changeLayoutMode(item.key)"
>
{{ item.value }}
</NButton>
<div class="w-full grid grid-cols-3 gap-x-2">
<BaseLayoutItem
mode="SIDER_MENU"
@update-layout-mode="updateLayoutMode"
/>
<BaseLayoutItem
mode="TOP_MENU"
@update-layout-mode="updateLayoutMode"
/>
<BaseLayoutItem
mode="SIDER_MIX_MENU"
@update-layout-mode="updateLayoutMode"
/>
</div>
</template>

0 comments on commit 082d53b

Please sign in to comment.