Skip to content

Commit

Permalink
feat(projects): new layout,tab and add update theme settings
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Mar 13, 2023
1 parent 488e6e3 commit 912c353
Show file tree
Hide file tree
Showing 30 changed files with 386 additions and 93 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@
<h1>Soybean Admin</h1>
</div>

![](https://img.shields.io/github/stars/honghuangdc/soybean-admin) [![license](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
[![license](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE) ![](https://img.shields.io/github/stars/honghuangdc/soybean-admin) ![](https://img.shields.io/github/forks/honghuangdc/soybean-admin)

## 简介

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -61,6 +61,7 @@
"@better-scroll/core": "^2.5.0",
"@soybeanjs/vue-admin-layout": "^1.1.1",
"@soybeanjs/vue-admin-tab": "^1.0.5",
"@soybeanjs/vue-materials": "^0.1.8",
"@vueuse/core": "^9.13.0",
"axios": "0.27.2",
"clipboard": "^2.0.11",
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/common/dark-mode-container.vue
@@ -1,6 +1,6 @@
<template>
<div
class="dark:bg-[#18181c] dark:text-white dark:text-opacity-82 transition-all duration-300 ease-in-out"
class="dark:bg-[#18181c] dark:text-white dark:text-opacity-82 transition-all"
:class="inverted ? 'bg-[#001428] text-white' : 'bg-white text-[#333639]'"
>
<slot></slot>
Expand Down
16 changes: 16 additions & 0 deletions src/constants/system.ts
Expand Up @@ -24,6 +24,22 @@ export const themeLayoutModeOptions: Common.OptionWithKey<UnionKey.ThemeLayoutMo
}
];

export const themeScrollModeLabels: Record<UnionKey.ThemeScrollMode, string> = {
wrapper: '外层滚动',
content: '主体滚动'
};

export const themeScrollModeOptions: Common.OptionWithKey<UnionKey.ThemeScrollMode>[] = [
{
value: 'wrapper',
label: themeScrollModeLabels.wrapper
},
{
value: 'content',
label: themeScrollModeLabels.content
}
];

export const themeTabModeLabels: Record<UnionKey.ThemeTabMode, string> = {
chrome: '谷歌风格',
button: '按钮风格'
Expand Down
16 changes: 9 additions & 7 deletions src/layouts/basic-layout/index.vue
@@ -1,18 +1,20 @@
<template>
<admin-layout
:mode="mode"
:is-mobile="isMobile"
:fixed-header-and-tab="theme.fixedHeaderAndTab"
:scroll-mode="theme.scrollMode"
:scroll-el-id="app.scrollElId"
:full-content="app.contentFull"
:fixed-top="theme.fixedHeaderAndTab"
:header-height="theme.header.height"
:tab-visible="theme.tab.visible"
:tab-height="theme.tab.height"
:content-class="app.disableMainXScroll ? 'overflow-x-hidden' : ''"
:sider-visible="siderVisible"
:sider-collapse="app.siderCollapse"
:sider-width="siderWidth"
:sider-collapsed-width="siderCollapsedWidth"
:sider-collapse="app.siderCollapse"
:fixed-footer="theme.footer.fixed"
:footer-visible="theme.footer.visible"
@update:sider-collapse="app.setSiderCollapse"
:fixed-footer="theme.footer.fixed"
>
<template #header>
<global-header v-bind="headerProps" />
Expand All @@ -33,7 +35,7 @@
</template>

<script setup lang="ts">
import AdminLayout from '@soybeanjs/vue-admin-layout';
import { AdminLayout } from '@soybeanjs/vue-materials';
import { useAppStore, useThemeStore } from '@/store';
import { useBasicLayout } from '@/composables';
import {
Expand All @@ -51,7 +53,7 @@ defineOptions({ name: 'BasicLayout' });
const app = useAppStore();
const theme = useThemeStore();
const { mode, isMobile, headerProps, siderVisible, siderWidth, siderCollapsedWidth } = useBasicLayout();
const { mode, headerProps, siderVisible, siderWidth, siderCollapsedWidth } = useBasicLayout();
</script>

<style scoped></style>
31 changes: 19 additions & 12 deletions src/layouts/common/global-content/index.vue
@@ -1,16 +1,23 @@
<template>
<div
:class="{ 'p-16px': showPadding }"
class="h-full bg-[#f6f9f8] dark:bg-[#101014] transition duration-300 ease-in-out"
>
<router-view v-slot="{ Component, route }">
<transition :name="theme.pageAnimateMode" mode="out-in" :appear="true">
<keep-alive :include="routeStore.cacheRoutes">
<component :is="Component" v-if="app.reloadFlag" :key="route.fullPath" />
</keep-alive>
</transition>
</router-view>
</div>
<router-view v-slot="{ Component, route }">
<transition
:name="theme.pageAnimateMode"
mode="out-in"
:appear="true"
@before-leave="app.setDisableMainXScroll(true)"
@after-enter="app.setDisableMainXScroll(false)"
>
<keep-alive :include="routeStore.cacheRoutes">
<component
:is="Component"
v-if="app.reloadFlag"
:key="route.fullPath"
:class="{ 'p-16px': showPadding }"
class="flex-grow bg-[#f6f9f8] dark:bg-[#101014] transition duration-300 ease-in-out"
/>
</keep-alive>
</transition>
</router-view>
</template>

<script setup lang="ts">
Expand Down
Expand Up @@ -59,12 +59,24 @@ function hide() {
dropdownVisible.value = false;
}
type DropdownKey = 'reload-current' | 'close-current' | 'close-other' | 'close-left' | 'close-right' | 'close-all';
type DropdownKey =
| 'full-content'
| 'reload-current'
| 'close-current'
| 'close-other'
| 'close-left'
| 'close-right'
| 'close-all';
type Option = DropdownOption & {
key: DropdownKey;
};
const options = computed<Option[]>(() => [
{
label: '内容全屏',
key: 'full-content',
icon: iconRender({ icon: 'gridicons-fullscreen' })
},
{
label: '重新加载',
key: 'reload-current',
Expand Down Expand Up @@ -100,6 +112,12 @@ const options = computed<Option[]>(() => [
]);
const actionMap = new Map<DropdownKey, () => void>([
[
'full-content',
() => {
app.setContentFull(true);
}
],
[
'reload-current',
() => {
Expand Down
32 changes: 16 additions & 16 deletions src/layouts/common/global-tab/components/tab-detail/index.vue
@@ -1,25 +1,26 @@
<template>
<div ref="tabRef" class="h-full" :class="[isChromeMode ? 'flex items-end' : 'flex-y-center']">
<component
:is="activeComponent"
v-for="(item, index) in tab.tabs"
<div ref="tabRef" class="flex h-full pr-18px" :class="[isChromeMode ? 'items-end' : 'items-center gap-12px']">
<AdminTab
v-for="item in tab.tabs"
:key="item.fullPath"
:is-active="tab.activeTab === item.fullPath"
:primary-color="theme.themeColor"
:closable="!(item.name === tab.homeTab.name || item.meta.affix)"
:mode="theme.tab.mode"
:dark-mode="theme.darkMode"
:class="{ '!mr-0': isChromeMode && index === tab.tabs.length - 1, 'mr-10px': !isChromeMode }"
:active="tab.activeTab === item.fullPath"
:active-color="theme.themeColor"
:closable="!(item.name === tab.homeTab.name || item.meta.affix)"
@click="tab.handleClickTab(item.fullPath)"
@close="tab.removeTab(item.fullPath)"
@contextmenu="handleContextMenu($event, item.fullPath, item.meta.affix)"
>
<svg-icon
:icon="item.meta.icon"
:local-icon="item.meta.localIcon"
class="inline-block align-text-bottom mr-4px text-16px"
/>
<template #prefix>
<svg-icon
:icon="item.meta.icon"
:local-icon="item.meta.localIcon"
class="inline-block align-text-bottom text-16px"
/>
</template>
{{ item.meta.title }}
</component>
</AdminTab>
</div>
<context-menu
:visible="dropdown.visible"
Expand All @@ -33,7 +34,7 @@

<script setup lang="ts">
import { computed, nextTick, reactive, ref, watch } from 'vue';
import { ButtonTab, ChromeTab } from '@soybeanjs/vue-admin-tab';
import { AdminTab } from '@soybeanjs/vue-materials';
import { useTabStore, useThemeStore } from '@/store';
import { ContextMenu } from './components';
Expand All @@ -49,7 +50,6 @@ const theme = useThemeStore();
const tab = useTabStore();
const isChromeMode = computed(() => theme.tab.mode === 'chrome');
const activeComponent = computed(() => (isChromeMode.value ? ChromeTab : ButtonTab));
// 获取当前激活的tab的clientX
const tabRef = ref<HTMLElement>();
Expand Down
20 changes: 11 additions & 9 deletions src/layouts/common/setting-drawer/components/dark-mode/index.vue
Expand Up @@ -4,23 +4,29 @@
<setting-menu label="深色主题">
<n-switch :value="theme.darkMode" @update:value="theme.setDarkMode">
<template #checked>
<icon-mdi-white-balance-sunny class="text-14px text-primary" />
<icon-mdi-white-balance-sunny class="text-14px text-white" />
</template>
<template #unchecked>
<icon-mdi-moon-waning-crescent class="text-14px text-primary" />
<icon-mdi-moon-waning-crescent class="text-14px text-white" />
</template>
</n-switch>
</setting-menu>
<setting-menu label="跟随系统">
<n-switch :value="theme.followSystemTheme" @update:value="theme.setFollowSystemTheme">
<template #checked>
<icon-ic-baseline-do-not-disturb class="text-14px text-primary" />
<icon-ic-baseline-do-not-disturb class="text-14px text-white" />
</template>
<template #unchecked>
<icon-ic-round-hdr-auto class="text-14px text-primary" />
<icon-ic-round-hdr-auto class="text-14px text-white" />
</template>
</n-switch>
</setting-menu>
<setting-menu label="侧边栏深色主题">
<n-switch :value="theme.sider.inverted" @update:value="theme.setSiderInverted" />
</setting-menu>
<setting-menu label="头部深色主题">
<n-switch :value="theme.header.inverted" @update:value="theme.setHeaderInverted" />
</setting-menu>
</n-space>
</template>

Expand All @@ -32,8 +38,4 @@ defineOptions({ name: 'DarkMode' });
const theme = useThemeStore();
</script>
<style scoped>
:deep(.n-switch__rail) {
background-color: #000e1c !important;
}
</style>
<style scoped></style>
@@ -1,3 +1,4 @@
import LayoutCheckbox from './layout-checkbox.vue';
import LayoutCard from './layout-card.vue';

export { LayoutCheckbox };
export { LayoutCheckbox, LayoutCard };
@@ -0,0 +1,81 @@
<template>
<div
class="border-2px rounded-6px cursor-pointer hover:border-primary"
:class="[checked ? 'border-primary' : 'border-transparent']"
>
<n-tooltip :placement="activeConfig.placement" trigger="hover">
<template #trigger>
<div
class="layout-card__shadow gap-6px w-96px h-64px p-6px rd-4px"
:class="[mode.includes('vertical') ? 'flex' : 'flex-col']"
>
<slot></slot>
</div>
</template>
<span>{{ label }}</span>
</n-tooltip>
</div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import type { PopoverPlacement } from 'naive-ui';
defineOptions({ name: 'LayoutCard' });
interface Props {
/** 布局模式 */
mode: UnionKey.ThemeLayoutMode;
/** 布局模式文本 */
label: string;
/** 选中状态 */
checked: boolean;
}
const props = defineProps<Props>();
type LayoutConfig = Record<
UnionKey.ThemeLayoutMode,
{
placement: PopoverPlacement;
headerClass: string;
menuClass: string;
mainClass: string;
}
>;
const layoutConfig: LayoutConfig = {
vertical: {
placement: 'bottom-start',
headerClass: '',
menuClass: 'w-1/3 h-full',
mainClass: 'w-2/3 h-3/4'
},
'vertical-mix': {
placement: 'bottom',
headerClass: '',
menuClass: 'w-1/4 h-full',
mainClass: 'w-2/3 h-3/4'
},
horizontal: {
placement: 'bottom',
headerClass: '',
menuClass: 'w-full h-1/4',
mainClass: 'w-full h-3/4'
},
'horizontal-mix': {
placement: 'bottom-end',
headerClass: '',
menuClass: 'w-full h-1/4',
mainClass: 'w-2/3 h-3/4'
}
};
const activeConfig = computed(() => layoutConfig[props.mode]);
</script>

<style scoped>
.layout-card__shadow {
box-shadow: 0 1px 2.5px rgba(0, 0, 0, 0.18);
}
</style>

0 comments on commit 912c353

Please sign in to comment.