<template>
  <section class="AppAiCode">
    <component :is="currentPage" v-bind="$props"/>
  </section>
</template>

<script>
import AcList from "./acList";
import AcAdd from "./acAdd";

export default {
  name: "AppAiCode",
  components: {AcAdd, AcList},
  label: "低代码生成平台",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  computed: {
    currentPage() {
      let {hash} = this.$route
      return hash == "#add" ? AcAdd : AcList
    }
  },
  provide() {
    return {
      top: this
    }
  },
  methods: {
    handleGetCode(id) {
      id && this.instance.post("/node/aicode/getCode", null, {
        params: {id},
        responseType: "blob"
      }).then(res => {
        if (res?.code == 1) {
          this.$message.error(res.err)
        } else {
          const link = document.createElement('a')
          let blob = new Blob([res], {type: 'application/zip'})
          link.style.display = 'none'
          link.href = URL.createObjectURL(blob)
          link.setAttribute('download', 'aicode.zip')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link)
        }
      })
    }
  },
  created() {
    this.dict.load("detailType")
  }
}
</script>

<style lang="scss" scoped>
.AppAiCode {
  height: 100%;

  & > section {
    height: 100%;
  }
}
</style>
