uptada BaiDuYun
This commit is contained in:
parent
7b28be8131
commit
251d1a70f2
@ -12,7 +12,8 @@
|
||||
|
||||
<script>
|
||||
import { baiducloudAPI } from '@/api/BaiDuTokenapi'
|
||||
import {reqBaiduJudgePrice} from '@/api/baidu'
|
||||
import { reqBaiduJudgePrice } from '@/api/baidu'
|
||||
|
||||
export default {
|
||||
name: 'baiduProductShow',
|
||||
data() {
|
||||
@ -26,30 +27,31 @@ export default {
|
||||
async created() {
|
||||
await this.getToken();
|
||||
},
|
||||
mounted(){
|
||||
mounted() {
|
||||
window.addEventListener('message', this.receiveMessage, false);
|
||||
},
|
||||
destroyed() {
|
||||
beforeDestroy() { // Vue2 中推荐使用 beforeDestroy
|
||||
window.removeEventListener('message', this.receiveMessage, false);
|
||||
},
|
||||
methods: {
|
||||
// 点击退订返回个信息 拿着信息请求 百度回调
|
||||
// 获取百度云token
|
||||
async getToken() {
|
||||
try {
|
||||
this.loading = true;
|
||||
const response = await baiducloudAPI();
|
||||
this.userToken = response.data;
|
||||
let resultUrlLast = 'https://console.vcp.baidu.com/api/loginvcp/login/securitytoken?'
|
||||
if (this.userToken) {
|
||||
// 构建最终的 URL
|
||||
resultUrlLast = resultUrlLast + '&redirectUrl=' + encodeURIComponent('https://console.vcp.baidu.com/billing/#/refund/list') + '&signinSecurityToken=' + encodeURIComponent(this.userToken)
|
||||
this.url = resultUrlLast
|
||||
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);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取百度云Token失败:', error);
|
||||
// 可以在这里添加用户提示,例如 this.$message.error('获取Token失败,请重试');
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
@ -57,38 +59,85 @@ export default {
|
||||
receiveMessage(event) {
|
||||
console.log('接收到消息:', event);
|
||||
|
||||
this.userid = sessionStorage.getItem('userId')
|
||||
// 安全性检查:验证消息来源(如果知道确切来源域名)
|
||||
// if (event.origin !== 'https://console.vcp.baidu.com') {
|
||||
// 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) {
|
||||
// 检查接收到的数据是否包含 orderId 或者 orderIdList
|
||||
this.loading = true
|
||||
const orderId = String(data.orderInfo.refundInfo.uuidList)
|
||||
// 提取订单ID
|
||||
const refundInfo = data.orderInfo.refundInfo;
|
||||
let orderId = '';
|
||||
|
||||
// 处理可能的 orderId 或 orderIdList (这里假设 uuidList 是主要字段)
|
||||
if (refundInfo.uuidList !== undefined) {
|
||||
// 如果 uuidList 是数组,根据后端需求决定是传递数组还是逗号分隔字符串
|
||||
// 这里假设后端期望字符串
|
||||
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);
|
||||
} else {
|
||||
console.warn('未在 refundInfo 中找到 orderId 或 orderIdList');
|
||||
this.$message.warning('退订信息不完整');
|
||||
return; // 如果没有订单ID,不继续执行
|
||||
}
|
||||
|
||||
console.log('接收到订单ID:', orderId);
|
||||
let ploay = {
|
||||
|
||||
// 获取用户ID
|
||||
this.userid = sessionStorage.getItem('userId');
|
||||
|
||||
if (!this.userid) {
|
||||
console.error('未获取到用户ID');
|
||||
this.$message.error('用户信息获取失败');
|
||||
return;
|
||||
}
|
||||
|
||||
// 构造请求参数
|
||||
const payload = {
|
||||
order_id: orderId,
|
||||
userid: this.userid
|
||||
}
|
||||
reqBaiduJudgePrice(ploay).then((res) => {
|
||||
console.log("二级接口是", res)
|
||||
if (res.status) {
|
||||
this.$router.push({
|
||||
name: 'userResource',
|
||||
params: {
|
||||
listUrl: this.$route.params.listUrl,
|
||||
url: this.$route.params.url
|
||||
}
|
||||
})
|
||||
this.$message.success('退订成功')
|
||||
};
|
||||
|
||||
} else {
|
||||
this.loading = false
|
||||
this.$message.error(res.msg)
|
||||
}
|
||||
})
|
||||
// 显示加载状态
|
||||
this.loading = true;
|
||||
|
||||
// 调用退订API
|
||||
reqBaiduJudgePrice(payload)
|
||||
.then((res) => {
|
||||
console.log("二级接口返回:", res);
|
||||
if (res.status) { // 假设 status 为 true 表示成功
|
||||
this.$message.success('退订成功');
|
||||
// 跳转页面
|
||||
this.$router.push({
|
||||
name: 'userResource',
|
||||
params: {
|
||||
listUrl: this.$route.params.listUrl,
|
||||
url: this.$route.params.url
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 显示后端返回的错误信息
|
||||
this.$message.error(res.msg || '退订失败');
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
// 捕获网络错误或请求异常
|
||||
console.error("调用退订接口失败:", error);
|
||||
this.$message.error('网络错误或服务异常,请稍后重试');
|
||||
})
|
||||
.finally(() => {
|
||||
// 无论成功或失败,都结束加载状态
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -102,6 +151,9 @@ export default {
|
||||
|
||||
.baidu-style {
|
||||
width: 100%;
|
||||
height: calc(100vh - 100px);
|
||||
height: calc(100vh - 100px); // Adjust based on your layout needs
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user