feat: 添加编辑页面基础版本选择功能
- 在编辑页面添加基础版本选择器 - 加载已有版本时自动填充 base_version_id - 更新版本时传递 base_version_id 参数 - 移除创建页面的调试代码 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,8 @@ const uploading = ref(false)
|
||||
const uploadProgress = ref(0)
|
||||
const uploadSpeed = ref('')
|
||||
const applications = ref<Application[]>([])
|
||||
const baseVersions = ref<{ id: number, version: string }[]>([])
|
||||
const loadingBaseVersions = ref(false)
|
||||
|
||||
const formData = ref({
|
||||
application_id: '',
|
||||
@@ -52,6 +54,7 @@ const formData = ref({
|
||||
changelog: '',
|
||||
entry_file: '',
|
||||
file: null as File | null,
|
||||
base_version_id: '' as string,
|
||||
})
|
||||
|
||||
const uploadedData = ref<UploadResponse | null>(null)
|
||||
@@ -103,6 +106,7 @@ async function fetchVersion() {
|
||||
formData.value.custom_download_url = ver.custom_download_url || ''
|
||||
formData.value.changelog = ver.changelog || ''
|
||||
formData.value.entry_file = ver.entry_file || ''
|
||||
formData.value.base_version_id = ver.base_version_id ? String(ver.base_version_id) : ''
|
||||
|
||||
// 加载已有文件信息
|
||||
if (ver.file_path && ver.file_size) {
|
||||
@@ -136,6 +140,56 @@ async function fetchApplications() {
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchBaseVersions(appId: string) {
|
||||
if (!appId) {
|
||||
baseVersions.value = []
|
||||
return
|
||||
}
|
||||
loadingBaseVersions.value = true
|
||||
try {
|
||||
const data = await api.get<{ versions: { id: number, version: string, update_type: string }[] }>(
|
||||
`/dev/versions?application_id=${appId}&update_type=full&page_size=100`
|
||||
)
|
||||
const versions = data?.versions || []
|
||||
baseVersions.value = versions.filter(v => v.update_type === 'full')
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取基础版本列表失败:', error)
|
||||
baseVersions.value = []
|
||||
}
|
||||
finally {
|
||||
loadingBaseVersions.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 监听应用变化
|
||||
watch(
|
||||
() => formData.value.application_id,
|
||||
(newAppId) => {
|
||||
if (newAppId && formData.value.update_type === 'patch') {
|
||||
fetchBaseVersions(newAppId)
|
||||
} else if (!newAppId) {
|
||||
baseVersions.value = []
|
||||
formData.value.base_version_id = ''
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
// 监听更新类型变化
|
||||
watch(
|
||||
() => formData.value.update_type,
|
||||
(newType) => {
|
||||
if (newType === 'patch' && formData.value.application_id) {
|
||||
fetchBaseVersions(formData.value.application_id)
|
||||
} else if (newType !== 'patch') {
|
||||
baseVersions.value = []
|
||||
formData.value.base_version_id = ''
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
function handleFileSelect(event: Event) {
|
||||
const target = event.target as HTMLInputElement
|
||||
if (target.files && target.files.length > 0) {
|
||||
@@ -222,6 +276,11 @@ async function handleSubmit() {
|
||||
entry_file: formData.value.entry_file,
|
||||
}
|
||||
|
||||
// 如果是补丁版本,添加基础版本ID
|
||||
if (formData.value.update_type === 'patch' && formData.value.base_version_id) {
|
||||
payload.base_version_id = Number(formData.value.base_version_id)
|
||||
}
|
||||
|
||||
console.log('[DEBUG] handleSubmit payload:', JSON.stringify(payload))
|
||||
|
||||
if (uploadedData.value) {
|
||||
@@ -523,6 +582,31 @@ onMounted(() => {
|
||||
</UiSelect>
|
||||
</div>
|
||||
|
||||
<!-- 基础版本选择(仅补丁类型) -->
|
||||
<div v-if="formData.update_type === 'patch'" class="space-y-2">
|
||||
<UiLabel>{{ t('admin.versions.createForm.baseVersion') }}</UiLabel>
|
||||
<p class="text-sm text-muted-foreground">
|
||||
{{ t('admin.versions.createForm.baseVersionDesc') }}
|
||||
</p>
|
||||
<UiSelect v-model="formData.base_version_id" :disabled="saving || loadingBaseVersions">
|
||||
<UiSelectTrigger>
|
||||
<UiSelectValue :placeholder="t('admin.versions.createForm.baseVersionPlaceholder')" />
|
||||
</UiSelectTrigger>
|
||||
<UiSelectContent>
|
||||
<UiSelectItem
|
||||
v-for="v in baseVersions"
|
||||
:key="v.id"
|
||||
:value="String(v.id)"
|
||||
>
|
||||
{{ v.version }}
|
||||
</UiSelectItem>
|
||||
</UiSelectContent>
|
||||
</UiSelect>
|
||||
<p v-if="baseVersions.length === 0 && !loadingBaseVersions" class="text-sm text-destructive">
|
||||
{{ t('admin.versions.createForm.noBaseVersion') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<UiLabel>{{ t('admin.versions.createForm.updateMethod') }}</UiLabel>
|
||||
<UiSelect v-model="formData.update_method" :disabled="saving">
|
||||
|
||||
@@ -136,11 +136,9 @@ async function fetchBaseVersions(appId: string) {
|
||||
const data = await api.get<{ versions: { id: number, version: string, update_type: string }[] }>(
|
||||
`/dev/versions?application_id=${appId}&update_type=full&page_size=100`
|
||||
)
|
||||
console.log('[DEBUG] fetchBaseVersions response:', data)
|
||||
// 只筛选全量版本
|
||||
const versions = data?.versions || []
|
||||
baseVersions.value = versions.filter(v => v.update_type === 'full')
|
||||
console.log('[DEBUG] baseVersions after filter:', baseVersions.value)
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取基础版本列表失败:', error)
|
||||
@@ -155,7 +153,6 @@ async function fetchBaseVersions(appId: string) {
|
||||
watch(
|
||||
() => formData.value.application_id,
|
||||
(newAppId) => {
|
||||
console.log('[DEBUG] application_id changed:', newAppId, 'update_type:', formData.value.update_type)
|
||||
if (newAppId && formData.value.update_type === 'patch') {
|
||||
fetchBaseVersions(newAppId)
|
||||
} else if (!newAppId) {
|
||||
@@ -171,7 +168,6 @@ watch(
|
||||
watch(
|
||||
() => formData.value.update_type,
|
||||
(newType) => {
|
||||
console.log('[DEBUG] update_type changed:', newType, 'application_id:', formData.value.application_id)
|
||||
if (newType === 'patch' && formData.value.application_id) {
|
||||
fetchBaseVersions(formData.value.application_id)
|
||||
} else if (newType !== 'patch') {
|
||||
@@ -529,11 +525,6 @@ onMounted(() => {
|
||||
</UiSelect>
|
||||
</div>
|
||||
|
||||
<!-- 调试信息 -->
|
||||
<div class="text-xs text-muted-foreground p-2 bg-muted rounded">
|
||||
DEBUG: update_type = "{{ formData.update_type }}"
|
||||
</div>
|
||||
|
||||
<!-- 基础版本选择(仅补丁类型) -->
|
||||
<div v-if="formData.update_type === 'patch'" class="space-y-2">
|
||||
<UiLabel>{{ t('admin.versions.createForm.baseVersion') }}</UiLabel>
|
||||
|
||||
Reference in New Issue
Block a user