uptada BaiDuYun

This commit is contained in:
hrx 2025-09-19 14:17:44 +08:00
parent 7b28be8131
commit 251d1a70f2

View File

@ -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.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
}
})
this.$message.success('退订成功')
});
} else {
this.loading = false
this.$message.error(res.msg)
//
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>