main #34

Merged
charles merged 191 commits from main into prod 2025-11-19 16:18:39 +08:00
2 changed files with 36 additions and 30 deletions
Showing only changes of commit ed5e271099 - Show all commits

View File

@ -40,6 +40,9 @@ export default {
<style lang="scss" >
$n: 9; //和items.length 相同
$t: .1s;
*{
box-sizing: border-box;
}
.share-dropdown-menu {
width: 250px;
position: relative;

View File

@ -30,7 +30,7 @@ export default {
mounted() {
window.addEventListener('message', this.receiveMessage, false);
},
beforeDestroy() { // Vue2 中推荐使用 beforeDestroy
beforeDestroy() { // Vue2 推荐使用 beforeDestroy
window.removeEventListener('message', this.receiveMessage, false);
},
methods: {
@ -41,63 +41,63 @@ export default {
const response = await baiducloudAPI();
this.userToken = response.data;
if (this.userToken) {
// 构建最终的 URL
const baseUrl = 'https://console.vcp.baidu.com/api/loginvcp/login/securitytoken?';
// 修复 URL 构建:移除 baseUrl 末尾的 '?' 或者确保第一个参数用 '?'
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}`;
// 使用 '?' 连接第一个参数
this.url = `${baseUrl}?redirectUrl=${redirectUrl}&signinSecurityToken=${token}`;
} else {
console.error('未能从API响应中获取到token:', response);
this.$message.error('获取登录信息失败,请重试。');
}
} catch (error) {
console.error('获取百度云Token失败:', error);
// 可以在这里添加用户提示,例如 this.$message.error('获取Token失败,请重试');
this.$message.error('网络错误,获取登录信息失败。');
} finally {
this.loading = false;
}
},
// 使用更健壮的 receiveMessage 方法
receiveMessage(event) {
console.log('接收到消息:', event);
// 安全性检查:验证消息来源(如果知道确切来源域名)
// if (event.origin !== 'https://console.vcp.baidu.com') {
// 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);
console.log('接收到的 data 是:', data);
// 检查接收到的数据是否包含退款信息
if (data && data.orderInfo && data.orderInfo.refundInfo) {
// 提取订单ID
const refundInfo = data.orderInfo.refundInfo;
let orderId = '';
// 处理可能的 orderId 或 orderIdList (这里假设 uuidList 是主要字段)
// 提取订单ID,按优先级处理 uuidList, orderId, orderIdList
let orderId = '';
if (refundInfo.uuidList !== undefined) {
// 如果 uuidList 是数组,根据后端需求决定是传递数组还是逗号分隔字符串
// 这里假设后端期望字符串
orderId = Array.isArray(refundInfo.uuidList) ? refundInfo.uuidList.join(',') : String(refundInfo.uuidList);
orderId = Array.isArray(refundInfo.uuidList) ? refundInfo.uuidList.join(',') : String(refundInfo.uuidList);
} else if (refundInfo.orderId !== undefined) {
orderId = String(refundInfo.orderId);
orderId = String(refundInfo.orderId);
} else if (refundInfo.orderIdList !== undefined) {
orderId = Array.isArray(refundInfo.orderIdList) ? refundInfo.orderIdList.join(',') : String(refundInfo.orderIdList);
orderId = Array.isArray(refundInfo.orderIdList) ? refundInfo.orderIdList.join(',') : String(refundInfo.orderIdList);
} else {
console.warn('未在 refundInfo 中找到 orderId 或 orderIdList');
this.$message.warning('退订信息不完整');
return; // 如果没有订单ID,不继续执行
console.warn('未在 refundInfo 中找到有效的订单ID字段 (uuidList, orderId, orderIdList)');
this.$message.warning('退订信息不完整,未找到订单ID。');
return; // 如果没有订单ID,不继续执行
}
console.log('接收到订单ID:', orderId);
console.log('处理后的订单ID:', orderId);
// 获取用户ID
this.userid = sessionStorage.getItem('userId');
if (!this.userid) {
console.error('未获取到用户ID');
this.$message.error('用户信息获取失败');
return;
console.error('未获取到用户ID (sessionStorage 中缺少 userId)');
this.$message.error('用户信息获取失败,请重新登录。');
return;
}
// 构造请求参数
@ -112,10 +112,10 @@ export default {
// 调用退订API
reqBaiduJudgePrice(payload)
.then((res) => {
console.log("二级接口返回:", res);
console.log("调用 reqBaiduJudgePrice 接口返回:", res);
if (res.status) { // 假设 status 为 true 表示成功
this.$message.success('退订成功');
// 跳转页面
// 跳转页面
this.$router.push({
name: 'userResource',
params: {
@ -124,19 +124,22 @@ export default {
}
});
} else {
// 显示后端返回的错误信息
this.$message.error(res.msg || '退订失败');
this.$message.error(res.msg || '退订失败,请稍后重试。');
}
})
.catch((error) => {
// 捕获网络错误或请求异常
console.error("调用退订接口失败:", error);
this.$message.error('网络错误或服务异常,请稍后重试');
// 捕获网络错误或请求异常 (如超时、连接失败)
console.error("调用退订接口 reqBaiduJudgePrice 失败 (网络/请求错误):", error);
// 可以根据 error 对象提供更具体的提示,例如区分超时和断网
this.$message.error('网络请求失败或服务异常,请检查网络连接后重试。');
})
.finally(() => {
// 无论成功或失败,都结束加载状态
this.loading = false;
});
} else {
console.log('接收到的消息不包含有效的退款信息。');
// 根据需要决定是否提示用户
}
}
}