index.vue 2.81 KB
<template>
  <div class="report-home">
    <h2>
      报表子应用
      <span class="right">{{ gs }}</span>
    </h2>
    <div id="nav">
      <span>切换路由:</span>
      <el-button-group class="right">
        <el-button type="primary" size="medium" @click="routerChange('/')">报表</el-button>
        <el-button type="primary" size="medium" @click="routerChange('/about')">穿梭框</el-button>
        <el-button type="primary" size="medium" @click="toAppReport('1-1')">表格</el-button>
        <el-button type="primary" size="medium" @click="toAppReport('1-2')">日历</el-button>
        <el-button type="primary" size="medium" @click="toAppReport({ path: 'sub01/changeData' })">aaaa</el-button>
      </el-button-group>
    </div>
    <div class="parent-child-communication">
      <h3>父子应用通信:</h3>
      <div style="margin-bottom: 20px;">
        <span>rxjs通信方案:{{ myMsg }}</span>
        <el-button class="right" type="primary" size="medium" @click="callParentChange('rxjs')">通知父应用变天了</el-button>
      </div>
      <div>
        <span>官方通信方案:{{ myMessage }}</span>
        <el-button class="right" type="primary" size="medium" @click="callParentChange('default')">通知父应用收到</el-button>
      </div>
      <img src="../assets/logo.png" alt="" srcset="" />
    </div>
  </div>
</template>

<script>
export default {
  name: 'report-home',
  data() {
    return {
      myMsg: '',
      gs: '',
      myMessage: ''
    }
  },
  methods: {
    /**
     * 路由切换
     * url 路由地址
     */
    routerChange(url) {
      this.$router.push(url).catch(err => {
        
      })
    },
    /**
     * 外部路由跳转
     * this.$history.push(menu)
     * menu 支持:1.string 视为id (每一个路由都有一个唯一id)
     *          2.对象 {path:'sub1/home',id:'1-1-1'} 以id为准 跳转对应模块
     *          3.对象 {path:'sub1/home'} 以path为准 跳转对应模块
  
     * 以上三种情况都跳转到对应的模块
     */
    toAppReport(menu) {
      this.$history.push(menu)
    },
    /**
     * 通知父应用变天了
     * type 通信方案
     */
    callParentChange(type) {
      if (type === 'default') {
        this.myMessage = '子应用scrm-sub-blog收到'
        this.$messenger.send({
          route: {
            id: '3-1',
            url: '/test1.html'
          },
          message: {
            from: 'scrm-sub-blog',
            token: '倘若有你,西湖一路无雨'
          }
        })
        return
      }
      this.myMsg = '倘若有你,西湖一路无雨'
      this.$globalState.dispatch({
        from: 'scrm-sub-blog',
        message: this.myMsg,
        time: new Date()
      })
    }
  }
}
</script>

<style lang="scss">
.parent-child-communication {
  padding: 20px 0;
  line-height: 36px;
}
</style>