fix: refine mobile navigation and settings
This commit is contained in:
@@ -369,6 +369,59 @@ export function habitActionState(cell?: { scheduled?: boolean; paused?: boolean
|
||||
return { writable: true, reason: '' }
|
||||
}
|
||||
|
||||
export function formatUserAgent(userAgent?: string | null): string {
|
||||
const ua = userAgent?.trim() ?? ''
|
||||
let device = '未知设备'
|
||||
if (/iPhone/i.test(ua)) device = 'iPhone'
|
||||
else if (/iPad/i.test(ua) || (/Macintosh/i.test(ua) && /Mobile/i.test(ua))) device = 'iPad'
|
||||
else if (/Android/i.test(ua) && /Mobile/i.test(ua)) device = 'Android 手机'
|
||||
else if (/Android/i.test(ua)) device = 'Android 平板'
|
||||
else if (/Windows/i.test(ua)) device = 'Windows'
|
||||
else if (/Macintosh|Mac OS X/i.test(ua)) device = 'Mac'
|
||||
else if (/Linux/i.test(ua)) device = 'Linux'
|
||||
|
||||
let browser = '未知浏览器'
|
||||
if (/Edg(?:e|iOS|A)?\//i.test(ua)) browser = 'Edge'
|
||||
else if (/Chrome\/|CriOS\//i.test(ua)) browser = 'Chrome'
|
||||
else if (/Firefox\/|FxiOS\//i.test(ua)) browser = 'Firefox'
|
||||
else if (/Safari\//i.test(ua) && /Version\//i.test(ua)) browser = 'Safari'
|
||||
return `${device} · ${browser}`
|
||||
}
|
||||
|
||||
export function formatLocalShortDateTime(value?: string | null, options: { timeZone?: string } = {}): string {
|
||||
const source = value?.trim()
|
||||
if (!source) return '未知时间'
|
||||
const calendar = /^(\d{4})-(\d{2})-(\d{2})T/.exec(source)
|
||||
if (calendar) {
|
||||
const [, year, month, day] = calendar
|
||||
const probe = new Date(Date.UTC(Number(year), Number(month) - 1, Number(day)))
|
||||
if (probe.getUTCFullYear() !== Number(year) || probe.getUTCMonth() + 1 !== Number(month) || probe.getUTCDate() !== Number(day)) return '未知时间'
|
||||
}
|
||||
const timezoneLess = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?$/i.test(source)
|
||||
const date = new Date(timezoneLess ? `${source}Z` : source)
|
||||
if (Number.isNaN(date.getTime())) return '未知时间'
|
||||
try {
|
||||
return new Intl.DateTimeFormat('zh-CN', { dateStyle: 'short', timeStyle: 'short', ...options }).format(date)
|
||||
} catch {
|
||||
return '未知时间'
|
||||
}
|
||||
}
|
||||
|
||||
const AUDIT_ACTIONS: Record<string, string> = {
|
||||
create: '创建', update: '更新', complete: '完成', delete: '删除', archive: '归档', restore: '恢复', move: '移动', import: '导入',
|
||||
}
|
||||
const AUDIT_ENTITIES: Record<string, string> = {
|
||||
task: '任务', list: '清单', folder: '文件夹', countdown: '倒数日', backup: '备份',
|
||||
}
|
||||
|
||||
export function formatAuditAction(action?: string | null): string {
|
||||
return action ? AUDIT_ACTIONS[action.toLowerCase()] ?? '其他操作' : '其他操作'
|
||||
}
|
||||
|
||||
export function formatAuditEntity(entityType?: string | null): string {
|
||||
return entityType ? AUDIT_ENTITIES[entityType.toLowerCase()] ?? '内容' : '内容'
|
||||
}
|
||||
|
||||
export function formatHabitApiError(detail: unknown): string {
|
||||
const source = detail && typeof detail === 'object' && !Array.isArray(detail) && 'detail' in detail
|
||||
? (detail as Record<string, unknown>).detail
|
||||
|
||||
Reference in New Issue
Block a user