优化页面、修复BUG
This commit is contained in:
24
client/src/utils/codeHighlight.ts
Normal file
24
client/src/utils/codeHighlight.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
const LANGUAGE_ALIASES: Record<string, string> = {
|
||||
js: 'javascript',
|
||||
ts: 'typescript',
|
||||
py: 'python',
|
||||
rb: 'ruby',
|
||||
sh: 'bash',
|
||||
yml: 'yaml',
|
||||
md: 'markdown',
|
||||
xml: 'xml',
|
||||
svg: 'xml',
|
||||
noise: 'xml'
|
||||
}
|
||||
|
||||
export function resolveHighlightLanguage(typeName?: string): string {
|
||||
if (!typeName) return 'plaintext'
|
||||
const key = typeName.trim().toLowerCase()
|
||||
if (!key) return 'plaintext'
|
||||
return LANGUAGE_ALIASES[key] || key
|
||||
}
|
||||
|
||||
export function isHtmlFrontendType(codeType?: { name?: string; category?: number } | null): boolean {
|
||||
if (!codeType) return false
|
||||
return codeType.category === 0 && (codeType.name || '').toLowerCase() === 'html'
|
||||
}
|
||||
22
client/src/utils/dateRange.ts
Normal file
22
client/src/utils/dateRange.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/** 格式化为 datetime-local 输入值 */
|
||||
export function formatDateTimeLocal(date: Date): string {
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`
|
||||
}
|
||||
|
||||
/** 默认范围:本月 1 日 00:00 ~ 今天 23:59 */
|
||||
export function getDefaultMonthRange(): { start: string; end: string } {
|
||||
const now = new Date()
|
||||
const start = new Date(now.getFullYear(), now.getMonth(), 1, 0, 0, 0)
|
||||
const end = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 0)
|
||||
return {
|
||||
start: formatDateTimeLocal(start),
|
||||
end: formatDateTimeLocal(end)
|
||||
}
|
||||
}
|
||||
|
||||
/** datetime-local -> API 查询参数 (YYYY-MM-DD HH:mm) */
|
||||
export function toApiDateTime(value: string): string {
|
||||
if (!value) return ''
|
||||
return value.replace('T', ' ')
|
||||
}
|
||||
Reference in New Issue
Block a user