This commit is contained in:
2025-10-31 16:48:49 +08:00
parent 94cb24041a
commit e62a2b3635

View File

@@ -616,27 +616,40 @@ export default {
}
} else if (res.data && typeof res.data === 'object') {
// 尝试多种可能的字段名(优先顺序很重要)
// 1. 直接获取 giftCouponKey
if (res.data.giftCouponKey) {
// 1. 直接获取 giftCouponKey但如果是null则不使用
if (res.data.giftCouponKey !== null && res.data.giftCouponKey !== undefined && res.data.giftCouponKey !== '') {
giftKey = res.data.giftCouponKey
}
// 2. 获取 giftKey
else if (res.data.giftKey) {
// 2. 获取 giftKey但如果是null则不使用
else if (res.data.giftKey !== null && res.data.giftKey !== undefined && res.data.giftKey !== '') {
giftKey = res.data.giftKey
}
// 3. 如果data里面还有data对象嵌套情况
else if (res.data.data && typeof res.data.data === 'object') {
giftKey = res.data.data.giftCouponKey || res.data.data.giftKey
if (res.data.data.giftCouponKey !== null && res.data.data.giftCouponKey !== undefined && res.data.data.giftCouponKey !== '') {
giftKey = res.data.data.giftCouponKey
} else if (res.data.data.giftKey !== null && res.data.data.giftKey !== undefined && res.data.data.giftKey !== '') {
giftKey = res.data.data.giftKey
}
}
// 4. 如果data是数组取第一个
else if (Array.isArray(res.data) && res.data.length > 0) {
const first = res.data[0]
giftKey = first.giftCouponKey || first.giftKey
if (first.giftCouponKey !== null && first.giftCouponKey !== undefined && first.giftCouponKey !== '') {
giftKey = first.giftCouponKey
} else if (first.giftKey !== null && first.giftKey !== undefined && first.giftKey !== '') {
giftKey = first.giftKey
}
}
}
console.log('解析到的礼金Key', giftKey, '完整data结构', JSON.stringify(res.data, null, 2))
// 如果giftCouponKey是null说明创建可能失败了
if (res.data && res.data.giftCouponKey === null) {
console.error('礼金Key为null创建可能失败。完整返回', JSON.stringify(res, null, 2))
}
if (giftKey) {
// 可选自动生成短链参考JD项目的完整流程
try {
@@ -679,11 +692,24 @@ export default {
this.$modal.msgSuccess('礼金创建成功礼金Key' + giftKey + '(短链生成失败)')
}
} else {
// 没有礼金Key但接口返回成功,可能是其他格式
// 没有礼金Key但接口返回成功
console.warn('未找到礼金Key完整返回', res)
console.warn('data的完整内容', JSON.stringify(res.data, null, 2))
// 即使没有Key也提示成功因为接口返回了code:200
this.$modal.msgWarning('礼金创建完成但未在返回数据中找到礼金Key。请查看控制台日志或联系技术支持。')
// 检查是否是null的情况
if (res.data && res.data.giftCouponKey === null) {
this.$modal.msgError('礼金创建失败返回的礼金Key为null。可能是商品链接不正确、商品不支持创建礼金或内部服务异常。请检查商品链接或稍后重试。')
} else {
// 其他情况
this.$modal.msgWarning('礼金创建完成但未在返回数据中找到礼金Key。请查看控制台日志或联系技术支持。')
}
// 即使失败也刷新列表(可能之前创建的会显示)
setTimeout(() => {
this.getList()
this.loadStatistics()
}, 500)
return // 不关闭对话框,让用户知道出问题了
}
// 关闭对话框并刷新