refactor: 移除min_version/base_version_id,后端自动确定基础版本
This commit is contained in:
@@ -226,7 +226,6 @@ func handleGetVersionByID(c *gin.Context) {
|
||||
"force_update": version.ForceUpdate,
|
||||
"update_strategy": version.UpdateStrategy,
|
||||
"update_method": version.UpdateMethod,
|
||||
"min_version": version.MinVersion,
|
||||
"changelog": version.Changelog,
|
||||
"status": computedStatus,
|
||||
"base_version_id": version.BaseVersionID,
|
||||
@@ -246,10 +245,8 @@ type CreateVersionRequest struct {
|
||||
ForceUpdate bool `json:"force_update"`
|
||||
UpdateStrategy string `json:"update_strategy"`
|
||||
UpdateMethod string `json:"update_method"`
|
||||
MinVersion string `json:"min_version"`
|
||||
Description string `json:"description"`
|
||||
Changelog string `json:"changelog"`
|
||||
BaseVersionID *uint `json:"base_version_id"`
|
||||
}
|
||||
|
||||
func handleCreateVersionGlobal(c *gin.Context) {
|
||||
@@ -288,11 +285,9 @@ func handleCreateVersionGlobal(c *gin.Context) {
|
||||
ForceUpdate: req.ForceUpdate,
|
||||
UpdateStrategy: req.UpdateStrategy,
|
||||
UpdateMethod: req.UpdateMethod,
|
||||
MinVersion: req.MinVersion,
|
||||
Description: req.Description,
|
||||
Changelog: req.Changelog,
|
||||
Status: "active",
|
||||
BaseVersionID: req.BaseVersionID,
|
||||
}
|
||||
|
||||
if version.UpdateStrategy == "" {
|
||||
@@ -302,6 +297,18 @@ func handleCreateVersionGlobal(c *gin.Context) {
|
||||
version.UpdateMethod = "manual"
|
||||
}
|
||||
|
||||
if version.UpdateStrategy == "forced" {
|
||||
version.ForceUpdate = true
|
||||
}
|
||||
|
||||
if version.UpdateMethod == "hot" {
|
||||
var lastFullVersion model.Version
|
||||
if err := database.DB.Where("application_id = ? AND update_method = ?", req.ApplicationID, "full").
|
||||
Order("id DESC").First(&lastFullVersion).Error; err == nil {
|
||||
version.BaseVersionID = &lastFullVersion.ID
|
||||
}
|
||||
}
|
||||
|
||||
if err := database.DB.Create(&version).Error; err != nil {
|
||||
response.Error(c, 500, "创建版本失败")
|
||||
return
|
||||
@@ -325,13 +332,10 @@ func handleCreateVersionGlobal(c *gin.Context) {
|
||||
|
||||
type UpdateVersionRequest struct {
|
||||
Version string `json:"version"`
|
||||
ForceUpdate bool `json:"force_update"`
|
||||
UpdateStrategy string `json:"update_strategy"`
|
||||
UpdateMethod string `json:"update_method"`
|
||||
MinVersion string `json:"min_version"`
|
||||
Description string `json:"description"`
|
||||
Changelog string `json:"changelog"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func handleUpdateVersionGlobal(c *gin.Context) {
|
||||
@@ -381,22 +385,21 @@ func handleUpdateVersionGlobal(c *gin.Context) {
|
||||
}
|
||||
if req.UpdateStrategy != "" {
|
||||
updates["update_strategy"] = req.UpdateStrategy
|
||||
if req.UpdateStrategy == "forced" {
|
||||
updates["force_update"] = true
|
||||
} else {
|
||||
updates["force_update"] = false
|
||||
}
|
||||
}
|
||||
if req.UpdateMethod != "" {
|
||||
updates["update_method"] = req.UpdateMethod
|
||||
}
|
||||
if req.MinVersion != "" {
|
||||
updates["min_version"] = req.MinVersion
|
||||
}
|
||||
if req.Description != "" {
|
||||
updates["description"] = req.Description
|
||||
}
|
||||
if req.Changelog != "" {
|
||||
updates["changelog"] = req.Changelog
|
||||
}
|
||||
if req.Status != "" {
|
||||
updates["status"] = req.Status
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Updates map: %+v\n", updates)
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ func handleAppCheckUpdate(c *gin.Context) {
|
||||
}
|
||||
|
||||
hasUpdate := clientVersion != latestVersion.Version
|
||||
if latestVersion.ForceUpdate {
|
||||
if latestVersion.UpdateStrategy == "forced" {
|
||||
hasUpdate = true
|
||||
}
|
||||
|
||||
@@ -104,7 +104,6 @@ func handleAppCheckUpdate(c *gin.Context) {
|
||||
"update_notes": latestVersion.Description,
|
||||
"update_strategy": latestVersion.UpdateStrategy,
|
||||
"update_method": latestVersion.UpdateMethod,
|
||||
"min_version": latestVersion.MinVersion,
|
||||
"changelog": latestVersion.Changelog,
|
||||
"files": files,
|
||||
})
|
||||
|
||||
@@ -47,7 +47,6 @@ const formData = ref({
|
||||
update_method: 'manual' as 'manual' | 'hot' | 'full',
|
||||
changelog: '',
|
||||
entry_file: '',
|
||||
base_version_id: '',
|
||||
file: null as File | null,
|
||||
})
|
||||
|
||||
@@ -96,7 +95,6 @@ async function fetchVersion() {
|
||||
formData.value.description = ver.description || ''
|
||||
formData.value.update_strategy = ver.update_strategy || 'optional'
|
||||
formData.value.update_method = ver.update_method || 'manual'
|
||||
formData.value.base_version_id = ver.base_version_id ? String(ver.base_version_id) : ''
|
||||
formData.value.changelog = ver.changelog || ''
|
||||
formData.value.entry_file = ver.entry_file || ''
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { CheckCircle, Eye, FileArchive, FilePlus, GitBranch, Loader2, Rocket, Upload, UploadCloud, X } from 'lucide-vue-next'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { toast } from 'vue-sonner'
|
||||
@@ -15,11 +15,6 @@ interface Application {
|
||||
name: string
|
||||
}
|
||||
|
||||
interface VersionOption {
|
||||
id: number
|
||||
version: string
|
||||
}
|
||||
|
||||
interface VersionFileInfo {
|
||||
file_path: string
|
||||
file_name: string
|
||||
@@ -42,7 +37,6 @@ const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const uploading = ref(false)
|
||||
const applications = ref<Application[]>([])
|
||||
const previousVersions = ref<VersionOption[]>([])
|
||||
|
||||
const formData = ref({
|
||||
application_id: '',
|
||||
@@ -52,7 +46,6 @@ const formData = ref({
|
||||
update_method: 'manual' as 'manual' | 'hot' | 'full',
|
||||
changelog: '',
|
||||
entry_file: '',
|
||||
base_version_id: '',
|
||||
file: null as File | null,
|
||||
})
|
||||
|
||||
@@ -119,21 +112,6 @@ async function fetchApplications() {
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchPreviousVersions(appId: string) {
|
||||
if (!appId)
|
||||
return
|
||||
try {
|
||||
const params = new URLSearchParams()
|
||||
params.append('application_id', appId)
|
||||
params.append('page_size', '100')
|
||||
const data = await api.get<{ versions: VersionOption[] }>(`/dev/versions?${params.toString()}`)
|
||||
previousVersions.value = data?.versions || []
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取历史版本失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
function handleFileSelect(event: Event) {
|
||||
const target = event.target as HTMLInputElement
|
||||
if (target.files && target.files.length > 0) {
|
||||
@@ -203,7 +181,6 @@ async function handleSubmit() {
|
||||
update_method: formData.value.update_method,
|
||||
changelog: formData.value.changelog,
|
||||
entry_file: formData.value.entry_file,
|
||||
base_version_id: formData.value.base_version_id ? Number(formData.value.base_version_id) : null,
|
||||
file_path: uploadedData.value.file_path,
|
||||
file_size: uploadedData.value.file_size,
|
||||
file_hash: uploadedData.value.file_hash,
|
||||
@@ -223,14 +200,6 @@ async function handleSubmit() {
|
||||
onMounted(() => {
|
||||
fetchApplications()
|
||||
})
|
||||
|
||||
watch(() => formData.value.application_id, (newAppId) => {
|
||||
formData.value.base_version_id = ''
|
||||
previousVersions.value = []
|
||||
if (newAppId) {
|
||||
fetchPreviousVersions(newAppId)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -462,30 +431,6 @@ watch(() => formData.value.application_id, (newAppId) => {
|
||||
</UiSelect>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<UiLabel>{{ t('admin.versions.createForm.baseVersion') }}</UiLabel>
|
||||
<UiSelect v-model="formData.base_version_id" :disabled="saving || !formData.application_id">
|
||||
<UiSelectTrigger>
|
||||
<UiSelectValue :placeholder="t('admin.versions.createForm.baseVersionPlaceholder')" />
|
||||
</UiSelectTrigger>
|
||||
<UiSelectContent>
|
||||
<UiSelectItem value="__none__">
|
||||
{{ t('admin.versions.createForm.noBaseVersion') }}
|
||||
</UiSelectItem>
|
||||
<UiSelectItem
|
||||
v-for="ver in previousVersions"
|
||||
:key="ver.id"
|
||||
:value="String(ver.id)"
|
||||
>
|
||||
v{{ ver.version }}
|
||||
</UiSelectItem>
|
||||
</UiSelectContent>
|
||||
</UiSelect>
|
||||
<p class="text-xs text-muted-foreground">
|
||||
{{ t('admin.versions.createForm.baseVersionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<UiLabel for="changelog">
|
||||
{{ t('admin.versions.createForm.changelog') }}
|
||||
|
||||
@@ -16,7 +16,6 @@ export const versionSchema = z.object({
|
||||
update_strategy: updateStrategySchema,
|
||||
update_method: updateMethodSchema,
|
||||
status: versionStatusSchema,
|
||||
base_version_id: z.number().nullable(),
|
||||
changelog: z.string(),
|
||||
created_at: z.string(),
|
||||
updated_at: z.string(),
|
||||
|
||||
Reference in New Issue
Block a user