fix: handle mixed channel warning for multi-platform bulk edit
Previously, preCheckMixedChannelRisk() skipped when selectedPlatforms had more than one entry, and the catch block in submitBulkUpdate had no 409 handling — so multi-platform conflicts just showed a generic error. - Rename canPreCheck(): only call pre-check API for single-platform antigravity/anthropic selections (API requires a single platform param) - Pass `built` into preCheckMixedChannelRisk() so pendingUpdatesForConfirm is set before returning false - submitBulkUpdate: add 409 mixed_channel_warning catch as fallback for multi-platform case, saving baseUpdates for retry - Remove needsMixedChannelCheck() gate on confirm_mixed_channel_risk flag; use mixedChannelConfirmed alone so multi-platform retry also works
This commit is contained in:
@@ -1254,8 +1254,11 @@ const buildUpdatePayload = (): Record<string, unknown> | null => {
|
|||||||
|
|
||||||
const mixedChannelConfirmed = ref(false)
|
const mixedChannelConfirmed = ref(false)
|
||||||
|
|
||||||
const needsMixedChannelCheck = () =>
|
// 是否需要预检查:改了分组 + 全是单一的 antigravity 或 anthropic 平台
|
||||||
|
// 多平台混合的情况由 submitBulkUpdate 的 409 catch 兜底
|
||||||
|
const canPreCheck = () =>
|
||||||
enableGroups.value &&
|
enableGroups.value &&
|
||||||
|
groupIds.value.length > 0 &&
|
||||||
props.selectedPlatforms.length === 1 &&
|
props.selectedPlatforms.length === 1 &&
|
||||||
(props.selectedPlatforms[0] === 'antigravity' || props.selectedPlatforms[0] === 'anthropic')
|
(props.selectedPlatforms[0] === 'antigravity' || props.selectedPlatforms[0] === 'anthropic')
|
||||||
|
|
||||||
@@ -1267,10 +1270,10 @@ const handleClose = () => {
|
|||||||
emit('close')
|
emit('close')
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkMixedChannelRisk = async (): Promise<boolean> => {
|
// 预检查:提交前调接口检测,有风险就弹窗阻止,返回 false 表示需要用户确认
|
||||||
if (!needsMixedChannelCheck()) return true
|
const preCheckMixedChannelRisk = async (built: Record<string, unknown>): Promise<boolean> => {
|
||||||
|
if (!canPreCheck()) return true
|
||||||
if (mixedChannelConfirmed.value) return true
|
if (mixedChannelConfirmed.value) return true
|
||||||
if (groupIds.value.length === 0) return true
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await adminAPI.accounts.checkMixedChannelRisk({
|
const result = await adminAPI.accounts.checkMixedChannelRisk({
|
||||||
@@ -1279,6 +1282,7 @@ const checkMixedChannelRisk = async (): Promise<boolean> => {
|
|||||||
})
|
})
|
||||||
if (!result.has_risk) return true
|
if (!result.has_risk) return true
|
||||||
|
|
||||||
|
pendingUpdatesForConfirm.value = built
|
||||||
mixedChannelWarningMessage.value = result.message || t('admin.accounts.bulkEdit.failed')
|
mixedChannelWarningMessage.value = result.message || t('admin.accounts.bulkEdit.failed')
|
||||||
showMixedChannelWarning.value = true
|
showMixedChannelWarning.value = true
|
||||||
return false
|
return false
|
||||||
@@ -1318,19 +1322,17 @@ const handleSubmit = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const canContinue = await checkMixedChannelRisk()
|
const canContinue = await preCheckMixedChannelRisk(built)
|
||||||
if (!canContinue) {
|
if (!canContinue) return
|
||||||
pendingUpdatesForConfirm.value = built
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
await submitBulkUpdate(built)
|
await submitBulkUpdate(built)
|
||||||
}
|
}
|
||||||
|
|
||||||
const submitBulkUpdate = async (updates: Record<string, unknown>) => {
|
const submitBulkUpdate = async (baseUpdates: Record<string, unknown>) => {
|
||||||
if (mixedChannelConfirmed.value && needsMixedChannelCheck()) {
|
// 无论是预检查确认还是 409 兜底确认,只要 mixedChannelConfirmed 为 true 就带上 flag
|
||||||
updates = { ...updates, confirm_mixed_channel_risk: true }
|
const updates = mixedChannelConfirmed.value
|
||||||
}
|
? { ...baseUpdates, confirm_mixed_channel_risk: true }
|
||||||
|
: baseUpdates
|
||||||
|
|
||||||
submitting.value = true
|
submitting.value = true
|
||||||
|
|
||||||
@@ -1353,8 +1355,15 @@ const submitBulkUpdate = async (updates: Record<string, unknown>) => {
|
|||||||
handleClose()
|
handleClose()
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
appStore.showError(error.message || t('admin.accounts.bulkEdit.failed'))
|
// 兜底:多平台混合场景下,预检查跳过,由后端 409 触发确认框
|
||||||
console.error('Error bulk updating accounts:', error)
|
if (error.status === 409 && error.error === 'mixed_channel_warning') {
|
||||||
|
pendingUpdatesForConfirm.value = baseUpdates
|
||||||
|
mixedChannelWarningMessage.value = error.message
|
||||||
|
showMixedChannelWarning.value = true
|
||||||
|
} else {
|
||||||
|
appStore.showError(error.message || t('admin.accounts.bulkEdit.failed'))
|
||||||
|
console.error('Error bulk updating accounts:', error)
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
submitting.value = false
|
submitting.value = false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user