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