fix: StatusBar 版本号改为从 package.json 动态注入

- electron.vite.config.ts 读取 package.json 注入 __APP_VERSION__ 全局常量
- StatusBar.vue 使用 __APP_VERSION__ 替代硬编码 v2.0
- env.d.ts 添加 __APP_VERSION__ 类型声明
This commit is contained in:
2026-07-12 00:37:06 +08:00
parent 19672045d6
commit faedfd7fa3
3 changed files with 9 additions and 2 deletions
+6
View File
@@ -1,6 +1,9 @@
import { defineConfig, externalizeDepsPlugin } from 'electron-vite' import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import { resolve } from 'path' import { resolve } from 'path'
import { readFileSync } from 'fs'
const pkg = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8'))
export default defineConfig({ export default defineConfig({
main: { main: {
@@ -17,6 +20,9 @@ export default defineConfig({
}, },
}, },
plugins: [vue()], plugins: [vue()],
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
},
server: { server: {
port: 5173, port: 5173,
}, },
@@ -2,7 +2,6 @@
import { computed } from 'vue' import { computed } from 'vue'
import { useConnectionStore } from '@renderer/stores/connection' import { useConnectionStore } from '@renderer/stores/connection'
import { useI18n } from '@renderer/i18n' import { useI18n } from '@renderer/i18n'
import { version } from '../../../../package.json'
const connStore = useConnectionStore() const connStore = useConnectionStore()
const { t } = useI18n() const { t } = useI18n()
@@ -31,7 +30,7 @@ const statusClass = computed(() => {
<span class="status-dot" :class="statusClass" /> <span class="status-dot" :class="statusClass" />
{{ statusText }} {{ statusText }}
</span> </span>
<span class="statusbar-right">JRedisDesktop v{{ version }}</span> <span class="statusbar-right">JRedisDesktop v{{ __APP_VERSION__ }}</span>
</footer> </footer>
</template> </template>
+2
View File
@@ -1,5 +1,7 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
declare const __APP_VERSION__: string
declare module '*.css' { declare module '*.css' {
const content: string const content: string
export default content export default content