<template>
  <!-- <c-list-page ref="cTableRef" :option="option" :params="{ platformType }">
    <template #top>
      <c-radio
        v-model="platformType"
        @change="handleChange"
        :option="{ dicData: platformTypeDic }"
      ></c-radio>
    </template>

    <template #parentId="{ form }">
      <a-tag>{{ form.parentId ? form.parentName : '根节点' }}</a-tag>
    </template>
  </c-list-page> -->
  <c-list-form :option="option" :params="{ platformType }">
    <template #top>
      <c-radio v-model="platformType" :option="{ dicData: platformTypeDic }"></c-radio>
      <c-button type="primary" class="ml-4" @click="handleExport">导出 menu.json</c-button>
    </template></c-list-form
  >
  <!-- <c-table ref="cTableRef" :option="option" :params="{ platformType }" :before="handleBefore">
    <template #top>
      <c-radio
        v-model="platformType"
        @change="handleChange"
        :option="{ dicData: platformTypeDic }"
      ></c-radio>
    </template>
    <template #menuLeft="{ record }">
      <a-button
        type="text"
        @click="toAdd(record)"
        v-if="userStore.permissions['sys_menu_add'] && record.menuType === 'menu'"
        >新增</a-button
      >
    </template>
  </c-table> -->
</template>
<script setup lang="ts">
import { ref } from 'vue'
import platformTypeDic from '@/enums/platform_type'
import useOption from './use-option'
import axios from '@/utils/axios'

const platformType = ref('sys')
const { option } = useOption(platformType)
const handleExport = (done: Function) => {
  axios
    .post('/sys/menu/export', undefined, {
      responseType: 'blob',
      headers: {
        'data-type': 'Buffer'
      }
    })
    .then((res) => {
      let filename = 'menu.json'
      if (res.headers && res.headers['content-disposition']) {
        filename = (res.headers['content-disposition'] as string).replace(
          'attachment;filename=',
          ''
        )
      }
      const url = window.URL.createObjectURL(new Blob([res.data]))
      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = url
      link.setAttribute('download', filename) // 指定下载后的文件名，防跳转
      document.body.appendChild(link)
      link.click()
    })
    .finally(() => {
      done()
    })
}
</script>
<style scoped lang="scss"></style>
