Browse Source

feat: 更新全局配置,优化页面访问控制逻辑;添加关于页面到前端白名单

as
npmrun 4 days ago
parent
commit
a1d30040e3
  1. 10
      app/app.vue
  2. 24
      app/components/admin/AdminSidebarNav.vue
  3. 1
      app/composables/useGlobalConfig.ts
  4. 2
      packages/common/config/index.ts
  5. BIN
      packages/drizzle-pkg/db.sqlite

10
app/app.vue

@ -1,3 +1,13 @@
<script lang="ts" setup>
const { siteName } = useGlobalConfig()
useHead({
title: siteName.value,
meta: [
{ name: 'description', content: 'This is my site.' },
],
})
</script>
<template> <template>
<NuxtLayout> <NuxtLayout>
<NuxtRouteAnnouncer atomic /> <NuxtRouteAnnouncer atomic />

24
app/components/admin/AdminSidebarNav.vue

@ -6,10 +6,11 @@ export interface NavItem {
children?: NavItem[] children?: NavItem[]
} }
defineProps<{ const props = defineProps<{
nav: NavItem[] nav: NavItem[]
}>() }>()
const route = useRoute()
const expandedMenus = ref<Set<string>>(new Set()) const expandedMenus = ref<Set<string>>(new Set())
const toggleMenu = (label: string) => { const toggleMenu = (label: string) => {
@ -21,6 +22,27 @@ const toggleMenu = (label: string) => {
} }
const isExpanded = (label: string) => expandedMenus.value.has(label) const isExpanded = (label: string) => expandedMenus.value.has(label)
const hasMatchingChild = (item: NavItem): boolean => {
if (!item.children) return false
return item.children.some(child => child.to === route.path || hasMatchingChild(child))
}
const expandMatchingParents = () => {
for (const item of props.nav) {
if (item.children && hasMatchingChild(item)) {
expandedMenus.value.add(item.label)
}
}
}
onMounted(() => {
expandMatchingParents()
})
watch(() => route.path, () => {
expandMatchingParents()
})
</script> </script>
<template> <template>

1
app/composables/useGlobalConfig.ts

@ -38,7 +38,6 @@ export function useGlobalConfig() {
const n = config.value.siteName?.trim() const n = config.value.siteName?.trim()
return n && n.length > 0 ? n : DEFAULT_GLOBAL_CONFIG.siteName return n && n.length > 0 ? n : DEFAULT_GLOBAL_CONFIG.siteName
}), }),
allowRegister: computed(() => config.value.allowRegister),
pending, pending,
error, error,
refresh, refresh,

2
packages/common/config/index.ts

@ -19,5 +19,5 @@ export const API_ALLOWLIST: RouteRule[] = [
export const FRONTEND_LOGIN_PATH = "/auth/login" export const FRONTEND_LOGIN_PATH = "/auth/login"
export const FRONTEND_REGISTER_PATH = "/auth/register" export const FRONTEND_REGISTER_PATH = "/auth/register"
export const FRONTEND_PAGE_ALLOWLIST = new Set(["/", FRONTEND_LOGIN_PATH, FRONTEND_REGISTER_PATH]) export const FRONTEND_PAGE_ALLOWLIST = new Set(["/", FRONTEND_LOGIN_PATH, FRONTEND_REGISTER_PATH, '/about'])
export const FRONTEND_PAGE_GUEST_ONLY = new Set([FRONTEND_LOGIN_PATH, FRONTEND_REGISTER_PATH]) export const FRONTEND_PAGE_GUEST_ONLY = new Set([FRONTEND_LOGIN_PATH, FRONTEND_REGISTER_PATH])

BIN
packages/drizzle-pkg/db.sqlite

Binary file not shown.
Loading…
Cancel
Save