1
This commit is contained in:
@@ -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,13 +692,26 @@ 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
|
||||
|
||||
// 检查是否是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 // 不关闭对话框,让用户知道出问题了
|
||||
}
|
||||
|
||||
// 关闭对话框并刷新
|
||||
this.createDialogVisible = false
|
||||
// 延迟刷新,确保用户能看到提示
|
||||
|
||||
Reference in New Issue
Block a user