<template>
  <div ref="mod">
    <a-modal
      :get-container="() => $refs.mod"
      :open="props.open"
      :title="props.title"
      :mask-closable="false"
      :width="props.width"
      @cancel="cancel"
      :footer="null"
    >
      <div v-if="!props.title" class="header">
        <slot name="header"></slot>
      </div>
      <div class="body">
        <slot></slot>
      </div>
      <div class="footer">
        <slot name="footer"></slot>
      </div>
    </a-modal>
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: 'BaseModal',
})

type Props = {
  open: boolean
  title: string
  width?: string | number
}
const emit = defineEmits<{
  (e: 'update:open', value: boolean): void
  (e: 'cancel'): void
}>()

const props = withDefaults(defineProps<Props>(), {
  open: false,
  title: '',
  width: 520,
})

// 关闭弹窗
const cancel = () => {
  emit('update:open', false)
  emit('cancel')
}
</script>

<style scoped lang="less">
:deep(.ant-modal) {
  .body {
    min-height: 200px;
    margin: 12px 0;
  }
  .footer {
    text-align: right;
  }
}
</style>
