diff --git a/src/api/admin/appVersion.ts b/src/api/admin/appVersion.ts index f6db78c..7b127c7 100644 --- a/src/api/admin/appVersion.ts +++ b/src/api/admin/appVersion.ts @@ -49,6 +49,10 @@ export const createAppVersionApi = (data: AppVersionSaveData) => { return request.post({ url: '/admin/app-versions', data }) } +export const batchCreateAppVersionsApi = (data: AppVersionSaveData[]) => { + return request.post({ url: '/admin/app-versions/batch', data }) +} + export const updateAppVersionApi = (id: string | number, data: AppVersionSaveData) => { return request.post({ url: `/admin/app-versions/${id}`, data }) } diff --git a/src/views/systemManagement/AppVersionView.vue b/src/views/systemManagement/AppVersionView.vue index 33d5aff..90da577 100644 --- a/src/views/systemManagement/AppVersionView.vue +++ b/src/views/systemManagement/AppVersionView.vue @@ -8,6 +8,7 @@ import PageHeading from '@/views/components/PageHeading.vue' import { AppIcons } from '@/constants/icons' import { dateCell } from '@/utils/format' import { + batchCreateAppVersionsApi, createAppVersionApi, deleteAppVersionApi, listAppVersionsApi, @@ -43,16 +44,23 @@ const formLoading = ref(false) const editingId = ref(null) const formRef = ref() -const emptyForm: AppVersionSaveData = { - platform: 'ANDROID', +/** 新建时两个平台一起配(各自可启停),编辑时用单份。 */ +interface PlatformBlock { + enabled: boolean + data: AppVersionSaveData +} +const emptyPlatform = (platform: 'ANDROID' | 'IOS'): AppVersionSaveData => ({ + platform, versionCode: 0, versionName: '', downloadUrl: '', updateContent: '', forceUpdate: 0, minSupportedCode: 0 -} -const form = ref({ ...emptyForm }) +}) +const androidBlock = ref({ enabled: true, data: emptyPlatform('ANDROID') }) +const iosBlock = ref({ enabled: true, data: emptyPlatform('IOS') }) +const editForm = ref(emptyPlatform('ANDROID')) const rules: FormRules = { platform: [{ required: true, message: '请选择平台', trigger: 'change' }], @@ -91,13 +99,14 @@ async function fetchList() { function openCreate() { editingId.value = null - form.value = { ...emptyForm } + androidBlock.value = { enabled: true, data: emptyPlatform('ANDROID') } + iosBlock.value = { enabled: true, data: emptyPlatform('IOS') } dialogOpen.value = true } function openEdit(row: AppVersionItem) { editingId.value = row.id - form.value = { + editForm.value = { platform: row.platform, versionCode: row.versionCode, versionName: row.versionName, @@ -110,26 +119,29 @@ function openEdit(row: AppVersionItem) { } async function submit() { - if (!formRef.value) return - await formRef.value.validate(async (valid) => { - if (!valid) return - formLoading.value = true - try { - if (editingId.value) { - await updateAppVersionApi(editingId.value, form.value) - ElMessage.success('已更新') - } else { - await createAppVersionApi(form.value) - ElMessage.success('已创建') + formLoading.value = true + try { + if (editingId.value) { + await updateAppVersionApi(editingId.value, editForm.value) + ElMessage.success('已更新') + } else { + const toCreate: AppVersionSaveData[] = [] + if (androidBlock.value.enabled) toCreate.push(androidBlock.value.data) + if (iosBlock.value.enabled) toCreate.push(iosBlock.value.data) + if (toCreate.length === 0) { + ElMessage.warning('至少启用一个平台') + return } - dialogOpen.value = false - await fetchList() - } catch { - /* axios interceptor 已弹消息 */ - } finally { - formLoading.value = false + await batchCreateAppVersionsApi(toCreate) + ElMessage.success(`已创建 ${toCreate.length} 条版本`) } - }) + dialogOpen.value = false + await fetchList() + } catch { + /* axios interceptor 已弹消息 */ + } finally { + formLoading.value = false + } } async function toggleStatus(row: AppVersionItem) { @@ -241,23 +253,23 @@ const forceText = computed(() => (v: number) => (v === 1 ? '强制' : '可选升 - + + - - - - Android - iOS - - - - + (v: number) => (v === 1 ? '强制' : '可选升 /> - + - + - - - - - - - - 低于此版本的客户端一律强制升级,0=不开启 + + + + + + + + + + + + + + + +
+
+
+ Android + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ iOS + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+