fix(payment): 修复后端返回空supported_types时支付提供商卡片消失的问题

统一处理后端返回的null类型supported_types,将其标准化为空数组,避免调用includes()时报错导致卡片无法显示,同时修复多处相关的类型判断逻辑
This commit is contained in:
SMGDev committed 2026-06-26 00:50:22 +08:00
1 parent ce6af41357
commit 65ad7df4f4
4 files changed
+83 -6

No files matched your search

+15 -4
View File
@@ -9777,7 +9777,15 @@ async function loadProviders() {
providersLoading.value = true;
try {
const res = await adminAPI.payment.getProviders();
providers.value = res.data || [];
// Normalize supported_types: backend returns null when the list is empty
// (Go nil slice → JSON null). Without this, ProviderCard's isSelected()
// throws TypeError on null.includes(), causing the card to vanish.
providers.value = (res.data || []).map((p) => ({
...p,
supported_types: Array.isArray(p.supported_types)
? p.supported_types
: [],
}));
} catch (err: unknown) {
appStore.showError(extractI18nErrorMessage(err, t, "payment.errors", t("common.error")));
} finally {
@@ -9871,9 +9879,12 @@ async function handleToggleField(
}
async function handleToggleType(provider: ProviderInstance, type: string) {
const updated = provider.supported_types.includes(type)
? provider.supported_types.filter((t) => t !== type)
: [...provider.supported_types, type];
const currentTypes = Array.isArray(provider.supported_types)
? provider.supported_types
: [];
const updated = currentTypes.includes(type)
? currentTypes.filter((t) => t !== type)
: [...currentTypes, type];
const conflict = findProviderEnablementConflict({
id: provider.id,
provider_key: provider.provider_key,