49 lines
1.3 KiB
Vue
49 lines
1.3 KiB
Vue
<template>
|
|||
|
|
<BaseModal id="confirmModal" :title="title" ref="modal">
|
||
|
|
<template #body>
|
||
|
|
<p class="text-main">{{ message }}</p>
|
||
|
|
</template>
|
||
|
|
<template #footer>
|
||
|
|
<button v-if="showCancel" type="button" class="btn-action btn-action-secondary" @click="close">Cancel</button>
|
||
|
|
<button type="button" class="btn-action" :class="confirmBtnClass" @click="confirm">
|
||
|
|
{{ confirmText }}
|
||
|
|
</button>
|
||
|
|
</template>
|
||
|
|
</BaseModal>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<script setup>
|
||
|
|
import { ref } from 'vue';
|
||
|
|
import BaseModal from './BaseModal.vue';
|
||
|
|
|
||
|
|
const emit = defineEmits(['confirm']);
|
||
|
|
const modal = ref(null);
|
||
|
|
|
||
|
|
const title = ref('');
|
||
|
|
const message = ref('');
|
||
|
|
const confirmText = ref('Confirm');
|
||
|
|
const confirmBtnClass = ref('btn-action-danger');
|
||
|
|
const showCancel = ref(true);
|
||
|
|
const data = ref(null);
|
||
|
|
|
||
|
|
const open = (opts) => {
|
||
|
|
title.value = opts.title || 'Are you sure?';
|
||
|
|
message.value = opts.message || '';
|
||
|
|
confirmText.value = opts.confirmText || 'Confirm';
|
||
|
|
confirmBtnClass.value = opts.confirmBtnClass || 'btn-action-danger';
|
||
|
|
showCancel.value = opts.showCancel !== false;
|
||
|
|
data.value = opts.data || null;
|
||
|
|
modal.value.show();
|
||
|
|
};
|
||
|
|
|
||
|
|
const close = () => {
|
||
|
|
modal.value.hide();
|
||
|
|
};
|
||
|
|
|
||
|
|
const confirm = () => {
|
||
|
|
emit('confirm', data.value);
|
||
|
|
close();
|
||
|
|
};
|
||
|
|
|
||
|
|
defineExpose({ open, close });
|
||
|
|
</script>
|