uptada BaiDuYun
This commit is contained in:
parent
7b28be8131
commit
251d1a70f2
@ -12,7 +12,8 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { baiducloudAPI } from '@/api/BaiDuTokenapi'
|
import { baiducloudAPI } from '@/api/BaiDuTokenapi'
|
||||||
import {reqBaiduJudgePrice} from '@/api/baidu'
|
import { reqBaiduJudgePrice } from '@/api/baidu'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'baiduProductShow',
|
name: 'baiduProductShow',
|
||||||
data() {
|
data() {
|
||||||
@ -26,30 +27,31 @@ export default {
|
|||||||
async created() {
|
async created() {
|
||||||
await this.getToken();
|
await this.getToken();
|
||||||
},
|
},
|
||||||
mounted(){
|
mounted() {
|
||||||
window.addEventListener('message', this.receiveMessage, false);
|
window.addEventListener('message', this.receiveMessage, false);
|
||||||
},
|
},
|
||||||
destroyed() {
|
beforeDestroy() { // Vue2 中推荐使用 beforeDestroy
|
||||||
window.removeEventListener('message', this.receiveMessage, false);
|
window.removeEventListener('message', this.receiveMessage, false);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 点击退订返回个信息 拿着信息请求 百度回调
|
|
||||||
// 获取百度云token
|
// 获取百度云token
|
||||||
async getToken() {
|
async getToken() {
|
||||||
try {
|
try {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
const response = await baiducloudAPI();
|
const response = await baiducloudAPI();
|
||||||
this.userToken = response.data;
|
this.userToken = response.data;
|
||||||
let resultUrlLast = 'https://console.vcp.baidu.com/api/loginvcp/login/securitytoken?'
|
|
||||||
if (this.userToken) {
|
if (this.userToken) {
|
||||||
// 构建最终的 URL
|
// 构建最终的 URL
|
||||||
resultUrlLast = resultUrlLast + '&redirectUrl=' + encodeURIComponent('https://console.vcp.baidu.com/billing/#/refund/list') + '&signinSecurityToken=' + encodeURIComponent(this.userToken)
|
const baseUrl = 'https://console.vcp.baidu.com/api/loginvcp/login/securitytoken?';
|
||||||
this.url = resultUrlLast
|
const redirectUrl = encodeURIComponent('https://console.vcp.baidu.com/billing/#/refund/list');
|
||||||
|
const token = encodeURIComponent(this.userToken);
|
||||||
|
this.url = `${baseUrl}&redirectUrl=${redirectUrl}&signinSecurityToken=${token}`;
|
||||||
} else {
|
} else {
|
||||||
console.error('未能从API响应中获取到token:', response);
|
console.error('未能从API响应中获取到token:', response);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取百度云Token失败:', error);
|
console.error('获取百度云Token失败:', error);
|
||||||
|
// 可以在这里添加用户提示,例如 this.$message.error('获取Token失败,请重试');
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
@ -57,38 +59,85 @@ export default {
|
|||||||
receiveMessage(event) {
|
receiveMessage(event) {
|
||||||
console.log('接收到消息:', 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;
|
const data = event.data;
|
||||||
console.log('data是', data);
|
console.log('data是', data);
|
||||||
|
|
||||||
|
// 检查接收到的数据是否包含退款信息
|
||||||
if (data && data.orderInfo && data.orderInfo.refundInfo) {
|
if (data && data.orderInfo && data.orderInfo.refundInfo) {
|
||||||
// 检查接收到的数据是否包含 orderId 或者 orderIdList
|
// 提取订单ID
|
||||||
this.loading = true
|
const refundInfo = data.orderInfo.refundInfo;
|
||||||
const orderId = String(data.orderInfo.refundInfo.uuidList)
|
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);
|
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,
|
order_id: orderId,
|
||||||
userid: this.userid
|
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.loading = true;
|
||||||
this.$message.error(res.msg)
|
|
||||||
}
|
// 调用退订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 {
|
.baidu-style {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: calc(100vh - 100px);
|
height: calc(100vh - 100px); // Adjust based on your layout needs
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user