<template>
  <div>
    <Modal v-model:open="data.isShowModal" title="确认提示" width="30%" @cancel="_close" @ok="handleConfirm">
      <div>
        <h4>{{ data.title }}</h4>
      </div>
      <div v-if="data.confirmText" style="margin-top: 10px">
        <div>
          <span>请输入红色字体内容进行确认：</span>
          <span style="font-size: 12px;color: red">{{ data.confirmText }}</span>
        </div>
        <div style="margin-top: 20px">
          <Input v-model:value="data.inputText" allowClear :placeholder="data.confirmText"/>
        </div>
      </div>
    </Modal>
  </div>
</template>

<script setup lang="ts">

import {reactive} from "vue";
import {Modal, Input} from 'ant-design-vue';


const data = reactive({
  isShowModal: false,
  inputText: '',
  title: '确认提示',
  confirmText: null,
  resolve: null,
  reject: null,
})

function handleConfirm() {
  //值判断
  if (data.confirmText && data.confirmText != data.inputText) {
    return;
  }
  //回调
  data.resolve ? data.resolve() : '';
  _close();
}

function _open(title, confirmText) {
  data.title = title || data.title;
  data.confirmText = confirmText;
  data.isShowModal = true;
  return new Promise((resolve, reject) => {
    data.resolve = resolve;
    data.reject = reject;
  });
}

function _close() {
  data.inputText = '';
  data.isShowModal = false;
  data.reject ? data.reject() : '';
}

defineExpose({_open, _close});
</script>

<style scoped>

</style>
