<template>
  <section class="mainEntry">
    <component ref="CurrentEntry" v-if="!!app" :is="app"/>
    <div v-else>
      <ai-result tips="应用建设中.." status="error" btn="返回主页" :btn-tap="back"/>
    </div>
  </section>
</template>

<script>
import AiResult from "../components/AiResult";

export default {
  name: "mainEntry",
  components: {AiResult},
  inject: {root: {}},
  data() {
    return {
      app: ""
    }
  },
  methods: {
    back() {
      // uni.reLaunch({url:""})
      this.root.goto({path: "/pages/loading"})
    }
  },
  onLoad(params) {
    this.app = params.app || ""
    sessionStorage.setItem("currentApp", params.app)
  },
  onShow() {
    this.app = this.$route.query.app || ""
    if (!this.app && sessionStorage.getItem("currentApp")) {
      this.$router.push({query: {app: sessionStorage.getItem("currentApp")}})
      location.reload()
    }
    this.$nextTick(() => {
      this.$refs.CurrentEntry?.emitShow?.()
    })
  },
  onReachBottom() {
    this.$refs.CurrentEntry?.emitReachBottom?.()
  }
}
</script>

<style lang="scss" scoped>
.mainEntry {
  min-height: 100vh;
  background: #f5f5f5;
}
</style>
