feat: add SingleRecordMnt component for student record maintenance with search, add, edit, view, and delete functionalities

This commit is contained in:
skytek_xinliang
2026-03-26 11:24:37 +08:00
parent 507afcc99c
commit 069141794e
116 changed files with 15247 additions and 107 deletions
+667
View File
@@ -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>