123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <template>
- <div class="iframe-main">
- <div class="iframe-dom" :style="{height: height }" ></div>
- </div>
- </template>
- <script>
- export default {
- head(){
- return {
- link: [
- { rel: 'stylesheet', href: '//yun.baoxiaohe.com/openflatform/css/v1.0/sdk.css' },],
- }
- },
- props:{
- bxhType:String,
- design:Number,
- height:{
- type: String,
- default: '99vh',
- },
- link:String,
- templateArr:{
- type: Array,
- default: ()=>{
- return []
- },
- }
- },
- data() {
- return {
- iframe: null,
- }
- },
- watch:{
- },
- mounted() {
- this.$nextTick(()=>{
- this.createBxh()
- });
- window.addEventListener("message", this.receiveData)
- },
- beforeDestroy() {
- window.removeEventListener("message", this.receiveData)
- },
- methods: {
- async createBxh() {
- if(this.bxhType=='3D'){
- let companyToken = await this.$axios.get("/bxh/company/token")
- let design=this.design || this.link
- this.init(design,companyToken.result,this.bxhType)
- }else if(this.bxhType=='design'){
- let token = await this.$axios.get("/bxh/token")
- this.init(this.design,token.result,this.bxhType)
- }else if(this.bxhType=='render'){
- let token = await this.$axios.get("/bxh/token")
- this.init(this.design,token.result,this.bxhType)
- }
- },
- init(id,token,bxhType) {
- this.iframe = new window.BXHIframe({
- // production: false,
- // env:true,
- elCls:'iframe-dom',
- prefixCls:'detail-iframe-sdk',
- locale:"en-US",
- params: {
- id,
- token3D:token,
- token,
- project_id: id,
- isShowRotate:false, //右下角的旋转按钮
- isShowFold:false, //右下角的折叠按钮
- locale:"en-US"
- },
- name: bxhType,
- })
- },
-
- receiveData(event) {
- if (event) {
- try {
- if (typeof event.data === "string") {
- const { event: e, name, params,preDesignParams } = JSON.parse(
- event.data
- )
- if (e === "needLogin") {
- this.iframe.preDesign({...preDesignParams,token: ''})
- } else if (e === "viewDetails") {
- this.iframe.render({ name, params })
- }else if (e === "viewDetails") {
- this.iframe.render({ name, params })
- } else if (e === "startDesign") {
- this.iframe.render({ params: { id: params.id, token: '' }, name: "design" })
- } else if (e === "logoutSuccess") {
- console.log("logoutSuccess")
- } else if (e === "reloadParams") {
- console.log("reloadParams")
- } else if (e === "saveSuccess") {
- console.log("saveSuccess")
- } else if (e === "saveFail") {
- console.log("saveFail")
- } else if (e === "loadSuccess") {
- console.log("loadSuccess")
- } else if (e === "toPreview3d") {
- console.log("手机端编辑器进入3d页面回调")
- } else if (e === "toEditor") {
- console.log("手机端从3d页面进入编辑器回调")
- }
- }
- } catch (error) {
- console.log(error)
- }
- }
- },
- },
- }
- </script>
- <style scoped>
- /* .iframe-main {
- width: 100%;
- height: 100%;
- } */
- .iframe-dom {
- position: relative;
- }
- </style>
|