feat: add SingleRecordMnt component for student record maintenance with search, add, edit, view, and delete functionalities
This commit is contained in:
@@ -0,0 +1,667 @@
|
||||
<template>
|
||||
<v-app v-bind="$attrs" class="sk-admin-layout">
|
||||
<v-navigation-drawer
|
||||
v-model="drawer" class="sk-admin-drawer" color="surface" :rail="isRail"
|
||||
:rail-width="railWidth" :temporary="isMobile" :width="drawerWidth">
|
||||
<template #prepend>
|
||||
|
||||
<!-- Sidebar Title -->
|
||||
<v-card class="sidebar-header d-flex align-center pa-0 pl-3 py-2" flat>
|
||||
<v-btn
|
||||
:aria-label="sidebarToggleLabel" color="grey" :icon="isRail ? 'mdi-menu-open' : 'mdi-menu'" size="32"
|
||||
variant="text" @click="toggleSidebar" />
|
||||
<v-card-text v-if="!isRail" class="sidebar-title flex-grow-1 py-0">
|
||||
<slot name="title">
|
||||
<div class="text-subtitle-1 font-weight-bold text-on-surface">
|
||||
{{ branding.title }}
|
||||
</div>
|
||||
<div class="text-caption text-medium-emphasis">
|
||||
{{ branding.subtitle }}
|
||||
</div>
|
||||
</slot>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
<v-divider />
|
||||
|
||||
<!-- User Info -->
|
||||
<v-card v-if="features.showUserInfo" class="user-info d-flex align-center pa-0 pl-3 py-2" flat>
|
||||
<v-avatar class="user-avatar" color="primary" size="32" variant="tonal">
|
||||
<span class="text-subtitle-2 font-weight-bold">{{ userProfile.avatarText }}</span>
|
||||
</v-avatar>
|
||||
<v-card-text v-if="!isRail" class="user-details flex-grow-1 py-0">
|
||||
<div class="user-name text-body-2 font-weight-medium">
|
||||
{{ userProfile.name }}
|
||||
</div>
|
||||
<div class="user-role text-caption text-medium-emphasis">
|
||||
{{ userProfile.role }}
|
||||
</div>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
<v-divider />
|
||||
|
||||
<v-sheet v-if="isMobile" class="mobile-menu-subheader d-flex flex-column align-stretch ga-2 px-3 py-2">
|
||||
<v-btn
|
||||
v-if="features.showFavorites" class="justify-start text-none"
|
||||
color="primary" rounded="pill" size="small" :variant="mobileFavoritesPanel ? 'flat' : 'outlined'"
|
||||
@click="openMobileFavoritesPanel">
|
||||
<span class="text-on-secondary text-caption font-weight-medium">{{ favoritesConfig.label }}</span>
|
||||
</v-btn>
|
||||
<v-btn
|
||||
v-for="step in mobileMenuLevels" :key="`mobile-level-${step.level}`"
|
||||
block class="justify-start text-none" :color="getMobileMenuBtnColor(step.level)"
|
||||
rounded="pill" size="small" :variant="getMobileMenuBtnVariant(step.level)" @click="goToMobileLevel(step.level)">
|
||||
{{ step.title }}
|
||||
</v-btn>
|
||||
</v-sheet>
|
||||
</template>
|
||||
|
||||
<!-- 桌面板選單 -->
|
||||
<template v-if="!isMobile">
|
||||
<SkAdminDrawerDesktopMenu
|
||||
v-model:opened="opened" :is-shrink="isRail" :menu-items="menuItems"
|
||||
@select="handleSelect" @unshrink="handleUnshrink" />
|
||||
</template>
|
||||
|
||||
<!-- 行動版選單 -->
|
||||
<template v-if="isMobile">
|
||||
<SkAdminDrawerMobileFavoritesPanel
|
||||
v-if="features.showFavorites && mobileFavoritesPanel"
|
||||
:favorite-items="favoriteItems" @select="handleSelectFavorite" />
|
||||
<SkAdminDrawerMobileMenuPanel
|
||||
v-else :mobile-current-items="mobileCurrentItems"
|
||||
@item-click="handleMobileMenuClick" />
|
||||
</template>
|
||||
</v-navigation-drawer>
|
||||
|
||||
<v-app-bar ref="appBarRef" class="" height="auto">
|
||||
<v-row class="flex-column" no-gutters>
|
||||
|
||||
<SkAdminAppBarTopCol
|
||||
:features="features" :is-mobile="isMobile" :logout-label="logoutLabel"
|
||||
:search-config="searchConfig" :search-value="searchValue" :show-breadcrumb-bar="showBreadcrumbBar"
|
||||
:show-favorites-bar="showFavoritesBar" :theme-toggle-label="themeToggleLabel" :toolbar-actions="toolbarActions"
|
||||
:toolbar-counts="toolbarCounts" @action="handleAction"
|
||||
@logout="emitLogout" @search="triggerSearch" @toggle-drawer="drawer = !drawer"
|
||||
@toggle-theme="toggleTheme" @update:search-value="searchValue = $event" @update:show-breadcrumb-bar="showBreadcrumbBar = $event"
|
||||
@update:show-favorites-bar="showFavoritesBar = $event">
|
||||
<template v-if="$slots.actions" #actions>
|
||||
<slot name="actions"></slot>
|
||||
</template>
|
||||
</SkAdminAppBarTopCol>
|
||||
|
||||
<SkAdminAppBarFavoritesCol
|
||||
:favorite-items="favoriteItems" :favorites-config="favoritesConfig" :features="features"
|
||||
:is-mobile="isMobile" :show-favorites-bar="showFavoritesBar" @add-favorite="emitAddFavorite"
|
||||
@remove-favorite="emitRemoveFavorite" @select="handleSelect"
|
||||
@toggle-favorites-bar="toggleFavoritesBar" />
|
||||
|
||||
<SkAdminAppBarBreadcrumbCol
|
||||
:breadcrumb-items="breadcrumbItems" :features="features" :is-mobile="isMobile"
|
||||
:show-breadcrumb-bar="showBreadcrumbBar" :show-favorites-bar="showFavoritesBar"
|
||||
@toggle-favorites-bar="toggleFavoritesBar">
|
||||
<template v-if="$slots['breadcrumb-actions']" #breadcrumb-actions>
|
||||
<slot name="breadcrumb-actions"></slot>
|
||||
</template>
|
||||
</SkAdminAppBarBreadcrumbCol>
|
||||
</v-row>
|
||||
</v-app-bar>
|
||||
|
||||
<!--
|
||||
動態 paddingTop:避免可變高度的 v-app-bar 遮住內容
|
||||
同時固定 v-main 的總高度,避免整頁滾動,改由內容區域自行滾動。
|
||||
-->
|
||||
<v-main class="d-flex flex-column overflow-hidden" :style="mainStyle">
|
||||
<v-container class="content-area" fluid>
|
||||
<slot></slot>
|
||||
</v-container>
|
||||
</v-main>
|
||||
|
||||
<v-slide-y-reverse-transition>
|
||||
<v-card v-if="helpWidgetVisible" class="help-widget" rounded="lg">
|
||||
<v-card-item class="py-2">
|
||||
<template #prepend>
|
||||
<v-icon color="primary">mdi-help-circle-outline</v-icon>
|
||||
</template>
|
||||
<v-card-title class="text-subtitle-2">操作說明</v-card-title>
|
||||
<template #append>
|
||||
<v-btn
|
||||
aria-label="關閉說明" icon="mdi-close" size="small" variant="text"
|
||||
@click="helpWidgetVisible = false" />
|
||||
</template>
|
||||
</v-card-item>
|
||||
<v-divider />
|
||||
<v-card-text class="text-body-2">
|
||||
這裡先放暫時說明內容。你可以保持此視窗開啟,並繼續操作頁面上的其他功能。
|
||||
</v-card-text>
|
||||
<v-card-actions class="justify-end pt-0">
|
||||
<v-btn color="primary" size="small" variant="text" @click="helpWidgetVisible = false">
|
||||
了解
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-slide-y-reverse-transition>
|
||||
|
||||
<!-- <v-btn v-if="isMobile" class="mobile-menu-btn" color="primary" icon="mdi-menu" @click="drawer = true" /> -->
|
||||
</v-app>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { useDisplay, useTheme } from 'vuetify'
|
||||
import { getNextThemeName } from '@/utils/theme'
|
||||
import SkAdminAppBarBreadcrumbCol from './sk-admin-layout/SkAdminAppBarBreadcrumbCol.vue'
|
||||
import SkAdminAppBarFavoritesCol from './sk-admin-layout/SkAdminAppBarFavoritesCol.vue'
|
||||
import SkAdminAppBarTopCol from './sk-admin-layout/SkAdminAppBarTopCol.vue'
|
||||
import SkAdminDrawerDesktopMenu from './sk-admin-layout/SkAdminDrawerDesktopMenu.vue'
|
||||
import SkAdminDrawerMobileFavoritesPanel from './sk-admin-layout/SkAdminDrawerMobileFavoritesPanel.vue'
|
||||
import SkAdminDrawerMobileMenuPanel from './sk-admin-layout/SkAdminDrawerMobileMenuPanel.vue'
|
||||
|
||||
const emit = defineEmits([
|
||||
'logout',
|
||||
'select',
|
||||
'search',
|
||||
'action',
|
||||
'toggle-sidebar',
|
||||
'toggle-theme',
|
||||
'add-favorite',
|
||||
'remove-favorite',
|
||||
'update:isRail',
|
||||
'update:favoritesBarVisible',
|
||||
'update:breadcrumbBarVisible',
|
||||
])
|
||||
|
||||
const defaultFeatures = {
|
||||
showThemeToggle: false,
|
||||
showFavorites: true,
|
||||
showBreadcrumb: true,
|
||||
showSearch: true,
|
||||
showToolbarActions: true,
|
||||
showUserInfo: true,
|
||||
}
|
||||
|
||||
const defaultBreadcrumbConfig = {
|
||||
homeLabel: '首頁',
|
||||
homeDisabled: true,
|
||||
homeIcon: 'mdi-home',
|
||||
}
|
||||
|
||||
const props = defineProps({
|
||||
systemTitle: { type: String, default: '管理系統' },
|
||||
systemSubtitle: { type: String, default: 'Campus System' },
|
||||
themeToggleLabel: { type: String, default: '切換主題' },
|
||||
logoutLabel: { type: String, default: '登出' },
|
||||
sidebarToggleLabel: { type: String, default: '切換側欄' },
|
||||
favoriteHeaderLabel: { type: String, default: '我的最愛' },
|
||||
favoriteItems: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
menuItems: {
|
||||
type: Array,
|
||||
default: () => [
|
||||
{ title: '首頁', path: '/' },
|
||||
],
|
||||
},
|
||||
userProfile: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
name: '王小明',
|
||||
role: '資訊工程系 - 學生',
|
||||
avatarText: '王',
|
||||
}),
|
||||
},
|
||||
searchConfig: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
placeholder: '搜尋功能名稱... (試試「成績」、「選課」、「請假」)',
|
||||
label: '搜尋',
|
||||
}),
|
||||
},
|
||||
toolbarActions: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
notificationsLabel: '通知',
|
||||
messagesLabel: '訊息',
|
||||
helpLabel: '說明',
|
||||
settingsLabel: '設定',
|
||||
}),
|
||||
},
|
||||
toolbarCounts: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
notifications: 0,
|
||||
messages: 0,
|
||||
}),
|
||||
},
|
||||
favoritesConfig: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
label: '常用',
|
||||
addLabel: '新增常用',
|
||||
showAdd: false,
|
||||
}),
|
||||
},
|
||||
breadcrumbConfig: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
homeLabel: '首頁',
|
||||
homeDisabled: true,
|
||||
homeIcon: 'mdi-home',
|
||||
}),
|
||||
},
|
||||
breadcrumbItems: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
favoritesBarVisible: {
|
||||
type: [Boolean, null],
|
||||
default: null,
|
||||
},
|
||||
breadcrumbBarVisible: {
|
||||
type: [Boolean, null],
|
||||
default: null,
|
||||
},
|
||||
isRail: {
|
||||
type: [Boolean, null],
|
||||
default: null,
|
||||
},
|
||||
features: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
showThemeToggle: false,
|
||||
showFavorites: true,
|
||||
showBreadcrumb: true,
|
||||
showSearch: true,
|
||||
showToolbarActions: true,
|
||||
showUserInfo: true,
|
||||
showMenuHeader: false,
|
||||
}),
|
||||
},
|
||||
drawerConfig: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
width: 280,
|
||||
railWidth: 56,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
// Feature toggle: UI 區塊顯示
|
||||
const features = computed(() => ({ ...defaultFeatures, ...props.features }))
|
||||
|
||||
// i18n / constants
|
||||
const branding = computed(() => ({
|
||||
title: props.systemTitle,
|
||||
subtitle: props.systemSubtitle,
|
||||
}))
|
||||
|
||||
// feature toggles & layout
|
||||
const display = useDisplay()
|
||||
const isMobile = computed(() => display.mdAndDown.value)
|
||||
const drawer = ref(true)
|
||||
const mobileFavoritesPanel = ref(false)
|
||||
const localIsRail = ref(false)
|
||||
const isRail = computed({
|
||||
get: () => (props.isRail ?? localIsRail.value),
|
||||
set: (value) => {
|
||||
if (props.isRail === null) {
|
||||
localIsRail.value = value
|
||||
return
|
||||
}
|
||||
emit('update:isRail', value)
|
||||
},
|
||||
})
|
||||
const opened = ref([])
|
||||
const appBarRef = ref(null)
|
||||
const appBarHeight = ref(0)
|
||||
const helpWidgetVisible = ref(false)
|
||||
const drawerWidth = computed(() => props.drawerConfig?.width)
|
||||
const railWidth = computed(() => props.drawerConfig?.railWidth)
|
||||
|
||||
// i18n computed text
|
||||
const searchValue = ref('')
|
||||
|
||||
// links/settings refs
|
||||
const theme = useTheme()
|
||||
const availableThemeNames = computed(() =>
|
||||
Object.keys(theme.themes.value ?? {}).filter((name) => name.startsWith('theme'))
|
||||
)
|
||||
|
||||
// composed computed objects
|
||||
const breadcrumbConfig = computed(() => ({ ...defaultBreadcrumbConfig, ...props.breadcrumbConfig }))
|
||||
|
||||
const breadcrumbItems = computed(() => {
|
||||
if (props.breadcrumbItems?.length) return props.breadcrumbItems
|
||||
return [
|
||||
{
|
||||
title: breadcrumbConfig.value.homeLabel,
|
||||
disabled: breadcrumbConfig.value.homeDisabled,
|
||||
icon: breadcrumbConfig.value.homeIcon,
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
// event handlers / API
|
||||
function toggleTheme () {
|
||||
const names = availableThemeNames.value
|
||||
if (names.length === 0) return
|
||||
|
||||
const current = theme.global.name.value
|
||||
const next = getNextThemeName(names, current)
|
||||
if (!next) return
|
||||
theme.change(next)
|
||||
emit('toggle-theme', next)
|
||||
}
|
||||
|
||||
function toggleSidebar () {
|
||||
if (isMobile.value) {
|
||||
drawer.value = !drawer.value
|
||||
} else {
|
||||
isRail.value = !isRail.value
|
||||
}
|
||||
emit('toggle-sidebar', { drawer: drawer.value, rail: isRail.value })
|
||||
}
|
||||
|
||||
const emitLogout = () => emit('logout')
|
||||
|
||||
// 將工具列按鈕行為轉成統一的 action 事件,交由外層應用處理
|
||||
function handleAction (type) {
|
||||
if (type === 'help') {
|
||||
helpWidgetVisible.value = true
|
||||
}
|
||||
emit('action', type)
|
||||
}
|
||||
|
||||
// 以按鈕或 Enter 觸發搜尋,避免每個字都觸發
|
||||
function triggerSearch () {
|
||||
const keyword = searchValue.value
|
||||
emit('search', keyword)
|
||||
// 觸發後清空欄位,避免彈窗出現仍保留文字
|
||||
searchValue.value = ''
|
||||
}
|
||||
|
||||
function emitAddFavorite () {
|
||||
emit('add-favorite')
|
||||
}
|
||||
|
||||
function emitRemoveFavorite (item) {
|
||||
emit('remove-favorite', item)
|
||||
}
|
||||
|
||||
function handleSelectFavorite (item) {
|
||||
handleSelect(item)
|
||||
mobileFavoritesPanel.value = false
|
||||
}
|
||||
|
||||
const mobileMenuPath = ref([])
|
||||
const mobileCurrentItems = computed(() =>
|
||||
mobileMenuPath.value.reduce((items, currentItem) => currentItem?.subItems ?? [], props.menuItems || [])
|
||||
)
|
||||
const mobileCurrentLevel = computed(() => mobileMenuPath.value.length + 1)
|
||||
const mobileMenuLevels = computed(() =>
|
||||
Array.from({ length: mobileCurrentLevel.value }, (_, index) => ({
|
||||
level: index + 1,
|
||||
title: index === 0 ? '主選單' : (mobileMenuPath.value[index - 1]?.title ?? `第${index + 1}層`),
|
||||
}))
|
||||
)
|
||||
|
||||
function goToMobileLevel (level) {
|
||||
mobileFavoritesPanel.value = false
|
||||
mobileMenuPath.value = mobileMenuPath.value.slice(0, Math.max(0, level - 1))
|
||||
}
|
||||
|
||||
function openMobileFavoritesPanel () {
|
||||
mobileMenuPath.value = []
|
||||
mobileFavoritesPanel.value = true
|
||||
}
|
||||
|
||||
function handleMobileMenuClick (item) {
|
||||
if (item?.subItems?.length) {
|
||||
mobileMenuPath.value = [...mobileMenuPath.value, item]
|
||||
return
|
||||
}
|
||||
handleSelect(item)
|
||||
}
|
||||
|
||||
const localFavoritesBarVisible = ref(true)
|
||||
const localBreadcrumbBarVisible = ref(true)
|
||||
const showFavoritesBar = computed({
|
||||
get: () => (props.favoritesBarVisible ?? localFavoritesBarVisible.value),
|
||||
set: (value) => {
|
||||
if (props.favoritesBarVisible === null) {
|
||||
localFavoritesBarVisible.value = value
|
||||
return
|
||||
}
|
||||
emit('update:favoritesBarVisible', value)
|
||||
},
|
||||
})
|
||||
const showBreadcrumbBar = computed({
|
||||
get: () => (props.breadcrumbBarVisible ?? localBreadcrumbBarVisible.value),
|
||||
set: (value) => {
|
||||
if (props.breadcrumbBarVisible === null) {
|
||||
localBreadcrumbBarVisible.value = value
|
||||
return
|
||||
}
|
||||
emit('update:breadcrumbBarVisible', value)
|
||||
},
|
||||
})
|
||||
|
||||
function toggleFavoritesBar (nextValue) {
|
||||
showFavoritesBar.value = typeof nextValue === 'boolean' ? nextValue : !showFavoritesBar.value
|
||||
}
|
||||
|
||||
let appBarObserver
|
||||
// 量測 v-app-bar 實際高度(常用功能/麵包屑顯示時會改變)
|
||||
function updateAppBarHeight () {
|
||||
const el = appBarRef.value?.$el ?? appBarRef.value
|
||||
if (!el) return
|
||||
appBarHeight.value = Math.round(el.getBoundingClientRect().height || 0)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 初次量測高度
|
||||
updateAppBarHeight()
|
||||
if (typeof ResizeObserver === 'undefined') return
|
||||
const el = appBarRef.value?.$el ?? appBarRef.value
|
||||
if (!el) return
|
||||
// 監聽高度變化,讓 v-main paddingTop 同步更新
|
||||
appBarObserver = new ResizeObserver(() => updateAppBarHeight())
|
||||
appBarObserver.observe(el)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (!appBarObserver) return
|
||||
appBarObserver.disconnect()
|
||||
appBarObserver = null
|
||||
})
|
||||
|
||||
function handleUnshrink () {
|
||||
isRail.value = false
|
||||
}
|
||||
|
||||
function handleSelect (item) {
|
||||
emit('select', item)
|
||||
if (isMobile.value) drawer.value = false
|
||||
}
|
||||
|
||||
const mainStyle = computed(() => {
|
||||
const appBarHeightValue = appBarHeight.value
|
||||
return {
|
||||
// 以 paddingTop 騰出 appBar 空間,避免內容被遮擋
|
||||
paddingTop: appBarHeightValue ? `${appBarHeightValue}px` : undefined,
|
||||
// 固定 v-main 高度,讓內容區塊能在固定高度內滾動
|
||||
height: '100vh',
|
||||
minHeight: 0,
|
||||
flex: '1 1 0',
|
||||
}
|
||||
})
|
||||
|
||||
// watch(isMobile, (value) => {
|
||||
// if (value) {
|
||||
// isRail.value = false
|
||||
// }
|
||||
// })
|
||||
watch(isMobile, (value) => {
|
||||
if (!value) {
|
||||
mobileFavoritesPanel.value = false
|
||||
mobileMenuPath.value = []
|
||||
}
|
||||
})
|
||||
watch(drawer, (value) => {
|
||||
if (!value) {
|
||||
mobileFavoritesPanel.value = false
|
||||
mobileMenuPath.value = []
|
||||
}
|
||||
})
|
||||
|
||||
function getMobileMenuBtnVariant (level) {
|
||||
return !mobileFavoritesPanel.value && level === mobileCurrentLevel.value
|
||||
? 'flat'
|
||||
: 'outlined'
|
||||
}
|
||||
|
||||
function getMobileMenuBtnColor (level) {
|
||||
return level === mobileCurrentLevel.value ? 'primary' : 'secondary'
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.sk-admin-layout {
|
||||
background: rgb(var(--v-theme-background));
|
||||
}
|
||||
|
||||
.sk-admin-drawer {
|
||||
border-right: 1px solid rgb(var(--v-theme-surface-variant));
|
||||
}
|
||||
|
||||
/* 第二層選單Padding */
|
||||
:deep(.sk-admin-drawer .v-list-group__items) {
|
||||
--indent-padding: 12px;
|
||||
}
|
||||
|
||||
/* 第三層選單Padding */
|
||||
:deep(.sk-admin-drawer .v-list-group__items .v-list-group__items) {
|
||||
--indent-padding: 20px;
|
||||
}
|
||||
|
||||
.menu-count {
|
||||
min-width: 28px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.content-area {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1 1 0;
|
||||
min-height: 0;
|
||||
padding: 8px;
|
||||
padding-top: 4px;
|
||||
background: rgb(var(--v-theme-background));
|
||||
}
|
||||
|
||||
|
||||
|
||||
.search-input-wrapper {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
:deep(.search-input-wrapper .v-field--appended) {
|
||||
padding-inline-end: 4px;
|
||||
}
|
||||
|
||||
.top-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.favorites-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
padding: 12px 16px;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.favorites-label {
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.mobile-favorites-panel,
|
||||
.mobile-menu-panel {
|
||||
min-height: 0;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.mobile-menu-subheader {
|
||||
border-bottom: 1px solid rgb(var(--v-theme-surface-variant));
|
||||
}
|
||||
|
||||
.favorites-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.favorite-item,
|
||||
.favorite-add {
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
.mobile-menu-btn {
|
||||
position: fixed;
|
||||
right: 20px;
|
||||
bottom: 20px;
|
||||
z-index: 200;
|
||||
box-shadow: 0 10px 24px rgba(var(--v-theme-on-surface), 0.25);
|
||||
}
|
||||
|
||||
.help-widget {
|
||||
position: fixed;
|
||||
right: 16px;
|
||||
bottom: 16px;
|
||||
z-index: 220;
|
||||
width: min(360px, calc(100vw - 32px));
|
||||
border: 1px solid rgb(var(--v-theme-surface-variant));
|
||||
box-shadow: 0 12px 24px rgba(var(--v-theme-on-surface), 0.15);
|
||||
}
|
||||
|
||||
.nav-text-overflow {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* 確保 v-list-group 的 activator 也有 hover 效果 */
|
||||
:deep(.v-list-group > .v-list-item) {
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease, color 0.2s ease;
|
||||
}
|
||||
|
||||
:deep(.v-list-group > .v-list-item:hover) {
|
||||
background: rgb(var(--v-theme-on-surface-variant));
|
||||
color: rgb(var(--v-theme-on-surface));
|
||||
}
|
||||
|
||||
/* 為所有 v-list-item 加上 transition */
|
||||
:deep(.v-list-item) {
|
||||
transition: background-color 0.2s ease, color 0.2s ease;
|
||||
}
|
||||
|
||||
/* 確保滾軸邊距 */
|
||||
:deep(.v-navigation-drawer__content) {
|
||||
/* scrollbar-gutter: stable; */
|
||||
}
|
||||
|
||||
@supports not (scrollbar-gutter: stable) {
|
||||
:deep(.v-navigation-drawer__content) {
|
||||
/* overflow-y: scroll; */
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,13 @@
|
||||
<template>
|
||||
<v-app>
|
||||
<v-main>
|
||||
<v-container class="pa-0" fluid height="100%">
|
||||
<slot></slot>
|
||||
</v-container>
|
||||
</v-main>
|
||||
</v-app>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
// 完全空白的佈局,僅提供 Vuetify 必要的容器結構
|
||||
</script>
|
||||
@@ -0,0 +1,251 @@
|
||||
<template>
|
||||
<v-app>
|
||||
<v-navigation-drawer v-model="drawer">
|
||||
<v-list v-model:opened="opened" color="primary" density="compact" prepend-gap="8">
|
||||
<!-- 收藏項目區塊 -->
|
||||
<template v-if="favoriteItems?.length">
|
||||
<v-list-subheader class="bg-primary-variant" color="on-primary">
|
||||
<div class="d-flex align-center w-100">
|
||||
<span class="flex-grow-1">{{ favoriteHeaderLabel }}</span>
|
||||
<v-btn
|
||||
density="compact" icon="mdi-unfold-less-horizontal" :ripple="false" variant="text"
|
||||
@click.stop="collapseFavoriteGroups" />
|
||||
</div>
|
||||
</v-list-subheader>
|
||||
<template v-for="item in favoriteItems" :key="item.path ?? item.title">
|
||||
<!-- 第一層:有子項目的群組 -->
|
||||
<v-list-group v-if="item.subItems?.length" :value="`fav:${item.path ?? item.title}`">
|
||||
<template #activator="{ props }">
|
||||
<v-list-item v-bind="props" :link="isNavigable(item)" :to="isNavigable(item) ? item.path : undefined">
|
||||
<!-- 第一層 title(父層) -->
|
||||
<template #title>
|
||||
<span class="text-body-2 nav-text-overflow">{{ item.title }}</span>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
<template v-for="subItem in item.subItems" :key="subItem.path ?? subItem.title">
|
||||
<!-- 第二層:無子項目的單一項目 -->
|
||||
<v-list-item :link="!!subItem.path" :to="subItem.path">
|
||||
<!-- 第二層 title(葉節點) -->
|
||||
<template #title>
|
||||
<v-tooltip location="end" :text="subItem.title">
|
||||
<template #activator="{ props: tooltipProps }">
|
||||
<span v-bind="tooltipProps" class="text-body-2 nav-text-overflow">{{ subItem.title }}</span>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
</v-list-group>
|
||||
<!-- 第一層:無子項目的單一項目 -->
|
||||
<v-list-item v-else :link="!!item.path" :to="item.path">
|
||||
<!-- 第一層 title(葉節點) -->
|
||||
<template #title>
|
||||
<v-tooltip location="end" :text="item.title">
|
||||
<template #activator="{ props: tooltipProps }">
|
||||
<span v-bind="tooltipProps" class="text-body-2 nav-text-overflow">{{ item.title }}</span>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<v-list-subheader class="bg-primary" color="on-primary">
|
||||
<div class="d-flex align-center w-100">
|
||||
<span class="flex-grow-1">{{ menuHeaderLabel }}</span>
|
||||
<v-btn
|
||||
density="compact" icon="mdi-unfold-less-horizontal" :ripple="false" variant="text"
|
||||
@click.stop="collapseMenuGroups" />
|
||||
</div>
|
||||
</v-list-subheader>
|
||||
<!-- 主選單區塊 -->
|
||||
<template v-for="item in menuItems" :key="item.path ?? item.title">
|
||||
<!-- 第一層:有子項目的群組 -->
|
||||
<v-list-group v-if="item.subItems?.length" :value="`menu:${item.path ?? item.title}`">
|
||||
<template #activator="{ props }">
|
||||
<v-list-item
|
||||
v-bind="props" :link="isNavigable(item) && !!item.path"
|
||||
:to="isNavigable(item) ? item.path : undefined">
|
||||
<!-- 第一層 title(父層) -->
|
||||
<template #title>
|
||||
<span class="text-body-2 nav-text-overflow">{{ item.title }}</span>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
<template v-for="subItem in item.subItems" :key="subItem.path ?? subItem.title">
|
||||
<!-- 第二層:有子項目的群組 -->
|
||||
<v-list-group
|
||||
v-if="subItem.subItems?.length"
|
||||
:value="`menu:${item.path ?? item.title}::${subItem.path ?? subItem.title}`">
|
||||
<template #activator="{ props: subProps }">
|
||||
<v-list-item
|
||||
v-bind="subProps" :link="isNavigable(subItem)"
|
||||
:to="isNavigable(subItem) ? subItem.path : undefined">
|
||||
<!-- 第二層 title(父層) -->
|
||||
<template #title>
|
||||
<span class="text-body-2 nav-text-overflow">{{ subItem.title }}</span>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
|
||||
<!-- 第三層:最底層項目 -->
|
||||
<v-list-item
|
||||
v-for="subSubItem in subItem.subItems" :key="subSubItem.path ?? subSubItem.title"
|
||||
:link="!!subSubItem.path" :to="subSubItem.path">
|
||||
<!-- 第三層 title(葉節點) -->
|
||||
<template #title>
|
||||
<v-tooltip location="end" :text="subSubItem.title">
|
||||
<template #activator="{ props: tooltipProps }">
|
||||
<span v-bind="tooltipProps" class="text-body-2 nav-text-overflow">{{ subSubItem.title }}</span>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</v-list-group>
|
||||
|
||||
<!-- 第二層:無子項目的單一項目 -->
|
||||
<v-list-item v-else :link="!!subItem.path" :to="subItem.path">
|
||||
<!-- 第二層 title(葉節點) -->
|
||||
<template #title>
|
||||
<v-tooltip location="end" :text="subItem.title">
|
||||
<template #activator="{ props: tooltipProps }">
|
||||
<span v-bind="tooltipProps" class="text-body-2 nav-text-overflow">{{ subItem.title }}</span>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
</v-list-group>
|
||||
<!-- 第一層:無子項目的單一項目 -->
|
||||
<v-list-item v-else :link="!!item.path" :to="item.path">
|
||||
<!-- 第一層 title(葉節點) -->
|
||||
<template #title>
|
||||
<v-tooltip location="end" :text="item.title">
|
||||
<template #activator="{ props: tooltipProps }">
|
||||
<span v-bind="tooltipProps" class="text-body-2 nav-text-overflow">{{ item.title }}</span>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
</v-list>
|
||||
</v-navigation-drawer>
|
||||
|
||||
<v-app-bar density="compact">
|
||||
<v-app-bar-nav-icon @click="drawer = !drawer" />
|
||||
<v-toolbar-title>{{ systemTitle }}</v-toolbar-title>
|
||||
<v-spacer />
|
||||
<v-tooltip location="bottom" :text="themeToggleLabel">
|
||||
<template #activator="{ props }">
|
||||
<v-btn v-bind="props" :aria-label="themeToggleLabel" icon="mdi-palette" variant="text" @click="toggleTheme" />
|
||||
</template>
|
||||
</v-tooltip>
|
||||
|
||||
<v-tooltip location="bottom" :text="logoutLabel">
|
||||
<template #activator="{ props }">
|
||||
<v-btn v-bind="props" :aria-label="logoutLabel" icon="mdi-logout" variant="text" @click="$emit('logout')" />
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</v-app-bar>
|
||||
|
||||
<v-main>
|
||||
<v-container class="pa-2" fluid height="100%">
|
||||
<slot></slot>
|
||||
</v-container>
|
||||
</v-main>
|
||||
</v-app>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { useTheme } from 'vuetify'
|
||||
import { getNextThemeName } from '@/utils/theme'
|
||||
|
||||
defineEmits(['logout'])
|
||||
|
||||
defineProps({
|
||||
systemTitle: { type: String, default: '管理系統' },
|
||||
themeToggleLabel: { type: String, default: '切換主題' },
|
||||
logoutLabel: { type: String, default: '登出' },
|
||||
favoriteHeaderLabel: { type: String, default: '我的最愛' },
|
||||
menuHeaderLabel: { type: String, default: '選單' },
|
||||
favoriteItems: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
menuItems: {
|
||||
type: Array,
|
||||
default: () => [
|
||||
{ title: '首頁', path: '/' },
|
||||
{ title: '設定', path: '/settings' },
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
const drawer = ref(true)
|
||||
|
||||
const opened = ref([])
|
||||
|
||||
const theme = useTheme()
|
||||
|
||||
const availableThemeNames = computed(() =>
|
||||
Object.keys(theme.themes.value ?? {}).filter((name) => name.startsWith('theme'))
|
||||
)
|
||||
|
||||
function toggleTheme () {
|
||||
const names = availableThemeNames.value
|
||||
if (names.length === 0) return
|
||||
|
||||
const current = theme.global.name.value
|
||||
const next = getNextThemeName(names, current)
|
||||
if (!next) return
|
||||
theme.change(next)
|
||||
}
|
||||
|
||||
function collapseFavoriteGroups () {
|
||||
opened.value = opened.value.filter((key) => !String(key).startsWith('fav:'))
|
||||
}
|
||||
|
||||
function collapseMenuGroups () {
|
||||
opened.value = opened.value.filter((key) => !String(key).startsWith('menu:'))
|
||||
}
|
||||
|
||||
const isNavigable = (item) => item?.navigable !== false
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.nav-text-overflow {
|
||||
display: inline-block;
|
||||
max-width: 100%;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* 確保 v-list-group 的 activator 也有 hover 效果 */
|
||||
:deep(.v-list-group > .v-list-item) {
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease, color 0.2s ease;
|
||||
}
|
||||
|
||||
:deep(.v-list-group > .v-list-item:hover) {
|
||||
background: rgb(var(--v-theme-on-surface-variant));
|
||||
color: rgb(var(--v-theme-on-surface));
|
||||
}
|
||||
|
||||
/* 為所有 v-list-item 加上 transition */
|
||||
:deep(.v-list-item) {
|
||||
transition: background-color 0.2s ease, color 0.2s ease;
|
||||
}
|
||||
|
||||
:deep(.v-navigation-drawer__content) {
|
||||
scrollbar-gutter: stable;
|
||||
}
|
||||
|
||||
@supports not (scrollbar-gutter: stable) {
|
||||
:deep(.v-navigation-drawer__content) {
|
||||
overflow-y: scroll;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,118 @@
|
||||
<template>
|
||||
<v-app>
|
||||
<v-app-bar color="surface">
|
||||
<v-toolbar-title>{{ systemTitle }}</v-toolbar-title>
|
||||
<v-spacer />
|
||||
<v-menu
|
||||
v-model="menuOpen"
|
||||
:close-on-content-click="false"
|
||||
:location="menuLocation"
|
||||
:max-height="menuMaxHeight"
|
||||
offset="8"
|
||||
scroll-strategy="reposition"
|
||||
:width="menuWidth"
|
||||
>
|
||||
<template #activator="{ props }">
|
||||
<v-btn v-bind="props" icon="mdi-dots-vertical" />
|
||||
</template>
|
||||
|
||||
<v-list :density="menuDensity">
|
||||
<template v-for="(item, index) in menuItems" :key="item?.key ?? item?.path ?? index">
|
||||
<v-list-group
|
||||
v-if="smAndDown && item?.subItems?.length"
|
||||
:value="item?.key ?? item?.path ?? index"
|
||||
>
|
||||
<template #activator="{ props }">
|
||||
<v-list-item v-bind="props" :prepend-icon="item.icon" :title="item.title" />
|
||||
</template>
|
||||
|
||||
<v-list-item
|
||||
v-for="(subItem, subIndex) in item.subItems"
|
||||
:key="subItem?.key ?? subItem?.path ?? subIndex"
|
||||
class="pl-6"
|
||||
:prepend-icon="subItem.icon"
|
||||
:title="subItem.title"
|
||||
@click="handleSelect(subItem)"
|
||||
/>
|
||||
</v-list-group>
|
||||
|
||||
<v-menu
|
||||
v-else-if="item?.subItems?.length"
|
||||
close-delay="120"
|
||||
:close-on-content-click="false"
|
||||
location="end top"
|
||||
offset="0"
|
||||
open-delay="80"
|
||||
:open-on-hover="submenuOpenOnHover"
|
||||
origin="start top"
|
||||
scroll-strategy="reposition"
|
||||
submenu
|
||||
>
|
||||
<template #activator="{ props }">
|
||||
<v-list-item
|
||||
v-bind="props"
|
||||
append-icon="mdi-chevron-right"
|
||||
:prepend-icon="item.icon"
|
||||
:title="item.title"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<v-list :density="menuDensity">
|
||||
<v-list-item
|
||||
v-for="(subItem, subIndex) in item.subItems"
|
||||
:key="subItem?.key ?? subItem?.path ?? subIndex"
|
||||
:prepend-icon="subItem.icon"
|
||||
:title="subItem.title"
|
||||
@click="handleSelect(subItem)"
|
||||
/>
|
||||
</v-list>
|
||||
</v-menu>
|
||||
|
||||
<v-list-item
|
||||
v-else
|
||||
:prepend-icon="item.icon"
|
||||
:title="item.title"
|
||||
@click="handleSelect(item)"
|
||||
/>
|
||||
</template>
|
||||
</v-list>
|
||||
</v-menu>
|
||||
</v-app-bar>
|
||||
|
||||
<v-main>
|
||||
<v-container fluid height="100%">
|
||||
<slot></slot>
|
||||
</v-container>
|
||||
</v-main>
|
||||
</v-app>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { useDisplay } from 'vuetify'
|
||||
|
||||
const emit = defineEmits(['select'])
|
||||
|
||||
defineProps({
|
||||
systemTitle: { type: String, default: '簡潔模式' },
|
||||
menuItems: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
})
|
||||
|
||||
const menuOpen = ref(false)
|
||||
|
||||
const { smAndDown } = useDisplay()
|
||||
|
||||
const menuDensity = computed(() => (smAndDown.value ? 'default' : 'compact'))
|
||||
const menuWidth = computed(() => (smAndDown.value ? 280 : 240))
|
||||
const menuMaxHeight = computed(() => (smAndDown.value ? 420 : 360))
|
||||
const menuLocation = computed(() => (smAndDown.value ? 'bottom end' : 'bottom end'))
|
||||
const submenuOpenOnHover = computed(() => !smAndDown.value)
|
||||
|
||||
function handleSelect (item) {
|
||||
menuOpen.value = false
|
||||
emit('select', item)
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,39 @@
|
||||
<template>
|
||||
<v-col
|
||||
v-if="features.showBreadcrumb && showBreadcrumbBar && !isMobile"
|
||||
class="d-flex align-center justify-space-between pr-2 pl-3 py-1 bg-surface">
|
||||
<v-breadcrumbs class="pa-0" density="compact" :items="breadcrumbItems">
|
||||
<template #prepend>
|
||||
<v-btn
|
||||
v-if="features.showFavorites && !showFavoritesBar" class="mr-2" color="primary" size="small"
|
||||
variant="outlined" @click="emit('toggle-favorites-bar', true)">
|
||||
常用
|
||||
</v-btn>
|
||||
</template>
|
||||
<template #item="{ item }">
|
||||
<div class="d-flex align-center ga-1">
|
||||
<v-icon v-if="item.icon" class="mr-1" size="14">{{ item.icon }}</v-icon>
|
||||
<span class="text-caption text-no-wrap">{{ item.title }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template #divider>
|
||||
<v-icon color="primary-variant" size="12">mdi-chevron-right</v-icon>
|
||||
</template>
|
||||
</v-breadcrumbs>
|
||||
<div class="page-actions">
|
||||
<slot name="breadcrumb-actions"></slot>
|
||||
</div>
|
||||
</v-col>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
defineProps({
|
||||
features: { type: Object, default: () => ({}) },
|
||||
showBreadcrumbBar: { type: Boolean, default: true },
|
||||
isMobile: { type: Boolean, default: false },
|
||||
breadcrumbItems: { type: Array, default: () => [] },
|
||||
showFavoritesBar: { type: Boolean, default: true },
|
||||
})
|
||||
|
||||
const emit = defineEmits(['toggle-favorites-bar'])
|
||||
</script>
|
||||
@@ -0,0 +1,59 @@
|
||||
<template>
|
||||
<v-col
|
||||
v-if="features.showFavorites && showFavoritesBar && !isMobile"
|
||||
class="d-flex align-center pr-2 pl-3 py-1 bg-surface">
|
||||
<div class="favorites-label text-body-2 text-no-wrap pe-2">
|
||||
{{ favoritesConfig.label }}
|
||||
</div>
|
||||
<div class="favorites-list flex-grow-1 d-flex flex-wrap ga-2">
|
||||
<transition-group class="d-flex flex-wrap ga-2" name="favorite-list" tag="div">
|
||||
<v-chip
|
||||
v-for="item in favoriteItems" :key="item.path ?? item.title" class="favorite-item" closable
|
||||
color="secondary" size="small" variant="outlined" @click="emit('select', item)"
|
||||
@click:close="emit('remove-favorite', item)">
|
||||
<v-icon v-if="item.icon" class="me-1" size="16">{{ item.icon }}</v-icon>
|
||||
<span class="text-caption">{{ item.title }}</span>
|
||||
</v-chip>
|
||||
</transition-group>
|
||||
<v-btn
|
||||
v-if="favoritesConfig.showAdd" class="favorite-add" color="primary" size="small" variant="outlined"
|
||||
@click="emit('add-favorite')">
|
||||
<v-icon class="mr-1" size="16">mdi-plus</v-icon>
|
||||
<span class="text-caption">{{ favoritesConfig.addLabel }}</span>
|
||||
</v-btn>
|
||||
</div>
|
||||
<v-btn color="grey" size="small" variant="text" @click="emit('toggle-favorites-bar', false)">
|
||||
<v-icon>mdi-eye-off</v-icon>
|
||||
</v-btn>
|
||||
</v-col>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
defineProps({
|
||||
features: { type: Object, default: () => ({}) },
|
||||
showFavoritesBar: { type: Boolean, default: true },
|
||||
isMobile: { type: Boolean, default: false },
|
||||
favoritesConfig: { type: Object, default: () => ({}) },
|
||||
favoriteItems: { type: Array, default: () => [] },
|
||||
})
|
||||
|
||||
const emit = defineEmits(['select', 'add-favorite', 'remove-favorite', 'toggle-favorites-bar'])
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.favorite-item {
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
.favorite-list-enter-active,
|
||||
.favorite-list-leave-active,
|
||||
.favorite-list-move {
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.favorite-list-enter-from,
|
||||
.favorite-list-leave-to {
|
||||
opacity: 0;
|
||||
transform: scale(0.92);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,184 @@
|
||||
<template>
|
||||
<v-col class="d-flex align-center bg-surface pr-2 pl-2 pl-m-3 py-1">
|
||||
<v-btn v-if="isMobile" icon="mdi-menu" size="small" variant="text" @click="emit('toggle-drawer')"></v-btn>
|
||||
|
||||
<div v-if="features.showSearch" class="search-input-wrapper">
|
||||
<v-text-field
|
||||
v-model="searchValueModel" :aria-label="searchConfig.label" class="search-input" density="compact"
|
||||
hide-details :placeholder="searchConfig.placeholder" variant="outlined"
|
||||
@keyup.enter="triggerSearch">
|
||||
<template v-if="!isMobile" #prepend-inner>
|
||||
<v-icon size="small">mdi-magnify</v-icon>
|
||||
</template>
|
||||
<template #append-inner>
|
||||
<v-btn :aria-label="searchConfig.label" color="primary" size="small" variant="text" @click="triggerSearch">
|
||||
開始搜尋
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-text-field>
|
||||
</div>
|
||||
|
||||
<div v-if="features.showToolbarActions" class="top-actions">
|
||||
<slot name="actions">
|
||||
|
||||
<!-- 通知 -->
|
||||
<v-tooltip location="bottom" :text="toolbarActions.notificationsLabel">
|
||||
<template #activator="{ props }">
|
||||
<v-btn
|
||||
v-bind="props" :aria-label="toolbarActions.notificationsLabel" icon size="small" variant="text"
|
||||
@click="emit('action', 'notifications')">
|
||||
<v-badge
|
||||
v-if="toolbarCounts.notifications" color="error" :content="toolbarCounts.notifications"
|
||||
offset-x="4" offset-y="-2">
|
||||
<v-icon>mdi-bell-outline</v-icon>
|
||||
</v-badge>
|
||||
<v-icon v-else>mdi-bell-outline</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
|
||||
<!-- 訊息 -->
|
||||
<v-tooltip location="bottom" :text="toolbarActions.messagesLabel">
|
||||
<template #activator="{ props }">
|
||||
<v-btn
|
||||
v-bind="props" :aria-label="toolbarActions.messagesLabel" icon size="small" variant="text"
|
||||
@click="emit('action', 'messages')">
|
||||
<v-badge
|
||||
v-if="toolbarCounts.messages" color="warning" :content="toolbarCounts.messages" offset-x="4"
|
||||
offset-y="-2">
|
||||
<v-icon>mdi-message-text-outline</v-icon>
|
||||
</v-badge>
|
||||
<v-icon v-else>mdi-message-text-outline</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
|
||||
<!-- 說明 -->
|
||||
<v-tooltip v-if="false" location="bottom" :text="toolbarActions.helpLabel">
|
||||
<template #activator="{ props }">
|
||||
<v-btn
|
||||
v-bind="props" :aria-label="toolbarActions.helpLabel" icon size="small" variant="text"
|
||||
@click="emit('action', 'help')">
|
||||
<v-icon>mdi-help</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
|
||||
<!-- 設定 -->
|
||||
<v-menu :close-on-content-click="false" location="bottom end">
|
||||
<template #activator="{ props: menuProps }">
|
||||
<v-tooltip location="bottom" :text="toolbarActions.settingsLabel">
|
||||
<template #activator="{ props: tooltipProps }">
|
||||
<v-btn
|
||||
v-bind="{ ...menuProps, ...tooltipProps }" :aria-label="toolbarActions.settingsLabel" icon size="small"
|
||||
variant="text">
|
||||
<v-icon>mdi-cog-outline</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
<v-list density="compact" width="180">
|
||||
<v-list-subheader class="text-subtitle-1 py-2">顯示設定</v-list-subheader>
|
||||
<v-list-item>
|
||||
<v-switch v-model="showFavoritesBarModel" color="primary" density="comfortable" hide-details>
|
||||
<template #label>
|
||||
<span class="text-body-2" style="width: 8ch;">常用功能</span>
|
||||
</template>
|
||||
</v-switch>
|
||||
</v-list-item>
|
||||
<v-list-item>
|
||||
<v-switch v-model="showBreadcrumbBarModel" color="primary" density="comfortable" hide-details>
|
||||
<template #label>
|
||||
<span class="text-body-2" style="width: 8ch;">路徑</span>
|
||||
</template>
|
||||
</v-switch>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</v-menu>
|
||||
|
||||
<!-- 登出 -->
|
||||
<v-tooltip location="bottom" :text="logoutLabel">
|
||||
<template #activator="{ props }">
|
||||
<v-btn v-bind="props" :aria-label="logoutLabel" icon size="small" variant="text" @click="emit('logout')">
|
||||
<v-icon>mdi-logout</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
|
||||
<v-tooltip v-if="features.showThemeToggle" location="bottom" :text="themeToggleLabel">
|
||||
<template #activator="{ props }">
|
||||
<v-btn v-bind="props" :aria-label="themeToggleLabel" icon variant="text" @click="emit('toggle-theme')">
|
||||
<v-icon>mdi-palette-outline</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</slot>
|
||||
</div>
|
||||
</v-col>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
isMobile: { type: Boolean, default: false },
|
||||
features: { type: Object, default: () => ({}) },
|
||||
searchValue: { type: String, default: '' },
|
||||
searchConfig: { type: Object, default: () => ({}) },
|
||||
toolbarActions: { type: Object, default: () => ({}) },
|
||||
toolbarCounts: { type: Object, default: () => ({}) },
|
||||
logoutLabel: { type: String, default: '' },
|
||||
themeToggleLabel: { type: String, default: '' },
|
||||
showFavoritesBar: { type: Boolean, default: true },
|
||||
showBreadcrumbBar: { type: Boolean, default: true },
|
||||
})
|
||||
|
||||
const emit = defineEmits([
|
||||
'toggle-drawer',
|
||||
'update:searchValue',
|
||||
'search',
|
||||
'action',
|
||||
'logout',
|
||||
'toggle-theme',
|
||||
'update:showFavoritesBar',
|
||||
'update:showBreadcrumbBar',
|
||||
])
|
||||
|
||||
const searchValueModel = computed({
|
||||
get: () => props.searchValue,
|
||||
set: (value) => emit('update:searchValue', value),
|
||||
})
|
||||
|
||||
const showFavoritesBarModel = computed({
|
||||
get: () => props.showFavoritesBar,
|
||||
set: (value) => emit('update:showFavoritesBar', value),
|
||||
})
|
||||
|
||||
const showBreadcrumbBarModel = computed({
|
||||
get: () => props.showBreadcrumbBar,
|
||||
set: (value) => emit('update:showBreadcrumbBar', value),
|
||||
})
|
||||
|
||||
function triggerSearch () {
|
||||
emit('search')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.search-input-wrapper {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
:deep(.search-input-wrapper .v-field--appended) {
|
||||
padding-inline-end: 4px;
|
||||
}
|
||||
|
||||
.top-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,176 @@
|
||||
<template>
|
||||
<v-list v-model:opened="openedModel" color="primary" density="compact" prepend-gap="8">
|
||||
<template v-for="item in menuItems" :key="item.path ?? item.title">
|
||||
<v-list-group v-if="item.subItems?.length" class="menu-group" :value="`menu:${item.path ?? item.title}`">
|
||||
<template #activator="{ props }">
|
||||
<v-list-item
|
||||
v-bind="isShrink ? undefined : props" :class="{ 'px-0': isShrink }"
|
||||
:link="isNavigable(item) && !!item.path" :to="isNavigable(item) ? item.path : undefined" @click="emitSelect(item)">
|
||||
<template #prepend>
|
||||
<v-icon v-if="item.icon" size="20">{{ item.icon }}</v-icon>
|
||||
<v-btn v-if="isShrink && !item.icon" class="" rounded size="36" spaced="start" variant="text">{{
|
||||
item.title?.charAt(0) }}</v-btn>
|
||||
</template>
|
||||
<template #title>
|
||||
<span v-if="!isShrink" class="text-body-2 nav-text-overflow">{{ item.title }}</span>
|
||||
</template>
|
||||
<template #append>
|
||||
<v-chip
|
||||
v-if="!isShrink && getItemCount(item) > 0" class="menu-count" color="secondary" size="x-small"
|
||||
variant="tonal">
|
||||
{{ getItemCount(item) }}
|
||||
</v-chip>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
|
||||
<template v-for="subItem in item.subItems" :key="subItem.path ?? subItem.title">
|
||||
<v-list-group
|
||||
v-if="subItem.subItems?.length"
|
||||
class="menu-group" :value="`menu:${item.path ?? item.title}::${subItem.path ?? subItem.title}`">
|
||||
<template #activator="{ props: subProps }">
|
||||
<v-list-item
|
||||
v-bind="subProps" :link="isNavigable(subItem)"
|
||||
:prepend-icon="subItem.icon || 'mdi-menu-right'" :to="isNavigable(subItem) ? subItem.path : undefined"
|
||||
@click="emitSelect(subItem)">
|
||||
<template #title>
|
||||
<span class="text-body-2 nav-text-overflow">{{ subItem.title }}</span>
|
||||
</template>
|
||||
<template #append>
|
||||
<v-chip
|
||||
v-if="getItemCount(subItem) > 0" class="menu-count" color="secondary" size="x-small"
|
||||
variant="tonal">
|
||||
{{ getItemCount(subItem) }}
|
||||
</v-chip>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
|
||||
<v-list-item
|
||||
v-for="subSubItem in subItem.subItems" :key="subSubItem.path ?? subSubItem.title"
|
||||
:link="!!subSubItem.path" prepend-icon="mdi-circle-small" :to="subSubItem.path"
|
||||
@click="emitSelect(subSubItem)">
|
||||
<template #title>
|
||||
<v-tooltip location="end" :text="subSubItem.title">
|
||||
<template #activator="{ props: tooltipProps }">
|
||||
<span v-bind="tooltipProps" class="text-body-2 nav-text-overflow">{{ subSubItem.title }}</span>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</v-list-group>
|
||||
|
||||
<v-list-item
|
||||
v-else :link="!!subItem.path" :prepend-icon="subItem.icon || 'mdi-menu-right'" :to="subItem.path"
|
||||
@click="emitSelect(subItem)">
|
||||
<template #title>
|
||||
<v-tooltip location="end" :text="subItem.title">
|
||||
<template #activator="{ props: tooltipProps }">
|
||||
<span v-bind="tooltipProps" class="text-body-2 nav-text-overflow">{{ subItem.title }}</span>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
</v-list-group>
|
||||
|
||||
<v-list-item v-else :class="{ 'px-0': isShrink }" :link="!!item.path" :to="item.path" @click="emitSelect(item)">
|
||||
<template #prepend>
|
||||
<v-icon v-if="item.icon" size="20">{{ item.icon }}</v-icon>
|
||||
<v-btn v-if="isShrink && !item.icon" class="" rounded size="36" spaced="start" variant="text">{{
|
||||
item.title?.charAt(0) }}</v-btn>
|
||||
</template>
|
||||
<template #title>
|
||||
<v-tooltip v-if="!isShrink" location="end" :text="item.title">
|
||||
<template #activator="{ props: tooltipProps }">
|
||||
<span v-bind="tooltipProps" class="text-body-2 nav-text-overflow">{{ item.title }}</span>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
</v-list>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, watch } from 'vue'
|
||||
|
||||
interface MenuItem {
|
||||
title?: string
|
||||
path?: string
|
||||
icon?: string
|
||||
navigable?: boolean
|
||||
subItems?: MenuItem[]
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
interface Props {
|
||||
opened?: string[]
|
||||
menuItems?: MenuItem[]
|
||||
isShrink?: boolean
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
opened: () => [],
|
||||
menuItems: () => [],
|
||||
isShrink: false,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:opened': [value: string[]]
|
||||
select: [item: MenuItem]
|
||||
unshrink: []
|
||||
}>()
|
||||
|
||||
const openedModel = computed({
|
||||
get: () => (props.isShrink ? [] : props.opened),
|
||||
set: (value) => {
|
||||
if (!props.isShrink) {
|
||||
emit('update:opened', value)
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
// 當側邊欄收縮時,自動收起所有展開的子選單
|
||||
watch(() => props.isShrink, (newVal) => {
|
||||
if (newVal) {
|
||||
openedModel.value = []
|
||||
}
|
||||
})
|
||||
|
||||
const isNavigable = (item: MenuItem) => item?.navigable !== false
|
||||
|
||||
function emitSelect (item: MenuItem) {
|
||||
// 收縮狀態下點擊選單項目時,先解除收縮再進行選擇
|
||||
// 這樣可以讓使用者看到完整的選單結構和導航結果
|
||||
if (props.isShrink) {
|
||||
emit('unshrink')
|
||||
}
|
||||
emit('select', item)
|
||||
}
|
||||
|
||||
function getItemCount (item: MenuItem) {
|
||||
if (!item?.subItems?.length) return 0
|
||||
const countLeaf = (list: MenuItem[]): number =>
|
||||
(list || []).reduce((total: number, current: MenuItem) => {
|
||||
if (current?.subItems?.length) return total + countLeaf(current.subItems)
|
||||
return total + 1
|
||||
}, 0)
|
||||
return countLeaf(item.subItems)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.menu-count {
|
||||
min-width: 28px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.nav-text-overflow {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,29 @@
|
||||
<template>
|
||||
<v-sheet class="mobile-favorites-panel d-flex flex-column" color="surface">
|
||||
<v-list class="px-2 py-2 flex-grow-1 overflow-auto" density="comfortable">
|
||||
<v-list-item
|
||||
v-for="item in favoriteItems" :key="item.path ?? item.title" class="mb-1" rounded="lg"
|
||||
@click="emit('select', item)">
|
||||
<v-list-item-title class="text-body-2">{{ item.title }}</v-list-item-title>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</v-sheet>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
defineProps({
|
||||
favoriteItems: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['select'])
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-favorites-panel {
|
||||
min-height: 0;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,32 @@
|
||||
<template>
|
||||
<v-sheet class="mobile-menu-panel d-flex flex-column" color="surface">
|
||||
<v-list class="px-2 py-2 flex-grow-1 overflow-auto" density="comfortable">
|
||||
<v-list-item
|
||||
v-for="item in mobileCurrentItems" :key="item.path ?? item.title" class="mb-1" rounded="lg"
|
||||
@click="emit('item-click', item)">
|
||||
<v-list-item-title class="text-body-2">{{ item.title }}</v-list-item-title>
|
||||
<template #append>
|
||||
<v-icon size="18">{{ item.subItems?.length ? 'mdi-chevron-right' : 'mdi-arrow-top-right' }}</v-icon>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</v-sheet>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
defineProps({
|
||||
mobileCurrentItems: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['item-click'])
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-menu-panel {
|
||||
min-height: 0;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user