uptada BaiDuYun

This commit is contained in:
hrx 2025-09-19 11:07:21 +08:00
parent ea954613f3
commit 0312ae479f

View File

@ -1,81 +1,62 @@
<template>
<div class="box">
<div v-if="loading">正在加载...</div>
<iframe v-else-if="url" :src="url" frameborder="0" class="baidu-style" ref="baiduIframe">
<iframe v-else-if="url" :src="url" frameborder="0" class="baidu-style">
</iframe>
<div v-else>
<p>无法加载内容请检查配置</p>
<p>请先登录百度云账号</p>
<button @click="getToken">重试</button>
</div>
</div>
</template>
<script>
import { baiducloudAPI, cancelCallbackAPI } from '@/api/BaiDuTokenapi'
export default {
name: 'BaiduProductShow',
name: 'baiduProductShow',
data() {
return {
userToken: '',
url: '',
loading: true,
// session storage userId
userid: 'USER_001'
};
}
},
async created() {
// sessionStorage userId
// this.userid = sessionStorage.getItem('userId') || 'DEFAULT_USER';
await this.getToken();
},
mounted() {
mounted(){
window.addEventListener('message', this.receiveMessage, false);
},
beforeDestroy() { // Vue 2 使 beforeDestroy
destroyed() {
window.removeEventListener('message', this.receiveMessage, false);
},
methods: {
// token
// 退
// token
async getToken() {
try {
this.loading = true;
const response = await mockBaiducloudAPI();
const response = await baiducloudAPI();
this.userToken = response.data;
console.log('获取到模拟Token:', this.userToken);
let resultUrlLast = 'https://console.vcp.baidu.com/api/loginvcp/login/securitytoken?'
if (this.userToken) {
// 使 iframe URL
const baseUrl = 'https://example.com'; // URL
const redirectUrl = encodeURIComponent(`${baseUrl}/billing/#/refund/list`);
const token = encodeURIComponent(this.userToken);
// URL ()
this.url = `${baseUrl}/api/loginvcp/login/securitytoken?redirectUrl=${redirectUrl}&signinSecurityToken=${token}`;
console.log('构建的 iframe URL:', this.url);
// URL
resultUrlLast = resultUrlLast + '&redirectUrl=' + encodeURIComponent('https://console.vcp.baidu.com/billing/#/refund/list') + '&signinSecurityToken=' + encodeURIComponent(this.userToken)
this.url = resultUrlLast
} else {
console.error('未能从API响应中获取到token:', response);
this.url = ''; // url 便
}
} catch (error) {
console.error('获取Token失败:', error);
this.url = ''; // URL
console.error('获取百度云Token失败:', error);
} finally {
// loading = false
// iframe
// iframe load
// setTimeout
setTimeout(() => {
this.loading = false;
}, 1500); //
this.loading = false;
}
},
receiveMessage(event) {
// if (event.origin !== "https://example.com") {
// //
// return;
// }
// console.log("iframeevent", event);
receiveMessage(event) {
console.log('接收到消息:', event);
this.userid = sessionStorage.getItem('userId')
const data = event.data;
if (data && data.orderInfo && data.orderInfo.orderId) {
// orderId orderIdList
@ -87,63 +68,23 @@ export default {
order_id: orderId,
userid: this.userid
}
reqBaiduJudgePrice(ploay).then((res) => {
console.log("二级接口是", res)
if (res.status) {
// let lastPloay = {
// orderid: res.orderid,
// product_url: this.$route.params.listUrl ? this.$route.params.listUrl : localStorage.getItem('userRescourseUrl')
// }
this.$router.push({
name: 'userResource',
params: {
listUrl: this.$route.params.listUrl,
url: this.$route.params.url
}
})
this.$message.success('购买成功')
// reqBaiduOrderCost(lastPloay).then(res => {
// if (res.status) {
// this.loading = false
// this.$message.success('')
// this.$router.push({
// name: 'userResource',
// params: {
// listUrl: this.$route.params.listUrl,
// url: this.$route.params.url
// }
// })
// }
//
// })
} else {
this.loading = false
this.$message.error(res.msg)
}
})
// ID
const orderLog = data
}
},
cancelCallbackAPI(ploay).then((res) => {
console.log(res);
})
}
}
};
}
</script>
<style lang="less" scoped>
.box {
padding: 10px;
height: 100%;
border: 1px solid #ccc; //
}
.baidu-style {
width: 100%;
height: calc(100vh - 100px);
border: 2px dashed #007bff; // 线 iframe
}
</style>