2025-10-24 23:10:22 +08:00

46 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { computed } from 'vue'
// 特殊映射表slug -> pageType
const SLUG_TO_PAGE_TYPE_MAP: Record<string, string> = {
'pagetype': 'PageType',
'todo': 'ToDo',
// 可以在这里添加更多映射
}
// URL slug 处理工具函数
export function slugToPageType(slug: string): string {
if (!slug) return ''
// 优先检查特殊映射
if (SLUG_TO_PAGE_TYPE_MAP[slug]) {
return SLUG_TO_PAGE_TYPE_MAP[slug]
}
// 默认转换规则
return slug
.split('-')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ')
}
export function pageTypeToSlug(pageType: string): string {
if (!pageType) return ''
// 默认转换规则
return pageType
.split(' ')
.map(word => word.toLowerCase())
.join('-')
}
// URL参数处理组合式函数
export function usePageTypeSlug(route: any) {
const pagetypeSlug = computed(() => (route.params.entity as string) || '')
const entity = computed(() => slugToPageType(pagetypeSlug.value))
return {
pagetypeSlug,
entity
}
}