From b7a611307e395a815bc8dd3b0851d1b9c32417ea Mon Sep 17 00:00:00 2001 From: HashMap Date: Wed, 11 Feb 2026 20:56:08 +0800 Subject: [PATCH] =?UTF-8?q?perf(vite.config=20|=20view/sidebar):=20CI/CD?= =?UTF-8?q?=20=E6=94=AF=E6=8C=81=20|=20=E6=9E=84=E5=BB=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + 适配Jenkins 持续集成功能。 + 当版本库中出现新版本将自动构建并部署,以保证服务器版本为最新 + 侧边栏下显示当前构建版本 和 构建时间 --- src/layout/components/Sidebar/index.vue | 28 +++++++++++++++++++++++++ vite.config.js | 22 +++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue index 9acc406..502d2df 100644 --- a/src/layout/components/Sidebar/index.vue +++ b/src/layout/components/Sidebar/index.vue @@ -21,6 +21,10 @@ /> + @@ -32,6 +36,12 @@ import useAppStore from '@/store/modules/app' import useSettingsStore from '@/store/modules/settings' import usePermissionStore from '@/store/modules/permission' +const buildTime = __BUILD_TIME__ +const commitId = __COMMIT_ID__ +const formatTime = (time) => { + return time.replace('T', ' ').substring(0, 16) +} + const route = useRoute() const appStore = useAppStore() const settingsStore = useSettingsStore() @@ -101,4 +111,22 @@ const activeMenu = computed(() => { } } } +.sidebar-container { + display: flex; + flex-direction: column; + height: 100%; +} + +.menu-wrapper { + flex: 1; +} + +.sidebar-version { + padding: 10px; + font-size: 12px; + color: #999; + text-align: left; + border-top: 1px solid #eee; +} + diff --git a/vite.config.js b/vite.config.js index 63c2628..81769ba 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,13 +1,27 @@ import path from 'path' import { defineConfig, loadEnv } from 'vite' import createVitePlugins from './vite/plugins' - +import { execSync } from 'node:child_process' const baseUrl = 'http://127.0.0.1:8080' // 后端接口 // https://vitejs.dev/config/ export default defineConfig(({ mode, command }) => { const env = loadEnv(mode, process.cwd()) const { VITE_APP_ENV } = env + + + let commitId = 'unknown' + + try { + commitId = execSync('git rev-parse --short HEAD') + .toString() + .trim() + } catch (e) { + console.log('git commit not found') + } + + const buildTime = new Date().toISOString() + return { // 部署生产环境和开发环境下的URL。 // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上 @@ -75,6 +89,10 @@ export default defineConfig(({ mode, command }) => { } ] } - } + }, + define: { + __BUILD_TIME__: JSON.stringify(buildTime), + __COMMIT_ID__: JSON.stringify(commitId) + }, } })