feat(admin): 新增转码设置页面

This commit is contained in:
Zhou Weidong committed 2026-10-22 11:29:48 +08:00
1 parent 723d056fc7
commit 218196ee9f
16 files changed
+1014 -3

No files matched your search

@@ -0,0 +1,79 @@
// Author: fruit.com.cn
import { nextTick } from 'vue'
import type { ComputedRef, Ref } from 'vue'
import { ElMessage } from 'element-plus'
import type { FormInstance } from 'element-plus'
import { getMediaTranscodeProfileApi, saveMediaTranscodeProfileApi } from '@/api/admin/media'
import type { MediaTranscodeProfile } from '@/api/admin/types'
import { applyProfileToForm, buildProfilePayload } from './transcodeProfileModel'
type Translate = (key: string, named?: Record<string, unknown>) => string
interface SettingsContext {
form: MediaTranscodeProfile
formRef: Ref<FormInstance | undefined>
loading: Ref<boolean>
saving: Ref<boolean>
loadError: Ref<string>
canManage: ComputedRef<boolean>
t: Translate
}
/** 读取服务端配置并回填表单。 */
export const loadTranscodeProfile = async (context: SettingsContext): Promise<void> => {
context.loading.value = true
context.loadError.value = ''
try {
const response = await getMediaTranscodeProfileApi()
if (response.code !== 0) {
context.loadError.value = response.message || context.t('transcodeSettings.loadFailed')
return
}
applyProfileToForm(context.form, response.data)
} catch {
context.loadError.value = context.t('transcodeSettings.loadFailed')
} finally {
context.loading.value = false
}
}
const validateProfile = async (context: SettingsContext): Promise<boolean> => {
if (!context.form.ladder.length) {
ElMessage.warning(context.t('transcodeSettings.validation.atLeastOneEnabled'))
return false
}
try {
await context.formRef.value?.validate()
return true
} catch (fields) {
const firstField = Object.keys((fields || {}) as Record<string, unknown>)[0]
if (firstField) {
await nextTick()
context.formRef.value?.scrollToField(firstField)
}
ElMessage.warning(context.t('transcodeSettings.validation.fixErrors'))
return false
}
}
/** 校验并保存,成功后用服务端返回值回填。 */
export const saveTranscodeProfile = async (context: SettingsContext): Promise<void> => {
if (!context.canManage.value || context.saving.value || !(await validateProfile(context))) {
return
}
context.saving.value = true
try {
const response = await saveMediaTranscodeProfileApi(buildProfilePayload(context.form))
if (response.code !== 0) {
ElMessage.error(response.message || context.t('transcodeSettings.saveFailed'))
return
}
applyProfileToForm(context.form, response.data)
ElMessage.success(context.t('transcodeSettings.saved'))
} catch {
ElMessage.error(context.t('transcodeSettings.saveFailed'))
} finally {
context.saving.value = false
}
}