uptada BaiDuYun
This commit is contained in:
parent
ed5e271099
commit
d0deabd832
@ -30,7 +30,7 @@ export default {
|
||||
mounted() {
|
||||
window.addEventListener('message', this.receiveMessage, false);
|
||||
},
|
||||
beforeDestroy() { // Vue2 推荐使用 beforeDestroy
|
||||
beforeDestroy() {
|
||||
window.removeEventListener('message', this.receiveMessage, false);
|
||||
},
|
||||
methods: {
|
||||
@ -41,11 +41,9 @@ export default {
|
||||
const response = await baiducloudAPI();
|
||||
this.userToken = response.data;
|
||||
if (this.userToken) {
|
||||
// 修复 URL 构建:移除 baseUrl 末尾的 '?' 或者确保第一个参数用 '?'
|
||||
const baseUrl = 'https://console.vcp.baidu.com/api/loginvcp/login/securitytoken'; // 移除末尾的 '?'
|
||||
const baseUrl = 'https://console.vcp.baidu.com/api/loginvcp/login/securitytoken';
|
||||
const redirectUrl = encodeURIComponent('https://console.vcp.baidu.com/billing/#/refund/list');
|
||||
const token = encodeURIComponent(this.userToken);
|
||||
// 使用 '?' 连接第一个参数
|
||||
this.url = `${baseUrl}?redirectUrl=${redirectUrl}&signinSecurityToken=${token}`;
|
||||
} else {
|
||||
console.error('未能从API响应中获取到token:', response);
|
||||
@ -58,32 +56,19 @@ export default {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
// 使用更健壮的 receiveMessage 方法
|
||||
|
||||
receiveMessage(event) {
|
||||
console.log('接收到消息:', event);
|
||||
|
||||
// 安全性检查:验证消息来源(如果知道确切来源域名)
|
||||
// const expectedOrigin = 'https://console.vcp.baidu.com';
|
||||
// if (event.origin !== expectedOrigin) {
|
||||
// console.warn('Received message from unexpected origin:', event.origin);
|
||||
// return;
|
||||
// }
|
||||
|
||||
const data = event.data;
|
||||
console.log('接收到的 data 是:', data);
|
||||
|
||||
// 检查接收到的数据是否包含退款信息
|
||||
if (data && data.orderInfo && data.orderInfo.refundInfo) {
|
||||
const refundInfo = data.orderInfo.refundInfo;
|
||||
|
||||
if (data && data.refundInfo && data.refundInfo.uuidList) {
|
||||
const refundInfo = data.refundInfo.uuidList;
|
||||
// 提取订单ID,按优先级处理 uuidList, orderId, orderIdList
|
||||
let orderId = '';
|
||||
if (refundInfo.uuidList !== undefined) {
|
||||
orderId = Array.isArray(refundInfo.uuidList) ? refundInfo.uuidList.join(',') : String(refundInfo.uuidList);
|
||||
} else if (refundInfo.orderId !== undefined) {
|
||||
orderId = String(refundInfo.orderId);
|
||||
} else if (refundInfo.orderIdList !== undefined) {
|
||||
orderId = Array.isArray(refundInfo.orderIdList) ? refundInfo.orderIdList.join(',') : String(refundInfo.orderIdList);
|
||||
orderId = refundInfo.uuidList[0];
|
||||
} else {
|
||||
console.warn('未在 refundInfo 中找到有效的订单ID字段 (uuidList, orderId, orderIdList)');
|
||||
this.$message.warning('退订信息不完整,未找到订单ID。');
|
||||
@ -113,7 +98,7 @@ export default {
|
||||
reqBaiduJudgePrice(payload)
|
||||
.then((res) => {
|
||||
console.log("调用 reqBaiduJudgePrice 接口返回:", res);
|
||||
if (res.status) { // 假设 status 为 true 表示成功
|
||||
if (res.status) {
|
||||
this.$message.success('退订成功');
|
||||
// 跳转页面
|
||||
this.$router.push({
|
||||
@ -139,7 +124,6 @@ export default {
|
||||
});
|
||||
} else {
|
||||
console.log('接收到的消息不包含有效的退款信息。');
|
||||
// 根据需要决定是否提示用户
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user