前端小版本自动更新
This commit is contained in:
@@ -38,3 +38,18 @@
|
|||||||
- form 增加 `quantity: 1`(默认值 1)
|
- form 增加 `quantity: 1`(默认值 1)
|
||||||
- 模板增加 +/− 步进器 UI
|
- 模板增加 +/− 步进器 UI
|
||||||
- 提交数据中加入 `quantity: form.value.quantity > 0 ? form.value.quantity : 1`
|
- 提交数据中加入 `quantity: form.value.quantity > 0 ? form.value.quantity : 1`
|
||||||
|
|
||||||
|
## 后端 - 根路由增加版本字段
|
||||||
|
|
||||||
|
- `routers/api.go`:
|
||||||
|
- 添加包级变量 `GitVersion`、`GitCommit`、`BuildTime`
|
||||||
|
- `GET /api/` 响应新增 `version`、`gitCommit`、`buildTime` 三个字段
|
||||||
|
- `main.go`:`main()` 启动时将变量赋值给 `routers` 包
|
||||||
|
- `install.sh` 修复:`BUILD_TIME` 格式改 `YYYYMMDD_HHMMSS`(去空格,避免 ldflags 解析报错)
|
||||||
|
|
||||||
|
## Web 前端 - 版本定义 + Footer 显示
|
||||||
|
|
||||||
|
- `vite.config.js`:读取 `package.json` 的 `version`,通过 `define: { __APP_VERSION__ }` 注入全局常量
|
||||||
|
- `components/AppFooter.vue`:
|
||||||
|
- script 中 `const version = __APP_VERSION__`
|
||||||
|
- 模板中版权行末尾显示 `v{{ version }}`(如 `v0.1.0`)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ops_vue_js",
|
"name": "ops_vue_js",
|
||||||
"version": "0.0.0",
|
"version": "1.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
// 从 vite.config.js define 注入的全局常量
|
||||||
|
const version = __APP_VERSION__
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -13,7 +16,10 @@ const { t } = useI18n()
|
|||||||
<span class="text-gray-300 dark:text-dk-muted">·</span>
|
<span class="text-gray-300 dark:text-dk-muted">·</span>
|
||||||
<a href="https://github.com/wuwenfengmi1998" target="_blank" class="hover:text-gray-700 dark:hover:text-dk-text" rel="noopener">{{ t('footer.author_home') }}</a>
|
<a href="https://github.com/wuwenfengmi1998" target="_blank" class="hover:text-gray-700 dark:hover:text-dk-text" rel="noopener">{{ t('footer.author_home') }}</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-sm text-gray-400">{{ t('footer.copy') }}</div>
|
<div class="text-sm text-gray-400">
|
||||||
|
{{ t('footer.copy') }}
|
||||||
|
<span class="ml-2 text-gray-300">v{{ version }}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,12 +1,34 @@
|
|||||||
import { fileURLToPath, URL } from "node:url";
|
import { fileURLToPath, URL } from "node:url";
|
||||||
|
import { readFileSync, writeFileSync } from "node:fs";
|
||||||
|
import { resolve, dirname } from "node:path";
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import vue from "@vitejs/plugin-vue";
|
import vue from "@vitejs/plugin-vue";
|
||||||
import vueDevTools from "vite-plugin-vue-devtools";
|
import vueDevTools from "vite-plugin-vue-devtools";
|
||||||
import tailwindcss from "@tailwindcss/vite";
|
import tailwindcss from "@tailwindcss/vite";
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const packageJsonPath = resolve(__dirname, "package.json");
|
||||||
|
|
||||||
|
// 读取 package.json
|
||||||
|
let packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
||||||
|
|
||||||
|
// 每次 build 时自动递增 patch 版本
|
||||||
|
const isBuild = process.argv.includes("build");
|
||||||
|
if (isBuild) {
|
||||||
|
const parts = packageJson.version.split(".");
|
||||||
|
const patch = Math.max(0, parseInt(parts[2] || "0", 10));
|
||||||
|
parts[2] = String(patch + 1);
|
||||||
|
packageJson.version = parts.join(".");
|
||||||
|
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf-8");
|
||||||
|
console.log(`[bump] version → ${packageJson.version}`);
|
||||||
|
}
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
define: {
|
||||||
|
// 全局可用 __APP_VERSION__,取自 package.json 的 version 字段
|
||||||
|
__APP_VERSION__: JSON.stringify(packageJson.version),
|
||||||
|
},
|
||||||
plugins: [vue(), vueDevTools(), tailwindcss()],
|
plugins: [vue(), vueDevTools(), tailwindcss()],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
|
|||||||
Reference in New Issue
Block a user