feat: implement version display with commit hash and date

This commit is contained in:
2026-05-09 14:05:25 +03:00
parent debf1b165f
commit 1e7587e11b
11 changed files with 199 additions and 5 deletions

View File

@@ -0,0 +1,55 @@
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
export interface BuildVersion {
version: string
commitHash: string
buildTime: string // ISO строка, например "2025-04-03T12:34:56Z"
}
export const useVersionStore = defineStore('version', () => {
const version = ref<BuildVersion | null>(null)
const loading = ref(false)
const error = ref<string | null>(null)
async function fetchVersion() {
if (version.value) return
loading.value = true
try {
const res = await fetch('/api/build-info')
if (!res.ok) throw new Error('Failed to fetch version')
const data = await res.json()
version.value = {
version: data.version || '0.0.0',
commitHash: data.commitHash || 'unknown',
buildTime: data.buildTime || ''
}
} catch (err: any) {
console.error(err)
error.value = err.message
version.value = { version: 'dev', commitHash: 'unknown', buildTime: '' }
} finally {
loading.value = false
}
}
// Отформатированная дата сборки (только дата, без времени)
const buildDateFormatted = computed(() => {
if (!version.value?.buildTime) return ''
const date = new Date(version.value.buildTime)
if (isNaN(date.getTime())) return ''
// Формат YYYY-MM-DD (универсальный, без локализации)
return date.toISOString().split('T')[0]
})
// Полная строка версии: "Версия: 1.2.3 (build abc1234 от 2025-04-03)"
// Принимает функцию перевода для слова "от"/"from"
const getFormattedVersion = (t: (key: string) => string) => {
if (!version.value) return t('common.version') + ': ...'
const { version: ver, commitHash } = version.value
const datePart = buildDateFormatted.value ? ` ${t('common.versionFrom')} ${buildDateFormatted.value}` : ''
return `${t('common.version')}: ${ver} (build ${commitHash}${datePart})`
}
return { version, loading, error, fetchVersion, buildDateFormatted, getFormattedVersion }
})