main #34

Merged
charles merged 191 commits from main into prod 2025-11-19 16:18:39 +08:00
Showing only changes of commit 1998ed5cf2 - Show all commits

View File

@ -62,22 +62,27 @@ export default {
const data = event.data;
console.log('接收到的 data 是:', data);
// 检查接收到的数据是否包含退款信息
if (data && data.refundInfo && data.refundInfo.uuidList) {
const refundInfo = data.refundInfo.uuidList;
// 提取订单ID,按优先级处理 uuidList, orderId, orderIdList
let orderId = '';
if (refundInfo.uuidList !== undefined) {
orderId = refundInfo.uuidList[0];
} else {
console.warn('未在 refundInfo 中找到有效的订单ID字段 (uuidList, orderId, orderIdList)');
this.$message.warning('退订信息不完整,未找到订单ID');
return; // 如果没有订单ID,不继续执行
}
// --- 修复后的逻辑 ---
// 1. 检查数据结构和来源 (可选但推荐)
// const expectedOrigin = 'https://console.vcp.baidu.com';
// if (event.origin !== expectedOrigin) {
// console.warn('Received message from unexpected origin:', event.origin);
// return;
// }
console.log('处理后的订单ID:', orderId);
// 2. 检查是否存在 refundInfo 和 uuidList
if (data && data.refundInfo && Array.isArray(data.refundInfo.uuidList) && data.refundInfo.uuidList.length > 0) {
const uuidListArray = data.refundInfo.uuidList; // 这是一个数组
// 获取用户ID
// 3. 提取订单ID (这里假设取第一个,或者根据需要处理整个数组)
// 如果只需要一个订单ID进行退订
const orderId = String(uuidListArray[0]);
// 如果需要处理多个订单ID,可以用逗号连接
// const orderId = uuidListArray.join(',');
console.log('提取到的订单ID:', orderId);
// 4. 获取用户ID
this.userid = sessionStorage.getItem('userId');
if (!this.userid) {
console.error('未获取到用户ID (sessionStorage 中缺少 userId)');
@ -85,20 +90,20 @@ export default {
return;
}
// 构造请求参数
// 5. 构造请求参数
const payload = {
order_id: orderId,
userid: this.userid
};
// 显示加载状态
// 6. 显示加载状态
this.loading = true;
// 调用退订API
// 7. 调用退订API
reqBaiduJudgePrice(payload)
.then((res) => {
console.log("调用 reqBaiduJudgePrice 接口返回:", res);
if (res.status) {
if (res.status) { // 假设 status 为 true 表示成功
this.$message.success('退订成功');
// 跳转页面
this.$router.push({
@ -109,13 +114,13 @@ export default {
}
});
} else {
// 显示后端返回的错误信息
this.$message.error(res.msg || '退订失败,请稍后重试');
}
})
.catch((error) => {
// 捕获网络错误或请求异常 (如超时、连接失败)
console.error("调用退订接口 reqBaiduJudgePrice 失败 (网络/请求错误):", error);
// 可以根据 error 对象提供更具体的提示,例如区分超时和断网
this.$message.error('网络请求失败或服务异常,请检查网络连接后重试');
})
.finally(() => {
@ -123,7 +128,8 @@ export default {
this.loading = false;
});
} else {
console.log('接收到的消息不包含有效的退款信息');
console.log('接收到的消息不包含有效的退款信息或 uuidList 为空');
// 根据需要决定是否提示用户
}
}
}
@ -138,7 +144,7 @@ export default {
.baidu-style {
width: 100%;
height: calc(100vh - 100px); // Adjust based on your layout needs
height: calc(100vh - 100px);
}
</style>