From 06edf3d165ef377a4ceebffb73b0c1a265444b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=92?= Date: Fri, 31 Oct 2025 15:47:31 +0800 Subject: [PATCH] 1 --- src/views/system/giftcoupon/index.vue | 78 +++++++++++++++++++++------ 1 file changed, 62 insertions(+), 16 deletions(-) diff --git a/src/views/system/giftcoupon/index.vue b/src/views/system/giftcoupon/index.vue index 6e5d713..e7c4408 100644 --- a/src/views/system/giftcoupon/index.vue +++ b/src/views/system/giftcoupon/index.vue @@ -456,21 +456,36 @@ export default { } // 调用创建礼金接口 + console.log('创建礼金请求参数:', params) const res = await createGiftCoupon(params) + console.log('创建礼金返回结果:', res) - if (res && res.code === 200) { + // 检查返回结果 + if (!res) { + this.$modal.msgError('接口返回为空,请检查网络连接') + return + } + + // 判断成功条件:code === 200 或者直接返回了giftCouponKey + const isSuccess = res.code === 200 || (res.data && (res.data.giftCouponKey || res.data.giftKey)) + + if (isSuccess) { // 解析返回的giftCouponKey(参考xbmessage中的处理方式) let giftKey = null if (typeof res.data === 'string') { giftKey = res.data } else if (res.data) { - giftKey = res.data.giftCouponKey || res.data.giftKey || res.data.data?.giftCouponKey + // 尝试多种可能的字段名 + giftKey = res.data.giftCouponKey || res.data.giftKey || (res.data.data && (res.data.data.giftCouponKey || res.data.data.giftKey)) } + console.log('解析到的礼金Key:', giftKey) + if (giftKey) { // 可选:自动生成短链(参考JD项目的完整流程) try { - const transferParams = { materialUrl: materialUrl } + const transferParams = {} + // 优先使用SKU ID作为materialUrl if (skuId && isUrl) { transferParams.materialUrl = skuId } else { @@ -478,41 +493,72 @@ export default { } transferParams.giftCouponKey = giftKey + console.log('转链请求参数:', transferParams) const tf = await transferWithGift(transferParams) + console.log('转链返回结果:', tf) + if (tf && tf.code === 200) { let shortUrl = '' if (typeof tf.data === 'string') { shortUrl = tf.data } else if (tf.data && tf.data.shortURL) { shortUrl = tf.data.shortURL + } else if (tf.data && typeof tf.data === 'object') { + // 尝试其他可能的字段 + shortUrl = tf.data.url || tf.data.link || '' } + if (shortUrl) { - this.$modal.msgSuccess('礼金创建成功,短链已生成') + this.$modal.msgSuccess('礼金创建成功!短链:' + shortUrl) + // 复制短链到剪贴板 + this.copyToClipboard(shortUrl) } else { - this.$modal.msgSuccess('礼金创建成功,礼金Key:' + giftKey) + this.$modal.msgSuccess('礼金创建成功!礼金Key:' + giftKey) } } else { - this.$modal.msgSuccess('礼金创建成功,礼金Key:' + giftKey) + this.$modal.msgSuccess('礼金创建成功!礼金Key:' + giftKey) } } catch (e) { - this.$modal.msgSuccess('礼金创建成功,礼金Key:' + giftKey) + console.error('生成短链失败', e) + this.$modal.msgSuccess('礼金创建成功!礼金Key:' + giftKey + '(短链生成失败)') } } else { - this.$modal.msgWarning('礼金创建完成,但未返回礼金Key,请检查') + // 没有礼金Key,但接口返回成功,可能是其他格式 + console.warn('未找到礼金Key,完整返回:', res) + this.$modal.msgWarning('礼金创建完成,但未返回礼金Key。返回数据:' + JSON.stringify(res.data).substring(0, 100)) } + // 关闭对话框并刷新 this.createDialogVisible = false - // 刷新列表和统计 - this.getList() - this.loadStatistics() + // 延迟刷新,确保用户能看到提示 + setTimeout(() => { + this.getList() + this.loadStatistics() + }, 500) } else { - // 错误处理 - const errorMsg = res?.msg || res?.data?.msg || '创建失败' - this.$modal.msgError(errorMsg) + // 错误处理 - 更详细的错误信息 + console.error('创建礼金失败,返回:', res) + let errorMsg = '创建失败' + if (res.msg) { + errorMsg = res.msg + } else if (res.data && res.data.msg) { + errorMsg = res.data.msg + } else if (res.message) { + errorMsg = res.message + } else if (typeof res === 'string') { + errorMsg = res + } + this.$modal.msgError('创建失败:' + errorMsg) } } catch (e) { - console.error('创建礼金失败', e) - this.$modal.msgError('创建失败:' + (e.message || e.msg || '未知错误')) + console.error('创建礼金异常', e) + let errorMsg = '未知错误' + if (e.response && e.response.data) { + errorMsg = e.response.data.msg || e.response.data.message || JSON.stringify(e.response.data) + } else if (e.message) { + errorMsg = e.message + } + this.$modal.msgError('创建失败:' + errorMsg) } finally { this.createLoading = false }